diff options
Diffstat (limited to 'names')
| -rw-r--r-- | names/server.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/names/server.js b/names/server.js index 4d7a81c..683702c 100644 --- a/names/server.js +++ b/names/server.js @@ -1882,6 +1882,21 @@ Bun.serve({ }); } + // LUD-21 verify for an invoice our node minted for a name (see below) + const vm = url.pathname.match(/^\/lnurlp\/verify\/([0-9a-f]{64})$/); + if (vm && req.method === 'GET') { + if (!rateOk(ip, 120)) return json({ status: 'ERROR', reason: 'rate limited' }, 429); + const rec = (state.invoices || {})[vm[1]]; + if (!rec || !ln) return json({ status: 'ERROR', reason: 'Not found' }, 404); + try { + const inv = (await ln.call('listinvoices', { payment_hash: vm[1] })).invoices?.[0]; + if (!inv) return json({ status: 'ERROR', reason: 'Not found' }, 404); + const settled = inv.status === 'paid'; + return json({ status: 'OK', settled, preimage: settled ? inv.payment_preimage || null : null, pr: inv.bolt11 || rec.bolt11 }); + } catch { + return json({ status: 'ERROR', reason: 'could not check the invoice' }, 500); + } + } const cb = url.pathname.match(/^\/lnurlp\/([a-z0-9._-]{1,30})\/cb$/i); if (cb && req.method === 'GET') { const name = cb[1].toLowerCase(); @@ -1955,7 +1970,10 @@ Bun.serve({ } persist(); log(`lnurl ${key}: issued ${sat} sat (forwarding on settle)`); - return json({ pr: inv.bolt11, routes: [] }); + // LUD-21: our node knows when its own invoice is paid, so the payer + // (the v3.coinos.io/<name>/receive page) can be told. An invoice the + // recipient's wallet minted has no such URL: only that wallet knows. + return json({ pr: inv.bolt11, routes: [], verify: `${PUBLIC_BASE}/lnurlp/verify/${inv.payment_hash}` }); } catch (e) { log('lnurl invoice failed: ' + e.message); return json({ status: 'ERROR', reason: 'could not create an invoice' }, 500); |
