Browse Source

anonymous keysend type with message content

loopout2
Evan Feenstra 4 years ago
parent
commit
f079467094
  1. 3
      dist/src/constants.js
  2. 2
      dist/src/constants.js.map
  3. 7
      dist/src/controllers/payment.js
  4. 2
      dist/src/controllers/payment.js.map
  5. 27
      dist/src/network/receive.js
  6. 2
      dist/src/network/receive.js.map
  7. 3
      src/constants.ts
  8. 6
      src/controllers/payment.ts
  9. 26
      src/network/receive.ts

3
dist/src/constants.js

@ -56,7 +56,8 @@ const constants = {
"bot_cmd": 24,
"bot_res": 25,
"heartbeat": 26,
"heartbeat_confirmation": 27
"heartbeat_confirmation": 27,
"keysend": 28,
},
payment_errors: {
"timeout": "Timed Out",

2
dist/src/constants.js.map

@ -1 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;KACrB;IACD,gBAAgB,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;QACb,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;KACb;IACD,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;KACd;IACD,aAAa,EAAE;QACb,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,EAAE;QACjB,0BAA0B,EAAE,EAAE;QAC9B,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;QACnB,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,wBAAwB,EAAE,EAAE;KAC7B;IACD,cAAc,EAAE;QACd,SAAS,EAAE,WAAW;QACtB,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,2BAA2B,EAAE,2BAA2B;QACxD,SAAS,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"}
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAA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S,EAAE,WAAW;QACtB,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,2BAA2B,EAAE,2BAA2B;QACxD,SAAS,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"}

7
dist/src/controllers/payment.js

@ -25,11 +25,16 @@ exports.sendPayment = (req, res) => __awaiter(void 0, void 0, void 0, function*
console.log('[send payment]', req.body);
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (destination_key && !contact_id && !chat_id) {
const msg = {
type: constants_1.default.message_types.keysend,
};
if (text)
msg.message = { content: text };
return helpers.performKeysendMessage({
sender: owner,
destination_key,
amount,
msg: {},
msg,
success: () => {
console.log('payment sent!');
res_1.success(res, { destination_key, amount });

2
dist/src/controllers/payment.js.map

File diff suppressed because one or more lines are too long

27
dist/src/network/receive.js

@ -276,18 +276,18 @@ function parseAndVerifyPayload(data) {
}
});
}
function saveAnonymousKeysend(response) {
function saveAnonymousKeysend(response, memo) {
return __awaiter(this, void 0, void 0, function* () {
let settleDate = parseInt(response['settle_date'] + '000');
yield models_1.models.Message.create({
chatId: 0,
type: constants_1.default.message_types.direct_payment,
type: constants_1.default.message_types.keysend,
sender: 0,
amount: response['amt_paid_sat'],
amountMsat: response['amt_paid_msat'],
paymentHash: '',
date: new Date(settleDate),
messageContent: response['memo'],
messageContent: memo,
status: constants_1.default.statuses.confirmed,
createdAt: new Date(settleDate),
updatedAt: new Date(settleDate)
@ -300,13 +300,30 @@ function parseKeysendInvoice(i) {
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 || (data && data.startsWith('{}'))) {
let isAnonymous = false;
let memo = '';
if (data) {
try {
const payload = JSON.parse(data);
if (payload.type === constants_1.default.message_types.keysend) {
isAnonymous = true;
memo = payload.message.content;
}
}
catch (e) {
isAnonymous = true;
}
}
else {
isAnonymous = true;
}
if (isAnonymous) {
socket.sendJson({
type: 'keysend',
response: { amount: value || 0 }
});
hub_1.sendNotification(-1, '', 'keysend', value || 0);
saveAnonymousKeysend(i);
saveAnonymousKeysend(i, memo);
return;
}
let payload;

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

File diff suppressed because one or more lines are too long

3
src/constants.ts

@ -54,7 +54,8 @@ const constants = {
"bot_cmd": 24,
"bot_res": 25,
"heartbeat": 26,
"heartbeat_confirmation": 27
"heartbeat_confirmation": 27,
"keysend": 28, // no e2e
},
payment_errors: {
"timeout": "Timed Out",

6
src/controllers/payment.ts

@ -31,11 +31,15 @@ export const sendPayment = async (req, res) => {
const owner = await models.Contact.findOne({ where: { isOwner: true }})
if (destination_key && !contact_id && !chat_id) {
const msg:{[k:string]:any} = {
type:constants.message_types.keysend,
}
if(text) msg.message = {content:text}
return helpers.performKeysendMessage({
sender:owner,
destination_key,
amount,
msg:{},
msg,
success: () => {
console.log('payment sent!')
success(res, {destination_key, amount})

26
src/network/receive.ts

@ -249,17 +249,17 @@ async function parseAndVerifyPayload(data){
}
}
async function saveAnonymousKeysend(response) {
async function saveAnonymousKeysend(response, memo) {
let settleDate = parseInt(response['settle_date'] + '000');
await models.Message.create({
chatId: 0,
type: constants.message_types.direct_payment,
type: constants.message_types.keysend,
sender: 0,
amount: response['amt_paid_sat'],
amountMsat: response['amt_paid_msat'],
paymentHash: '',
date: new Date(settleDate),
messageContent: response['memo'],
messageContent: memo,
status: constants.statuses.confirmed,
createdAt: new Date(settleDate),
updatedAt: new Date(settleDate)
@ -271,13 +271,29 @@ export async function parseKeysendInvoice(i){
const buf = recs && recs[SPHINX_CUSTOM_RECORD_KEY]
const data = buf && buf.toString()
const value = i && i.value && parseInt(i.value)
if(!data || (data&&data.startsWith('{}'))) {
let isAnonymous = false
let memo = ''
if(data){
try {
const payload = JSON.parse(data)
if(payload.type===constants.message_types.keysend) {
isAnonymous = true
memo = payload.message.content
}
} catch(e) {
isAnonymous = true
}
} else {
isAnonymous = true
}
if(isAnonymous) {
socket.sendJson({
type:'keysend',
response: {amount:value||0}
})
sendNotification(-1, '', 'keysend', value||0)
saveAnonymousKeysend(i)
saveAnonymousKeysend(i, memo)
return
}

Loading…
Cancel
Save