aboutsummaryrefslogtreecommitdiffstats
path: root/names/server.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-23 09:21:29 -0700
committerAdam Soltys <[email protected]>2026-11-23 09:21:29 -0700
commite40c5eb1918f41130022f73e3db8a3087837f02f (patch)
treea7358387c7c33f17a7e10171e0c21873a62da20b /names/server.js
parentdf023414aa176cfc63b90c1a258474e8247b3441 (diff)
downloadcoinosv3-server-e40c5eb1918f41130022f73e3db8a3087837f02f.tar.gz
coinosv3-server-e40c5eb1918f41130022f73e3db8a3087837f02f.zip
names: LUD-21 verify for invoices our node mints
A name's LNURL-pay callback now returns a `verify` URL when the invoice comes from our node (the recipient's wallet was not listening), and GET /lnurlp/verify/<hash> answers {status, settled, preimage, pr} from CLN. The v3.coinos.io/<name>/receive pay page (coinosv3) polls it to say "Paid". An invoice the recipient's own wallet minted has no verify URL: only that wallet knows when it is paid. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
Diffstat (limited to 'names/server.js')
-rw-r--r--names/server.js20
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);