From cc7d9d734c379da3fdc3750f17b210425ec5fffe Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 24 Apr 2024 03:28:25 +0200 Subject: [PATCH] Support LNURL-verify (#1103) --- pages/api/lnurlp/[username]/pay.js | 3 ++- pages/api/lnurlp/[username]/verify/[hash].js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pages/api/lnurlp/[username]/verify/[hash].js diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index c4b3c411..30896194 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -90,7 +90,8 @@ export default async ({ query: { username, amount, nostr, comment, payerdata: pa return res.status(200).json({ pr: invoice.request, - routes: [] + routes: [], + verify: `${process.env.NEXT_PUBLIC_URL}/api/lnurlp/${username}/verify/${invoice.id}` }) } catch (error) { console.log(error) diff --git a/pages/api/lnurlp/[username]/verify/[hash].js b/pages/api/lnurlp/[username]/verify/[hash].js new file mode 100644 index 00000000..a8887b41 --- /dev/null +++ b/pages/api/lnurlp/[username]/verify/[hash].js @@ -0,0 +1,15 @@ +import lnd from '@/api/lnd' +import { getInvoice } from 'ln-service' + +export default async ({ query: { hash } }, res) => { + try { + const inv = await getInvoice({ id: hash, lnd }) + const settled = inv.is_confirmed + return res.status(200).json({ status: 'OK', settled, preimage: settled ? inv.secret : null, pr: inv.request }) + } catch (err) { + if (err[1] === 'UnexpectedLookupInvoiceErr') { + return res.status(404).json({ status: 'ERROR', reason: 'not found' }) + } + return res.status(500).json({ status: 'ERROR', reason: 'internal server error' }) + } +}