From 47fb252db851655c4b71ca6e5e12fed669bfe2c3 Mon Sep 17 00:00:00 2001 From: Daniel Candia Flores Date: Tue, 20 Aug 2024 18:46:15 -0400 Subject: [PATCH 1/4] Remove the lightning prefix from the lnInvoice --- bot/commands.js | 4 +++- bot/validations.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bot/commands.js b/bot/commands.js index 98d09b65..d96c5409 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -21,6 +21,7 @@ const OrderEvents = require('./modules/events/orders'); const { resolvLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); +const { removeLightningPrefix } = require('./bot_utils'); const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => { try { @@ -32,7 +33,8 @@ const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => { return; } - order.buyer_invoice = buyerInvoice; + // ISSUE: 542 + order.buyer_invoice = removeLightningPrefix(buyerInvoice); // We need the i18n context to send the message with the correct language const i18nCtx = await getUserI18nContext(seller); // If the buyer is the creator, at this moment the seller already paid the hold invoice diff --git a/bot/validations.js b/bot/validations.js index 781622b9..81dee182 100644 --- a/bot/validations.js +++ b/bot/validations.js @@ -5,6 +5,7 @@ const { Order, User, Community } = require('../models'); const { isIso4217, isDisputeSolver } = require('../util'); const { existLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); +const { removeLightningPrefix } = require('./bot_utils'); // We look in database if the telegram user exists, // if not, it creates a new user @@ -305,7 +306,11 @@ const validateLightningAddress = async lightningAddress => { const validateInvoice = async (ctx, lnInvoice) => { try { - const invoice = parsePaymentRequest({ request: lnInvoice }); + // ISSUE: 542 + + const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice); + const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice }); + const latestDate = new Date( Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW) ).toISOString(); @@ -344,7 +349,11 @@ const validateInvoice = async (ctx, lnInvoice) => { const isValidInvoice = async (ctx, lnInvoice) => { try { - const invoice = parsePaymentRequest({ request: lnInvoice }); + // ISSUE: 542 + + const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice); + const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice }); + const latestDate = new Date( Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW) ).toISOString(); From 26fc8781affbd06c54584b9e0339afaeb98275df Mon Sep 17 00:00:00 2001 From: Daniel Candia Flores Date: Tue, 20 Aug 2024 21:57:16 -0400 Subject: [PATCH 2/4] Commit missed file --- bot/bot_utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bot/bot_utils.js diff --git a/bot/bot_utils.js b/bot/bot_utils.js new file mode 100644 index 00000000..717fe264 --- /dev/null +++ b/bot/bot_utils.js @@ -0,0 +1,15 @@ +const removeLightningPrefix = function (invoice) { + const prefix = 'lightning:'; + + // Check if the invoice starts with the prefix + if (invoice.startsWith(prefix)) { + return invoice.substring(prefix.length); + } + + // Return the invoice as is if no prefix is found + return invoice; +}; + +module.exports = { + removeLightningPrefix +}; \ No newline at end of file From af8fba917391fe432bc450e94a8bda5c5ea9dedc Mon Sep 17 00:00:00 2001 From: Daniel Candia Flores Date: Wed, 21 Aug 2024 15:08:14 -0400 Subject: [PATCH 3/4] Move to folder util and rename the bot_utils.js file --- bot/commands.js | 2 +- bot/validations.js | 2 +- bot/bot_utils.js => util/valitationUtils.js | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename bot/bot_utils.js => util/valitationUtils.js (100%) diff --git a/bot/commands.js b/bot/commands.js index d96c5409..099aa3cc 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -21,7 +21,7 @@ const OrderEvents = require('./modules/events/orders'); const { resolvLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); -const { removeLightningPrefix } = require('./bot_utils'); +const { removeLightningPrefix } = require('../util/valitationUtils'); const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => { try { diff --git a/bot/validations.js b/bot/validations.js index 81dee182..c9aab38c 100644 --- a/bot/validations.js +++ b/bot/validations.js @@ -5,7 +5,7 @@ const { Order, User, Community } = require('../models'); const { isIso4217, isDisputeSolver } = require('../util'); const { existLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); -const { removeLightningPrefix } = require('./bot_utils'); +const { removeLightningPrefix } = require('../util/valitationUtils'); // We look in database if the telegram user exists, // if not, it creates a new user diff --git a/bot/bot_utils.js b/util/valitationUtils.js similarity index 100% rename from bot/bot_utils.js rename to util/valitationUtils.js From 83ec8928c683e80e224ecd0396e67fd27c2f54a3 Mon Sep 17 00:00:00 2001 From: Daniel Candia Flores Date: Mon, 26 Aug 2024 11:09:33 -0400 Subject: [PATCH 4/4] Change valitationUtils to Typescript file --- util/{valitationUtils.js => valitationUtils.ts} | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) rename util/{valitationUtils.js => valitationUtils.ts} (72%) diff --git a/util/valitationUtils.js b/util/valitationUtils.ts similarity index 72% rename from util/valitationUtils.js rename to util/valitationUtils.ts index 717fe264..39e887ae 100644 --- a/util/valitationUtils.js +++ b/util/valitationUtils.ts @@ -1,4 +1,4 @@ -const removeLightningPrefix = function (invoice) { +export const removeLightningPrefix = (invoice: string): string => { const prefix = 'lightning:'; // Check if the invoice starts with the prefix @@ -9,7 +9,3 @@ const removeLightningPrefix = function (invoice) { // Return the invoice as is if no prefix is found return invoice; }; - -module.exports = { - removeLightningPrefix -}; \ No newline at end of file