Browse Source

Merge pull request #49 from stakwork/escrow

Escrow
hosting-provider v0.9.15
Evan Feenstra 5 years ago
committed by GitHub
parent
commit
635de719a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      api/controllers/chatTribes.ts
  2. 6
      api/controllers/chats.ts
  3. 3
      api/controllers/confirmations.ts
  4. 40
      api/controllers/contacts.ts
  5. 4
      api/controllers/index.ts
  6. 3
      api/controllers/messages.ts
  7. 46
      api/crypto/rsa.ts
  8. 4
      api/helpers.ts
  9. 3
      api/models/index.ts
  10. 6
      api/models/ts/chat.ts
  11. 29
      api/models/ts/timer.ts
  12. 10
      api/network/receive.ts
  13. 21
      api/network/send.ts
  14. 1
      api/utils/lightning.ts
  15. 38
      api/utils/setup.ts
  16. 44
      api/utils/timers.ts
  17. 8
      api/utils/tribes.ts
  18. 17
      dist/api/controllers/chatTribes.js
  19. 2
      dist/api/controllers/chatTribes.js.map
  20. 6
      dist/api/controllers/chats.js
  21. 2
      dist/api/controllers/chats.js.map
  22. 4
      dist/api/controllers/confirmations.js
  23. 2
      dist/api/controllers/confirmations.js.map
  24. 35
      dist/api/controllers/contacts.js
  25. 2
      dist/api/controllers/contacts.js.map
  26. 2
      dist/api/controllers/index.js
  27. 2
      dist/api/controllers/index.js.map
  28. 3
      dist/api/controllers/messages.js
  29. 2
      dist/api/controllers/messages.js.map
  30. 44
      dist/api/crypto/rsa.js
  31. 2
      dist/api/crypto/rsa.js.map
  32. 4
      dist/api/helpers.js
  33. 2
      dist/api/helpers.js.map
  34. 3
      dist/api/models/index.js
  35. 2
      dist/api/models/index.js.map
  36. 8
      dist/api/models/ts/chat.js
  37. 2
      dist/api/models/ts/chat.js.map
  38. 48
      dist/api/models/ts/timer.js
  39. 1
      dist/api/models/ts/timer.js.map
  40. 10
      dist/api/network/receive.js
  41. 2
      dist/api/network/receive.js.map
  42. 21
      dist/api/network/send.js
  43. 2
      dist/api/network/send.js.map
  44. 1
      dist/api/utils/lightning.js
  45. 2
      dist/api/utils/lightning.js.map
  46. 40
      dist/api/utils/setup.js
  47. 2
      dist/api/utils/setup.js.map
  48. 67
      dist/api/utils/timers.js
  49. 1
      dist/api/utils/timers.js.map
  50. 8
      dist/api/utils/tribes.js
  51. 2
      dist/api/utils/tribes.js.map

18
api/controllers/chatTribes.ts

@ -99,6 +99,8 @@ async function editTribe(req, res) {
is_listed,
price_per_message,
price_to_join,
escrow_amount,
escrow_millis,
img,
description,
tags,
@ -123,6 +125,8 @@ async function editTribe(req, res) {
host: chat.host,
price_per_message: price_per_message||0,
price_to_join: price_to_join||0,
escrow_amount: escrow_amount||0,
escrow_millis: escrow_millis||0,
description,
tags,
img,
@ -138,7 +142,9 @@ async function editTribe(req, res) {
photoUrl: img||'',
name: name,
pricePerMessage: price_per_message||0,
priceToJoin: price_to_join||0
priceToJoin: price_to_join||0,
escrowAmount: escrow_amount||0,
escrowMillis: escrow_millis||0,
})
success(res, jsonUtils.chatToJson(chat))
} else {
@ -190,12 +196,15 @@ async function replayChatHistory(chat, contact) {
msg = await decryptMessage(msg, chat)
const data = await personalizeMessage(msg, contact, true)
const mqttTopic = `${contact.publicKey}/${chat.uuid}`
await network.signAndSend({data}, owner.publicKey, mqttTopic)
await network.signAndSend({
data,
dest: contact.publicKey,
}, mqttTopic)
})
}
async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join): Promise<{[k:string]:any}> {
async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis): Promise<{[k:string]:any}> {
let date = new Date()
date.setMilliseconds(0)
if (!(owner && contactIds && Array.isArray(contactIds))) {
@ -220,6 +229,8 @@ async function createTribeChatParams(owner, contactIds, name, img, price_per_mes
host: tribes.getHost(),
pricePerMessage: price_per_message||0,
priceToJoin: price_to_join||0,
escrowMillis: escrow_millis||0,
escrowAmount: escrow_amount||0,
}
}
@ -234,3 +245,4 @@ async function asyncForEach(array, callback) {
await callback(array[index], index, array);
}
}

6
api/controllers/chats.ts

@ -46,6 +46,8 @@ async function createGroupChat(req, res) {
is_listed,
price_per_message,
price_to_join,
escrow_amount,
escrow_millis,
img,
description,
tags,
@ -69,7 +71,7 @@ async function createGroupChat(req, res) {
let chatParams:any = null
let okToCreate = true
if(is_tribe){
chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join)
chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis)
if(is_listed && chatParams.uuid){
// publish to tribe server
try {
@ -80,6 +82,8 @@ async function createGroupChat(req, res) {
group_key: chatParams.groupKey,
price_per_message: price_per_message||0,
price_to_join: price_to_join||0,
escrow_amount: escrow_amount||0,
escrow_millis: escrow_millis||0,
description, tags, img,
owner_pubkey: owner.publicKey,
owner_alias: owner.alias,

3
api/controllers/confirmations.ts

@ -8,6 +8,7 @@ import * as path from 'path'
const constants = require(path.join(__dirname,'../../config/constants.json'))
export function sendConfirmation({ chat, sender, msg_id }) {
if(!msg_id) return
network.sendMessage({
chat,
sender,
@ -17,7 +18,7 @@ export function sendConfirmation({ chat, sender, msg_id }) {
}
export async function receiveConfirmation(payload) {
console.log('=> received confirmation')
console.log('=> received confirmation', (payload.message&&payload.message.id))
const dat = payload.content || payload
const chat_uuid = dat.chat.uuid

40
api/controllers/contacts.ts

@ -72,14 +72,22 @@ const updateContact = async (req, res) => {
let attrs = extractAttrs(req.body)
const contact = await models.Contact.findOne({ where: { id: req.params.id }})
let shouldUpdateContactKey = (contact.isOwner && contact.contactKey == null && attrs["contact_key"] != null)
let shouldSendUpdatedSelf = (
contact.isOwner && (
(contact.contactKey == null && attrs["contact_key"] != null) || // CREATE CONTACT KEY!
attrs["contact_key"]==null // OR NO NEW CONTACT KEY
)
)
// update self
const owner = await contact.update(jsonUtils.jsonToContact(attrs))
success(res, jsonUtils.contactToJson(owner))
if (!shouldUpdateContactKey) return
if (!shouldSendUpdatedSelf) return
const contactIds = await models.Contact.findAll({where:{deleted:false}}).map(c => c.id)
// send updated owner info to others
const contactIds = await models.Contact.findAll({where:{deleted:false}})
.filter(c=> !c.fromGroup && c.id!==1 && c.publicKey).map(c=> c.id)
if (contactIds.length == 0) return
helpers.sendContactKeys({
@ -187,8 +195,8 @@ const deleteContact = async (req, res) => {
success(res, {})
}
const receiveConfirmContactKey = async (payload) => {
console.log(`=> confirm contact key for ${payload.sender&&payload.sender.pub_key}`, JSON.stringify(payload))
const receiveContactKey = async (payload) => {
console.log('=> received contact key', JSON.stringify(payload))
const dat = payload.content || payload
const sender_pub_key = dat.sender.pub_key
@ -196,7 +204,9 @@ const receiveConfirmContactKey = async (payload) => {
const sender_alias = dat.sender.alias || 'Unknown'
const sender_photo_url = dat.sender.photo_url
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
if (sender_contact_key && sender) {
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias
@ -208,10 +218,16 @@ const receiveConfirmContactKey = async (payload) => {
response: jsonUtils.contactToJson(sender)
})
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
})
}
const receiveContactKey = async (payload) => {
console.log('=> received contact key', JSON.stringify(payload))
const receiveConfirmContactKey = async (payload) => {
console.log(`=> confirm contact key for ${payload.sender&&payload.sender.pub_key}`, JSON.stringify(payload))
const dat = payload.content || payload
const sender_pub_key = dat.sender.pub_key
@ -219,9 +235,7 @@ const receiveContactKey = async (payload) => {
const sender_alias = dat.sender.alias || 'Unknown'
const sender_photo_url = dat.sender.photo_url
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
if (sender_contact_key && sender) {
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias
@ -233,12 +247,6 @@ const receiveContactKey = async (payload) => {
response: jsonUtils.contactToJson(sender)
})
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
})
}
const extractAttrs = body => {

4
api/controllers/index.ts

@ -13,6 +13,8 @@ import * as uploads from './uploads'
import * as confirmations from './confirmations'
import {checkTag} from '../utils/gitinfo'
import * as path from 'path'
import * as timers from '../utils/timers'
const env = process.env.NODE_ENV || 'development';
console.log("=> env:",env)
@ -29,6 +31,8 @@ async function set(app) {
console.log('=> could not auth with media server', e.message)
}
timers.reloadTimers()
app.get('/chats', chats.getChats)
app.post('/group', chats.createGroupChat)
app.post('/chats/:chat_id/:mute_unmute', chats.mute)

3
api/controllers/messages.ts

@ -183,7 +183,8 @@ const receiveMessage = async (payload) => {
updatedAt: date,
status: constants.statuses.received
}
if(chat_type===constants.chat_types.tribe) {
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {
msg.senderAlias = sender_alias
if(remote_content) msg.remoteMessageContent=remote_content
}

46
api/crypto/rsa.ts

@ -1,13 +1,23 @@
import * as crypto from "crypto";
const BLOCK_SIZE=256
const MAX_CHUNK_SIZE=BLOCK_SIZE-11 // 11 is the PCKS1 padding
export function encrypt(key, txt){
try{
const buf = Buffer.from(txt)
let finalBuf = Buffer.from([])
const n = Math.ceil(buf.length/MAX_CHUNK_SIZE)
const arr = Array(n).fill(0)
const pubc = cert.pub(key)
const buf = crypto.publicEncrypt({
key:pubc,
padding:crypto.constants.RSA_PKCS1_PADDING,
}, Buffer.from(txt,'utf-8'))
return buf.toString('base64')
arr.forEach((_,i)=>{
const f = crypto.publicEncrypt({
key:pubc,
padding:crypto.constants.RSA_PKCS1_PADDING,
}, buf.subarray(i*MAX_CHUNK_SIZE,i*MAX_CHUNK_SIZE+MAX_CHUNK_SIZE))
finalBuf = Buffer.concat([finalBuf,f])
})
return finalBuf.toString('base64')
} catch(e) {
return ''
}
@ -15,12 +25,19 @@ export function encrypt(key, txt){
export function decrypt(privateKey, enc){
try{
const buf = Buffer.from(enc, 'base64')
let finalDec = ''
const n = Math.ceil(buf.length/BLOCK_SIZE)
const arr = Array(n).fill(0)
const privc = cert.priv(privateKey)
const buf = crypto.privateDecrypt({
key:privc,
padding:crypto.constants.RSA_PKCS1_PADDING,
}, Buffer.from(enc,'base64'))
return buf.toString('utf-8')
arr.forEach((_,i)=>{
const b = crypto.privateDecrypt({
key:privc,
padding:crypto.constants.RSA_PKCS1_PADDING,
}, buf.subarray(i*BLOCK_SIZE,i*BLOCK_SIZE+BLOCK_SIZE))
finalDec += b.toString('utf-8')
})
return finalDec
} catch(e) {
return ''
}
@ -50,7 +67,7 @@ export function genKeys(): Promise<{[k:string]:string}>{
export function testRSA(){
crypto.generateKeyPair('rsa', {
modulusLength: 2048
}, (err, publicKey, priv)=>{
}, (err, publicKey, privateKey)=>{
const pubPEM = publicKey.export({
type:'pkcs1',format:'pem'
})
@ -59,8 +76,13 @@ export function testRSA(){
const msg = 'hi'
const enc = encrypt(pub, msg)
const privPEM = privateKey.export({
type:'pkcs1',format:'pem'
})
const priv = cert.unpriv(privPEM)
const dec = decrypt(priv, enc)
console.log("FINAL:",dec)
console.log("SUCESS:",msg===dec)
})
}

4
api/helpers.ts

@ -83,8 +83,8 @@ const performKeysendMessage = async ({ destination_key, amount, msg, success, fa
amt: Math.max(amount, 3)
}
try {
const r = await network.signAndSend(opts, sender.publicKey)
console.log("=> external keysend")
const r = await network.signAndSend(opts)
// console.log("=> keysend to new contact")
if (success) success(r)
} catch (e) {
console.log("MESSAGE ERROR", e)

3
api/models/index.ts

@ -7,6 +7,7 @@ import Message from './ts/message'
import Subscription from './ts/subscription'
import MediaKey from './ts/mediaKey'
import ChatMember from './ts/chatMember'
import Timer from './ts/timer'
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname,'../../config/config.json'))[env]
@ -14,7 +15,7 @@ const config = require(path.join(__dirname,'../../config/config.json'))[env]
const sequelize = new Sequelize({
...config,
logging: process.env.SQL_LOG==='true' ? console.log : false,
models: [Chat,Contact,Invite,Message,Subscription,MediaKey,ChatMember]
models: [Chat,Contact,Invite,Message,Subscription,MediaKey,ChatMember,Timer]
})
const models = sequelize.models

6
api/models/ts/chat.ts

@ -60,6 +60,12 @@ export default class Chat extends Model<Chat> {
@Column
pricePerMessage: number
@Column(DataType.BIGINT)
escrowAmount: number
@Column(DataType.BIGINT)
escrowMillis: number
@Column
ownerPubkey: string

29
api/models/ts/timer.ts

@ -0,0 +1,29 @@
import { Table, Column, Model, DataType } from 'sequelize-typescript';
@Table({tableName: 'sphinx_timers', underscored: true})
export default class Timer extends Model<Timer> {
@Column({
type: DataType.BIGINT,
primaryKey: true,
unique: true,
autoIncrement: true
})
id: number
@Column(DataType.BIGINT)
chatId: number
@Column(DataType.BIGINT)
msgId: number
@Column(DataType.BIGINT)
millis: number
@Column(DataType.BIGINT)
receiver: number
@Column(DataType.DECIMAL)
amount: number
}

10
api/network/receive.ts

@ -10,6 +10,7 @@ import {modifyPayloadAndSaveMediaKey,purchaseFromOriginalSender,sendFinalMemeIfF
// import {modifyPayloadAndSaveMediaKey} from './modify'
import {decryptMessage,encryptTribeBroadcast} from '../utils/msg'
import { Op } from 'sequelize'
import * as timers from '../utils/timers'
const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types
@ -53,6 +54,15 @@ async function onReceive(payload){
// CHECK PRICES
if(needsPricePerJoin) {
if(payload.message.amount<chat.pricePerMessage) doAction=false
if(chat.escrowAmount) {
timers.addTimer({ // pay them back
amount: chat.escrowAmount,
millis:chat.escrowMillis,
receiver: senderContact.id,
msgId: payload.message.id,
chatId: chat.id,
})
}
}
// check price to join
if(payload.type===msgtypes.group_join) {

21
api/network/send.ts

@ -10,8 +10,7 @@ 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
let msg = newmsg(type, chat, sender, message)
// console.log(type,message)
if(!(sender&&sender.publicKey)) {
@ -32,9 +31,9 @@ export async function sendMessage(params) {
let isTribeOwner = false
const chatUUID = chat.uuid
if(isTribe) {
if(type===constants.message_types.confirmation) {
return // dont send confs for tribe
}
// if(type===constants.message_types.confirmation) {
// return // dont send confs for tribe
// }
console.log("is tribe!")
const tribeOwnerPubKey = chat.ownerPubkey
if(sender.publicKey===tribeOwnerPubKey){
@ -74,7 +73,7 @@ export async function sendMessage(params) {
try {
const mqttTopic = networkType==='mqtt' ? `${destkey}/${chatUUID}` : ''
const r = await signAndSend(opts, sender.publicKey, mqttTopic)
const r = await signAndSend(opts, mqttTopic)
yes = r
} catch (e) {
console.log("KEYSEND ERROR", e)
@ -89,13 +88,17 @@ export async function sendMessage(params) {
}
}
export function signAndSend(opts, pubkey, mqttTopic?:string){
export function signAndSend(opts, mqttTopic?:string){
// console.log('sign and send!!!!',opts.data)
return new Promise(async function(resolve, reject) {
if(!opts.data || typeof opts.data!=='object') {
if(!opts || typeof opts!=='object') {
return reject('object plz')
}
let data = JSON.stringify(opts.data)
if(!opts.dest) {
return reject('no dest pubkey')
}
let data = JSON.stringify(opts.data||{})
opts.amt = opts.amt || 0
const sig = await LND.signAscii(data)
data = data + sig

1
api/utils/lightning.ts

@ -391,6 +391,7 @@ export {
getLock,
setLock,
getRoute,
keysend,
keysendMessage,
signMessage,
verifyMessage,

38
api/utils/setup.ts

@ -6,7 +6,7 @@ import * as publicIp from 'public-ip'
import password from '../utils/password'
import {checkTag, checkCommitHash} from '../utils/gitinfo'
const USER_VERSION = 3
const USER_VERSION = 4
const setupDatabase = async () => {
console.log('=> [db] starting setup...')
@ -31,6 +31,20 @@ async function setVersion(){
}
async function migrate(){
try{
await sequelize.query(`
CREATE TABLE sphinx_timers (
id BIGINT,
chat_id BIGINT,
receiver BIGINT,
millis BIGINT,
msg_id BIGINT,
amount DECIMAL
)`)
} catch(e){console.log(e)}
addTableColumn('sphinx_chats', 'escrow_amount', 'BIGINT')
addTableColumn('sphinx_chats', 'escrow_millis', 'BIGINT')
addTableColumn('sphinx_contacts', 'private_photo', 'BOOLEAN')
addTableColumn('sphinx_media_keys', 'media_type')
@ -41,28 +55,6 @@ async function migrate(){
addTableColumn('sphinx_messages', 'reply_uuid')
addTableColumn('sphinx_media_keys', 'sender', 'BIGINT')
addTableColumn('sphinx_chats', 'group_key')
addTableColumn('sphinx_chats', 'group_private_key')
addTableColumn('sphinx_chats', 'host')
addTableColumn('sphinx_chats', 'price_to_join', 'BIGINT')
addTableColumn('sphinx_chats', 'price_per_message', 'BIGINT')
addTableColumn('sphinx_chats', 'owner_pubkey')
addTableColumn('sphinx_messages', 'sender_alias')
addTableColumn('sphinx_chat_members', 'alias')
addTableColumn('sphinx_contacts', 'from_group')
try{
await sequelize.query(`
CREATE TABLE sphinx_chat_members (
chat_id INT,
contact_id INT,
alias TEXT,
role INT,
total_spent INT,
total_messages INT,
last_active DATETIME
)`)
} catch(e){}
}
async function addTableColumn(table:string, column:string, type='TEXT') {

44
api/utils/timers.ts

@ -0,0 +1,44 @@
import { models } from '../models'
import * as network from '../network'
import * as path from 'path'
const constants = require(path.join(__dirname,'../../config/constants.json'))
export async function addTimer({amount, millis, receiver, msgId, chatId}){
const now = new Date().valueOf()
const when = now + millis
const t = await models.Timer.create({
amount, millis:when, receiver, msgId, chatId,
})
setTimer(when, async ()=>{
payBack(t)
})
}
export function setTimer(when:number, cb){
const now = new Date().valueOf()
const ms = when-now
if(ms<0) cb() // fire right away if its already passed
else setTimeout(cb, ms)
}
export async function reloadTimers(){
const timers = await models.Timer.findAll()
timers && timers.forEach(t=>{
setTimer(t.millis, async ()=>{
payBack(t)
})
})
}
export async function payBack(t){
const chat = await models.Chat.findOne({ where: {id:t.chatId} })
const owner = await models.Contact.findOne({ where: {isOwner:true} })
if(!chat) return
const theChat = {...chat.dataValues, contactIds:[t.receiver]}
network.sendMessage({
chat: theChat,
sender: owner,
message: {id:t.msgId},
amount: t.amount,
type: constants.message_types.confirmation,
})
models.Timer.destroy({where:{id:t.id}})
}

8
api/utils/tribes.ts

@ -69,7 +69,7 @@ export function publish(topic, msg) {
if (client) client.publish(topic, msg)
}
export async function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey }) {
export async function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis }) {
try {
await fetch('https://' + host + '/tribes', {
method: 'POST',
@ -79,6 +79,8 @@ export async function declare({ uuid, name, description, tags, img, group_key, h
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
owner_alias, owner_pubkey,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
}),
headers: { 'Content-Type': 'application/json' }
})
@ -89,7 +91,7 @@ export async function declare({ uuid, name, description, tags, img, group_key, h
}
}
export async function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias }) {
export async function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis }) {
try {
const token = await genSignedTimestamp()
await fetch('https://' + host + '/tribe?token=' + token, {
@ -99,6 +101,8 @@ export async function edit({ uuid, host, name, description, tags, img, price_per
name, description, tags, img: img || '',
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
owner_alias,
}),
headers: { 'Content-Type': 'application/json' }

17
dist/api/controllers/chatTribes.js

@ -100,7 +100,7 @@ function joinTribe(req, res) {
exports.joinTribe = joinTribe;
function editTribe(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const { name, is_listed, price_per_message, price_to_join, img, description, tags, } = req.body;
const { name, is_listed, price_per_message, price_to_join, escrow_amount, escrow_millis, img, description, tags, } = req.body;
const { id } = req.params;
if (!id)
return res_1.failure(res, 'group id is required');
@ -118,6 +118,8 @@ function editTribe(req, res) {
host: chat.host,
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
description,
tags,
img,
@ -133,7 +135,9 @@ function editTribe(req, res) {
photoUrl: img || '',
name: name,
pricePerMessage: price_per_message || 0,
priceToJoin: price_to_join || 0
priceToJoin: price_to_join || 0,
escrowAmount: escrow_amount || 0,
escrowMillis: escrow_millis || 0,
});
res_1.success(res, jsonUtils.chatToJson(chat));
}
@ -182,12 +186,15 @@ function replayChatHistory(chat, contact) {
msg = yield msg_1.decryptMessage(msg, chat);
const data = yield msg_1.personalizeMessage(msg, contact, true);
const mqttTopic = `${contact.publicKey}/${chat.uuid}`;
yield network.signAndSend({ data }, owner.publicKey, mqttTopic);
yield network.signAndSend({
data,
dest: contact.publicKey,
}, mqttTopic);
}));
});
}
exports.replayChatHistory = replayChatHistory;
function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join) {
function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis) {
return __awaiter(this, void 0, void 0, function* () {
let date = new Date();
date.setMilliseconds(0);
@ -212,6 +219,8 @@ function createTribeChatParams(owner, contactIds, name, img, price_per_message,
host: tribes.getHost(),
pricePerMessage: price_per_message || 0,
priceToJoin: price_to_join || 0,
escrowMillis: escrow_millis || 0,
escrowAmount: escrow_amount || 0,
};
});
}

2
dist/api/controllers/chatTribes.js.map

File diff suppressed because one or more lines are too long

6
dist/api/controllers/chats.js

@ -49,7 +49,7 @@ exports.mute = mute;
// or can u add contacts as members?
function createGroupChat(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const { name, is_tribe, is_listed, price_per_message, price_to_join, img, description, tags, } = req.body;
const { name, is_tribe, is_listed, price_per_message, price_to_join, escrow_amount, escrow_millis, img, description, tags, } = req.body;
const contact_ids = req.body.contact_ids || [];
const members = {}; //{pubkey:{key,alias}, ...}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
@ -66,7 +66,7 @@ function createGroupChat(req, res) {
let chatParams = null;
let okToCreate = true;
if (is_tribe) {
chatParams = yield chatTribes_1.createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join);
chatParams = yield chatTribes_1.createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join, escrow_amount, escrow_millis);
if (is_listed && chatParams.uuid) {
// publish to tribe server
try {
@ -77,6 +77,8 @@ function createGroupChat(req, res) {
group_key: chatParams.groupKey,
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
description, tags, img,
owner_pubkey: owner.publicKey,
owner_alias: owner.alias,

2
dist/api/controllers/chats.js.map

File diff suppressed because one or more lines are too long

4
dist/api/controllers/confirmations.js

@ -17,6 +17,8 @@ const network = require("../network");
const path = require("path");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function sendConfirmation({ chat, sender, msg_id }) {
if (!msg_id)
return;
network.sendMessage({
chat,
sender,
@ -27,7 +29,7 @@ function sendConfirmation({ chat, sender, msg_id }) {
exports.sendConfirmation = sendConfirmation;
function receiveConfirmation(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> received confirmation');
console.log('=> received confirmation', (payload.message && payload.message.id));
const dat = payload.content || payload;
const chat_uuid = dat.chat.uuid;
const msg_id = dat.message.id;

2
dist/api/controllers/confirmations.js.map

@ -1 +1 @@
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../../../api/controllers/confirmations.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,wCAAgC;AAChC,sCAAgC;AAChC,0CAAyC;AACzC,2CAA0C;AAC1C,sCAAqC;AACrC,6BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E,SAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;IACxD,OAAO,CAAC,WAAW,CAAC;QACnB,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,EAAC,EAAE,EAAC,MAAM,EAAC;QACpB,IAAI,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AAM,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"}

35
dist/api/controllers/contacts.js

@ -70,12 +70,17 @@ const updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function*
console.log('=> updateContact called', { body: req.body, params: req.params, query: req.query });
let attrs = extractAttrs(req.body);
const contact = yield models_1.models.Contact.findOne({ where: { id: req.params.id } });
let shouldUpdateContactKey = (contact.isOwner && contact.contactKey == null && attrs["contact_key"] != null);
let shouldSendUpdatedSelf = (contact.isOwner && ((contact.contactKey == null && attrs["contact_key"] != null) || // CREATE CONTACT KEY!
attrs["contact_key"] == null // OR NO NEW CONTACT KEY
));
// update self
const owner = yield contact.update(jsonUtils.jsonToContact(attrs));
res_1.success(res, jsonUtils.contactToJson(owner));
if (!shouldUpdateContactKey)
if (!shouldSendUpdatedSelf)
return;
const contactIds = yield models_1.models.Contact.findAll({ where: { deleted: false } }).map(c => c.id);
// send updated owner info to others
const contactIds = yield models_1.models.Contact.findAll({ where: { deleted: false } })
.filter(c => !c.fromGroup && c.id !== 1 && c.publicKey).map(c => c.id);
if (contactIds.length == 0)
return;
helpers.sendContactKeys({
@ -172,13 +177,14 @@ const deleteContact = (req, res) => __awaiter(void 0, void 0, void 0, function*
res_1.success(res, {});
});
exports.deleteContact = deleteContact;
const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log(`=> confirm contact key for ${payload.sender && payload.sender.pub_key}`, JSON.stringify(payload));
const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> received contact key', JSON.stringify(payload));
const dat = payload.content || payload;
const sender_pub_key = dat.sender.pub_key;
const sender_contact_key = dat.sender.contact_key;
const sender_alias = dat.sender.alias || 'Unknown';
const sender_photo_url = dat.sender.photo_url;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } });
if (sender_contact_key && sender) {
const objToUpdate = { contactKey: sender_contact_key };
@ -192,16 +198,20 @@ const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0,
response: jsonUtils.contactToJson(sender)
});
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
});
});
exports.receiveConfirmContactKey = receiveConfirmContactKey;
const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> received contact key', JSON.stringify(payload));
exports.receiveContactKey = receiveContactKey;
const receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log(`=> confirm contact key for ${payload.sender && payload.sender.pub_key}`, JSON.stringify(payload));
const dat = payload.content || payload;
const sender_pub_key = dat.sender.pub_key;
const sender_contact_key = dat.sender.contact_key;
const sender_alias = dat.sender.alias || 'Unknown';
const sender_photo_url = dat.sender.photo_url;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed } });
if (sender_contact_key && sender) {
const objToUpdate = { contactKey: sender_contact_key };
@ -215,13 +225,8 @@ const receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, functio
response: jsonUtils.contactToJson(sender)
});
}
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
});
});
exports.receiveContactKey = receiveContactKey;
exports.receiveConfirmContactKey = receiveConfirmContactKey;
const extractAttrs = body => {
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo"];
let attrs = {};

2
dist/api/controllers/contacts.js.map

File diff suppressed because one or more lines are too long

2
dist/api/controllers/index.js

@ -24,6 +24,7 @@ const uploads = require("./uploads");
const confirmations = require("./confirmations");
const gitinfo_1 = require("../utils/gitinfo");
const path = require("path");
const timers = require("../utils/timers");
const env = process.env.NODE_ENV || 'development';
console.log("=> env:", env);
const constants = require(path.join(__dirname, '../../config/constants.json'));
@ -38,6 +39,7 @@ function set(app) {
catch (e) {
console.log('=> could not auth with media server', e.message);
}
timers.reloadTimers();
app.get('/chats', chats.getChats);
app.post('/group', chats.createGroupChat);
app.post('/chats/:chat_id/:mute_unmute', chats.mute);

2
dist/api/controllers/index.js.map

File diff suppressed because one or more lines are too long

3
dist/api/controllers/messages.js

@ -166,7 +166,8 @@ const receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function*
updatedAt: date,
status: constants.statuses.received
};
if (chat_type === constants.chat_types.tribe) {
const isTribe = chat_type === constants.chat_types.tribe;
if (isTribe) {
msg.senderAlias = sender_alias;
if (remote_content)
msg.remoteMessageContent = remote_content;

2
dist/api/controllers/messages.js.map

File diff suppressed because one or more lines are too long

44
dist/api/crypto/rsa.js

@ -1,14 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = require("crypto");
const BLOCK_SIZE = 256;
const MAX_CHUNK_SIZE = BLOCK_SIZE - 11; // 11 is the PCKS1 padding
function encrypt(key, txt) {
try {
const buf = Buffer.from(txt);
let finalBuf = Buffer.from([]);
const n = Math.ceil(buf.length / MAX_CHUNK_SIZE);
const arr = Array(n).fill(0);
const pubc = cert.pub(key);
const buf = crypto.publicEncrypt({
key: pubc,
padding: crypto.constants.RSA_PKCS1_PADDING,
}, Buffer.from(txt, 'utf-8'));
return buf.toString('base64');
arr.forEach((_, i) => {
const f = crypto.publicEncrypt({
key: pubc,
padding: crypto.constants.RSA_PKCS1_PADDING,
}, buf.subarray(i * MAX_CHUNK_SIZE, i * MAX_CHUNK_SIZE + MAX_CHUNK_SIZE));
finalBuf = Buffer.concat([finalBuf, f]);
});
return finalBuf.toString('base64');
}
catch (e) {
return '';
@ -17,12 +26,19 @@ function encrypt(key, txt) {
exports.encrypt = encrypt;
function decrypt(privateKey, enc) {
try {
const buf = Buffer.from(enc, 'base64');
let finalDec = '';
const n = Math.ceil(buf.length / BLOCK_SIZE);
const arr = Array(n).fill(0);
const privc = cert.priv(privateKey);
const buf = crypto.privateDecrypt({
key: privc,
padding: crypto.constants.RSA_PKCS1_PADDING,
}, Buffer.from(enc, 'base64'));
return buf.toString('utf-8');
arr.forEach((_, i) => {
const b = crypto.privateDecrypt({
key: privc,
padding: crypto.constants.RSA_PKCS1_PADDING,
}, buf.subarray(i * BLOCK_SIZE, i * BLOCK_SIZE + BLOCK_SIZE));
finalDec += b.toString('utf-8');
});
return finalDec;
}
catch (e) {
return '';
@ -53,15 +69,19 @@ exports.genKeys = genKeys;
function testRSA() {
crypto.generateKeyPair('rsa', {
modulusLength: 2048
}, (err, publicKey, priv) => {
}, (err, publicKey, privateKey) => {
const pubPEM = publicKey.export({
type: 'pkcs1', format: 'pem'
});
const pub = cert.unpub(pubPEM);
const msg = 'hi';
const enc = encrypt(pub, msg);
const privPEM = privateKey.export({
type: 'pkcs1', format: 'pem'
});
const priv = cert.unpriv(privPEM);
const dec = decrypt(priv, enc);
console.log("FINAL:", dec);
console.log("SUCESS:", msg === dec);
});
}
exports.testRSA = testRSA;

2
dist/api/crypto/rsa.js.map

@ -1 +1 @@
{"version":3,"file":"rsa.js","sourceRoot":"","sources":["../../../api/crypto/rsa.ts"],"names":[],"mappings":";;AAAA,iCAAiC;AAEjC,SAAgB,OAAO,CAAC,GAAG,EAAE,GAAG;IAC9B,IAAG;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC;YAC/B,GAAG,EAAC,IAAI;YACR,OAAO,EAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB;SAC3C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAC,OAAO,CAAC,CAAC,CAAA;QAC5B,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAC9B;IAAC,OAAM,CAAC,EAAE;QACT,OAAO,EAAE,CAAA;KACV;AACH,CAAC;AAXD,0BAWC;AAED,SAAgB,OAAO,CAAC,UAAU,EAAE,GAAG;IACrC,IAAG;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACnC,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC;YAChC,GAAG,EAAC,KAAK;YACT,OAAO,EAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB;SAC3C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAC,QAAQ,CAAC,CAAC,CAAA;QAC7B,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;KAC7B;IAAC,OAAM,CAAC,EAAE;QACT,OAAO,EAAE,CAAA;KACV;AACH,CAAC;AAXD,0BAWC;AAED,SAAgB,OAAO;IACrB,OAAO,IAAI,OAAO,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AAC,CAAC,OAAO,CAAC,iCAAiC,EAAC,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"}

4
dist/api/helpers.js

@ -90,8 +90,8 @@ const performKeysendMessage = ({ destination_key, amount, msg, success, failure,
amt: Math.max(amount, 3)
};
try {
const r = yield network.signAndSend(opts, sender.publicKey);
console.log("=> external keysend");
const r = yield network.signAndSend(opts);
// console.log("=> keysend to new contact")
if (success)
success(r);
}

2
dist/api/helpers.js.map

File diff suppressed because one or more lines are too long

3
dist/api/models/index.js

@ -9,9 +9,10 @@ const message_1 = require("./ts/message");
const subscription_1 = require("./ts/subscription");
const mediaKey_1 = require("./ts/mediaKey");
const chatMember_1 = require("./ts/chatMember");
const timer_1 = require("./ts/timer");
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, '../../config/config.json'))[env];
const sequelize = new sequelize_typescript_1.Sequelize(Object.assign(Object.assign({}, config), { logging: process.env.SQL_LOG === 'true' ? console.log : false, models: [chat_1.default, contact_1.default, invite_1.default, message_1.default, subscription_1.default, mediaKey_1.default, chatMember_1.default] }));
const sequelize = new sequelize_typescript_1.Sequelize(Object.assign(Object.assign({}, config), { logging: process.env.SQL_LOG === 'true' ? console.log : false, models: [chat_1.default, contact_1.default, invite_1.default, message_1.default, subscription_1.default, mediaKey_1.default, chatMember_1.default, timer_1.default] }));
exports.sequelize = sequelize;
const models = sequelize.models;
exports.models = models;

2
dist/api/models/index.js.map

@ -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;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"}
{"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;AACxC,sCAA8B;AAE9B,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,EAAC,eAAK,CAAC,IAC5E,CAAA;AAIA,8BAAS;AAHX,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;AAI7B,wBAAM"}

8
dist/api/models/ts/chat.js

@ -85,6 +85,14 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", Number)
], Chat.prototype, "pricePerMessage", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Chat.prototype, "escrowAmount", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Chat.prototype, "escrowMillis", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)

2
dist/api/models/ts/chat.js.map

@ -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;CA8D5C,CAAA;AAtDC;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,CAAC,+BAAQ,CAAC,MAAM,CAAC;;oCACV;AAGd;IADC,6BAAM;;wCACW;AAGlB;IADC,6BAAM;;qCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;uCAAA;AAGf;IADC,6BAAM;8BACI,IAAI;uCAAA;AAOf;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;qCACc;AAGhB;IADC,6BAAM;;sCACS;AAGhB;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"}
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../../api/models/ts/chat.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,IAAI,GAAzB,MAAqB,IAAK,SAAQ,4BAAW;CAoE5C,CAAA;AA5DC;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,CAAC,+BAAQ,CAAC,MAAM,CAAC;;oCACV;AAGd;IADC,6BAAM;;wCACW;AAGlB;IADC,6BAAM;;qCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;uCAAA;AAGf;IADC,6BAAM;8BACI,IAAI;uCAAA;AAOf;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;qCACc;AAGhB;IADC,6BAAM;;sCACS;AAGhB;IADC,6BAAM;;6CACgB;AAGvB;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;yCACY;AAGnB;IADC,6BAAM;;6CACgB;AAGvB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACJ;AAGpB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACJ;AAGpB;IADC,6BAAM;;yCACY;AAlEA,IAAI;IADxB,4BAAK,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACjC,IAAI,CAoExB;kBApEoB,IAAI"}

48
dist/api/models/ts/timer.js

@ -0,0 +1,48 @@
"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 Timer = class Timer extends sequelize_typescript_1.Model {
};
__decorate([
sequelize_typescript_1.Column({
type: sequelize_typescript_1.DataType.BIGINT,
primaryKey: true,
unique: true,
autoIncrement: true
}),
__metadata("design:type", Number)
], Timer.prototype, "id", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Timer.prototype, "chatId", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Timer.prototype, "msgId", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Timer.prototype, "millis", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Timer.prototype, "receiver", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.DECIMAL),
__metadata("design:type", Number)
], Timer.prototype, "amount", void 0);
Timer = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_timers', underscored: true })
], Timer);
exports.default = Timer;
//# sourceMappingURL=timer.js.map

1
dist/api/models/ts/timer.js.map

@ -0,0 +1 @@
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../../../api/models/ts/timer.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,KAAK,GAA1B,MAAqB,KAAM,SAAQ,4BAAY;CAyB9C,CAAA;AAjBC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;iCACQ;AAGV;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;qCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;oCACX;AAGb;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;qCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;uCACR;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,OAAO,CAAC;;qCACX;AAvBK,KAAK;IADzB,4BAAK,CAAC,EAAC,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GAClC,KAAK,CAyBzB;kBAzBoB,KAAK"}

10
dist/api/network/receive.js

@ -21,6 +21,7 @@ const modify_1 = require("./modify");
// import {modifyPayloadAndSaveMediaKey} from './modify'
const msg_1 = require("../utils/msg");
const sequelize_1 = require("sequelize");
const timers = require("../utils/timers");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types;
exports.typesToForward = [
@ -66,6 +67,15 @@ function onReceive(payload) {
if (needsPricePerJoin) {
if (payload.message.amount < chat.pricePerMessage)
doAction = false;
if (chat.escrowAmount) {
timers.addTimer({
amount: chat.escrowAmount,
millis: chat.escrowMillis,
receiver: senderContact.id,
msgId: payload.message.id,
chatId: chat.id,
});
}
}
// check price to join
if (payload.type === msgtypes.group_join) {

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

21
dist/api/network/send.js

@ -18,8 +18,7 @@ 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;
let msg = newmsg(type, chat, sender, message);
// console.log(type,message)
if (!(sender && sender.publicKey)) {
console.log("NO SENDER?????");
@ -38,9 +37,9 @@ function sendMessage(params) {
let isTribeOwner = false;
const chatUUID = chat.uuid;
if (isTribe) {
if (type === constants.message_types.confirmation) {
return; // dont send confs for tribe
}
// if(type===constants.message_types.confirmation) {
// return // dont send confs for tribe
// }
console.log("is tribe!");
const tribeOwnerPubKey = chat.ownerPubkey;
if (sender.publicKey === tribeOwnerPubKey) {
@ -77,7 +76,7 @@ function sendMessage(params) {
};
try {
const mqttTopic = networkType === 'mqtt' ? `${destkey}/${chatUUID}` : '';
const r = yield signAndSend(opts, sender.publicKey, mqttTopic);
const r = yield signAndSend(opts, mqttTopic);
yes = r;
}
catch (e) {
@ -97,14 +96,18 @@ function sendMessage(params) {
});
}
exports.sendMessage = sendMessage;
function signAndSend(opts, pubkey, mqttTopic) {
function signAndSend(opts, 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') {
if (!opts || typeof opts !== 'object') {
return reject('object plz');
}
let data = JSON.stringify(opts.data);
if (!opts.dest) {
return reject('no dest pubkey');
}
let data = JSON.stringify(opts.data || {});
opts.amt = opts.amt || 0;
const sig = yield LND.signAscii(data);
data = data + sig;
// console.log("ACTUALLY SEND", mqttTopic)

2
dist/api/network/send.js.map

File diff suppressed because one or more lines are too long

1
dist/api/utils/lightning.js

@ -146,6 +146,7 @@ const keysend = (opts) => {
});
});
};
exports.keysend = keysend;
const MAX_MSG_LENGTH = 972; // 1146 - 20 ???
function keysendMessage(opts) {
return __awaiter(this, void 0, void 0, function* () {

2
dist/api/utils/lightning.js.map

File diff suppressed because one or more lines are too long

40
dist/api/utils/setup.js

@ -16,7 +16,7 @@ const QRCode = require("qrcode");
const publicIp = require("public-ip");
const password_1 = require("../utils/password");
const gitinfo_1 = require("../utils/gitinfo");
const USER_VERSION = 3;
const USER_VERSION = 4;
const setupDatabase = () => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> [db] starting setup...');
yield setVersion();
@ -44,6 +44,22 @@ function setVersion() {
}
function migrate() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield models_1.sequelize.query(`
CREATE TABLE sphinx_timers (
id BIGINT,
chat_id BIGINT,
receiver BIGINT,
millis BIGINT,
msg_id BIGINT,
amount DECIMAL
)`);
}
catch (e) {
console.log(e);
}
addTableColumn('sphinx_chats', 'escrow_amount', 'BIGINT');
addTableColumn('sphinx_chats', 'escrow_millis', 'BIGINT');
addTableColumn('sphinx_contacts', 'private_photo', 'BOOLEAN');
addTableColumn('sphinx_media_keys', 'media_type');
addTableColumn('sphinx_media_keys', 'original_muid');
@ -51,28 +67,6 @@ function migrate() {
addTableColumn('sphinx_messages', 'uuid');
addTableColumn('sphinx_messages', 'reply_uuid');
addTableColumn('sphinx_media_keys', 'sender', 'BIGINT');
addTableColumn('sphinx_chats', 'group_key');
addTableColumn('sphinx_chats', 'group_private_key');
addTableColumn('sphinx_chats', 'host');
addTableColumn('sphinx_chats', 'price_to_join', 'BIGINT');
addTableColumn('sphinx_chats', 'price_per_message', 'BIGINT');
addTableColumn('sphinx_chats', 'owner_pubkey');
addTableColumn('sphinx_messages', 'sender_alias');
addTableColumn('sphinx_chat_members', 'alias');
addTableColumn('sphinx_contacts', 'from_group');
try {
yield models_1.sequelize.query(`
CREATE TABLE sphinx_chat_members (
chat_id INT,
contact_id INT,
alias TEXT,
role INT,
total_spent INT,
total_messages INT,
last_active DATETIME
)`);
}
catch (e) { }
});
}
function addTableColumn(table, column, type = 'TEXT') {

2
dist/api/utils/setup.js.map

@ -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;AAmGQ,sCAAa;AAjGtB,SAAe,UAAU;;QACvB,IAAI;YACF,MAAM,kBAAS,CAAC,KAAK,CAAC,yBAAyB,YAAY,E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BAA6B,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"}

67
dist/api/utils/timers.js

@ -0,0 +1,67 @@
"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 network = require("../network");
const path = require("path");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function addTimer({ amount, millis, receiver, msgId, chatId }) {
return __awaiter(this, void 0, void 0, function* () {
const now = new Date().valueOf();
const when = now + millis;
const t = yield models_1.models.Timer.create({
amount, millis: when, receiver, msgId, chatId,
});
setTimer(when, () => __awaiter(this, void 0, void 0, function* () {
payBack(t);
}));
});
}
exports.addTimer = addTimer;
function setTimer(when, cb) {
const now = new Date().valueOf();
const ms = when - now;
if (ms < 0)
cb(); // fire right away if its already passed
else
setTimeout(cb, ms);
}
exports.setTimer = setTimer;
function reloadTimers() {
return __awaiter(this, void 0, void 0, function* () {
const timers = yield models_1.models.Timer.findAll();
timers && timers.forEach(t => {
setTimer(t.millis, () => __awaiter(this, void 0, void 0, function* () {
payBack(t);
}));
});
});
}
exports.reloadTimers = reloadTimers;
function payBack(t) {
return __awaiter(this, void 0, void 0, function* () {
const chat = yield models_1.models.Chat.findOne({ where: { id: t.chatId } });
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (!chat)
return;
const theChat = Object.assign(Object.assign({}, chat.dataValues), { contactIds: [t.receiver] });
network.sendMessage({
chat: theChat,
sender: owner,
message: { id: t.msgId },
amount: t.amount,
type: constants.message_types.confirmation,
});
models_1.models.Timer.destroy({ where: { id: t.id } });
});
}
exports.payBack = payBack;
//# sourceMappingURL=timers.js.map

1
dist/api/utils/timers.js.map

@ -0,0 +1 @@
{"version":3,"file":"timers.js","sourceRoot":"","sources":["../../../api/utils/timers.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAkC;AAClC,sCAAqC;AACrC,6BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E,SAAsB,QAAQ,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAC;;QACpE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;QAChC,MAAM,IAAI,GAAG,GAAG,GAAG,MAAM,CAAA;QACzB,MAAM,CAAC,GAAG,MAAM,eAAM,CAAC,KAAK,CAAC,MAAM,CAAC;YAChC,MAAM,EAAE,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM;SAC/C,CAAC,CAAA;QACF,QAAQ,CAAC,IAAI,EAAE,GAAQ,EAAE;YACrB,OAAO,CAAC,CAAC,CAAC,CAAA;QACd,CAAC,CAAA,CAAC,CAAA;IACN,CAAC;CAAA;AATD,4BASC;AACD,SAAgB,QAAQ,CAAC,IAAW,EAAE,EAAE;IACvC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAChC,MAAM,EAAE,GAAG,IAAI,GAAC,GAAG,CAAA;IACnB,IAAG,EAAE,GAAC,CAAC;QAAE,EAA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AAC,CAAA;IAC3C,CAAC;CAAA;AAbD,0BAaC"}

8
dist/api/utils/tribes.js

@ -84,7 +84,7 @@ function publish(topic, msg) {
client.publish(topic, msg);
}
exports.publish = publish;
function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey }) {
function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis }) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield fetch('https://' + host + '/tribes', {
@ -95,6 +95,8 @@ function declare({ uuid, name, description, tags, img, group_key, host, price_pe
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
owner_alias, owner_pubkey,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
}),
headers: { 'Content-Type': 'application/json' }
});
@ -107,7 +109,7 @@ function declare({ uuid, name, description, tags, img, group_key, host, price_pe
});
}
exports.declare = declare;
function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias }) {
function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = yield genSignedTimestamp();
@ -118,6 +120,8 @@ function edit({ uuid, host, name, description, tags, img, price_per_message, pri
name, description, tags, img: img || '',
price_per_message: price_per_message || 0,
price_to_join: price_to_join || 0,
escrow_amount: escrow_amount || 0,
escrow_millis: escrow_millis || 0,
owner_alias,
}),
headers: { 'Content-Type': 'application/json' }

2
dist/api/utils/tribes.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save