committed by
GitHub
114 changed files with 144646 additions and 33227 deletions
@ -0,0 +1,24 @@ |
|||||
|
import { Table, Column, Model } from 'sequelize-typescript'; |
||||
|
|
||||
|
@Table({tableName: 'sphinx_chat_members', underscored: true}) |
||||
|
export default class ChatMember extends Model<ChatMember> { |
||||
|
|
||||
|
@Column |
||||
|
chatId: number |
||||
|
|
||||
|
@Column |
||||
|
contactId: number |
||||
|
|
||||
|
@Column |
||||
|
role: number |
||||
|
|
||||
|
@Column |
||||
|
totalSpent: number |
||||
|
|
||||
|
@Column |
||||
|
totalMessages: number |
||||
|
|
||||
|
@Column |
||||
|
lastActive: Date |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
import {sendMessage,signAndSend} from './send' |
||||
|
import {initGrpcSubscriptions,initTribesSubscriptions,parseKeysendInvoice} from './receive' |
||||
|
|
||||
|
/* |
||||
|
Abstracts between lightning network and MQTT depending on Chat type and sender |
||||
|
*/ |
||||
|
|
||||
|
export { |
||||
|
sendMessage,signAndSend, |
||||
|
initGrpcSubscriptions, |
||||
|
initTribesSubscriptions, |
||||
|
parseKeysendInvoice, |
||||
|
} |
||||
|
|
@ -0,0 +1,88 @@ |
|||||
|
import * as path from 'path' |
||||
|
import RNCryptor from '../utils/rncryptor' |
||||
|
import * as fetch from 'node-fetch' |
||||
|
import {parseLDAT} from '../utils/ldat' |
||||
|
import * as rsa from '../crypto/rsa' |
||||
|
import * as crypto from 'crypto' |
||||
|
import * as meme from '../utils/meme' |
||||
|
import * as FormData from 'form-data' |
||||
|
|
||||
|
const constants = require(path.join(__dirname,'../../config/constants.json')) |
||||
|
const msgtypes = constants.message_types |
||||
|
|
||||
|
export async function modifyPayload(payload, chat) { |
||||
|
if(payload.type===msgtypes.attachment) { |
||||
|
|
||||
|
const mt = payload.message && payload.message.mediaToken |
||||
|
const key = payload.message && payload.message.mediaKey |
||||
|
const typ = payload.message && payload.message.mediaType |
||||
|
if(!mt || !key) return payload |
||||
|
|
||||
|
const terms = parseLDAT(mt) |
||||
|
if(!terms.host) return payload |
||||
|
|
||||
|
try { |
||||
|
const r = await fetch(`https://${terms.host}/file/${mt}`, { |
||||
|
headers: {'Authorization': `Bearer ${meme.mediaToken}`} |
||||
|
}) |
||||
|
const buf = await r.buffer() |
||||
|
|
||||
|
const decMediaKey = rsa.decrypt(chat.groupPrivateKey, key) |
||||
|
|
||||
|
const imgBase64 = RNCryptor.Decrypt(decMediaKey, buf.toString('base64')) |
||||
|
|
||||
|
const newKey = crypto.randomBytes(20).toString('hex') |
||||
|
|
||||
|
const encImg = RNCryptor.Encrypt(newKey, imgBase64) |
||||
|
|
||||
|
var encImgBuffer = Buffer.from(encImg,'base64'); |
||||
|
|
||||
|
const form = new FormData() |
||||
|
form.append('file', encImgBuffer, { |
||||
|
contentType: typ||'image/jpg', |
||||
|
filename: 'Image.jpg', |
||||
|
knownLength:encImgBuffer.length, |
||||
|
}) |
||||
|
const formHeaders = form.getHeaders() |
||||
|
const resp = await fetch(`https://${terms.host}/file`, { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
...formHeaders, // THIS IS REQUIRED!!!
|
||||
|
'Authorization': `Bearer ${meme.mediaToken}`, |
||||
|
}, |
||||
|
body:form |
||||
|
}) |
||||
|
|
||||
|
let json = await resp.json() |
||||
|
if(!json.muid) return payload |
||||
|
|
||||
|
// PUT NEW TERMS, to finish in personalizeMessage
|
||||
|
const amt = terms.meta&&terms.meta.amt |
||||
|
const ttl = terms.meta&&terms.meta.ttl |
||||
|
const mediaTerms: {[k:string]:any} = { |
||||
|
muid:json.muid, ttl:ttl||31536000, |
||||
|
meta:{...amt && {amt}}, |
||||
|
skipSigning: amt ? true : false // only sign if its free
|
||||
|
} |
||||
|
|
||||
|
const encKey = rsa.encrypt(chat.groupKey, newKey) |
||||
|
|
||||
|
return fillmsg(payload, {mediaTerms,mediaKey:encKey}) // key is re-encrypted later
|
||||
|
} catch(e) { |
||||
|
console.log("[modify] error", e) |
||||
|
return payload |
||||
|
} |
||||
|
// how to link w og msg? ogMediaToken?
|
||||
|
} else { |
||||
|
return payload |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function fillmsg(full, props){ |
||||
|
return { |
||||
|
...full, message: { |
||||
|
...full.message, |
||||
|
...props, |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,209 @@ |
|||||
|
import * as path from 'path' |
||||
|
import * as lndService from '../grpc' |
||||
|
import {getInfo} from '../utils/lightning' |
||||
|
import {controllers} from '../controllers' |
||||
|
import * as tribes from '../utils/tribes' |
||||
|
import {SPHINX_CUSTOM_RECORD_KEY, verifyAscii} from '../utils/lightning' |
||||
|
import { models } from '../models' |
||||
|
import {sendMessage} from './send' |
||||
|
import {modifyPayload} from './modify' |
||||
|
import {decryptMessage,encryptTribeBroadcast} from '../utils/msg' |
||||
|
|
||||
|
const constants = require(path.join(__dirname,'../../config/constants.json')) |
||||
|
const msgtypes = constants.message_types |
||||
|
|
||||
|
const typesToForward=[ |
||||
|
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment |
||||
|
] |
||||
|
const typesToModify=[ |
||||
|
msgtypes.attachment |
||||
|
] |
||||
|
const typesThatNeedPricePerMessage = [ |
||||
|
msgtypes.message, msgtypes.attachment |
||||
|
] |
||||
|
async function onReceive(payload){ |
||||
|
console.log("=>>> onReceive",payload) |
||||
|
// if tribe, owner must forward to MQTT
|
||||
|
let doAction = true |
||||
|
const toAddIn:{[k:string]:any} = {} |
||||
|
const isTribe = payload.chat && payload.chat.type===constants.chat_types.tribe |
||||
|
if(isTribe && typesToForward.includes(payload.type)){ |
||||
|
const needsPricePerJoin = typesThatNeedPricePerMessage.includes(payload.type) |
||||
|
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}}) |
||||
|
const tribeOwnerPubKey = chat && chat.ownerPubkey |
||||
|
const owner = await models.Contact.findOne({where: {isOwner:true}}) |
||||
|
if(owner.publicKey===tribeOwnerPubKey){ |
||||
|
toAddIn.isTribeOwner = true |
||||
|
// CHECK THEY ARE IN THE GROUP if message
|
||||
|
if(needsPricePerJoin) { |
||||
|
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}}) |
||||
|
const senderMember = senderContact && await models.ChatMember.findOne({where:{contactId:senderContact.id, chatId:chat.id}}) |
||||
|
if(!senderMember) doAction=false |
||||
|
} |
||||
|
// CHECK PRICES
|
||||
|
if(needsPricePerJoin) { |
||||
|
if(payload.message.amount<chat.pricePerMessage) doAction=false |
||||
|
} |
||||
|
// check price to join
|
||||
|
if(payload.type===msgtypes.group_join) { |
||||
|
if(payload.message.amount<chat.priceToJoin) doAction=false |
||||
|
} |
||||
|
if(doAction) forwardMessageToTribe(payload) |
||||
|
else console.log('=> insufficient payment for this action') |
||||
|
} |
||||
|
} |
||||
|
if(doAction) doTheAction({...payload, ...toAddIn}) |
||||
|
} |
||||
|
|
||||
|
async function doTheAction(data){ |
||||
|
let payload = data |
||||
|
if(payload.isTribeOwner) { |
||||
|
// decrypt and re-encrypt with self pubkey
|
||||
|
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}}) |
||||
|
const pld = await decryptMessage(data, chat) |
||||
|
const me = await models.Contact.findOne({where:{isOwner:true}}) |
||||
|
payload = await encryptTribeBroadcast(pld, me, true) // true=isTribeOwner
|
||||
|
} |
||||
|
if(ACTIONS[payload.type]) { |
||||
|
ACTIONS[payload.type](payload) |
||||
|
} else { |
||||
|
console.log('Incorrect payload type:', payload.type) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function forwardMessageToTribe(ogpayload){ |
||||
|
const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}}) |
||||
|
|
||||
|
let payload |
||||
|
if(typesToModify.includes(ogpayload.type)){ |
||||
|
payload = await modifyPayload(ogpayload, chat) |
||||
|
} else { |
||||
|
payload = ogpayload |
||||
|
} |
||||
|
//console.log("FORWARD TO TRIBE",payload) // filter out the sender?
|
||||
|
|
||||
|
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
|
||||
|
const owner = await models.Contact.findOne({where:{isOwner:true}}) |
||||
|
const type = payload.type |
||||
|
const message = payload.message |
||||
|
// HERE: NEED TO MAKE SURE ALIAS IS UNIQUE
|
||||
|
// ASK xref TABLE and put alias there too?
|
||||
|
sendMessage({ |
||||
|
sender: { |
||||
|
...owner.dataValues, |
||||
|
...payload.sender&&payload.sender.alias && {alias:payload.sender.alias} |
||||
|
}, |
||||
|
chat, type, message, |
||||
|
skipPubKey: payload.sender.pub_key, |
||||
|
success: ()=>{}, |
||||
|
receive: ()=>{} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
const ACTIONS = { |
||||
|
[msgtypes.contact_key]: controllers.contacts.receiveContactKey, |
||||
|
[msgtypes.contact_key_confirmation]: controllers.contacts.receiveConfirmContactKey, |
||||
|
[msgtypes.message]: controllers.messages.receiveMessage, |
||||
|
[msgtypes.invoice]: controllers.invoices.receiveInvoice, |
||||
|
[msgtypes.direct_payment]: controllers.payments.receivePayment, |
||||
|
[msgtypes.confirmation]: controllers.confirmations.receiveConfirmation, |
||||
|
[msgtypes.attachment]: controllers.media.receiveAttachment, |
||||
|
[msgtypes.purchase]: controllers.media.receivePurchase, |
||||
|
[msgtypes.purchase_accept]: controllers.media.receivePurchaseAccept, |
||||
|
[msgtypes.purchase_deny]: controllers.media.receivePurchaseDeny, |
||||
|
[msgtypes.group_create]: controllers.chats.receiveGroupCreateOrInvite, |
||||
|
[msgtypes.group_invite]: controllers.chats.receiveGroupCreateOrInvite, |
||||
|
[msgtypes.group_join]: controllers.chats.receiveGroupJoin, |
||||
|
[msgtypes.group_leave]: controllers.chats.receiveGroupLeave, |
||||
|
} |
||||
|
|
||||
|
export async function initGrpcSubscriptions() { |
||||
|
try{ |
||||
|
await getInfo() |
||||
|
await lndService.subscribeInvoices(parseKeysendInvoice) |
||||
|
} catch(e) { |
||||
|
throw e |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function initTribesSubscriptions(){ |
||||
|
tribes.connect(async(topic, message)=>{ // onMessage callback
|
||||
|
try{ |
||||
|
const msg = message.toString() |
||||
|
console.log("=====> msg received! TOPIC", topic, "MESSAGE", msg) |
||||
|
// check topic is signed by sender?
|
||||
|
const payload = await parseAndVerifyPayload(msg) |
||||
|
onReceive(payload) |
||||
|
} catch(e){} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// VERIFY PUBKEY OF SENDER from sig
|
||||
|
async function parseAndVerifyPayload(data){ |
||||
|
let payload |
||||
|
const li = data.lastIndexOf('}') |
||||
|
const msg = data.substring(0,li+1) |
||||
|
const sig = data.substring(li+1) |
||||
|
try { |
||||
|
payload = JSON.parse(msg) |
||||
|
if(payload) { |
||||
|
const v = await verifyAscii(msg, sig) |
||||
|
if(v && v.valid && v.pubkey) { |
||||
|
payload.sender = payload.sender||{} |
||||
|
payload.sender.pub_key=v.pubkey |
||||
|
return payload |
||||
|
} else { |
||||
|
return payload // => RM THIS
|
||||
|
} |
||||
|
} |
||||
|
} catch(e) { |
||||
|
if(payload) return payload // => RM THIS
|
||||
|
return null |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function parseKeysendInvoice(i){ |
||||
|
const recs = i.htlcs && i.htlcs[0] && i.htlcs[0].custom_records |
||||
|
const buf = recs && recs[SPHINX_CUSTOM_RECORD_KEY] |
||||
|
const data = buf && buf.toString() |
||||
|
const value = i && i.value && parseInt(i.value) |
||||
|
if(!data) return |
||||
|
|
||||
|
let payload |
||||
|
if(data[0]==='{'){ |
||||
|
try { |
||||
|
payload = await parseAndVerifyPayload(data) |
||||
|
} catch(e){} |
||||
|
} else { |
||||
|
const threads = weave(data) |
||||
|
if(threads) payload = await parseAndVerifyPayload(threads) |
||||
|
} |
||||
|
if(payload){ |
||||
|
const dat = payload |
||||
|
if(value && dat && dat.message){ |
||||
|
dat.message.amount = value // ADD IN TRUE VALUE
|
||||
|
} |
||||
|
onReceive(dat) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const chunks = {} |
||||
|
function weave(p){ |
||||
|
const pa = p.split('_') |
||||
|
if(pa.length<4) return |
||||
|
const ts = pa[0] |
||||
|
const i = pa[1] |
||||
|
const n = pa[2] |
||||
|
const m = pa.filter((u,i)=>i>2).join('_') |
||||
|
chunks[ts] = chunks[ts] ? [...chunks[ts], {i,n,m}] : [{i,n,m}] |
||||
|
if(chunks[ts].length===parseInt(n)){ |
||||
|
// got em all!
|
||||
|
const all = chunks[ts] |
||||
|
let payload = '' |
||||
|
all.slice().sort((a,b)=>a.i-b.i).forEach(obj=>{ |
||||
|
payload += obj.m |
||||
|
}) |
||||
|
delete chunks[ts] |
||||
|
return payload |
||||
|
} |
||||
|
} |
@ -0,0 +1,153 @@ |
|||||
|
import { models } from '../models' |
||||
|
import * as LND from '../utils/lightning' |
||||
|
import {personalizeMessage, decryptMessage} from '../utils/msg' |
||||
|
import * as path from 'path' |
||||
|
import * as tribes from '../utils/tribes' |
||||
|
|
||||
|
const constants = require(path.join(__dirname,'../../config/constants.json')) |
||||
|
|
||||
|
type NetworkType = undefined | 'mqtt' | 'lightning' |
||||
|
|
||||
|
export async function sendMessage(params) { |
||||
|
const { type, chat, message, sender, amount, success, failure, skipPubKey } = params |
||||
|
const m = newmsg(type, chat, sender, message) |
||||
|
let msg = m |
||||
|
|
||||
|
// console.log(type,message)
|
||||
|
if(!(sender&&sender.publicKey)) { |
||||
|
console.log("NO SENDER?????") |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
let contactIds = (typeof chat.contactIds==='string' ? JSON.parse(chat.contactIds) : chat.contactIds) || [] |
||||
|
if(contactIds.length===1) { |
||||
|
if (contactIds[0]===1) { |
||||
|
if(success) success(true) |
||||
|
return // if no contacts thats fine (like create public tribe)
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
let networkType:NetworkType = undefined |
||||
|
const isTribe = chat.type===constants.chat_types.tribe |
||||
|
let isTribeOwner = false |
||||
|
const chatUUID = chat.uuid |
||||
|
if(isTribe) { |
||||
|
if(type===constants.message_types.confirmation) { |
||||
|
return // dont send confs for tribe
|
||||
|
} |
||||
|
console.log("is tribe!") |
||||
|
const tribeOwnerPubKey = chat.ownerPubkey |
||||
|
if(sender.publicKey===tribeOwnerPubKey){ |
||||
|
console.log('im owner! mqtt!') |
||||
|
isTribeOwner = true |
||||
|
networkType = 'mqtt' // broadcast to all
|
||||
|
// decrypt message.content and message.mediaKey w groupKey
|
||||
|
msg = await decryptMessage(msg, chat) |
||||
|
} else { |
||||
|
// if tribe, send to owner only
|
||||
|
const tribeOwner = await models.Contact.findOne({where: {publicKey:tribeOwnerPubKey}}) |
||||
|
contactIds = tribeOwner ? [tribeOwner.id] : [] |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
let yes:any = null |
||||
|
let no:any = null |
||||
|
console.log('all contactIds',contactIds) |
||||
|
await asyncForEach(contactIds, async contactId => { |
||||
|
if (contactId == 1) { // dont send to self
|
||||
|
return |
||||
|
} |
||||
|
|
||||
|
const contact = await models.Contact.findOne({ where: { id: contactId } }) |
||||
|
const destkey = contact.publicKey |
||||
|
if(destkey===skipPubKey) { |
||||
|
return // skip (for tribe owner broadcasting, not back to the sender)
|
||||
|
} |
||||
|
console.log('-> sending to ', contact.id, destkey) |
||||
|
|
||||
|
const m = await personalizeMessage(msg, contact, isTribeOwner) |
||||
|
const opts = { |
||||
|
dest: destkey, |
||||
|
data: m, |
||||
|
amt: Math.max((amount||0), 3) |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
const mqttTopic = networkType==='mqtt' ? `${destkey}/${chatUUID}` : '' |
||||
|
const r = await signAndSend(opts, sender.publicKey, mqttTopic) |
||||
|
yes = r |
||||
|
} catch (e) { |
||||
|
console.log("KEYSEND ERROR", e) |
||||
|
no = e |
||||
|
} |
||||
|
await sleep(2) |
||||
|
}) |
||||
|
if(yes){ |
||||
|
if(success) success(yes) |
||||
|
} else { |
||||
|
if(failure) failure(no) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function signAndSend(opts, pubkey, mqttTopic?:string){ |
||||
|
// console.log('sign and send!!!!',opts.data)
|
||||
|
return new Promise(async function(resolve, reject) { |
||||
|
if(!opts.data || typeof opts.data!=='object') { |
||||
|
return reject('object plz') |
||||
|
} |
||||
|
let data = JSON.stringify(opts.data) |
||||
|
|
||||
|
const sig = await LND.signAscii(data) |
||||
|
data = data + sig |
||||
|
|
||||
|
// console.log("ACTUALLY SEND", mqttTopic)
|
||||
|
try { |
||||
|
if(mqttTopic) { |
||||
|
await tribes.publish(mqttTopic, data) |
||||
|
} else { |
||||
|
await LND.keysendMessage({...opts,data}) |
||||
|
} |
||||
|
resolve(true) |
||||
|
} catch(e) { |
||||
|
reject(e) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
function newmsg(type, chat, sender, message){ |
||||
|
const includeGroupKey = type===constants.message_types.group_create || type===constants.message_types.group_invite |
||||
|
const includeAlias = sender && sender.alias && chat.type===constants.chat_types.tribe |
||||
|
return { |
||||
|
type: type, |
||||
|
chat: { |
||||
|
uuid: chat.uuid, |
||||
|
...chat.name && { name: chat.name }, |
||||
|
...(chat.type||chat.type===0) && { type: chat.type }, |
||||
|
...chat.members && { members: chat.members }, |
||||
|
...(includeGroupKey&&chat.groupKey) && { groupKey: chat.groupKey }, |
||||
|
...(includeGroupKey&&chat.host) && { host: chat.host } |
||||
|
}, |
||||
|
message: message, |
||||
|
sender: { |
||||
|
...includeAlias && {alias: sender.alias}, |
||||
|
pub_key: sender.publicKey, |
||||
|
// ...sender.contactKey && {contact_key: sender.contactKey}
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function asyncForEach(array, callback) { |
||||
|
for (let index = 0; index < array.length; index++) { |
||||
|
await callback(array[index], index, array); |
||||
|
} |
||||
|
} |
||||
|
async function sleep(ms) { |
||||
|
return new Promise(resolve => setTimeout(resolve, ms)) |
||||
|
} |
||||
|
|
||||
|
// function urlBase64FromHex(ascii){
|
||||
|
// return Buffer.from(ascii,'hex').toString('base64').replace(/\//g, '_').replace(/\+/g, '-')
|
||||
|
// }
|
||||
|
// function urlBase64FromBytes(buf){
|
||||
|
// return Buffer.from(buf).toString('base64').replace(/\//g, '_').replace(/\+/g, '-')
|
||||
|
// }
|
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
let mediaToken = '' |
||||
|
|
||||
|
function setMediaToken(mt) { |
||||
|
mediaToken = mt |
||||
|
} |
||||
|
|
||||
|
export {mediaToken, setMediaToken} |
@ -0,0 +1,5 @@ |
|||||
|
|
||||
|
|
||||
|
import * as RNCryptor from './rncryptor' |
||||
|
|
||||
|
export default RNCryptor |
@ -0,0 +1,104 @@ |
|||||
|
var sjcl = require('./sjcl') |
||||
|
|
||||
|
var RNCryptor = {}; |
||||
|
|
||||
|
/* |
||||
|
Takes password string and salt WordArray |
||||
|
Returns key bitArray |
||||
|
*/ |
||||
|
|
||||
|
RNCryptor.KeyForPassword = function(password, salt) { |
||||
|
var hmacSHA1 = function (key) { |
||||
|
var hasher = new sjcl.misc.hmac(key, sjcl.hash.sha1); |
||||
|
this.encrypt = function () { |
||||
|
return hasher.encrypt.apply(hasher, arguments); |
||||
|
}; |
||||
|
}; |
||||
|
return sjcl.misc.pbkdf2(password, salt, 10000, 32 * 8, hmacSHA1); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
Takes password string and plaintext base64 |
||||
|
options: |
||||
|
iv |
||||
|
encryption_salt |
||||
|
html_salt |
||||
|
Returns ciphertext base64 |
||||
|
*/ |
||||
|
RNCryptor.Encrypt = function(password, plaintextBase64, options) { |
||||
|
var plaintext = sjcl.codec.base64.toBits(plaintextBase64); |
||||
|
|
||||
|
options = options || {} |
||||
|
var encryption_salt = options["encryption_salt"] || sjcl.random.randomWords(8 / 4); // FIXME: Need to seed PRNG
|
||||
|
var encryption_key = RNCryptor.KeyForPassword(password, encryption_salt); |
||||
|
|
||||
|
var hmac_salt = options["hmac_salt"] || sjcl.random.randomWords(8 / 4); |
||||
|
var hmac_key = RNCryptor.KeyForPassword(password, hmac_salt); |
||||
|
|
||||
|
var iv = options["iv"] || sjcl.random.randomWords(16 / 4); |
||||
|
|
||||
|
var version = sjcl.codec.hex.toBits("03"); |
||||
|
var options = sjcl.codec.hex.toBits("01"); |
||||
|
|
||||
|
var message = sjcl.bitArray.concat(version, options); |
||||
|
message = sjcl.bitArray.concat(message, encryption_salt); |
||||
|
message = sjcl.bitArray.concat(message, hmac_salt); |
||||
|
message = sjcl.bitArray.concat(message, iv); |
||||
|
|
||||
|
var aes = new sjcl.cipher.aes(encryption_key); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."](); |
||||
|
var encrypted = sjcl.mode.cbc.encrypt(aes, plaintext, iv); |
||||
|
|
||||
|
message = sjcl.bitArray.concat(message, encrypted); |
||||
|
|
||||
|
var hmac = new sjcl.misc.hmac(hmac_key).encrypt(message); |
||||
|
message = sjcl.bitArray.concat(message, hmac); |
||||
|
|
||||
|
return sjcl.codec.base64.fromBits(message); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
Takes password string and message (ciphertext) base64 |
||||
|
options: |
||||
|
iv |
||||
|
encryption_salt |
||||
|
html_salt |
||||
|
Returns plaintext base64 |
||||
|
*/ |
||||
|
RNCryptor.Decrypt = function(password, messageBase64, options) { |
||||
|
var message = sjcl.codec.base64.toBits(messageBase64); |
||||
|
|
||||
|
options = options || {} |
||||
|
|
||||
|
var version = sjcl.bitArray.extract(message, 0 * 8, 8); |
||||
|
var options = sjcl.bitArray.extract(message, 1 * 8, 8); |
||||
|
|
||||
|
var encryption_salt = sjcl.bitArray.bitSlice(message, 2 * 8, 10 * 8); |
||||
|
var encryption_key = RNCryptor.KeyForPassword(password, encryption_salt); |
||||
|
|
||||
|
var hmac_salt = sjcl.bitArray.bitSlice(message, 10 * 8, 18 * 8); |
||||
|
var hmac_key = RNCryptor.KeyForPassword(password, hmac_salt); |
||||
|
|
||||
|
var iv = sjcl.bitArray.bitSlice(message, 18 * 8, 34 * 8); |
||||
|
|
||||
|
var ciphertext_end = sjcl.bitArray.bitLength(message) - (32 * 8); |
||||
|
|
||||
|
var ciphertext = sjcl.bitArray.bitSlice(message, 34 * 8, ciphertext_end); |
||||
|
|
||||
|
var hmac = sjcl.bitArray.bitSlice(message, ciphertext_end); |
||||
|
|
||||
|
var expected_hmac = new sjcl.misc.hmac(hmac_key).encrypt(sjcl.bitArray.bitSlice(message, 0, ciphertext_end)); |
||||
|
|
||||
|
// .equal is of consistent time
|
||||
|
if (! sjcl.bitArray.equal(hmac, expected_hmac)) { |
||||
|
throw new sjcl.exception.corrupt("HMAC mismatch or bad password."); |
||||
|
} |
||||
|
|
||||
|
var aes = new sjcl.cipher.aes(encryption_key); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."](); |
||||
|
var decrypted = sjcl.mode.cbc.decrypt(aes, ciphertext, iv); |
||||
|
|
||||
|
return sjcl.codec.base64.fromBits(decrypted); |
||||
|
} |
||||
|
|
||||
|
module.exports = RNCryptor |
@ -0,0 +1,55 @@ |
|||||
|
"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}}; |
||||
|
sjcl.cipher.aes=function(a){this.u[0][0][0]||this.N();var b,c,d,e,f=this.u[0][4],g=this.u[1];b=a.length;var h=1;if(4!==b&&6!==b&&8!==b)throw new sjcl.exception.invalid("invalid aes key size");this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=f[c>>>24]<<24^f[c>>16&255]<<16^f[c>>8&255]<<8^f[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:g[0][f[c>>>24]]^g[1][f[c>>16&255]]^g[2][f[c>>8&255]]^g[3][f[c& |
||||
|
255]]}; |
||||
|
sjcl.cipher.aes.prototype={encrypt:function(a){return r(this,a,0)},decrypt:function(a){return r(this,a,1)},u:[[[],[],[],[],[]],[[],[],[],[],[]]],N:function(){var a=this.u[0],b=this.u[1],c=a[4],d=b[4],e,f,g,h=[],k=[],n,l,m,p;for(e=0;0x100>e;e++)k[(h[e]=e<<1^283*(e>>7))^e]=e;for(f=g=0;!c[f];f^=n||1,g=k[g]||1)for(m=g^g<<1^g<<2^g<<3^g<<4,m=m>>8^m&255^99,c[f]=m,d[m]=f,l=h[e=h[n=h[f]]],p=0x1010101*l^0x10001*e^0x101*n^0x1010100*f,l=0x101*h[m]^0x1010100*m,e=0;4>e;e++)a[e][f]=l=l<<24^l>>>8,b[e][m]=p=p<<24^p>>>8;for(e= |
||||
|
0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}}; |
||||
|
function r(a,b,c){if(4!==b.length)throw new sjcl.exception.invalid("invalid aes block size");var d=a.b[c],e=b[0]^d[0],f=b[c?3:1]^d[1],g=b[2]^d[2];b=b[c?1:3]^d[3];var h,k,n,l=d.length/4-2,m,p=4,q=[0,0,0,0];h=a.u[c];a=h[0];var u=h[1],v=h[2],w=h[3],x=h[4];for(m=0;m<l;m++)h=a[e>>>24]^u[f>>16&255]^v[g>>8&255]^w[b&255]^d[p],k=a[f>>>24]^u[g>>16&255]^v[b>>8&255]^w[e&255]^d[p+1],n=a[g>>>24]^u[b>>16&255]^v[e>>8&255]^w[f&255]^d[p+2],b=a[b>>>24]^u[e>>16&255]^v[f>>8&255]^w[g&255]^d[p+3],p+=4,e=h,f=k,g=n;for(m= |
||||
|
0;4>m;m++)q[c?3&-m:m]=x[e>>>24]<<24^x[f>>16&255]<<16^x[g>>8&255]<<8^x[b&255]^d[p++],h=e,e=f,f=g,g=b,b=h;return q} |
||||
|
sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.Y(a.slice(b/32),32-(b&31)).slice(1);return void 0===c?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(0===a.length||0===b.length)return a.concat(b);var c=a[a.length-1],d=sjcl.bitArray.getPartial(c);return 32===d?a.concat(b):sjcl.bitArray.Y(b,d,c|0,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;return 0=== |
||||
|
b?0:32*(b-1)+sjcl.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(32*a.length<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;b=b&31;0<c&&b&&(a[c-1]=sjcl.bitArray.partial(b,a[c-1]&2147483648>>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return!1;var c=0,d;for(d=0;d<a.length;d++)c|=a[d]^b[d];return 0=== |
||||
|
c},Y:function(a,b,c,d){var e;e=0;for(void 0===d&&(d=[]);32<=b;b-=32)d.push(c),c=0;if(0===b)return d.concat(a);for(e=0;e<a.length;e++)d.push(c|a[e]>>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32<b+a?c:d.pop(),1));return d},B:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]},byteswapM:function(a){var b,c;for(b=0;b<a.length;++b)c=a[b],a[b]=c>>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}}; |
||||
|
sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d<c/8;d++)0===(d&3)&&(e=a[d/4]),b+=String.fromCharCode(e>>>8>>>8>>>8),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c<a.length;c++)d=d<<8|a.charCodeAt(c),3===(c&3)&&(b.push(d),d=0);c&3&&b.push(sjcl.bitArray.partial(8*(c&3),d));return b}}; |
||||
|
sjcl.codec.hex={fromBits:function(a){var b="",c;for(c=0;c<a.length;c++)b+=((a[c]|0)+0xf00000000000).toString(16).substr(4);return b.substr(0,sjcl.bitArray.bitLength(a)/4)},toBits:function(a){var b,c=[],d;a=a.replace(/\s|0x/g,"");d=a.length;a=a+"00000000";for(b=0;b<a.length;b+=8)c.push(parseInt(a.substr(b,8),16)^0);return sjcl.bitArray.clamp(c,4*d)}}; |
||||
|
sjcl.codec.base64={S:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,f=sjcl.codec.base64.S,g=0,h=sjcl.bitArray.bitLength(a);c&&(f=f.substr(0,62)+"-_");for(c=0;6*d.length<h;)d+=f.charAt((g^a[c]>>>e)>>>26),6>e?(g=a[c]<<6-e,e+=26,c++):(g<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,f=sjcl.codec.base64.S,g=0,h;b&&(f=f.substr(0,62)+"-_");for(d=0;d<a.length;d++){h=f.indexOf(a.charAt(d)); |
||||
|
if(0>h)throw new sjcl.exception.invalid("this isn't base64!");26<e?(e-=26,c.push(g^h>>>e),g=h<<32-e):(e+=6,g^=h<<32-e)}e&56&&c.push(sjcl.bitArray.partial(e&56,g,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};sjcl.hash.sha256=function(a){this.b[0]||this.N();a?(this.g=a.g.slice(0),this.f=a.f.slice(0),this.c=a.c):this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()}; |
||||
|
sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.g=this.D.slice(0);this.f=[];this.c=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.f=sjcl.bitArray.concat(this.f,a);b=this.c;a=this.c=b+sjcl.bitArray.bitLength(a);if(0x1fffffffffffff<a)throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!==typeof Uint32Array){var d=new Uint32Array(c),e=0;for(b=512+b-(512+b&0x1ff);b<=a;b+=512)this.l(d.subarray(16*e, |
||||
|
16*(e+1))),e+=1;c.splice(0,16*e)}else for(b=512+b-(512+b&0x1ff);b<=a;b+=512)this.l(c.splice(0,16));return this},finalize:function(){var a,b=this.f,c=this.g,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+2;a&15;a++)b.push(0);b.push(Math.floor(this.c/0x100000000));for(b.push(this.c|0);b.length;)this.l(b.splice(0,16));this.reset();return c},D:[],b:[],N:function(){function a(a){return 0x100000000*(a-Math.floor(a))|0}for(var b=0,c=2,d,e;64>b;c++){e=!0;for(d=2;d*d<=c;d++)if(0===c%d){e= |
||||
|
!1;break}e&&(8>b&&(this.D[b]=a(Math.pow(c,.5))),this.b[b]=a(Math.pow(c,1/3)),b++)}},l:function(a){var b,c,d,e=this.g,f=this.b,g=e[0],h=e[1],k=e[2],n=e[3],l=e[4],m=e[5],p=e[6],q=e[7];for(b=0;64>b;b++)16>b?c=a[b]:(c=a[b+1&15],d=a[b+14&15],c=a[b&15]=(c>>>7^c>>>18^c>>>3^c<<25^c<<14)+(d>>>17^d>>>19^d>>>10^d<<15^d<<13)+a[b&15]+a[b+9&15]|0),c=c+q+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(m^p))+f[b],q=p,p=m,m=l,l=n+c|0,n=k,k=h,h=g,g=c+(h&k^n&(h^k))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+g| |
||||
|
0;e[1]=e[1]+h|0;e[2]=e[2]+k|0;e[3]=e[3]+n|0;e[4]=e[4]+l|0;e[5]=e[5]+m|0;e[6]=e[6]+p|0;e[7]=e[7]+q|0}};sjcl.hash.sha1=function(a){a?(this.g=a.g.slice(0),this.f=a.f.slice(0),this.c=a.c):this.reset()};sjcl.hash.sha1.hash=function(a){return(new sjcl.hash.sha1).update(a).finalize()}; |
||||
|
sjcl.hash.sha1.prototype={blockSize:512,reset:function(){this.g=this.D.slice(0);this.f=[];this.c=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.f=sjcl.bitArray.concat(this.f,a);b=this.c;a=this.c=b+sjcl.bitArray.bitLength(a);if(0x1fffffffffffff<a)throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!==typeof Uint32Array){var d=new Uint32Array(c),e=0;for(b=this.blockSize+b-(this.blockSize+b&this.blockSize-1);b<= |
||||
|
a;b+=this.blockSize)this.l(d.subarray(16*e,16*(e+1))),e+=1;c.splice(0,16*e)}else for(b=this.blockSize+b-(this.blockSize+b&this.blockSize-1);b<=a;b+=this.blockSize)this.l(c.splice(0,16));return this},finalize:function(){var a,b=this.f,c=this.g,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+2;a&15;a++)b.push(0);b.push(Math.floor(this.c/0x100000000));for(b.push(this.c|0);b.length;)this.l(b.splice(0,16));this.reset();return c},D:[1732584193,4023233417,2562383102,271733878,3285377520], |
||||
|
b:[1518500249,1859775393,2400959708,3395469782],l:function(a){var b,c,d,e,f,g,h=this.g,k;if("undefined"!==typeof Uint32Array)for(k=Array(80),c=0;16>c;c++)k[c]=a[c];else k=a;c=h[0];d=h[1];e=h[2];f=h[3];g=h[4];for(a=0;79>=a;a++)16<=a&&(b=k[a-3]^k[a-8]^k[a-14]^k[a-16],k[a]=b<<1|b>>>31),b=19>=a?d&e|~d&f:39>=a?d^e^f:59>=a?d&e|d&f|e&f:79>=a?d^e^f:void 0,b=(c<<5|c>>>27)+b+g+k[a]+this.b[Math.floor(a/20)]|0,g=f,f=e,e=d<<30|d>>>2,d=c,c=b;h[0]=h[0]+c|0;h[1]=h[1]+d|0;h[2]=h[2]+e|0;h[3]=h[3]+f|0;h[4]=h[4]+g|0}}; |
||||
|
sjcl.mode.ccm={name:"ccm",F:[],listenProgress:function(a){sjcl.mode.ccm.F.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.F.indexOf(a);-1<a&&sjcl.mode.ccm.F.splice(a,1)},da:function(a){var b=sjcl.mode.ccm.F.slice(),c;for(c=0;c<b.length;c+=1)b[c](a)},encrypt:function(a,b,c,d,e){var f,g=b.slice(0),h=sjcl.bitArray,k=h.bitLength(c)/8,n=h.bitLength(g)/8;e=e||64;d=d||[];if(7>k)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(f=2;4>f&&n>>>8*f;f++);f<15-k&&(f=15-k);c=h.clamp(c, |
||||
|
8*(15-f));b=sjcl.mode.ccm.U(a,b,c,d,e,f);g=sjcl.mode.ccm.V(a,g,c,b,e,f);return h.concat(g.data,g.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var f=sjcl.bitArray,g=f.bitLength(c)/8,h=f.bitLength(b),k=f.clamp(b,h-e),n=f.bitSlice(b,h-e),h=(h-e)/8;if(7>g)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(b=2;4>b&&h>>>8*b;b++);b<15-g&&(b=15-g);c=f.clamp(c,8*(15-b));k=sjcl.mode.ccm.V(a,k,c,n,e,b);a=sjcl.mode.ccm.U(a,k.data,c,d,e,b);if(!f.equal(k.tag,a))throw new sjcl.exception.corrupt("ccm: tag doesn't match"); |
||||
|
return k.data},ka:function(a,b,c,d,e,f){var g=[],h=sjcl.bitArray,k=h.B;d=[h.partial(8,(b.length?64:0)|d-2<<2|f-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length)for(c=h.bitLength(b)/8,65279>=c?g=[h.partial(16,c)]:0xffffffff>=c&&(g=h.concat([h.partial(16,65534)],[c])),g=h.concat(g,b),b=0;b<g.length;b+=4)d=a.encrypt(k(d,g.slice(b,b+4).concat([0,0,0])));return d},U:function(a,b,c,d,e,f){var g=sjcl.bitArray,h=g.B;e/=8;if(e%2||4>e||16<e)throw new sjcl.exception.invalid("ccm: invalid tag length"); |
||||
|
if(0xffffffff<d.length||0xffffffff<b.length)throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");c=sjcl.mode.ccm.ka(a,d,c,e,g.bitLength(b)/8,f);for(d=0;d<b.length;d+=4)c=a.encrypt(h(c,b.slice(d,d+4).concat([0,0,0])));return g.clamp(c,8*e)},V:function(a,b,c,d,e,f){var g,h=sjcl.bitArray;g=h.B;var k=b.length,n=h.bitLength(b),l=k/50,m=l;c=h.concat([h.partial(8,f-1)],c).concat([0,0,0]).slice(0,4);d=h.bitSlice(g(d,a.encrypt(c)),0,e);if(!k)return{tag:d,data:[]};for(g=0;g<k;g+=4)g>l&&(sjcl.mode.ccm.da(g/ |
||||
|
k),l+=m),c[3]++,e=a.encrypt(c),b[g]^=e[0],b[g+1]^=e[1],b[g+2]^=e[2],b[g+3]^=e[3];return{tag:d,data:h.clamp(b,n)}}};void 0===sjcl.beware&&(sjcl.beware={}); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]=function(){sjcl.mode.cbc={name:"cbc",encrypt:function(a,b,c,d){if(d&&d.length)throw new sjcl.exception.invalid("cbc can't authenticate data");if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("cbc iv must be 128 bits");var e=sjcl.bitArray,f=e.B,g=e.bitLength(b),h=0,k=[];if(g&7)throw new sjcl.exception.invalid("pkcs#5 padding only works for multiples of a byte");for(d=0;h+128<=g;d+=4,h+=128)c=a.encrypt(f(c, |
||||
|
b.slice(d,d+4))),k.splice(d,0,c[0],c[1],c[2],c[3]);g=0x1010101*(16-(g>>3&15));c=a.encrypt(f(c,e.concat(b,[g,g,g,g]).slice(d,d+4)));k.splice(d,0,c[0],c[1],c[2],c[3]);return k},decrypt:function(a,b,c,d){if(d&&d.length)throw new sjcl.exception.invalid("cbc can't authenticate data");if(128!==sjcl.bitArray.bitLength(c))throw new sjcl.exception.invalid("cbc iv must be 128 bits");if(sjcl.bitArray.bitLength(b)&127||!b.length)throw new sjcl.exception.corrupt("cbc ciphertext must be a positive multiple of the block size"); |
||||
|
var e=sjcl.bitArray,f=e.B,g,h=[];for(d=0;d<b.length;d+=4)g=b.slice(d,d+4),c=f(c,a.decrypt(g)),h.splice(d,0,c[0],c[1],c[2],c[3]),c=g;g=h[d-1]&255;if(0===g||16<g)throw new sjcl.exception.corrupt("pkcs#5 padding corrupt");c=0x1010101*g;if(!e.equal(e.bitSlice([c,c,c,c],0,8*g),e.bitSlice(h,32*h.length-8*g,32*h.length)))throw new sjcl.exception.corrupt("pkcs#5 padding corrupt");return e.bitSlice(h,0,32*h.length-8*g)}}}; |
||||
|
sjcl.misc.hmac=function(a,b){this.W=b=b||sjcl.hash.sha256;var c=[[],[]],d,e=b.prototype.blockSize/32;this.A=[new b,new b];a.length>e&&(a=b.hash(a));for(d=0;d<e;d++)c[0][d]=a[d]^909522486,c[1][d]=a[d]^1549556828;this.A[0].update(c[0]);this.A[1].update(c[1]);this.P=new b(this.A[0])};sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(a){if(this.Z)throw new sjcl.exception.invalid("encrypt on already updated hmac called!");this.update(a);return this.digest(a)}; |
||||
|
sjcl.misc.hmac.prototype.reset=function(){this.P=new this.W(this.A[0]);this.Z=!1};sjcl.misc.hmac.prototype.update=function(a){this.Z=!0;this.P.update(a)};sjcl.misc.hmac.prototype.digest=function(){var a=this.P.finalize(),a=(new this.W(this.A[1])).update(a).finalize();this.reset();return a}; |
||||
|
sjcl.misc.pbkdf2=function(a,b,c,d,e){c=c||1E4;if(0>d||0>c)throw new sjcl.exception.invalid("invalid params to pbkdf2");"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));e=e||sjcl.misc.hmac;a=new e(a);var f,g,h,k,n=[],l=sjcl.bitArray;for(k=1;32*n.length<(d||1);k++){e=f=a.encrypt(l.concat(b,[k]));for(g=1;g<c;g++)for(f=a.encrypt(f),h=0;h<f.length;h++)e[h]^=f[h];n=n.concat(e)}d&&(n=l.clamp(n,d));return n}; |
||||
|
sjcl.prng=function(a){this.h=[new sjcl.hash.sha256];this.o=[0];this.O=0;this.G={};this.M=0;this.T={};this.X=this.i=this.s=this.fa=0;this.b=[0,0,0,0,0,0,0,0];this.m=[0,0,0,0];this.K=void 0;this.L=a;this.C=!1;this.J={progress:{},seeded:{}};this.w=this.ea=0;this.H=1;this.I=2;this.aa=0x10000;this.R=[0,48,64,96,128,192,0x100,384,512,768,1024];this.ba=3E4;this.$=80}; |
||||
|
sjcl.prng.prototype={randomWords:function(a,b){var c=[],d;d=this.isReady(b);var e;if(d===this.w)throw new sjcl.exception.notReady("generator isn't seeded");if(d&this.I){d=!(d&this.H);e=[];var f=0,g;this.X=e[0]=(new Date).valueOf()+this.ba;for(g=0;16>g;g++)e.push(0x100000000*Math.random()|0);for(g=0;g<this.h.length&&(e=e.concat(this.h[g].finalize()),f+=this.o[g],this.o[g]=0,d||!(this.O&1<<g));g++);this.O>=1<<this.h.length&&(this.h.push(new sjcl.hash.sha256),this.o.push(0));this.i-=f;f>this.s&&(this.s= |
||||
|
f);this.O++;this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.K=new sjcl.cipher.aes(this.b);for(d=0;4>d&&(this.m[d]=this.m[d]+1|0,!this.m[d]);d++);}for(d=0;d<a;d+=4)0===(d+1)%this.aa&&t(this),e=y(this),c.push(e[0],e[1],e[2],e[3]);t(this);return c.slice(0,a)},setDefaultParanoia:function(a,b){if(0===a&&"Setting paranoia=0 will ruin your security; use it only for testing"!==b)throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.L=a},addEntropy:function(a, |
||||
|
b,c){c=c||"user";var d,e,f=(new Date).valueOf(),g=this.G[c],h=this.isReady(),k=0;d=this.T[c];void 0===d&&(d=this.T[c]=this.fa++);void 0===g&&(g=this.G[c]=0);this.G[c]=(this.G[c]+1)%this.h.length;switch(typeof a){case "number":void 0===b&&(b=1);this.h[g].update([d,this.M++,1,b,f,1,a|0]);break;case "object":c=Object.prototype.toString.call(a);if("[object Uint32Array]"===c){e=[];for(c=0;c<a.length;c++)e.push(a[c]);a=e}else for("[object Array]"!==c&&(k=1),c=0;c<a.length&&!k;c++)"number"!==typeof a[c]&& |
||||
|
(k=1);if(!k){if(void 0===b)for(c=b=0;c<a.length;c++)for(e=a[c];0<e;)b++,e=e>>>1;this.h[g].update([d,this.M++,2,b,f,a.length].concat(a))}break;case "string":void 0===b&&(b=a.length);this.h[g].update([d,this.M++,3,b,f,a.length]);this.h[g].update(a);break;default:k=1}if(k)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this.o[g]+=b;this.i+=b;h===this.w&&(this.isReady()!==this.w&&z("seeded",Math.max(this.s,this.i)),z("progress",this.getProgress()))}, |
||||
|
isReady:function(a){a=this.R[void 0!==a?a:this.L];return this.s&&this.s>=a?this.o[0]>this.$&&(new Date).valueOf()>this.X?this.I|this.H:this.H:this.i>=a?this.I|this.w:this.w},getProgress:function(a){a=this.R[a?a:this.L];return this.s>=a?1:this.i>a?1:this.i/a},startCollectors:function(){if(!this.C){this.a={loadTimeCollector:A(this,this.ja),mouseCollector:A(this,this.la),keyboardCollector:A(this,this.ia),accelerometerCollector:A(this,this.ca),touchCollector:A(this,this.na)};if(window.addEventListener)window.addEventListener("load", |
||||
|
this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new sjcl.exception.bug("can't attach event"); |
||||
|
this.C=!0}},stopCollectors:function(){this.C&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove", |
||||
|
this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.C=!1)},addEventListener:function(a,b){this.J[a][this.ea++]=b},removeEventListener:function(a,b){var c,d,e=this.J[a],f=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&f.push(d);for(c=0;c<f.length;c++)d=f[c],delete e[d]},ia:function(){B(this,1)},la:function(a){var b,c;try{b=a.x||a.clientX||a.offsetX||0,c=a.y||a.clientY||a.offsetY||0}catch(d){c=b=0}0!=b&&0!=c&&this.addEntropy([b,c],2,"mouse");B(this,0)},na:function(a){a= |
||||
|
a.touches[0]||a.changedTouches[0];this.addEntropy([a.pageX||a.clientX,a.pageY||a.clientY],1,"touch");B(this,0)},ja:function(){B(this,2)},ca:function(a){a=a.accelerationIncludingGravity.x||a.accelerationIncludingGravity.y||a.accelerationIncludingGravity.z;if(window.orientation){var b=window.orientation;"number"===typeof b&&this.addEntropy(b,1,"accelerometer")}a&&this.addEntropy(a,2,"accelerometer");B(this,0)}}; |
||||
|
function z(a,b){var c,d=sjcl.random.J[a],e=[];for(c in d)d.hasOwnProperty(c)&&e.push(d[c]);for(c=0;c<e.length;c++)e[c](b)}function B(a,b){"undefined"!==typeof window&&window.performance&&"function"===typeof window.performance.now?a.addEntropy(window.performance.now(),b,"loadtime"):a.addEntropy((new Date).valueOf(),b,"loadtime")}function t(a){a.b=y(a).concat(y(a));a.K=new sjcl.cipher.aes(a.b)}function y(a){for(var b=0;4>b&&(a.m[b]=a.m[b]+1|0,!a.m[b]);b++);return a.K.encrypt(a.m)} |
||||
|
function A(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6); |
||||
|
a:try{var C,D,E,F;if(F="undefined"!==typeof module&&module.exports){var G;try{G=require("crypto")}catch(a){G=null}F=D=G}if(F&&D.randomBytes)C=D.randomBytes(128),C=new Uint32Array((new Uint8Array(C)).buffer),sjcl.random.addEntropy(C,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){E=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(E);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(E); |
||||
|
else break a;sjcl.random.addEntropy(E,1024,"crypto['getRandomValues']")}}catch(a){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(a))} |
||||
|
sjcl.json={defaults:{v:1,iter:1E4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json,f=e.j({iv:sjcl.random.randomWords(4,0)},e.defaults),g;e.j(f,c);c=f.adata;"string"===typeof f.salt&&(f.salt=sjcl.codec.base64.toBits(f.salt));"string"===typeof f.iv&&(f.iv=sjcl.codec.base64.toBits(f.iv));if(!sjcl.mode[f.mode]||!sjcl.cipher[f.cipher]||"string"===typeof a&&100>=f.iter||64!==f.ts&&96!==f.ts&&128!==f.ts||128!==f.ks&&192!==f.ks&&0x100!==f.ks||2>f.iv.length|| |
||||
|
4<f.iv.length)throw new sjcl.exception.invalid("json encrypt: invalid parameters");"string"===typeof a?(g=sjcl.misc.cachedPbkdf2(a,f),a=g.key.slice(0,f.ks/32),f.salt=g.salt):sjcl.ecc&&a instanceof sjcl.ecc.elGamal.publicKey&&(g=a.kem(),f.kemtag=g.tag,a=g.key.slice(0,f.ks/32));"string"===typeof b&&(b=sjcl.codec.utf8String.toBits(b));"string"===typeof c&&(f.adata=c=sjcl.codec.utf8String.toBits(c));g=new sjcl.cipher[f.cipher](a);e.j(d,f);d.key=a;f.ct="ccm"===f.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&& |
||||
|
b instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.encrypt(g,b,f.iv,c,f.ts):sjcl.mode[f.mode].encrypt(g,b,f.iv,c,f.ts);return f},encrypt:function(a,b,c,d){var e=sjcl.json,f=e.ha.apply(e,arguments);return e.encode(f)},ga:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json;b=e.j(e.j(e.j({},e.defaults),b),c,!0);var f,g;f=b.adata;"string"===typeof b.salt&&(b.salt=sjcl.codec.base64.toBits(b.salt));"string"===typeof b.iv&&(b.iv=sjcl.codec.base64.toBits(b.iv));if(!sjcl.mode[b.mode]||!sjcl.cipher[b.cipher]||"string"=== |
||||
|
typeof a&&100>=b.iter||64!==b.ts&&96!==b.ts&&128!==b.ts||128!==b.ks&&192!==b.ks&&0x100!==b.ks||!b.iv||2>b.iv.length||4<b.iv.length)throw new sjcl.exception.invalid("json decrypt: invalid parameters");"string"===typeof a?(g=sjcl.misc.cachedPbkdf2(a,b),a=g.key.slice(0,b.ks/32),b.salt=g.salt):sjcl.ecc&&a instanceof sjcl.ecc.elGamal.secretKey&&(a=a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0,b.ks/32));"string"===typeof f&&(f=sjcl.codec.utf8String.toBits(f));g=new sjcl.cipher[b.cipher](a);f="ccm"=== |
||||
|
b.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&b.ct instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.decrypt(g,b.ct,b.iv,b.tag,f,b.ts):sjcl.mode[b.mode].decrypt(g,b.ct,b.iv,f,b.ts);e.j(d,b);d.key=a;return 1===c.raw?f:sjcl.codec.utf8String.fromBits(f)},decrypt:function(a,b,c,d){var e=sjcl.json;return e.ga(a,e.decode(b),c,d)},encode:function(a){var b,c="{",d="";for(b in a)if(a.hasOwnProperty(b)){if(!b.match(/^[a-z0-9]+$/i))throw new sjcl.exception.invalid("json encode: invalid property name");c+=d+'"'+ |
||||
|
b+'":';d=",";switch(typeof a[b]){case "number":case "boolean":c+=a[b];break;case "string":c+='"'+escape(a[b])+'"';break;case "object":c+='"'+sjcl.codec.base64.fromBits(a[b],0)+'"';break;default:throw new sjcl.exception.bug("json encode: unsupported type");}}return c+"}"},decode:function(a){a=a.replace(/\s/g,"");if(!a.match(/^\{.*\}$/))throw new sjcl.exception.invalid("json decode: this isn't json!");a=a.replace(/^\{|\}$/g,"").split(/,/);var b={},c,d;for(c=0;c<a.length;c++){if(!(d=a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new sjcl.exception.invalid("json decode: this isn't json!"); |
||||
|
null!=d[3]?b[d[2]]=parseInt(d[3],10):null!=d[4]?b[d[2]]=d[2].match(/^(ct|adata|salt|iv)$/)?sjcl.codec.base64.toBits(d[4]):unescape(d[4]):null!=d[5]&&(b[d[2]]="true"===d[5])}return b},j:function(a,b,c){void 0===a&&(a={});if(void 0===b)return a;for(var d in b)if(b.hasOwnProperty(d)){if(c&&void 0!==a[d]&&a[d]!==b[d])throw new sjcl.exception.invalid("required parameter overridden");a[d]=b[d]}return a},pa:function(a,b){var c={},d;for(d in a)a.hasOwnProperty(d)&&a[d]!==b[d]&&(c[d]=a[d]);return c},oa:function(a, |
||||
|
b){var c={},d;for(d=0;d<b.length;d++)void 0!==a[b[d]]&&(c[b[d]]=a[b[d]]);return c}};sjcl.encrypt=sjcl.json.encrypt;sjcl.decrypt=sjcl.json.decrypt;sjcl.misc.ma={};sjcl.misc.cachedPbkdf2=function(a,b){var c=sjcl.misc.ma,d;b=b||{};d=b.iter||1E3;c=c[a]=c[a]||{};d=c[d]=c[d]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):sjcl.random.randomWords(2,0)};c=void 0===b.salt?d.firstSalt:b.salt;d[c]=d[c]||sjcl.misc.pbkdf2(a,c,b.iter);return{key:d[c].slice(0),salt:c.slice(0)}}; |
||||
|
"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl}); |
@ -0,0 +1,118 @@ |
|||||
|
|
||||
|
import * as grpc from 'grpc' |
||||
|
import {loadCredentials} from './lightning' |
||||
|
import * as path from 'path' |
||||
|
import * as ByteBuffer from 'bytebuffer' |
||||
|
|
||||
|
// var protoLoader = require('@grpc/proto-loader')
|
||||
|
const env = process.env.NODE_ENV || 'development'; |
||||
|
const config = require(path.join(__dirname,'../../config/app.json'))[env] |
||||
|
|
||||
|
var signerClient = <any> null; |
||||
|
|
||||
|
export const loadSigner = () => { |
||||
|
console.log("LOAD SIGNER RRRRRR",signerClient?true:false) |
||||
|
if (signerClient) { |
||||
|
return signerClient |
||||
|
} else { |
||||
|
console.log("LOAD SIGNER AGAIN!!!!") |
||||
|
try{ |
||||
|
var credentials = loadCredentials() |
||||
|
var lnrpcDescriptor = grpc.load("signer.proto"); |
||||
|
var signer: any = lnrpcDescriptor.signrpc |
||||
|
signerClient = new signer.Signer(config.node_ip + ':' + config.lnd_port, credentials); |
||||
|
console.log("SIGNER CLIENT",signerClient) |
||||
|
return signerClient |
||||
|
} catch(e) { |
||||
|
throw e |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const signMessage = (msg) => { |
||||
|
return new Promise(async(resolve, reject)=> { |
||||
|
let signer = await loadSigner() |
||||
|
try { |
||||
|
const options = { |
||||
|
msg:ByteBuffer.fromHex(msg), |
||||
|
key_loc:{key_family:6, key_index:0}, |
||||
|
} |
||||
|
signer.signMessage(options, function(err,sig){ |
||||
|
if(err || !sig.signature) { |
||||
|
reject(err) |
||||
|
} else { |
||||
|
resolve(sig.signature) |
||||
|
} |
||||
|
}) |
||||
|
} catch(e) { |
||||
|
reject(e) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
export const signBuffer = (msg) => { |
||||
|
return new Promise(async (resolve, reject)=> { |
||||
|
let signer = await loadSigner() |
||||
|
try { |
||||
|
const options = {msg} |
||||
|
signer.signMessage(options, function(err,sig){ |
||||
|
if(err || !sig.signature) { |
||||
|
reject(err) |
||||
|
} else { |
||||
|
resolve(sig.signature) |
||||
|
} |
||||
|
}) |
||||
|
} catch(e) { |
||||
|
reject(e) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
function verifyMessage(msg,sig,pubkey): Promise<{[k:string]:any}> { |
||||
|
return new Promise(async(resolve, reject)=> { |
||||
|
let signer = await loadSigner() |
||||
|
try { |
||||
|
const options = { |
||||
|
msg:ByteBuffer.fromHex(msg), |
||||
|
signature:sig, |
||||
|
pubkey:ByteBuffer.fromHex(pubkey), |
||||
|
} |
||||
|
signer.verifyMessage(options, function(err,res){ |
||||
|
if(err) { |
||||
|
reject(err) |
||||
|
} else { |
||||
|
resolve(res) |
||||
|
} |
||||
|
}) |
||||
|
} catch(e) { |
||||
|
reject(e) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
export async function signAscii(ascii) { |
||||
|
try { |
||||
|
const sig = await signMessage(ascii_to_hexa(ascii)) |
||||
|
return sig |
||||
|
} catch(e) { |
||||
|
throw e |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function verifyAscii(ascii:string,sig:Buffer,pubkey:string): Promise<{[k:string]:any}>{ |
||||
|
try { |
||||
|
const r = await verifyMessage(ascii_to_hexa(ascii),sig,pubkey) |
||||
|
return r |
||||
|
} catch(e) { |
||||
|
throw e |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function ascii_to_hexa(str){ |
||||
|
var arr1 = <string[]> []; |
||||
|
for (var n = 0, l = str.length; n < l; n ++) { |
||||
|
var hex = Number(str.charCodeAt(n)).toString(16); |
||||
|
arr1.push(hex); |
||||
|
} |
||||
|
return arr1.join(''); |
||||
|
} |
@ -0,0 +1,101 @@ |
|||||
|
|
||||
|
import * as moment from 'moment' |
||||
|
import * as zbase32 from './zbase32' |
||||
|
import * as LND from './lightning' |
||||
|
import * as path from 'path' |
||||
|
import * as mqtt from 'mqtt' |
||||
|
import * as fetch from 'node-fetch' |
||||
|
|
||||
|
const env = process.env.NODE_ENV || 'development' |
||||
|
const config = require(path.join(__dirname,'../../config/app.json'))[env] |
||||
|
|
||||
|
let client:any |
||||
|
|
||||
|
export async function connect(onMessage) { |
||||
|
try{ |
||||
|
const info = await LND.getInfo() |
||||
|
|
||||
|
async function reconnect(){ |
||||
|
client = null |
||||
|
const pwd = await genSignedTimestamp() |
||||
|
console.log('[tribes] try to connect:',`tls://${config.tribes_host}:8883`) |
||||
|
client = mqtt.connect(`tls://${config.tribes_host}:8883`,{ |
||||
|
username:info.identity_pubkey, |
||||
|
password:pwd, |
||||
|
reconnectPeriod:0, // dont auto reconnect
|
||||
|
}) |
||||
|
client.on('connect', function () { |
||||
|
console.log("[tribes] connected!") |
||||
|
client.subscribe(`${info.identity_pubkey}/#`) |
||||
|
}) |
||||
|
client.on('close', function (e) { |
||||
|
setTimeout(()=> reconnect(), 2000) |
||||
|
}) |
||||
|
client.on('error', function (e) { |
||||
|
console.log('[tribes] error: ',e.message||e) |
||||
|
}) |
||||
|
client.on('message', function(topic, message) { |
||||
|
if(onMessage) onMessage(topic, message) |
||||
|
}) |
||||
|
} |
||||
|
reconnect() |
||||
|
|
||||
|
} catch(e){ |
||||
|
console.log("TRIBES ERROR",e) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function subscribe(topic){ |
||||
|
if(client) client.subscribe(topic) |
||||
|
} |
||||
|
|
||||
|
export function publish(topic,msg){ |
||||
|
if(client) client.publish(topic,msg) |
||||
|
} |
||||
|
|
||||
|
export async function declare({uuid,name,description,tags,img,groupKey,host,pricePerMessage,priceToJoin,ownerAlias,ownerPubkey}) { |
||||
|
const r = await fetch('https://' + host + '/tribes', { |
||||
|
method: 'POST' , |
||||
|
body: JSON.stringify({ |
||||
|
uuid, groupKey, |
||||
|
name, description, tags, img:img||'', |
||||
|
pricePerMessage:pricePerMessage||0, |
||||
|
priceToJoin:priceToJoin||0, |
||||
|
ownerAlias, ownerPubkey, |
||||
|
|
||||
|
}), |
||||
|
headers: { 'Content-Type': 'application/json' } |
||||
|
}) |
||||
|
const j = await r.json() |
||||
|
console.log(j) |
||||
|
} |
||||
|
|
||||
|
export async function genSignedTimestamp(){ |
||||
|
const now = moment().unix() |
||||
|
const tsBytes = Buffer.from(now.toString(16), 'hex') |
||||
|
const sig = await LND.signBuffer(tsBytes) |
||||
|
const sigBytes = zbase32.decode(sig) |
||||
|
const totalLength = tsBytes.length + sigBytes.length |
||||
|
const buf = Buffer.concat([tsBytes, sigBytes], totalLength) |
||||
|
return urlBase64(buf) |
||||
|
} |
||||
|
|
||||
|
export async function verifySignedTimestamp(stsBase64){ |
||||
|
const stsBuf = Buffer.from(stsBase64, 'base64') |
||||
|
const sig = stsBuf.subarray(4,92) |
||||
|
const sigZbase32 = zbase32.encode(sig) |
||||
|
const r = await LND.verifyBytes(stsBuf.subarray(0,4), sigZbase32) // sig needs to be zbase32 :(
|
||||
|
if (r.valid) { |
||||
|
return r.pubkey |
||||
|
} else { |
||||
|
return false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function getHost() { |
||||
|
return config.tribes_host || '' |
||||
|
} |
||||
|
|
||||
|
function urlBase64(buf){ |
||||
|
return buf.toString('base64').replace(/\//g, '_').replace(/\+/g, '-') |
||||
|
} |
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../../../api/controllers/confirmations.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,wCAAgC;AAChC,sCAAgC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ACpC,CAAC,CAAA;wBACF,MAAM,CAAC,QAAQ,CAAC;4BACf,IAAI,EAAE,cAAc;4BACpB,QAAQ,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC;yBACxD,CAAC,CAAA;qBACF;oBACD,IAAI,EAAE,CAAA;gBACP,CAAC;aAAA,CAAC,CAAA;SACF;aAAM,EAAE,YAAY;YACpB,MAAM,QAAQ,GAAG,MAAM,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC7C,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE;oBACN,MAAM,EAAE,IAAI,CAAC,EAAE;oBACf,MAAM,EAAE,KAAK,CAAC,EAAE;oBAChB,IAAI,EAAE;wBACL,SAAS,CAAC,aAAa,CAAC,OAAO;wBAC/B,SAAS,CAAC,aAAa,CAAC,OAAO;wBAC/B,SAAS,CAAC,aAAa,CAAC,UAAU;qBAClC;oBACD,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO;iBAClC;gBACD,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;aAC9B,CAAC,CAAA;YAEF,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;YAC3B,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;YAEvD,MAAM,CAAC,QAAQ,CAAC;gBACf,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC;aACxD,CAAC,CAAA;SACF;IACF,CAAC;CAAA;AA3DD,kDA2DC"} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||
{"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,EAAE,CAAC,CAAA;QACnD,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,+BAA+B,EAAC,EAAE,CAAC,CAAA;QACjD,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IACnC,CAAC;IACD,GAAG,EAAC,UAAS,GAAG;QACd,OAAO,kCAAkC;YACvC,GAAG,GAAG,IAAI;YACV,8BAA8B,CAAA;IAClC,CAAC;IACD,IAAI,EAAC,UAAS,GAAG;QACf,OAAO,mCAAmC;YACxC,GAAG,GAAG,IAAI;YACV,+BAA+B,CAAA;IACnC,CAAC;CACF,CAAA"} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/models/index.ts"],"names":[],"mappings":";;AAAA,+DAA+C;AAC/C,6BAA4B;AAC5B,oCAA4B;AAC5B,0CAAkC;AAClC,wCAAgC;AAChC,0CAAkC;AAClC,oDAA4C;AAC5C,4CAAoC;AAEpC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,0BAA0B,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE5E,MAAM,SAAS,GAAG,IAAI,gCAAS,iCAC1B,MAAM,KACT,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,KAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAC3D,MAAM,EAAE,CAAC,cAAI,EAAC,iBAAO,EAAC,gBAAM,EAAC,iBAAO,EAAC,sBAAY,EAAC,kBAAQ,CAAC,IAC3D,CAAA;AAIA,8BAAS;AAHX,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;AAI7B,wBAAM"} |
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/models/index.ts"],"names":[],"mappings":";;AAAA,+DAA+C;AAC/C,6BAA4B;AAC5B,oCAA4B;AAC5B,0CAAkC;AAClC,wCAAgC;AAChC,0CAAkC;AAClC,oDAA4C;AAC5C,4CAAoC;AACpC,gDAAwC;AAExC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,0BAA0B,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAE5E,MAAM,SAAS,GAAG,IAAI,gCAAS,iCAC1B,MAAM,KACT,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,KAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAC3D,MAAM,EAAE,CAAC,cAAI,EAAC,iBAAO,EAAC,gBAAM,EAAC,iBAAO,EAAC,sBAAY,EAAC,kBAAQ,EAAC,oBAAU,CAAC,IACtE,CAAA;AAIA,8BAAS;AAHX,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;AAI7B,wBAAM"} |
@ -1 +1 @@ |
|||||
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../../api/models/ts/chat.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,IAAI,GAAzB,MAAqB,IAAK,SAAQ,4BAAW;CA4C5C,CAAA;AApCC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;gCACQ;AAGV;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;sCACS;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;kCACZ;AAGZ;IADC,6BAAM,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hB;IADC,6BAAM;;6CACgB;AAGvB;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;yCACY;AAGnB;IADC,6BAAM;;6CACgB;AAGvB;IADC,6BAAM;;yCACY;AA5DA,IAAI;IADxB,4BAAK,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACjC,IAAI,CA8DxB;kBA9DoB,IAAI"} |
@ -0,0 +1,43 @@ |
|||||
|
"use strict"; |
||||
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
||||
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
||||
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
||||
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
||||
|
return c > 3 && r && Object.defineProperty(target, key, r), r; |
||||
|
}; |
||||
|
var __metadata = (this && this.__metadata) || function (k, v) { |
||||
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const sequelize_typescript_1 = require("sequelize-typescript"); |
||||
|
let ChatMember = class ChatMember extends sequelize_typescript_1.Model { |
||||
|
}; |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Number) |
||||
|
], ChatMember.prototype, "chatId", void 0); |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Number) |
||||
|
], ChatMember.prototype, "contactId", void 0); |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Number) |
||||
|
], ChatMember.prototype, "role", void 0); |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Number) |
||||
|
], ChatMember.prototype, "totalSpent", void 0); |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Number) |
||||
|
], ChatMember.prototype, "totalMessages", void 0); |
||||
|
__decorate([ |
||||
|
sequelize_typescript_1.Column, |
||||
|
__metadata("design:type", Date) |
||||
|
], ChatMember.prototype, "lastActive", void 0); |
||||
|
ChatMember = __decorate([ |
||||
|
sequelize_typescript_1.Table({ tableName: 'sphinx_chat_members', underscored: true }) |
||||
|
], ChatMember); |
||||
|
exports.default = ChatMember; |
||||
|
//# sourceMappingURL=chatMember.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"chatMember.js","sourceRoot":"","sources":["../../../../api/models/ts/chatMember.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAA4D;AAG5D,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CAoBxD,CAAA;AAjBC;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM;;wCACK;AAGZ;IADC,6BAAM;;8CACW;AAGlB;IADC,6BAAM;;iDACc;AAGrB;IADC,6BAAM;8BACK,IAAI;8CAAA;AAlBG,UAAU;IAD9B,4BAAK,CAAC,EAAC,SAAS,EAAE,qBAAqB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACxC,UAAU,CAoB9B;kBApBoB,UAAU"} |
@ -1 +1 @@ |
|||||
{"version":3,"file":"contact.js","sourceRoot":"","sources":["../../../../api/models/ts/contact.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,OAAO,GAA5B,MAAqB,OAAQ,SAAQ,4BAAc;CAqDlD,CAAA;AA7CC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;mCACQ;AAGV;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;sCACM;AAGb;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;;wCACS;AAOhB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;wCACc;AAGhB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;yCACR;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;uCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,IAAI,CAAC;;2CACJ;AAGlB;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;8BACI,IAAI;0CAAA;AAnDI,OAAO;IAD3B,4BAAK,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACpC,OAAO,CAqD3B;kBArDoB,OAAO"} |
{"version":3,"file":"contact.js","sourceRoot":"","sources":["../../../../api/models/ts/contact.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,OAAO,GAA5B,MAAqB,OAAQ,SAAQ,4BAAc;CAwDlD,CAAA;AAhDC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;mCACQ;AAGV;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;sCACM;AAGb;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;;wCACS;AAOhB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,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,IAAI,EAAC,CAAC;GACpC,OAAO,CAkF3B;kBAlFoB,OAAO"} |
@ -0,0 +1,10 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const send_1 = require("./send"); |
||||
|
exports.sendMessage = send_1.sendMessage; |
||||
|
exports.signAndSend = send_1.signAndSend; |
||||
|
const receive_1 = require("./receive"); |
||||
|
exports.initGrpcSubscriptions = receive_1.initGrpcSubscriptions; |
||||
|
exports.initTribesSubscriptions = receive_1.initTribesSubscriptions; |
||||
|
exports.parseKeysendInvoice = receive_1.parseKeysendInvoice; |
||||
|
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/network/index.ts"],"names":[],"mappings":";;AAAA,iCAA8C;AAQ1C,sBARI,kBAAW,CAQJ;AAAC,sBARI,kBAAW,CAQJ;AAP3B,uCAA2F;AAQvF,gCARI,+BAAqB,CAQJ;AACrB,kCAT0B,iCAAuB,CAS1B;AACvB,8BAVkD,6BAAmB,CAUlD"} |
@ -0,0 +1,84 @@ |
|||||
|
"use strict"; |
||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
||||
|
return new (P || (P = Promise))(function (resolve, reject) { |
||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
||||
|
}); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const path = require("path"); |
||||
|
const rncryptor_1 = require("../utils/rncryptor"); |
||||
|
const fetch = require("node-fetch"); |
||||
|
const ldat_1 = require("../utils/ldat"); |
||||
|
const rsa = require("../crypto/rsa"); |
||||
|
const crypto = require("crypto"); |
||||
|
const meme = require("../utils/meme"); |
||||
|
const FormData = require("form-data"); |
||||
|
const constants = require(path.join(__dirname, '../../config/constants.json')); |
||||
|
const msgtypes = constants.message_types; |
||||
|
function modifyPayload(payload, chat) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
if (payload.type === msgtypes.attachment) { |
||||
|
const mt = payload.message && payload.message.mediaToken; |
||||
|
const key = payload.message && payload.message.mediaKey; |
||||
|
const typ = payload.message && payload.message.mediaType; |
||||
|
if (!mt || !key) |
||||
|
return payload; |
||||
|
const terms = ldat_1.parseLDAT(mt); |
||||
|
if (!terms.host) |
||||
|
return payload; |
||||
|
try { |
||||
|
const r = yield fetch(`https://${terms.host}/file/${mt}`, { |
||||
|
headers: { 'Authorization': `Bearer ${meme.mediaToken}` } |
||||
|
}); |
||||
|
const buf = yield r.buffer(); |
||||
|
const decMediaKey = rsa.decrypt(chat.groupPrivateKey, key); |
||||
|
const imgBase64 = rncryptor_1.default.Decrypt(decMediaKey, buf.toString('base64')); |
||||
|
const newKey = crypto.randomBytes(20).toString('hex'); |
||||
|
const encImg = rncryptor_1.default.Encrypt(newKey, imgBase64); |
||||
|
var encImgBuffer = Buffer.from(encImg, 'base64'); |
||||
|
const form = new FormData(); |
||||
|
form.append('file', encImgBuffer, { |
||||
|
contentType: typ || 'image/jpg', |
||||
|
filename: 'Image.jpg', |
||||
|
knownLength: encImgBuffer.length, |
||||
|
}); |
||||
|
const formHeaders = form.getHeaders(); |
||||
|
const resp = yield fetch(`https://${terms.host}/file`, { |
||||
|
method: 'POST', |
||||
|
headers: Object.assign(Object.assign({}, formHeaders), { 'Authorization': `Bearer ${meme.mediaToken}` }), |
||||
|
body: form |
||||
|
}); |
||||
|
let json = yield resp.json(); |
||||
|
if (!json.muid) |
||||
|
return payload; |
||||
|
// PUT NEW TERMS, to finish in personalizeMessage
|
||||
|
const amt = terms.meta && terms.meta.amt; |
||||
|
const ttl = terms.meta && terms.meta.ttl; |
||||
|
const mediaTerms = { |
||||
|
muid: json.muid, ttl: ttl || 31536000, |
||||
|
meta: Object.assign({}, amt && { amt }), |
||||
|
skipSigning: amt ? true : false // only sign if its free
|
||||
|
}; |
||||
|
const encKey = rsa.encrypt(chat.groupKey, newKey); |
||||
|
return fillmsg(payload, { mediaTerms, mediaKey: encKey }); // key is re-encrypted later
|
||||
|
} |
||||
|
catch (e) { |
||||
|
console.log("[modify] error", e); |
||||
|
return payload; |
||||
|
} |
||||
|
// how to link w og msg? ogMediaToken?
|
||||
|
} |
||||
|
else { |
||||
|
return payload; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.modifyPayload = modifyPayload; |
||||
|
function fillmsg(full, props) { |
||||
|
return Object.assign(Object.assign({}, full), { message: Object.assign(Object.assign({}, full.message), props) }); |
||||
|
} |
||||
|
//# sourceMappingURL=modify.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"modify.js","sourceRoot":"","sources":["../../../api/network/modify.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA4B;AAC5B,kDAA0C;AAC1C,oCAAmC;AACnC,wCAAuC;AACvC,qCAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,sCAAqC;AAErC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAC7E,MAAM,QAAQ,GAAG,SAAS,CAAC,aAAa,CAAA;AAExC,SAAsB,aAAa,CAAC,OAAO,EAAE,IAAI;;QAC/C,IAAG,OAAO,CAAC,IAAI,KAAG,QAAQ,CAAC,UAAU,EAAE;YAErC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAA;YACxD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAA;YACvD,MAAM,GAAG,G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AED,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK;IAC3B,uCACI,IAAI,KAAE,OAAO,kCACZ,IAAI,CAAC,OAAO,GACZ,KAAK,KAET;AACF,CAAC"} |
@ -0,0 +1,240 @@ |
|||||
|
"use strict"; |
||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
||||
|
return new (P || (P = Promise))(function (resolve, reject) { |
||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
||||
|
}); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const path = require("path"); |
||||
|
const lndService = require("../grpc"); |
||||
|
const lightning_1 = require("../utils/lightning"); |
||||
|
const controllers_1 = require("../controllers"); |
||||
|
const tribes = require("../utils/tribes"); |
||||
|
const lightning_2 = require("../utils/lightning"); |
||||
|
const models_1 = require("../models"); |
||||
|
const send_1 = require("./send"); |
||||
|
const modify_1 = require("./modify"); |
||||
|
const msg_1 = require("../utils/msg"); |
||||
|
const constants = require(path.join(__dirname, '../../config/constants.json')); |
||||
|
const msgtypes = constants.message_types; |
||||
|
const typesToForward = [ |
||||
|
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment |
||||
|
]; |
||||
|
const typesToModify = [ |
||||
|
msgtypes.attachment |
||||
|
]; |
||||
|
const typesThatNeedPricePerMessage = [ |
||||
|
msgtypes.message, msgtypes.attachment |
||||
|
]; |
||||
|
function onReceive(payload) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
console.log("=>>> onReceive", payload); |
||||
|
// if tribe, owner must forward to MQTT
|
||||
|
let doAction = true; |
||||
|
const toAddIn = {}; |
||||
|
const isTribe = payload.chat && payload.chat.type === constants.chat_types.tribe; |
||||
|
if (isTribe && typesToForward.includes(payload.type)) { |
||||
|
const needsPricePerJoin = typesThatNeedPricePerMessage.includes(payload.type); |
||||
|
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } }); |
||||
|
const tribeOwnerPubKey = chat && chat.ownerPubkey; |
||||
|
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
||||
|
if (owner.publicKey === tribeOwnerPubKey) { |
||||
|
toAddIn.isTribeOwner = true; |
||||
|
// CHECK THEY ARE IN THE GROUP if message
|
||||
|
if (needsPricePerJoin) { |
||||
|
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } }); |
||||
|
const senderMember = senderContact && (yield models_1.models.ChatMember.findOne({ where: { contactId: senderContact.id, chatId: chat.id } })); |
||||
|
if (!senderMember) |
||||
|
doAction = false; |
||||
|
} |
||||
|
// CHECK PRICES
|
||||
|
if (needsPricePerJoin) { |
||||
|
if (payload.message.amount < chat.pricePerMessage) |
||||
|
doAction = false; |
||||
|
} |
||||
|
// check price to join
|
||||
|
if (payload.type === msgtypes.group_join) { |
||||
|
if (payload.message.amount < chat.priceToJoin) |
||||
|
doAction = false; |
||||
|
} |
||||
|
if (doAction) |
||||
|
forwardMessageToTribe(payload); |
||||
|
else |
||||
|
console.log('=> insufficient payment for this action'); |
||||
|
} |
||||
|
} |
||||
|
if (doAction) |
||||
|
doTheAction(Object.assign(Object.assign({}, payload), toAddIn)); |
||||
|
}); |
||||
|
} |
||||
|
function doTheAction(data) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
let payload = data; |
||||
|
if (payload.isTribeOwner) { |
||||
|
// decrypt and re-encrypt with self pubkey
|
||||
|
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } }); |
||||
|
const pld = yield msg_1.decryptMessage(data, chat); |
||||
|
const me = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
||||
|
payload = yield msg_1.encryptTribeBroadcast(pld, me, true); // true=isTribeOwner
|
||||
|
} |
||||
|
if (ACTIONS[payload.type]) { |
||||
|
ACTIONS[payload.type](payload); |
||||
|
} |
||||
|
else { |
||||
|
console.log('Incorrect payload type:', payload.type); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
function forwardMessageToTribe(ogpayload) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const chat = yield models_1.models.Chat.findOne({ where: { uuid: ogpayload.chat.uuid } }); |
||||
|
let payload; |
||||
|
if (typesToModify.includes(ogpayload.type)) { |
||||
|
payload = yield modify_1.modifyPayload(ogpayload, chat); |
||||
|
} |
||||
|
else { |
||||
|
payload = ogpayload; |
||||
|
} |
||||
|
//console.log("FORWARD TO TRIBE",payload) // filter out the sender?
|
||||
|
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
|
||||
|
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); |
||||
|
const type = payload.type; |
||||
|
const message = payload.message; |
||||
|
// HERE: NEED TO MAKE SURE ALIAS IS UNIQUE
|
||||
|
// ASK xref TABLE and put alias there too?
|
||||
|
send_1.sendMessage({ |
||||
|
sender: Object.assign(Object.assign({}, owner.dataValues), payload.sender && payload.sender.alias && { alias: payload.sender.alias }), |
||||
|
chat, type, message, |
||||
|
skipPubKey: payload.sender.pub_key, |
||||
|
success: () => { }, |
||||
|
receive: () => { } |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
const ACTIONS = { |
||||
|
[msgtypes.contact_key]: controllers_1.controllers.contacts.receiveContactKey, |
||||
|
[msgtypes.contact_key_confirmation]: controllers_1.controllers.contacts.receiveConfirmContactKey, |
||||
|
[msgtypes.message]: controllers_1.controllers.messages.receiveMessage, |
||||
|
[msgtypes.invoice]: controllers_1.controllers.invoices.receiveInvoice, |
||||
|
[msgtypes.direct_payment]: controllers_1.controllers.payments.receivePayment, |
||||
|
[msgtypes.confirmation]: controllers_1.controllers.confirmations.receiveConfirmation, |
||||
|
[msgtypes.attachment]: controllers_1.controllers.media.receiveAttachment, |
||||
|
[msgtypes.purchase]: controllers_1.controllers.media.receivePurchase, |
||||
|
[msgtypes.purchase_accept]: controllers_1.controllers.media.receivePurchaseAccept, |
||||
|
[msgtypes.purchase_deny]: controllers_1.controllers.media.receivePurchaseDeny, |
||||
|
[msgtypes.group_create]: controllers_1.controllers.chats.receiveGroupCreateOrInvite, |
||||
|
[msgtypes.group_invite]: controllers_1.controllers.chats.receiveGroupCreateOrInvite, |
||||
|
[msgtypes.group_join]: controllers_1.controllers.chats.receiveGroupJoin, |
||||
|
[msgtypes.group_leave]: controllers_1.controllers.chats.receiveGroupLeave, |
||||
|
}; |
||||
|
function initGrpcSubscriptions() { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
try { |
||||
|
yield lightning_1.getInfo(); |
||||
|
yield lndService.subscribeInvoices(parseKeysendInvoice); |
||||
|
} |
||||
|
catch (e) { |
||||
|
throw e; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.initGrpcSubscriptions = initGrpcSubscriptions; |
||||
|
function initTribesSubscriptions() { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
tribes.connect((topic, message) => __awaiter(this, void 0, void 0, function* () { |
||||
|
try { |
||||
|
const msg = message.toString(); |
||||
|
console.log("=====> msg received! TOPIC", topic, "MESSAGE", msg); |
||||
|
// check topic is signed by sender?
|
||||
|
const payload = yield parseAndVerifyPayload(msg); |
||||
|
onReceive(payload); |
||||
|
} |
||||
|
catch (e) { } |
||||
|
})); |
||||
|
}); |
||||
|
} |
||||
|
exports.initTribesSubscriptions = initTribesSubscriptions; |
||||
|
// VERIFY PUBKEY OF SENDER from sig
|
||||
|
function parseAndVerifyPayload(data) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
let payload; |
||||
|
const li = data.lastIndexOf('}'); |
||||
|
const msg = data.substring(0, li + 1); |
||||
|
const sig = data.substring(li + 1); |
||||
|
try { |
||||
|
payload = JSON.parse(msg); |
||||
|
if (payload) { |
||||
|
const v = yield lightning_2.verifyAscii(msg, sig); |
||||
|
if (v && v.valid && v.pubkey) { |
||||
|
payload.sender = payload.sender || {}; |
||||
|
payload.sender.pub_key = v.pubkey; |
||||
|
return payload; |
||||
|
} |
||||
|
else { |
||||
|
return payload; // => RM THIS
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
catch (e) { |
||||
|
if (payload) |
||||
|
return payload; // => RM THIS
|
||||
|
return null; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
function parseKeysendInvoice(i) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const recs = i.htlcs && i.htlcs[0] && i.htlcs[0].custom_records; |
||||
|
const buf = recs && recs[lightning_2.SPHINX_CUSTOM_RECORD_KEY]; |
||||
|
const data = buf && buf.toString(); |
||||
|
const value = i && i.value && parseInt(i.value); |
||||
|
if (!data) |
||||
|
return; |
||||
|
let payload; |
||||
|
if (data[0] === '{') { |
||||
|
try { |
||||
|
payload = yield parseAndVerifyPayload(data); |
||||
|
} |
||||
|
catch (e) { } |
||||
|
} |
||||
|
else { |
||||
|
const threads = weave(data); |
||||
|
if (threads) |
||||
|
payload = yield parseAndVerifyPayload(threads); |
||||
|
} |
||||
|
if (payload) { |
||||
|
const dat = payload; |
||||
|
if (value && dat && dat.message) { |
||||
|
dat.message.amount = value; // ADD IN TRUE VALUE
|
||||
|
} |
||||
|
onReceive(dat); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.parseKeysendInvoice = parseKeysendInvoice; |
||||
|
const chunks = {}; |
||||
|
function weave(p) { |
||||
|
const pa = p.split('_'); |
||||
|
if (pa.length < 4) |
||||
|
return; |
||||
|
const ts = pa[0]; |
||||
|
const i = pa[1]; |
||||
|
const n = pa[2]; |
||||
|
const m = pa.filter((u, i) => i > 2).join('_'); |
||||
|
chunks[ts] = chunks[ts] ? [...chunks[ts], { i, n, m }] : [{ i, n, m }]; |
||||
|
if (chunks[ts].length === parseInt(n)) { |
||||
|
// got em all!
|
||||
|
const all = chunks[ts]; |
||||
|
let payload = ''; |
||||
|
all.slice().sort((a, b) => a.i - b.i).forEach(obj => { |
||||
|
payload += obj.m; |
||||
|
}); |
||||
|
delete chunks[ts]; |
||||
|
return payload; |
||||
|
} |
||||
|
} |
||||
|
//# sourceMappingURL=receive.js.map
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,155 @@ |
|||||
|
"use strict"; |
||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
||||
|
return new (P || (P = Promise))(function (resolve, reject) { |
||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
||||
|
}); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const models_1 = require("../models"); |
||||
|
const LND = require("../utils/lightning"); |
||||
|
const msg_1 = require("../utils/msg"); |
||||
|
const path = require("path"); |
||||
|
const tribes = require("../utils/tribes"); |
||||
|
const constants = require(path.join(__dirname, '../../config/constants.json')); |
||||
|
function sendMessage(params) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const { type, chat, message, sender, amount, success, failure, skipPubKey } = params; |
||||
|
const m = newmsg(type, chat, sender, message); |
||||
|
let msg = m; |
||||
|
// console.log(type,message)
|
||||
|
if (!(sender && sender.publicKey)) { |
||||
|
console.log("NO SENDER?????"); |
||||
|
return; |
||||
|
} |
||||
|
let contactIds = (typeof chat.contactIds === 'string' ? JSON.parse(chat.contactIds) : chat.contactIds) || []; |
||||
|
if (contactIds.length === 1) { |
||||
|
if (contactIds[0] === 1) { |
||||
|
if (success) |
||||
|
success(true); |
||||
|
return; // if no contacts thats fine (like create public tribe)
|
||||
|
} |
||||
|
} |
||||
|
let networkType = undefined; |
||||
|
const isTribe = chat.type === constants.chat_types.tribe; |
||||
|
let isTribeOwner = false; |
||||
|
const chatUUID = chat.uuid; |
||||
|
if (isTribe) { |
||||
|
if (type === constants.message_types.confirmation) { |
||||
|
return; // dont send confs for tribe
|
||||
|
} |
||||
|
console.log("is tribe!"); |
||||
|
const tribeOwnerPubKey = chat.ownerPubkey; |
||||
|
if (sender.publicKey === tribeOwnerPubKey) { |
||||
|
console.log('im owner! mqtt!'); |
||||
|
isTribeOwner = true; |
||||
|
networkType = 'mqtt'; // broadcast to all
|
||||
|
// decrypt message.content and message.mediaKey w groupKey
|
||||
|
msg = yield msg_1.decryptMessage(msg, chat); |
||||
|
} |
||||
|
else { |
||||
|
// if tribe, send to owner only
|
||||
|
const tribeOwner = yield models_1.models.Contact.findOne({ where: { publicKey: tribeOwnerPubKey } }); |
||||
|
contactIds = tribeOwner ? [tribeOwner.id] : []; |
||||
|
} |
||||
|
} |
||||
|
let yes = null; |
||||
|
let no = null; |
||||
|
console.log('all contactIds', contactIds); |
||||
|
yield asyncForEach(contactIds, (contactId) => __awaiter(this, void 0, void 0, function* () { |
||||
|
if (contactId == 1) { // dont send to self
|
||||
|
return; |
||||
|
} |
||||
|
const contact = yield models_1.models.Contact.findOne({ where: { id: contactId } }); |
||||
|
const destkey = contact.publicKey; |
||||
|
if (destkey === skipPubKey) { |
||||
|
return; // skip (for tribe owner broadcasting, not back to the sender)
|
||||
|
} |
||||
|
console.log('-> sending to ', contact.id, destkey); |
||||
|
const m = yield msg_1.personalizeMessage(msg, contact, isTribeOwner); |
||||
|
const opts = { |
||||
|
dest: destkey, |
||||
|
data: m, |
||||
|
amt: Math.max((amount || 0), 3) |
||||
|
}; |
||||
|
try { |
||||
|
const mqttTopic = networkType === 'mqtt' ? `${destkey}/${chatUUID}` : ''; |
||||
|
const r = yield signAndSend(opts, sender.publicKey, mqttTopic); |
||||
|
yes = r; |
||||
|
} |
||||
|
catch (e) { |
||||
|
console.log("KEYSEND ERROR", e); |
||||
|
no = e; |
||||
|
} |
||||
|
yield sleep(2); |
||||
|
})); |
||||
|
if (yes) { |
||||
|
if (success) |
||||
|
success(yes); |
||||
|
} |
||||
|
else { |
||||
|
if (failure) |
||||
|
failure(no); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.sendMessage = sendMessage; |
||||
|
function signAndSend(opts, pubkey, mqttTopic) { |
||||
|
// console.log('sign and send!!!!',opts.data)
|
||||
|
return new Promise(function (resolve, reject) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
if (!opts.data || typeof opts.data !== 'object') { |
||||
|
return reject('object plz'); |
||||
|
} |
||||
|
let data = JSON.stringify(opts.data); |
||||
|
const sig = yield LND.signAscii(data); |
||||
|
data = data + sig; |
||||
|
// console.log("ACTUALLY SEND", mqttTopic)
|
||||
|
try { |
||||
|
if (mqttTopic) { |
||||
|
yield tribes.publish(mqttTopic, data); |
||||
|
} |
||||
|
else { |
||||
|
yield LND.keysendMessage(Object.assign(Object.assign({}, opts), { data })); |
||||
|
} |
||||
|
resolve(true); |
||||
|
} |
||||
|
catch (e) { |
||||
|
reject(e); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
exports.signAndSend = signAndSend; |
||||
|
function newmsg(type, chat, sender, message) { |
||||
|
const includeGroupKey = type === constants.message_types.group_create || type === constants.message_types.group_invite; |
||||
|
const includeAlias = sender && sender.alias && chat.type === constants.chat_types.tribe; |
||||
|
return { |
||||
|
type: type, |
||||
|
chat: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ uuid: chat.uuid }, chat.name && { name: chat.name }), (chat.type || chat.type === 0) && { type: chat.type }), chat.members && { members: chat.members }), (includeGroupKey && chat.groupKey) && { groupKey: chat.groupKey }), (includeGroupKey && chat.host) && { host: chat.host }), |
||||
|
message: message, |
||||
|
sender: Object.assign(Object.assign({}, includeAlias && { alias: sender.alias }), { pub_key: sender.publicKey }) |
||||
|
}; |
||||
|
} |
||||
|
function asyncForEach(array, callback) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
for (let index = 0; index < array.length; index++) { |
||||
|
yield callback(array[index], index, array); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
function sleep(ms) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
return new Promise(resolve => setTimeout(resolve, ms)); |
||||
|
}); |
||||
|
} |
||||
|
// function urlBase64FromHex(ascii){
|
||||
|
// return Buffer.from(ascii,'hex').toString('base64').replace(/\//g, '_').replace(/\+/g, '-')
|
||||
|
// }
|
||||
|
// function urlBase64FromBytes(buf){
|
||||
|
// return Buffer.from(buf).toString('base64').replace(/\//g, '_').replace(/\+/g, '-')
|
||||
|
// }
|
||||
|
//# sourceMappingURL=send.js.map
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../api/utils/json.ts"],"names":[],"mappings":";;AAAA,wCAA6C;AAC7C,oCAAmC;AAEnC,SAAS,UAAU,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,IAAE,CAAC,CAAA;IAC5B,IAAI,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAA;IACxC,IAAG,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,UAAU,KAAG,QAAQ,EAAC;QACtD,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;KACzC;IACD,OAAO,cAAO,iCACT,IAAI,KACP,UAAU,IACV,CAAA;AACJ,CAAC;AAsCC,gCAAU;AApCZ,SAAS,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAQ;IACxC,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,IAAE,GAAG,CAAA;IACnC,I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C,CAAC,CAAC,IAAI,IAChD,CAAA;AACJ,CAAC;AAuBC,sCAAa;AArBf,SAAS,aAAa,CAAC,OAAO;IAC5B,IAAG,CAAC,OAAO;QAAE,OAAO,EAAE,CAAA;IACtB,OAAO,cAAO,CAAC,OAAO,CAAC,UAAU,IAAE,OAAO,CAAC,CAAA;AAC7C,CAAC;AAmBC,sCAAa;AAjBf,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,cAAO,CAAC,MAAM,CAAC,UAAU,IAAE,MAAM,CAAC,CAAA;AAkBjE,oCAAY;AAhBd,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAO,CAAC,IAAI,CAAC,CAAA;AAiB3C,sCAAa;AAff,SAAS,kBAAkB,CAAC,YAAY,EAAE,IAAI;IAC5C,MAAM,GAAG,GAAG,YAAY,CAAC,UAAU,IAAI,YAAY,CAAA;IACnD,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACpD,OAAO,cAAO,iCACT,GAAG,KACN,QAAQ;QACR,IAAI,EACJ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IACpC,CAAA;AACJ,CAAC;AAQC,gDAAkB"} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,9 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
let mediaToken = ''; |
||||
|
exports.mediaToken = mediaToken; |
||||
|
function setMediaToken(mt) { |
||||
|
exports.mediaToken = mediaToken = mt; |
||||
|
} |
||||
|
exports.setMediaToken = setMediaToken; |
||||
|
//# sourceMappingURL=meme.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"meme.js","sourceRoot":"","sources":["../../../api/utils/meme.ts"],"names":[],"mappings":";;AACA,IAAI,UAAU,GAAG,EAAE,CAAA;AAMX,gCAAU;AAJlB,SAAS,aAAa,CAAC,EAAE;IACrB,qBAAA,UAAU,GAAG,EAAE,CAAA;AACnB,CAAC;AAEmB,sCAAa"} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,5 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const RNCryptor = require("./rncryptor"); |
||||
|
exports.default = RNCryptor; |
||||
|
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../api/utils/rncryptor/index.js"],"names":[],"mappings":";;AAEA,yCAAwC;AAExC,kBAAe,SAAS,CAAA"} |
@ -0,0 +1,78 @@ |
|||||
|
var sjcl = require('./sjcl'); |
||||
|
var RNCryptor = {}; |
||||
|
/* |
||||
|
Takes password string and salt WordArray |
||||
|
Returns key bitArray |
||||
|
*/ |
||||
|
RNCryptor.KeyForPassword = function (password, salt) { |
||||
|
var hmacSHA1 = function (key) { |
||||
|
var hasher = new sjcl.misc.hmac(key, sjcl.hash.sha1); |
||||
|
this.encrypt = function () { |
||||
|
return hasher.encrypt.apply(hasher, arguments); |
||||
|
}; |
||||
|
}; |
||||
|
return sjcl.misc.pbkdf2(password, salt, 10000, 32 * 8, hmacSHA1); |
||||
|
}; |
||||
|
/* |
||||
|
Takes password string and plaintext base64 |
||||
|
options: |
||||
|
iv |
||||
|
encryption_salt |
||||
|
html_salt |
||||
|
Returns ciphertext base64 |
||||
|
*/ |
||||
|
RNCryptor.Encrypt = function (password, plaintextBase64, options) { |
||||
|
var plaintext = sjcl.codec.base64.toBits(plaintextBase64); |
||||
|
options = options || {}; |
||||
|
var encryption_salt = options["encryption_salt"] || sjcl.random.randomWords(8 / 4); // FIXME: Need to seed PRNG
|
||||
|
var encryption_key = RNCryptor.KeyForPassword(password, encryption_salt); |
||||
|
var hmac_salt = options["hmac_salt"] || sjcl.random.randomWords(8 / 4); |
||||
|
var hmac_key = RNCryptor.KeyForPassword(password, hmac_salt); |
||||
|
var iv = options["iv"] || sjcl.random.randomWords(16 / 4); |
||||
|
var version = sjcl.codec.hex.toBits("03"); |
||||
|
var options = sjcl.codec.hex.toBits("01"); |
||||
|
var message = sjcl.bitArray.concat(version, options); |
||||
|
message = sjcl.bitArray.concat(message, encryption_salt); |
||||
|
message = sjcl.bitArray.concat(message, hmac_salt); |
||||
|
message = sjcl.bitArray.concat(message, iv); |
||||
|
var aes = new sjcl.cipher.aes(encryption_key); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."](); |
||||
|
var encrypted = sjcl.mode.cbc.encrypt(aes, plaintext, iv); |
||||
|
message = sjcl.bitArray.concat(message, encrypted); |
||||
|
var hmac = new sjcl.misc.hmac(hmac_key).encrypt(message); |
||||
|
message = sjcl.bitArray.concat(message, hmac); |
||||
|
return sjcl.codec.base64.fromBits(message); |
||||
|
}; |
||||
|
/* |
||||
|
Takes password string and message (ciphertext) base64 |
||||
|
options: |
||||
|
iv |
||||
|
encryption_salt |
||||
|
html_salt |
||||
|
Returns plaintext base64 |
||||
|
*/ |
||||
|
RNCryptor.Decrypt = function (password, messageBase64, options) { |
||||
|
var message = sjcl.codec.base64.toBits(messageBase64); |
||||
|
options = options || {}; |
||||
|
var version = sjcl.bitArray.extract(message, 0 * 8, 8); |
||||
|
var options = sjcl.bitArray.extract(message, 1 * 8, 8); |
||||
|
var encryption_salt = sjcl.bitArray.bitSlice(message, 2 * 8, 10 * 8); |
||||
|
var encryption_key = RNCryptor.KeyForPassword(password, encryption_salt); |
||||
|
var hmac_salt = sjcl.bitArray.bitSlice(message, 10 * 8, 18 * 8); |
||||
|
var hmac_key = RNCryptor.KeyForPassword(password, hmac_salt); |
||||
|
var iv = sjcl.bitArray.bitSlice(message, 18 * 8, 34 * 8); |
||||
|
var ciphertext_end = sjcl.bitArray.bitLength(message) - (32 * 8); |
||||
|
var ciphertext = sjcl.bitArray.bitSlice(message, 34 * 8, ciphertext_end); |
||||
|
var hmac = sjcl.bitArray.bitSlice(message, ciphertext_end); |
||||
|
var expected_hmac = new sjcl.misc.hmac(hmac_key).encrypt(sjcl.bitArray.bitSlice(message, 0, ciphertext_end)); |
||||
|
// .equal is of consistent time
|
||||
|
if (!sjcl.bitArray.equal(hmac, expected_hmac)) { |
||||
|
throw new sjcl.exception.corrupt("HMAC mismatch or bad password."); |
||||
|
} |
||||
|
var aes = new sjcl.cipher.aes(encryption_key); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."](); |
||||
|
var decrypted = sjcl.mode.cbc.decrypt(aes, ciphertext, iv); |
||||
|
return sjcl.codec.base64.fromBits(decrypted); |
||||
|
}; |
||||
|
module.exports = RNCryptor; |
||||
|
//# sourceMappingURL=rncryptor.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"rncryptor.js","sourceRoot":"","sources":["../../../../api/utils/rncryptor/rncryptor.js"],"names":[],"mappings":"AAAA,IAAI,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE5B,IAAI,SAAS,GAAG,EAAE,CAAC;AAEnB;;;EAGE;AAEF,SAAS,CAAC,cAAc,GAAG,UAAS,QAAQ,EAAE,IAAI;IAChD,IAAI,QAAQ,GAAG,UAAU,GAAG;QACxB,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG;YACX,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC;IACN,CAAC,CAAC;IACF,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;AACnE,CAAC,CAAA;AAED;;;;;;;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CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,qEAAqE,CAAC,EAAE,CAAC;IACrF,IAAI,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAE3D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,SAAS,CAAA"} |
@ -0,0 +1,503 @@ |
|||||
|
"use strict"; |
||||
|
var sjcl = { cipher: {}, hash: {}, keyexchange: {}, mode: {}, misc: {}, codec: {}, exception: { corrupt: function (a) { this.toString = function () { return "CORRUPT: " + this.message; }; this.message = a; }, invalid: function (a) { this.toString = function () { return "INVALID: " + this.message; }; this.message = a; }, bug: function (a) { this.toString = function () { return "BUG: " + this.message; }; this.message = a; }, notReady: function (a) { this.toString = function () { return "NOT READY: " + this.message; }; this.message = a; } } }; |
||||
|
sjcl.cipher.aes = function (a) { |
||||
|
this.u[0][0][0] || this.N(); |
||||
|
var b, c, d, e, f = this.u[0][4], g = this.u[1]; |
||||
|
b = a.length; |
||||
|
var h = 1; |
||||
|
if (4 !== b && 6 !== b && 8 !== b) |
||||
|
throw new sjcl.exception.invalid("invalid aes key size"); |
||||
|
this.b = [d = a.slice(0), e = []]; |
||||
|
for (a = b; a < 4 * b + 28; a++) { |
||||
|
c = d[a - 1]; |
||||
|
if (0 === a % b || 8 === b && 4 === a % b) |
||||
|
c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7)); |
||||
|
d[a] = d[a - b] ^ c; |
||||
|
} |
||||
|
for (b = 0; a; b++, a--) |
||||
|
c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & |
||||
|
255]]; |
||||
|
}; |
||||
|
sjcl.cipher.aes.prototype = { encrypt: function (a) { return r(this, a, 0); }, decrypt: function (a) { return r(this, a, 1); }, u: [[[], [], [], [], []], [[], [], [], [], []]], N: function () { |
||||
|
var a = this.u[0], b = this.u[1], c = a[4], d = b[4], e, f, g, h = [], k = [], n, l, m, p; |
||||
|
for (e = 0; 0x100 > e; e++) |
||||
|
k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e; |
||||
|
for (f = g = 0; !c[f]; f ^= n || 1, g = k[g] || 1) |
||||
|
for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, l = h[e = h[n = h[f]]], p = 0x1010101 * l ^ 0x10001 * e ^ 0x101 * n ^ 0x1010100 * f, l = 0x101 * h[m] ^ 0x1010100 * m, e = 0; 4 > e; e++) |
||||
|
a[e][f] = l = l << 24 ^ l >>> 8, b[e][m] = p = p << 24 ^ p >>> 8; |
||||
|
for (e = |
||||
|
0; 5 > e; e++) |
||||
|
a[e] = a[e].slice(0), b[e] = b[e].slice(0); |
||||
|
} }; |
||||
|
function r(a, b, c) { |
||||
|
if (4 !== b.length) |
||||
|
throw new sjcl.exception.invalid("invalid aes block size"); |
||||
|
var d = a.b[c], e = b[0] ^ d[0], f = b[c ? 3 : 1] ^ d[1], g = b[2] ^ d[2]; |
||||
|
b = b[c ? 1 : 3] ^ d[3]; |
||||
|
var h, k, n, l = d.length / 4 - 2, m, p = 4, q = [0, 0, 0, 0]; |
||||
|
h = a.u[c]; |
||||
|
a = h[0]; |
||||
|
var u = h[1], v = h[2], w = h[3], x = h[4]; |
||||
|
for (m = 0; m < l; m++) |
||||
|
h = a[e >>> 24] ^ u[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ u[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], n = a[g >>> 24] ^ u[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ u[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = n; |
||||
|
for (m = |
||||
|
0; 4 > m; m++) |
||||
|
q[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h; |
||||
|
return q; |
||||
|
} |
||||
|
sjcl.bitArray = { bitSlice: function (a, b, c) { a = sjcl.bitArray.Y(a.slice(b / 32), 32 - (b & 31)).slice(1); return void 0 === c ? a : sjcl.bitArray.clamp(a, c - b); }, extract: function (a, b, c) { var d = Math.floor(-b - c & 31); return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1; }, concat: function (a, b) { if (0 === a.length || 0 === b.length) |
||||
|
return a.concat(b); var c = a[a.length - 1], d = sjcl.bitArray.getPartial(c); return 32 === d ? a.concat(b) : sjcl.bitArray.Y(b, d, c | 0, a.slice(0, a.length - 1)); }, bitLength: function (a) { |
||||
|
var b = a.length; |
||||
|
return 0 === |
||||
|
b ? 0 : 32 * (b - 1) + sjcl.bitArray.getPartial(a[b - 1]); |
||||
|
}, clamp: function (a, b) { if (32 * a.length < b) |
||||
|
return a; a = a.slice(0, Math.ceil(b / 32)); var c = a.length; b = b & 31; 0 < c && b && (a[c - 1] = sjcl.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)); return a; }, partial: function (a, b, c) { return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 0x10000000000 * a; }, getPartial: function (a) { return Math.round(a / 0x10000000000) || 32; }, equal: function (a, b) { |
||||
|
if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) |
||||
|
return !1; |
||||
|
var c = 0, d; |
||||
|
for (d = 0; d < a.length; d++) |
||||
|
c |= a[d] ^ b[d]; |
||||
|
return 0 === |
||||
|
c; |
||||
|
}, Y: function (a, b, c, d) { var e; e = 0; for (void 0 === d && (d = []); 32 <= b; b -= 32) |
||||
|
d.push(c), c = 0; if (0 === b) |
||||
|
return d.concat(a); for (e = 0; e < a.length; e++) |
||||
|
d.push(c | a[e] >>> b), c = a[e] << 32 - b; e = a.length ? a[a.length - 1] : 0; a = sjcl.bitArray.getPartial(e); d.push(sjcl.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1)); return d; }, B: function (a, b) { return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]; }, byteswapM: function (a) { var b, c; for (b = 0; b < a.length; ++b) |
||||
|
c = a[b], a[b] = c >>> 24 | c >>> 8 & 0xff00 | (c & 0xff00) << 8 | c << 24; return a; } }; |
||||
|
sjcl.codec.utf8String = { fromBits: function (a) { var b = "", c = sjcl.bitArray.bitLength(a), d, e; for (d = 0; d < c / 8; d++) |
||||
|
0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8; return decodeURIComponent(escape(b)); }, toBits: function (a) { a = unescape(encodeURIComponent(a)); var b = [], c, d = 0; for (c = 0; c < a.length; c++) |
||||
|
d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0); c & 3 && b.push(sjcl.bitArray.partial(8 * (c & 3), d)); return b; } }; |
||||
|
sjcl.codec.hex = { fromBits: function (a) { var b = "", c; for (c = 0; c < a.length; c++) |
||||
|
b += ((a[c] | 0) + 0xf00000000000).toString(16).substr(4); return b.substr(0, sjcl.bitArray.bitLength(a) / 4); }, toBits: function (a) { var b, c = [], d; a = a.replace(/\s|0x/g, ""); d = a.length; a = a + "00000000"; for (b = 0; b < a.length; b += 8) |
||||
|
c.push(parseInt(a.substr(b, 8), 16) ^ 0); return sjcl.bitArray.clamp(c, 4 * d); } }; |
||||
|
sjcl.codec.base64 = { S: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", fromBits: function (a, b, c) { var d = "", e = 0, f = sjcl.codec.base64.S, g = 0, h = sjcl.bitArray.bitLength(a); c && (f = f.substr(0, 62) + "-_"); for (c = 0; 6 * d.length < h;) |
||||
|
d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6); for (; d.length & 3 && !b;) |
||||
|
d += "="; return d; }, toBits: function (a, b) { |
||||
|
a = a.replace(/\s|=/g, ""); |
||||
|
var c = [], d, e = 0, f = sjcl.codec.base64.S, g = 0, h; |
||||
|
b && (f = f.substr(0, 62) + "-_"); |
||||
|
for (d = 0; d < a.length; d++) { |
||||
|
h = f.indexOf(a.charAt(d)); |
||||
|
if (0 > h) |
||||
|
throw new sjcl.exception.invalid("this isn't base64!"); |
||||
|
26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e); |
||||
|
} |
||||
|
e & 56 && c.push(sjcl.bitArray.partial(e & 56, g, 1)); |
||||
|
return c; |
||||
|
} }; |
||||
|
sjcl.codec.base64url = { fromBits: function (a) { return sjcl.codec.base64.fromBits(a, 1, 1); }, toBits: function (a) { return sjcl.codec.base64.toBits(a, 1); } }; |
||||
|
sjcl.hash.sha256 = function (a) { this.b[0] || this.N(); a ? (this.g = a.g.slice(0), this.f = a.f.slice(0), this.c = a.c) : this.reset(); }; |
||||
|
sjcl.hash.sha256.hash = function (a) { return (new sjcl.hash.sha256).update(a).finalize(); }; |
||||
|
sjcl.hash.sha256.prototype = { blockSize: 512, reset: function () { this.g = this.D.slice(0); this.f = []; this.c = 0; return this; }, update: function (a) { |
||||
|
"string" === typeof a && (a = sjcl.codec.utf8String.toBits(a)); |
||||
|
var b, c = this.f = sjcl.bitArray.concat(this.f, a); |
||||
|
b = this.c; |
||||
|
a = this.c = b + sjcl.bitArray.bitLength(a); |
||||
|
if (0x1fffffffffffff < a) |
||||
|
throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits"); |
||||
|
if ("undefined" !== typeof Uint32Array) { |
||||
|
var d = new Uint32Array(c), e = 0; |
||||
|
for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) |
||||
|
this.l(d.subarray(16 * e, 16 * (e + 1))), e += 1; |
||||
|
c.splice(0, 16 * e); |
||||
|
} |
||||
|
else |
||||
|
for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) |
||||
|
this.l(c.splice(0, 16)); |
||||
|
return this; |
||||
|
}, finalize: function () { var a, b = this.f, c = this.g, b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]); for (a = b.length + 2; a & 15; a++) |
||||
|
b.push(0); b.push(Math.floor(this.c / 0x100000000)); for (b.push(this.c | 0); b.length;) |
||||
|
this.l(b.splice(0, 16)); this.reset(); return c; }, D: [], b: [], N: function () { |
||||
|
function a(a) { return 0x100000000 * (a - Math.floor(a)) | 0; } |
||||
|
for (var b = 0, c = 2, d, e; 64 > b; c++) { |
||||
|
e = !0; |
||||
|
for (d = 2; d * d <= c; d++) |
||||
|
if (0 === c % d) { |
||||
|
e = |
||||
|
!1; |
||||
|
break; |
||||
|
} |
||||
|
e && (8 > b && (this.D[b] = a(Math.pow(c, .5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++); |
||||
|
} |
||||
|
}, l: function (a) { |
||||
|
var b, c, d, e = this.g, f = this.b, g = e[0], h = e[1], k = e[2], n = e[3], l = e[4], m = e[5], p = e[6], q = e[7]; |
||||
|
for (b = 0; 64 > b; b++) |
||||
|
16 > b ? c = a[b] : (c = a[b + 1 & 15], d = a[b + 14 & 15], c = a[b & 15] = (c >>> 7 ^ c >>> 18 ^ c >>> 3 ^ c << 25 ^ c << 14) + (d >>> 17 ^ d >>> 19 ^ d >>> 10 ^ d << 15 ^ d << 13) + a[b & 15] + a[b + 9 & 15] | 0), c = c + q + (l >>> 6 ^ l >>> 11 ^ l >>> 25 ^ l << 26 ^ l << 21 ^ l << 7) + (p ^ l & (m ^ p)) + f[b], q = p, p = m, m = l, l = n + c | 0, n = k, k = h, h = g, g = c + (h & k ^ n & (h ^ k)) + (h >>> 2 ^ h >>> 13 ^ h >>> 22 ^ h << 30 ^ h << 19 ^ h << 10) | 0; |
||||
|
e[0] = e[0] + g | |
||||
|
0; |
||||
|
e[1] = e[1] + h | 0; |
||||
|
e[2] = e[2] + k | 0; |
||||
|
e[3] = e[3] + n | 0; |
||||
|
e[4] = e[4] + l | 0; |
||||
|
e[5] = e[5] + m | 0; |
||||
|
e[6] = e[6] + p | 0; |
||||
|
e[7] = e[7] + q | 0; |
||||
|
} }; |
||||
|
sjcl.hash.sha1 = function (a) { a ? (this.g = a.g.slice(0), this.f = a.f.slice(0), this.c = a.c) : this.reset(); }; |
||||
|
sjcl.hash.sha1.hash = function (a) { return (new sjcl.hash.sha1).update(a).finalize(); }; |
||||
|
sjcl.hash.sha1.prototype = { blockSize: 512, reset: function () { this.g = this.D.slice(0); this.f = []; this.c = 0; return this; }, update: function (a) { |
||||
|
"string" === typeof a && (a = sjcl.codec.utf8String.toBits(a)); |
||||
|
var b, c = this.f = sjcl.bitArray.concat(this.f, a); |
||||
|
b = this.c; |
||||
|
a = this.c = b + sjcl.bitArray.bitLength(a); |
||||
|
if (0x1fffffffffffff < a) |
||||
|
throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits"); |
||||
|
if ("undefined" !== typeof Uint32Array) { |
||||
|
var d = new Uint32Array(c), e = 0; |
||||
|
for (b = this.blockSize + b - (this.blockSize + b & this.blockSize - 1); b <= |
||||
|
a; b += this.blockSize) |
||||
|
this.l(d.subarray(16 * e, 16 * (e + 1))), e += 1; |
||||
|
c.splice(0, 16 * e); |
||||
|
} |
||||
|
else |
||||
|
for (b = this.blockSize + b - (this.blockSize + b & this.blockSize - 1); b <= a; b += this.blockSize) |
||||
|
this.l(c.splice(0, 16)); |
||||
|
return this; |
||||
|
}, finalize: function () { var a, b = this.f, c = this.g, b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]); for (a = b.length + 2; a & 15; a++) |
||||
|
b.push(0); b.push(Math.floor(this.c / 0x100000000)); for (b.push(this.c | 0); b.length;) |
||||
|
this.l(b.splice(0, 16)); this.reset(); return c; }, D: [1732584193, 4023233417, 2562383102, 271733878, 3285377520], |
||||
|
b: [1518500249, 1859775393, 2400959708, 3395469782], l: function (a) { var b, c, d, e, f, g, h = this.g, k; if ("undefined" !== typeof Uint32Array) |
||||
|
for (k = Array(80), c = 0; 16 > c; c++) |
||||
|
k[c] = a[c]; |
||||
|
else |
||||
|
k = a; c = h[0]; d = h[1]; e = h[2]; f = h[3]; g = h[4]; for (a = 0; 79 >= a; a++) |
||||
|
16 <= a && (b = k[a - 3] ^ k[a - 8] ^ k[a - 14] ^ k[a - 16], k[a] = b << 1 | b >>> 31), b = 19 >= a ? d & e | ~d & f : 39 >= a ? d ^ e ^ f : 59 >= a ? d & e | d & f | e & f : 79 >= a ? d ^ e ^ f : void 0, b = (c << 5 | c >>> 27) + b + g + k[a] + this.b[Math.floor(a / 20)] | 0, g = f, f = e, e = d << 30 | d >>> 2, d = c, c = b; h[0] = h[0] + c | 0; h[1] = h[1] + d | 0; h[2] = h[2] + e | 0; h[3] = h[3] + f | 0; h[4] = h[4] + g | 0; } }; |
||||
|
sjcl.mode.ccm = { name: "ccm", F: [], listenProgress: function (a) { sjcl.mode.ccm.F.push(a); }, unListenProgress: function (a) { a = sjcl.mode.ccm.F.indexOf(a); -1 < a && sjcl.mode.ccm.F.splice(a, 1); }, da: function (a) { var b = sjcl.mode.ccm.F.slice(), c; for (c = 0; c < b.length; c += 1) |
||||
|
b[c](a); }, encrypt: function (a, b, c, d, e) { |
||||
|
var f, g = b.slice(0), h = sjcl.bitArray, k = h.bitLength(c) / 8, n = h.bitLength(g) / 8; |
||||
|
e = e || 64; |
||||
|
d = d || []; |
||||
|
if (7 > k) |
||||
|
throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"); |
||||
|
for (f = 2; 4 > f && n >>> 8 * f; f++) |
||||
|
; |
||||
|
f < 15 - k && (f = 15 - k); |
||||
|
c = h.clamp(c, 8 * (15 - f)); |
||||
|
b = sjcl.mode.ccm.U(a, b, c, d, e, f); |
||||
|
g = sjcl.mode.ccm.V(a, g, c, b, e, f); |
||||
|
return h.concat(g.data, g.tag); |
||||
|
}, decrypt: function (a, b, c, d, e) { |
||||
|
e = e || 64; |
||||
|
d = d || []; |
||||
|
var f = sjcl.bitArray, g = f.bitLength(c) / 8, h = f.bitLength(b), k = f.clamp(b, h - e), n = f.bitSlice(b, h - e), h = (h - e) / 8; |
||||
|
if (7 > g) |
||||
|
throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"); |
||||
|
for (b = 2; 4 > b && h >>> 8 * b; b++) |
||||
|
; |
||||
|
b < 15 - g && (b = 15 - g); |
||||
|
c = f.clamp(c, 8 * (15 - b)); |
||||
|
k = sjcl.mode.ccm.V(a, k, c, n, e, b); |
||||
|
a = sjcl.mode.ccm.U(a, k.data, c, d, e, b); |
||||
|
if (!f.equal(k.tag, a)) |
||||
|
throw new sjcl.exception.corrupt("ccm: tag doesn't match"); |
||||
|
return k.data; |
||||
|
}, ka: function (a, b, c, d, e, f) { var g = [], h = sjcl.bitArray, k = h.B; d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)]; d = h.concat(d, c); d[3] |= e; d = a.encrypt(d); if (b.length) |
||||
|
for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 0xffffffff >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) |
||||
|
d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0]))); return d; }, U: function (a, b, c, d, e, f) { |
||||
|
var g = sjcl.bitArray, h = g.B; |
||||
|
e /= 8; |
||||
|
if (e % 2 || 4 > e || 16 < e) |
||||
|
throw new sjcl.exception.invalid("ccm: invalid tag length"); |
||||
|
if (0xffffffff < d.length || 0xffffffff < b.length) |
||||
|
throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data"); |
||||
|
c = sjcl.mode.ccm.ka(a, d, c, e, g.bitLength(b) / 8, f); |
||||
|
for (d = 0; d < b.length; d += 4) |
||||
|
c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0]))); |
||||
|
return g.clamp(c, 8 * e); |
||||
|
}, V: function (a, b, c, d, e, f) { |
||||
|
var g, h = sjcl.bitArray; |
||||
|
g = h.B; |
||||
|
var k = b.length, n = h.bitLength(b), l = k / 50, m = l; |
||||
|
c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4); |
||||
|
d = h.bitSlice(g(d, a.encrypt(c)), 0, e); |
||||
|
if (!k) |
||||
|
return { tag: d, data: [] }; |
||||
|
for (g = 0; g < k; g += 4) |
||||
|
g > l && (sjcl.mode.ccm.da(g / |
||||
|
k), l += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3]; |
||||
|
return { tag: d, data: h.clamp(b, n) }; |
||||
|
} }; |
||||
|
void 0 === sjcl.beware && (sjcl.beware = {}); |
||||
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."] = function () { |
||||
|
sjcl.mode.cbc = { name: "cbc", encrypt: function (a, b, c, d) { |
||||
|
if (d && d.length) |
||||
|
throw new sjcl.exception.invalid("cbc can't authenticate data"); |
||||
|
if (128 !== sjcl.bitArray.bitLength(c)) |
||||
|
throw new sjcl.exception.invalid("cbc iv must be 128 bits"); |
||||
|
var e = sjcl.bitArray, f = e.B, g = e.bitLength(b), h = 0, k = []; |
||||
|
if (g & 7) |
||||
|
throw new sjcl.exception.invalid("pkcs#5 padding only works for multiples of a byte"); |
||||
|
for (d = 0; h + 128 <= g; d += 4, h += 128) |
||||
|
c = a.encrypt(f(c, b.slice(d, d + 4))), k.splice(d, 0, c[0], c[1], c[2], c[3]); |
||||
|
g = 0x1010101 * (16 - (g >> 3 & 15)); |
||||
|
c = a.encrypt(f(c, e.concat(b, [g, g, g, g]).slice(d, d + 4))); |
||||
|
k.splice(d, 0, c[0], c[1], c[2], c[3]); |
||||
|
return k; |
||||
|
}, decrypt: function (a, b, c, d) { |
||||
|
if (d && d.length) |
||||
|
throw new sjcl.exception.invalid("cbc can't authenticate data"); |
||||
|
if (128 !== sjcl.bitArray.bitLength(c)) |
||||
|
throw new sjcl.exception.invalid("cbc iv must be 128 bits"); |
||||
|
if (sjcl.bitArray.bitLength(b) & 127 || !b.length) |
||||
|
throw new sjcl.exception.corrupt("cbc ciphertext must be a positive multiple of the block size"); |
||||
|
var e = sjcl.bitArray, f = e.B, g, h = []; |
||||
|
for (d = 0; d < b.length; d += 4) |
||||
|
g = b.slice(d, d + 4), c = f(c, a.decrypt(g)), h.splice(d, 0, c[0], c[1], c[2], c[3]), c = g; |
||||
|
g = h[d - 1] & 255; |
||||
|
if (0 === g || 16 < g) |
||||
|
throw new sjcl.exception.corrupt("pkcs#5 padding corrupt"); |
||||
|
c = 0x1010101 * g; |
||||
|
if (!e.equal(e.bitSlice([c, c, c, c], 0, 8 * g), e.bitSlice(h, 32 * h.length - 8 * g, 32 * h.length))) |
||||
|
throw new sjcl.exception.corrupt("pkcs#5 padding corrupt"); |
||||
|
return e.bitSlice(h, 0, 32 * h.length - 8 * g); |
||||
|
} }; |
||||
|
}; |
||||
|
sjcl.misc.hmac = function (a, b) { this.W = b = b || sjcl.hash.sha256; var c = [[], []], d, e = b.prototype.blockSize / 32; this.A = [new b, new b]; a.length > e && (a = b.hash(a)); for (d = 0; d < e; d++) |
||||
|
c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828; this.A[0].update(c[0]); this.A[1].update(c[1]); this.P = new b(this.A[0]); }; |
||||
|
sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (a) { if (this.Z) |
||||
|
throw new sjcl.exception.invalid("encrypt on already updated hmac called!"); this.update(a); return this.digest(a); }; |
||||
|
sjcl.misc.hmac.prototype.reset = function () { this.P = new this.W(this.A[0]); this.Z = !1; }; |
||||
|
sjcl.misc.hmac.prototype.update = function (a) { this.Z = !0; this.P.update(a); }; |
||||
|
sjcl.misc.hmac.prototype.digest = function () { var a = this.P.finalize(), a = (new this.W(this.A[1])).update(a).finalize(); this.reset(); return a; }; |
||||
|
sjcl.misc.pbkdf2 = function (a, b, c, d, e) { c = c || 1E4; if (0 > d || 0 > c) |
||||
|
throw new sjcl.exception.invalid("invalid params to pbkdf2"); "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a)); "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b)); e = e || sjcl.misc.hmac; a = new e(a); var f, g, h, k, n = [], l = sjcl.bitArray; for (k = 1; 32 * n.length < (d || 1); k++) { |
||||
|
e = f = a.encrypt(l.concat(b, [k])); |
||||
|
for (g = 1; g < c; g++) |
||||
|
for (f = a.encrypt(f), h = 0; h < f.length; h++) |
||||
|
e[h] ^= f[h]; |
||||
|
n = n.concat(e); |
||||
|
} d && (n = l.clamp(n, d)); return n; }; |
||||
|
sjcl.prng = function (a) { this.h = [new sjcl.hash.sha256]; this.o = [0]; this.O = 0; this.G = {}; this.M = 0; this.T = {}; this.X = this.i = this.s = this.fa = 0; this.b = [0, 0, 0, 0, 0, 0, 0, 0]; this.m = [0, 0, 0, 0]; this.K = void 0; this.L = a; this.C = !1; this.J = { progress: {}, seeded: {} }; this.w = this.ea = 0; this.H = 1; this.I = 2; this.aa = 0x10000; this.R = [0, 48, 64, 96, 128, 192, 0x100, 384, 512, 768, 1024]; this.ba = 3E4; this.$ = 80; }; |
||||
|
sjcl.prng.prototype = { randomWords: function (a, b) { |
||||
|
var c = [], d; |
||||
|
d = this.isReady(b); |
||||
|
var e; |
||||
|
if (d === this.w) |
||||
|
throw new sjcl.exception.notReady("generator isn't seeded"); |
||||
|
if (d & this.I) { |
||||
|
d = !(d & this.H); |
||||
|
e = []; |
||||
|
var f = 0, g; |
||||
|
this.X = e[0] = (new Date).valueOf() + this.ba; |
||||
|
for (g = 0; 16 > g; g++) |
||||
|
e.push(0x100000000 * Math.random() | 0); |
||||
|
for (g = 0; g < this.h.length && (e = e.concat(this.h[g].finalize()), f += this.o[g], this.o[g] = 0, d || !(this.O & 1 << g)); g++) |
||||
|
; |
||||
|
this.O >= 1 << this.h.length && (this.h.push(new sjcl.hash.sha256), this.o.push(0)); |
||||
|
this.i -= f; |
||||
|
f > this.s && (this.s = |
||||
|
f); |
||||
|
this.O++; |
||||
|
this.b = sjcl.hash.sha256.hash(this.b.concat(e)); |
||||
|
this.K = new sjcl.cipher.aes(this.b); |
||||
|
for (d = 0; 4 > d && (this.m[d] = this.m[d] + 1 | 0, !this.m[d]); d++) |
||||
|
; |
||||
|
} |
||||
|
for (d = 0; d < a; d += 4) |
||||
|
0 === (d + 1) % this.aa && t(this), e = y(this), c.push(e[0], e[1], e[2], e[3]); |
||||
|
t(this); |
||||
|
return c.slice(0, a); |
||||
|
}, setDefaultParanoia: function (a, b) { if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) |
||||
|
throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing"); this.L = a; }, addEntropy: function (a, b, c) { |
||||
|
c = c || "user"; |
||||
|
var d, e, f = (new Date).valueOf(), g = this.G[c], h = this.isReady(), k = 0; |
||||
|
d = this.T[c]; |
||||
|
void 0 === d && (d = this.T[c] = this.fa++); |
||||
|
void 0 === g && (g = this.G[c] = 0); |
||||
|
this.G[c] = (this.G[c] + 1) % this.h.length; |
||||
|
switch (typeof a) { |
||||
|
case "number": |
||||
|
void 0 === b && (b = 1); |
||||
|
this.h[g].update([d, this.M++, 1, b, f, 1, a | 0]); |
||||
|
break; |
||||
|
case "object": |
||||
|
c = Object.prototype.toString.call(a); |
||||
|
if ("[object Uint32Array]" === c) { |
||||
|
e = []; |
||||
|
for (c = 0; c < a.length; c++) |
||||
|
e.push(a[c]); |
||||
|
a = e; |
||||
|
} |
||||
|
else |
||||
|
for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) |
||||
|
"number" !== typeof a[c] && |
||||
|
(k = 1); |
||||
|
if (!k) { |
||||
|
if (void 0 === b) |
||||
|
for (c = b = 0; c < a.length; c++) |
||||
|
for (e = a[c]; 0 < e;) |
||||
|
b++, e = e >>> 1; |
||||
|
this.h[g].update([d, this.M++, 2, b, f, a.length].concat(a)); |
||||
|
} |
||||
|
break; |
||||
|
case "string": |
||||
|
void 0 === b && (b = a.length); |
||||
|
this.h[g].update([d, this.M++, 3, b, f, a.length]); |
||||
|
this.h[g].update(a); |
||||
|
break; |
||||
|
default: k = 1; |
||||
|
} |
||||
|
if (k) |
||||
|
throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"); |
||||
|
this.o[g] += b; |
||||
|
this.i += b; |
||||
|
h === this.w && (this.isReady() !== this.w && z("seeded", Math.max(this.s, this.i)), z("progress", this.getProgress())); |
||||
|
}, |
||||
|
isReady: function (a) { a = this.R[void 0 !== a ? a : this.L]; return this.s && this.s >= a ? this.o[0] > this.$ && (new Date).valueOf() > this.X ? this.I | this.H : this.H : this.i >= a ? this.I | this.w : this.w; }, getProgress: function (a) { a = this.R[a ? a : this.L]; return this.s >= a ? 1 : this.i > a ? 1 : this.i / a; }, startCollectors: function () { |
||||
|
if (!this.C) { |
||||
|
this.a = { loadTimeCollector: A(this, this.ja), mouseCollector: A(this, this.la), keyboardCollector: A(this, this.ia), accelerometerCollector: A(this, this.ca), touchCollector: A(this, this.na) }; |
||||
|
if (window.addEventListener) |
||||
|
window.addEventListener("load", this.a.loadTimeCollector, !1), window.addEventListener("mousemove", this.a.mouseCollector, !1), window.addEventListener("keypress", this.a.keyboardCollector, !1), window.addEventListener("devicemotion", this.a.accelerometerCollector, !1), window.addEventListener("touchmove", this.a.touchCollector, !1); |
||||
|
else if (document.attachEvent) |
||||
|
document.attachEvent("onload", this.a.loadTimeCollector), document.attachEvent("onmousemove", this.a.mouseCollector), document.attachEvent("keypress", this.a.keyboardCollector); |
||||
|
else |
||||
|
throw new sjcl.exception.bug("can't attach event"); |
||||
|
this.C = !0; |
||||
|
} |
||||
|
}, stopCollectors: function () { |
||||
|
this.C && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, !1), window.removeEventListener("mousemove", this.a.mouseCollector, !1), window.removeEventListener("keypress", this.a.keyboardCollector, !1), window.removeEventListener("devicemotion", this.a.accelerometerCollector, !1), window.removeEventListener("touchmove", this.a.touchCollector, !1)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent("onmousemove", this.a.mouseCollector), document.detachEvent("keypress", this.a.keyboardCollector)), this.C = !1); |
||||
|
}, addEventListener: function (a, b) { this.J[a][this.ea++] = b; }, removeEventListener: function (a, b) { var c, d, e = this.J[a], f = []; for (d in e) |
||||
|
e.hasOwnProperty(d) && e[d] === b && f.push(d); for (c = 0; c < f.length; c++) |
||||
|
d = f[c], delete e[d]; }, ia: function () { B(this, 1); }, la: function (a) { var b, c; try { |
||||
|
b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0; |
||||
|
} |
||||
|
catch (d) { |
||||
|
c = b = 0; |
||||
|
} 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse"); B(this, 0); }, na: function (a) { |
||||
|
a = |
||||
|
a.touches[0] || a.changedTouches[0]; |
||||
|
this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch"); |
||||
|
B(this, 0); |
||||
|
}, ja: function () { B(this, 2); }, ca: function (a) { a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z; if (window.orientation) { |
||||
|
var b = window.orientation; |
||||
|
"number" === typeof b && this.addEntropy(b, 1, "accelerometer"); |
||||
|
} a && this.addEntropy(a, 2, "accelerometer"); B(this, 0); } }; |
||||
|
function z(a, b) { var c, d = sjcl.random.J[a], e = []; for (c in d) |
||||
|
d.hasOwnProperty(c) && e.push(d[c]); for (c = 0; c < e.length; c++) |
||||
|
e[c](b); } |
||||
|
function B(a, b) { "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy((new Date).valueOf(), b, "loadtime"); } |
||||
|
function t(a) { a.b = y(a).concat(y(a)); a.K = new sjcl.cipher.aes(a.b); } |
||||
|
function y(a) { for (var b = 0; 4 > b && (a.m[b] = a.m[b] + 1 | 0, !a.m[b]); b++) |
||||
|
; return a.K.encrypt(a.m); } |
||||
|
function A(a, b) { return function () { b.apply(a, arguments); }; } |
||||
|
sjcl.random = new sjcl.prng(6); |
||||
|
a: try { |
||||
|
var C, D, E, F; |
||||
|
if (F = "undefined" !== typeof module && module.exports) { |
||||
|
var G; |
||||
|
try { |
||||
|
G = require("crypto"); |
||||
|
} |
||||
|
catch (a) { |
||||
|
G = null; |
||||
|
} |
||||
|
F = D = G; |
||||
|
} |
||||
|
if (F && D.randomBytes) |
||||
|
C = D.randomBytes(128), C = new Uint32Array((new Uint8Array(C)).buffer), sjcl.random.addEntropy(C, 1024, "crypto['randomBytes']"); |
||||
|
else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) { |
||||
|
E = new Uint32Array(32); |
||||
|
if (window.crypto && window.crypto.getRandomValues) |
||||
|
window.crypto.getRandomValues(E); |
||||
|
else if (window.msCrypto && window.msCrypto.getRandomValues) |
||||
|
window.msCrypto.getRandomValues(E); |
||||
|
else |
||||
|
break a; |
||||
|
sjcl.random.addEntropy(E, 1024, "crypto['getRandomValues']"); |
||||
|
} |
||||
|
} |
||||
|
catch (a) { |
||||
|
"undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a)); |
||||
|
} |
||||
|
sjcl.json = { defaults: { v: 1, iter: 1E4, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" }, ha: function (a, b, c, d) { |
||||
|
c = c || {}; |
||||
|
d = d || {}; |
||||
|
var e = sjcl.json, f = e.j({ iv: sjcl.random.randomWords(4, 0) }, e.defaults), g; |
||||
|
e.j(f, c); |
||||
|
c = f.adata; |
||||
|
"string" === typeof f.salt && (f.salt = sjcl.codec.base64.toBits(f.salt)); |
||||
|
"string" === typeof f.iv && (f.iv = sjcl.codec.base64.toBits(f.iv)); |
||||
|
if (!sjcl.mode[f.mode] || !sjcl.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 0x100 !== f.ks || 2 > f.iv.length || |
||||
|
4 < f.iv.length) |
||||
|
throw new sjcl.exception.invalid("json encrypt: invalid parameters"); |
||||
|
"string" === typeof a ? (g = sjcl.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32)); |
||||
|
"string" === typeof b && (b = sjcl.codec.utf8String.toBits(b)); |
||||
|
"string" === typeof c && (f.adata = c = sjcl.codec.utf8String.toBits(c)); |
||||
|
g = new sjcl.cipher[f.cipher](a); |
||||
|
e.j(d, f); |
||||
|
d.key = a; |
||||
|
f.ct = "ccm" === f.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && |
||||
|
b instanceof ArrayBuffer ? sjcl.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl.mode[f.mode].encrypt(g, b, f.iv, c, f.ts); |
||||
|
return f; |
||||
|
}, encrypt: function (a, b, c, d) { var e = sjcl.json, f = e.ha.apply(e, arguments); return e.encode(f); }, ga: function (a, b, c, d) { |
||||
|
c = c || {}; |
||||
|
d = d || {}; |
||||
|
var e = sjcl.json; |
||||
|
b = e.j(e.j(e.j({}, e.defaults), b), c, !0); |
||||
|
var f, g; |
||||
|
f = b.adata; |
||||
|
"string" === typeof b.salt && (b.salt = sjcl.codec.base64.toBits(b.salt)); |
||||
|
"string" === typeof b.iv && (b.iv = sjcl.codec.base64.toBits(b.iv)); |
||||
|
if (!sjcl.mode[b.mode] || !sjcl.cipher[b.cipher] || "string" === |
||||
|
typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 0x100 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) |
||||
|
throw new sjcl.exception.invalid("json decrypt: invalid parameters"); |
||||
|
"string" === typeof a ? (g = sjcl.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.secretKey && (a = a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)); |
||||
|
"string" === typeof f && (f = sjcl.codec.utf8String.toBits(f)); |
||||
|
g = new sjcl.cipher[b.cipher](a); |
||||
|
f = "ccm" === |
||||
|
b.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts); |
||||
|
e.j(d, b); |
||||
|
d.key = a; |
||||
|
return 1 === c.raw ? f : sjcl.codec.utf8String.fromBits(f); |
||||
|
}, decrypt: function (a, b, c, d) { var e = sjcl.json; return e.ga(a, e.decode(b), c, d); }, encode: function (a) { |
||||
|
var b, c = "{", d = ""; |
||||
|
for (b in a) |
||||
|
if (a.hasOwnProperty(b)) { |
||||
|
if (!b.match(/^[a-z0-9]+$/i)) |
||||
|
throw new sjcl.exception.invalid("json encode: invalid property name"); |
||||
|
c += d + '"' + |
||||
|
b + '":'; |
||||
|
d = ","; |
||||
|
switch (typeof a[b]) { |
||||
|
case "number": |
||||
|
case "boolean": |
||||
|
c += a[b]; |
||||
|
break; |
||||
|
case "string": |
||||
|
c += '"' + escape(a[b]) + '"'; |
||||
|
break; |
||||
|
case "object": |
||||
|
c += '"' + sjcl.codec.base64.fromBits(a[b], 0) + '"'; |
||||
|
break; |
||||
|
default: throw new sjcl.exception.bug("json encode: unsupported type"); |
||||
|
} |
||||
|
} |
||||
|
return c + "}"; |
||||
|
}, decode: function (a) { |
||||
|
a = a.replace(/\s/g, ""); |
||||
|
if (!a.match(/^\{.*\}$/)) |
||||
|
throw new sjcl.exception.invalid("json decode: this isn't json!"); |
||||
|
a = a.replace(/^\{|\}$/g, "").split(/,/); |
||||
|
var b = {}, c, d; |
||||
|
for (c = 0; c < a.length; c++) { |
||||
|
if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) |
||||
|
throw new sjcl.exception.invalid("json decode: this isn't json!"); |
||||
|
null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]); |
||||
|
} |
||||
|
return b; |
||||
|
}, j: function (a, b, c) { void 0 === a && (a = {}); if (void 0 === b) |
||||
|
return a; for (var d in b) |
||||
|
if (b.hasOwnProperty(d)) { |
||||
|
if (c && void 0 !== a[d] && a[d] !== b[d]) |
||||
|
throw new sjcl.exception.invalid("required parameter overridden"); |
||||
|
a[d] = b[d]; |
||||
|
} return a; }, pa: function (a, b) { var c = {}, d; for (d in a) |
||||
|
a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]); return c; }, oa: function (a, b) { var c = {}, d; for (d = 0; d < b.length; d++) |
||||
|
void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]); return c; } }; |
||||
|
sjcl.encrypt = sjcl.json.encrypt; |
||||
|
sjcl.decrypt = sjcl.json.decrypt; |
||||
|
sjcl.misc.ma = {}; |
||||
|
sjcl.misc.cachedPbkdf2 = function (a, b) { var c = sjcl.misc.ma, d; b = b || {}; d = b.iter || 1E3; c = c[a] = c[a] || {}; d = c[d] = c[d] || { firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl.random.randomWords(2, 0) }; c = void 0 === b.salt ? d.firstSalt : b.salt; d[c] = d[c] || sjcl.misc.pbkdf2(a, c, b.iter); return { key: d[c].slice(0), salt: c.slice(0) }; }; |
||||
|
"undefined" !== typeof module && module.exports && (module.exports = sjcl); |
||||
|
"function" === typeof define && define([], function () { return sjcl; }); |
||||
|
//# sourceMappingURL=sjcl.js.map
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@ |
|||||
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../api/utils/setup.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA2C;AAC3C,sCAA2C;AAC3C,iDAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,gDAAwC;AACxC,8CAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,MAAM,aAAa,GAAG,GAAS,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IACxC,MAAM,UAAU,EAAE,CAAA;IAClB,IAAI;QACF,MAAM,kBAAS,CAAC,IAAI,EAAE,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;KACpC;IAAC,OAAM,CAAC,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAC,CAAC,CAAC,CAAA;KAChC;IACD,MAAM,OAAO,EAAE,CAAA;IACf,iBAAiB,EAAE,CAAA;IACnB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AACnC,CAAC,CAAA,CAAA;AAgEQ,sCAAa;AA9DtB,SAAe,UAAU;;QAC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AC,OAAO,KAAK,KAAK,kBAAQ,IAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC3E,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;QAC1C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChB,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAC,EAAC,IAAI,EAAC,UAAU,EAAC,EAAE,UAAU,GAAG,EAAE,GAAG;YACvD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA"} |
@ -0,0 +1,136 @@ |
|||||
|
"use strict"; |
||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
||||
|
return new (P || (P = Promise))(function (resolve, reject) { |
||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
||||
|
}); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const grpc = require("grpc"); |
||||
|
const lightning_1 = require("./lightning"); |
||||
|
const path = require("path"); |
||||
|
const ByteBuffer = require("bytebuffer"); |
||||
|
// var protoLoader = require('@grpc/proto-loader')
|
||||
|
const env = process.env.NODE_ENV || 'development'; |
||||
|
const config = require(path.join(__dirname, '../../config/app.json'))[env]; |
||||
|
var signerClient = null; |
||||
|
exports.loadSigner = () => { |
||||
|
console.log("LOAD SIGNER RRRRRR", signerClient ? true : false); |
||||
|
if (signerClient) { |
||||
|
return signerClient; |
||||
|
} |
||||
|
else { |
||||
|
console.log("LOAD SIGNER AGAIN!!!!"); |
||||
|
try { |
||||
|
var credentials = lightning_1.loadCredentials(); |
||||
|
var lnrpcDescriptor = grpc.load("signer.proto"); |
||||
|
var signer = lnrpcDescriptor.signrpc; |
||||
|
signerClient = new signer.Signer(config.node_ip + ':' + config.lnd_port, credentials); |
||||
|
console.log("SIGNER CLIENT", signerClient); |
||||
|
return signerClient; |
||||
|
} |
||||
|
catch (e) { |
||||
|
throw e; |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
exports.signMessage = (msg) => { |
||||
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () { |
||||
|
let signer = yield exports.loadSigner(); |
||||
|
try { |
||||
|
const options = { |
||||
|
msg: ByteBuffer.fromHex(msg), |
||||
|
key_loc: { key_family: 6, key_index: 0 }, |
||||
|
}; |
||||
|
signer.signMessage(options, function (err, sig) { |
||||
|
if (err || !sig.signature) { |
||||
|
reject(err); |
||||
|
} |
||||
|
else { |
||||
|
resolve(sig.signature); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
catch (e) { |
||||
|
reject(e); |
||||
|
} |
||||
|
})); |
||||
|
}; |
||||
|
exports.signBuffer = (msg) => { |
||||
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () { |
||||
|
let signer = yield exports.loadSigner(); |
||||
|
try { |
||||
|
const options = { msg }; |
||||
|
signer.signMessage(options, function (err, sig) { |
||||
|
if (err || !sig.signature) { |
||||
|
reject(err); |
||||
|
} |
||||
|
else { |
||||
|
resolve(sig.signature); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
catch (e) { |
||||
|
reject(e); |
||||
|
} |
||||
|
})); |
||||
|
}; |
||||
|
function verifyMessage(msg, sig, pubkey) { |
||||
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { |
||||
|
let signer = yield exports.loadSigner(); |
||||
|
try { |
||||
|
const options = { |
||||
|
msg: ByteBuffer.fromHex(msg), |
||||
|
signature: sig, |
||||
|
pubkey: ByteBuffer.fromHex(pubkey), |
||||
|
}; |
||||
|
signer.verifyMessage(options, function (err, res) { |
||||
|
if (err) { |
||||
|
reject(err); |
||||
|
} |
||||
|
else { |
||||
|
resolve(res); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
catch (e) { |
||||
|
reject(e); |
||||
|
} |
||||
|
})); |
||||
|
} |
||||
|
function signAscii(ascii) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
try { |
||||
|
const sig = yield exports.signMessage(ascii_to_hexa(ascii)); |
||||
|
return sig; |
||||
|
} |
||||
|
catch (e) { |
||||
|
throw e; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.signAscii = signAscii; |
||||
|
function verifyAscii(ascii, sig, pubkey) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
try { |
||||
|
const r = yield verifyMessage(ascii_to_hexa(ascii), sig, pubkey); |
||||
|
return r; |
||||
|
} |
||||
|
catch (e) { |
||||
|
throw e; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.verifyAscii = verifyAscii; |
||||
|
function ascii_to_hexa(str) { |
||||
|
var arr1 = []; |
||||
|
for (var n = 0, l = str.length; n < l; n++) { |
||||
|
var hex = Number(str.charCodeAt(n)).toString(16); |
||||
|
arr1.push(hex); |
||||
|
} |
||||
|
return arr1.join(''); |
||||
|
} |
||||
|
//# sourceMappingURL=signer.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../api/utils/signer.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,6BAA4B;AAC5B,2CAA2C;AAC3C,6BAA4B;AAC5B,yCAAwC;AAExC,kDAAkD;AAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzE,IAAI,YAAY,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&& this.__awaiter) || function (thisArg, _arguments, P, generator) { |
||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
||||
|
return new (P || (P = Promise))(function (resolve, reject) { |
||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
||||
|
}); |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const moment = require("moment"); |
||||
|
const zbase32 = require("./zbase32"); |
||||
|
const LND = require("./lightning"); |
||||
|
const path = require("path"); |
||||
|
const mqtt = require("mqtt"); |
||||
|
const fetch = require("node-fetch"); |
||||
|
const env = process.env.NODE_ENV || 'development'; |
||||
|
const config = require(path.join(__dirname, '../../config/app.json'))[env]; |
||||
|
let client; |
||||
|
function connect(onMessage) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
try { |
||||
|
const info = yield LND.getInfo(); |
||||
|
function reconnect() { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
client = null; |
||||
|
const pwd = yield genSignedTimestamp(); |
||||
|
console.log('[tribes] try to connect:', `tls://${config.tribes_host}:8883`); |
||||
|
client = mqtt.connect(`tls://${config.tribes_host}:8883`, { |
||||
|
username: info.identity_pubkey, |
||||
|
password: pwd, |
||||
|
reconnectPeriod: 0, |
||||
|
}); |
||||
|
client.on('connect', function () { |
||||
|
console.log("[tribes] connected!"); |
||||
|
client.subscribe(`${info.identity_pubkey}/#`); |
||||
|
}); |
||||
|
client.on('close', function (e) { |
||||
|
setTimeout(() => reconnect(), 2000); |
||||
|
}); |
||||
|
client.on('error', function (e) { |
||||
|
console.log('[tribes] error: ', e.message || e); |
||||
|
}); |
||||
|
client.on('message', function (topic, message) { |
||||
|
if (onMessage) |
||||
|
onMessage(topic, message); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
reconnect(); |
||||
|
} |
||||
|
catch (e) { |
||||
|
console.log("TRIBES ERROR", e); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.connect = connect; |
||||
|
function subscribe(topic) { |
||||
|
if (client) |
||||
|
client.subscribe(topic); |
||||
|
} |
||||
|
exports.subscribe = subscribe; |
||||
|
function publish(topic, msg) { |
||||
|
if (client) |
||||
|
client.publish(topic, msg); |
||||
|
} |
||||
|
exports.publish = publish; |
||||
|
function declare({ uuid, name, description, tags, img, groupKey, host, pricePerMessage, priceToJoin, ownerAlias, ownerPubkey }) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const r = yield fetch('https://' + host + '/tribes', { |
||||
|
method: 'POST', |
||||
|
body: JSON.stringify({ |
||||
|
uuid, groupKey, |
||||
|
name, description, tags, img: img || '', |
||||
|
pricePerMessage: pricePerMessage || 0, |
||||
|
priceToJoin: priceToJoin || 0, |
||||
|
ownerAlias, ownerPubkey, |
||||
|
}), |
||||
|
headers: { 'Content-Type': 'application/json' } |
||||
|
}); |
||||
|
const j = yield r.json(); |
||||
|
console.log(j); |
||||
|
}); |
||||
|
} |
||||
|
exports.declare = declare; |
||||
|
function genSignedTimestamp() { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const now = moment().unix(); |
||||
|
const tsBytes = Buffer.from(now.toString(16), 'hex'); |
||||
|
const sig = yield LND.signBuffer(tsBytes); |
||||
|
const sigBytes = zbase32.decode(sig); |
||||
|
const totalLength = tsBytes.length + sigBytes.length; |
||||
|
const buf = Buffer.concat([tsBytes, sigBytes], totalLength); |
||||
|
return urlBase64(buf); |
||||
|
}); |
||||
|
} |
||||
|
exports.genSignedTimestamp = genSignedTimestamp; |
||||
|
function verifySignedTimestamp(stsBase64) { |
||||
|
return __awaiter(this, void 0, void 0, function* () { |
||||
|
const stsBuf = Buffer.from(stsBase64, 'base64'); |
||||
|
const sig = stsBuf.subarray(4, 92); |
||||
|
const sigZbase32 = zbase32.encode(sig); |
||||
|
const r = yield LND.verifyBytes(stsBuf.subarray(0, 4), sigZbase32); // sig needs to be zbase32 :(
|
||||
|
if (r.valid) { |
||||
|
return r.pubkey; |
||||
|
} |
||||
|
else { |
||||
|
return false; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
exports.verifySignedTimestamp = verifySignedTimestamp; |
||||
|
function getHost() { |
||||
|
return config.tribes_host || ''; |
||||
|
} |
||||
|
exports.getHost = getHost; |
||||
|
function urlBase64(buf) { |
||||
|
return buf.toString('base64').replace(/\//g, '_').replace(/\+/g, '-'); |
||||
|
} |
||||
|
//# sourceMappingURL=tribes.js.map
|
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"tribes.js","sourceRoot":"","sources":["../../../api/utils/tribes.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,iCAAgC;AAChC,qCAAoC;AACpC,mCAAkC;AAClC,6BAA4B;AAC5B,6BAA4B;AAC5B,oCAAmC;AAEnC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAA;AACjD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzE,IAAI,MAAU,CAAA;AAEd,SAAsB,OAAO,CAAC,SAAS;;QACnC,IAAG;YACC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,EAAE,CAAA;YAEhC,SAAe,SAAS;;oBACpB,MAAM,GAAG,IAAI,CAAA;oBACb,MAAM,GAAG,GAAG,MAAM,kBAAkB,EAAE,CAAA;oBACtC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAC,SAAS,MAAM,CAAC,WAAW,OAAO,CAAC,CAAA;oBAC1E,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,MAAM,CAAC,WAAW,OAAO,EAAC;wBACrD,QA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