From e16c056ef1ace808c810a4f178ec6a07a16adec8 Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 7 Oct 2021 13:36:12 -0700 Subject: [PATCH] attempt description hash encoding --- pages/api/lnurlp/[username]/pay.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index a99a4237..6e5f9c4e 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -1,6 +1,18 @@ import models from '../../../../api/models' import lnd from '../../../../api/lnd' import { createInvoice } from 'ln-service' +import crypto from 'crypto' + +function utf8ByteArray (str) { + const utf8 = unescape(encodeURIComponent(str)) + + const arr = [] + for (let i = 0; i < utf8.length; i++) { + arr.push(utf8.charCodeAt(i)) + } + + return Buffer.from(arr) +} export default async ({ query: { username, amount } }, res) => { const user = await models.user.findUnique({ where: { name: username } }) @@ -14,10 +26,15 @@ export default async ({ query: { username, amount } }, res) => { // generate invoice const expiresAt = new Date(new Date().setHours(new Date().getHours() + 3)) - const description = `Funding @${username} on stacker.news` + const description = `${amount} msats for @${user.name} on stacker.news` + const descriptionHash = crypto + .createHash('sha256') + .update(utf8ByteArray(`Funding @${username} on stacker.news`)) + .digest('hex') try { const invoice = await createInvoice({ description, + description_hash: descriptionHash, lnd, mtokens: amount, expires_at: expiresAt