Browse Source

escrow spam protection

hosting-provider
Evan Feenstra 5 years ago
parent
commit
a947924261
  1. 15
      api/controllers/chatTribes.ts
  2. 6
      api/controllers/chats.ts
  3. 4
      api/helpers.ts
  4. 3
      api/models/index.ts
  5. 6
      api/models/ts/chat.ts
  6. 23
      api/models/ts/timer.ts
  7. 8
      api/network/receive.ts
  8. 12
      api/network/send.ts
  9. 1
      api/utils/lightning.ts
  10. 36
      api/utils/setup.ts
  11. 37
      api/utils/timers.ts
  12. 8
      api/utils/tribes.ts
  13. 14
      dist/api/controllers/chatTribes.js
  14. 2
      dist/api/controllers/chatTribes.js.map
  15. 6
      dist/api/controllers/chats.js
  16. 2
      dist/api/controllers/chats.js.map
  17. 4
      dist/api/helpers.js
  18. 2
      dist/api/helpers.js.map
  19. 3
      dist/api/models/index.js
  20. 2
      dist/api/models/index.js.map
  21. 8
      dist/api/models/ts/chat.js
  22. 2
      dist/api/models/ts/chat.js.map
  23. 40
      dist/api/models/ts/timer.js
  24. 1
      dist/api/models/ts/timer.js.map
  25. 8
      dist/api/network/receive.js
  26. 2
      dist/api/network/receive.js.map
  27. 12
      dist/api/network/send.js
  28. 2
      dist/api/network/send.js.map
  29. 1
      dist/api/utils/lightning.js
  30. 2
      dist/api/utils/lightning.js.map
  31. 38
      dist/api/utils/setup.js
  32. 2
      dist/api/utils/setup.js.map
  33. 60
      dist/api/utils/timers.js
  34. 1
      dist/api/utils/timers.js.map
  35. 8
      dist/api/utils/tribes.js
  36. 2
      dist/api/utils/tribes.js.map

15
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,12 @@ 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}, 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 +226,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 +242,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,

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

23
api/models/ts/timer.ts

@ -0,0 +1,23 @@
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)
millis: number
@Column(DataType.BIGINT)
receiver: number
@Column(DataType.DECIMAL)
amount: number
}

8
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,13 @@ 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,
})
}
}
// check price to join
if(payload.type===msgtypes.group_join) {

12
api/network/send.ts

@ -74,7 +74,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 +89,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,

36
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,18 @@ async function setVersion(){
}
async function migrate(){
try{
await sequelize.query(`
CREATE TABLE sphinx_timers (
id BIGINT,
receiver BIGINT,
millis BIGINT,
amount DECIMAL
)`)
} catch(e){console.log(e)}
addTableColumn('sphinx_chats', 'escrow_amount', 'BIGINT')
addTableColumn('sphinx_messages', 'escrow_millis', 'BIGINT')
addTableColumn('sphinx_contacts', 'private_photo', 'BOOLEAN')
addTableColumn('sphinx_media_keys', 'media_type')
@ -41,28 +53,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') {

37
api/utils/timers.ts

@ -0,0 +1,37 @@
import { models } from '../models'
import * as network from '../network'
export async function addTimer({amount, millis, receiver}){
const now = new Date().valueOf()
const when = now + millis
const t = await models.Timer.create({
amount, millis:when, receiver,
})
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 contact = await models.Contact.findOne({where:{id:t.receiver}})
if(contact){
network.signAndSend({
amt: t.amount,
dest: contact.publicKey,
})
}
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' }

14
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,12 @@ 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 }, 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 +216,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/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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A;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;IAD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AAM,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"}

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

@ -0,0 +1,40 @@
"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, "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;CAmB9C,CAAA;AAXC;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;;uCACR;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,OAAO,CAAC;;qCACX;AAjBK,KAAK;IADzB,4BAAK,CAAC,EAAC,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GAClC,KAAK,CAmBzB;kBAnBoB,KAAK"}

8
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,13 @@ 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,
});
}
}
// 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

12
dist/api/network/send.js

@ -77,7 +77,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 +97,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

38
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,20 @@ function setVersion() {
}
function migrate() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield models_1.sequelize.query(`
CREATE TABLE sphinx_timers (
id BIGINT,
receiver BIGINT,
millis BIGINT,
amount DECIMAL
)`);
}
catch (e) {
console.log(e);
}
addTableColumn('sphinx_chats', 'escrow_amount', 'BIGINT');
addTableColumn('sphinx_messages', 'escrow_millis', 'BIGINT');
addTableColumn('sphinx_contacts', 'private_photo', 'BOOLEAN');
addTableColumn('sphinx_media_keys', 'media_type');
addTableColumn('sphinx_media_keys', 'original_muid');
@ -51,28 +65,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,C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AAG,MAAM,CAAC,IAAI,CAAC,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"}

60
dist/api/utils/timers.js

@ -0,0 +1,60 @@
"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");
function addTimer({ amount, millis, receiver }) {
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,
});
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 contact = yield models_1.models.Contact.findOne({ where: { id: t.receiver } });
if (contact) {
network.signAndSend({
amt: t.amount,
dest: contact.publicKey,
});
}
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;AAErC,SAAsB,QAAQ,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAC;;QACrD,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;SAChC,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,EAAE,EAAE,CAAA,CAAC,wCAAwC;;QACjD,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AALD,4BAKC;AACD,SAAsB,YAAY;;QACjC,MAAM,MAAM,GAAG,MAAM,eAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;QAC3C,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA,EAAE;YAC3B,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,GAAQ,EAAE;gBAC5B,OAAO,CAAC,CAAC,CAAC,CAAA;YACX,CAAC,CAAA,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC;CAAA;AAPD,oCAOC;AACD,SAAsB,OAAO,CAAC,CAAC;;QAC3B,MAAM,OAAO,GAAG,MAAM,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC,EAAC,EAAE,EAAC,CAAC,CAAC,QAAQ,EAAC,EAAC,CAAC,CAAA;QACrE,IAAG,OAAO,EAAC;YACP,OAAO,CAAC,WAAW,CAAC;gBAChB,GAAG,EAAE,CAAC,CAAC,MAAM;gBACb,IAAI,EAAE,OAAO,CAAC,SAAS;aAC1B,CAAC,CAAA;SACL;QACD,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAC,KAAK,EAAC,EAAC,EAAE,EAAC,CAAC,CAAC,EAAE,EAAC,EAAC,CAAC,CAAA;IAC3C,CAAC;CAAA;AATD,0BASC"}

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