From 36773e3a3ca45d06cbc12412cb9dbcfc8e6a2957 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Tue, 30 Jan 2024 21:16:53 +0100 Subject: [PATCH] update: direct payment can also have content for bot payment --- dist/src/controllers/botapi/pay.js | 28 +++++++++++--------------- dist/src/controllers/botapi/pay.js.map | 2 +- src/controllers/botapi/pay.ts | 20 +++++++++++++++++- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/dist/src/controllers/botapi/pay.js b/dist/src/controllers/botapi/pay.js index f3e29d887..efcf2567b 100644 --- a/dist/src/controllers/botapi/pay.js +++ b/dist/src/controllers/botapi/pay.js @@ -17,10 +17,11 @@ const socket = require("../../utils/socket"); const constants_1 = require("../../constants"); const logger_1 = require("../../utils/logger"); const errMsgString_1 = require("../../utils/errMsgString"); +const rsa = require("../../crypto/rsa"); const index_1 = require("./index"); function pay(a) { return __awaiter(this, void 0, void 0, function* () { - const { amount, bot_name, msg_uuid, reply_uuid, recipient_id, parent_id } = a; + const { amount, bot_name, msg_uuid, reply_uuid, recipient_id, parent_id, content, } = a; logger_1.sphinxLogger.info(`=> BOT PAY ${JSON.stringify(a, null, 2)}`); if (!a.recipient_id) return logger_1.sphinxLogger.error(`no recipient_id`); @@ -31,24 +32,19 @@ function pay(a) { const tenant = owner.id; const alias = bot_name || owner.alias; const botContactId = -1; + const encryptedForMeText = rsa.encrypt(owner.contactKey, content || ''); + const encryptedText = rsa.encrypt(chat.groupKey, content || ''); + const textMap = { chat: encryptedText }; const date = new Date(); date.setMilliseconds(0); - const msg = { - chatId: chat.id, - uuid: msg_uuid || short.generate(), - type: reply_uuid + const msg = Object.assign({ chatId: chat.id, uuid: msg_uuid || short.generate(), type: reply_uuid ? constants_1.default.message_types.boost - : constants_1.default.message_types.direct_payment, - sender: botContactId, - amount: amount || 0, - date: date, - status: constants_1.default.statuses.confirmed, - replyUuid: reply_uuid || '', - createdAt: date, - updatedAt: date, - senderAlias: alias, - tenant, - }; + : constants_1.default.message_types.direct_payment, sender: botContactId, amount: amount || 0, date: date, status: constants_1.default.statuses.confirmed, replyUuid: reply_uuid || '', createdAt: date, updatedAt: date, senderAlias: alias, tenant }, (reply_uuid + ? {} + : { + messageContent: encryptedForMeText, + remoteMessageContent: JSON.stringify(textMap), + })); if (parent_id) msg.parentId = parent_id; const message = (yield models_1.models.Message.create(msg)); diff --git a/dist/src/controllers/botapi/pay.js.map b/dist/src/controllers/botapi/pay.js.map index 33d49e2eb..b40a8b3cc 100644 --- a/dist/src/controllers/botapi/pay.js.map +++ b/dist/src/controllers/botapi/pay.js.map @@ -1 +1 @@ -{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../../src/controllers/botapi/pay.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oCAAmC;AACnC,yCAAwC;AACxC,yCAA8C;AAC9C,8CAA6C;AAC7C,6CAA4C;AAC5C,+CAAuC;AACvC,+CAAiD;AACjD,2DAAuD;AACvD,mCAAgD;AAEhD,SAA8B,GAAG,CAAC,CAAS;;QACzC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;QAE7E,qBAAY,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;QAC7D,IAAI,CAAC,CAAC,CAAC,YAAY;YAAE,OAAO,qBAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;QACjE,MAAM,GAAG,GAAG,MAAM,IAAA,sBAAc,EAAC,CAAC,CAAC,CAAA;QACnC,IAAI,CAAC,GAAG;YAAE,OAAM;QAChB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;QAC3B,MAAM,MAAM,GAAW,KAAK,CAAC,EAAE,CAAA;QAC/B,MAAM,KAAK,GAAG,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAA;QACr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AAE;gBACX,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC;aAChC;YACD,MAAM,EAAE,MAAM,IAAI,CAAC;YACnB,IAAI,EAAE,UAAU;gBACd,CAAC,CAAC,mBAAS,CAAC,aAAa,CAAC,KAAK;gBAC/B,CAAC,CAAC,mBAAS,CAAC,aAAa,CAAC,cAAc;YAC1C,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAClC,OAAO,EAAE,CAAO,CAAC,EAAE,EAAE;gBACnB,MAAM,QAAQ,GAAG,IAAA,2BAAY,EAAC,CAAC,CAAC,CAAA;gBAChC,MAAM,OAAO,CAAC,MAAM,CAAC;oBACnB,YAAY,EAAE,QAAQ;oBACtB,MAAM,EAAE,mBAAS,CAAC,QAAQ,CAAC,MAAM;iBAClC,CAAC,CAAA;gBACF,OAAO,qBAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC9B,CAAC,CAAA;YACD,WAAW,EAAE,IAAI;YACjB,iBAAiB,EAAE,YAAY;SAChC,CAAC,CAAA;IACJ,CAAC;CAAA;AAxED,sBAwEC"} \ No newline at end of file +{"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../../src/controllers/botapi/pay.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oCAAmC;AACnC,yCAAwC;AACxC,yCAA8C;AAC9C,8CAA6C;AAC7C,6CAA4C;AAC5C,+CAAuC;AACvC,+CAAiD;AACjD,2DAAuD;AACvD,wCAAuC;AACvC,mCAAgD;AAEhD,SAA8B,GAAG,CAAC,CAAS;;QACzC,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,O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AAC,aAAa,CAAC,KAAK;gBAC/B,CAAC,CAAC,mBAAS,CAAC,aAAa,CAAC,cAAc;YAC1C,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAClC,OAAO,EAAE,CAAO,CAAC,EAAE,EAAE;gBACnB,MAAM,QAAQ,GAAG,IAAA,2BAAY,EAAC,CAAC,CAAC,CAAA;gBAChC,MAAM,OAAO,CAAC,MAAM,CAAC;oBACnB,YAAY,EAAE,QAAQ;oBACtB,MAAM,EAAE,mBAAS,CAAC,QAAQ,CAAC,MAAM;iBAClC,CAAC,CAAA;gBACF,OAAO,qBAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC9B,CAAC,CAAA;YACD,WAAW,EAAE,IAAI;YACjB,iBAAiB,EAAE,YAAY;SAChC,CAAC,CAAA;IACJ,CAAC;CAAA;AAzFD,sBAyFC"} \ No newline at end of file diff --git a/src/controllers/botapi/pay.ts b/src/controllers/botapi/pay.ts index 63d9cd56d..0e8adbd4b 100644 --- a/src/controllers/botapi/pay.ts +++ b/src/controllers/botapi/pay.ts @@ -6,10 +6,19 @@ import * as socket from '../../utils/socket' import constants from '../../constants' import { sphinxLogger } from '../../utils/logger' import { errMsgString } from '../../utils/errMsgString' +import * as rsa from '../../crypto/rsa' import { Action, validateAction } from './index' export default async function pay(a: Action): Promise { - const { amount, bot_name, msg_uuid, reply_uuid, recipient_id, parent_id } = a + const { + amount, + bot_name, + msg_uuid, + reply_uuid, + recipient_id, + parent_id, + content, + } = a sphinxLogger.info(`=> BOT PAY ${JSON.stringify(a, null, 2)}`) if (!a.recipient_id) return sphinxLogger.error(`no recipient_id`) @@ -19,6 +28,9 @@ export default async function pay(a: Action): Promise { const tenant: number = owner.id const alias = bot_name || owner.alias const botContactId = -1 + const encryptedForMeText = rsa.encrypt(owner.contactKey, content || '') + const encryptedText = rsa.encrypt(chat.groupKey, content || '') + const textMap = { chat: encryptedText } const date = new Date() date.setMilliseconds(0) @@ -37,6 +49,12 @@ export default async function pay(a: Action): Promise { updatedAt: date, senderAlias: alias, tenant, + ...(reply_uuid + ? {} + : { + messageContent: encryptedForMeText, + remoteMessageContent: JSON.stringify(textMap), + }), } if (parent_id) msg.parentId = parent_id const message: Message = (await models.Message.create(msg)) as Message