aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-12-03 21:38:31 -0700
committerAdam Soltys <[email protected]>2026-12-03 21:38:31 -0700
commit9f55be849bbac1aa5071fa5a93289fda6fe08e08 (patch)
tree6fa201dfd44529ab087bd1e2597aae4f94e42843 /tools
parent882045fac8a47d4e7a8592c3c287a0570a7eedf0 (diff)
downloadcoinosv3-9f55be849bbac1aa5071fa5a93289fda6fe08e08.tar.gz
coinosv3-9f55be849bbac1aa5071fa5a93289fda6fe08e08.zip
A Lightning address the browser can't fetch (speed.app) is fetched through the registrar.
"another thing is coinos cannot reach speed.app wallet, not sure why" (Shark, relayed by Adam 2026-12-04). speed.app answers /.well-known/lnurlp/<name> with a 301 to appapi.tryspeed.com that has no Access-Control-Allow-Origin, and a browser won't follow a cross-origin redirect without one, so paying any @speed.app address said "couldn't reach speed.app". When the browser can't reach a Lightning address's host at all (fetch throws), the wallet now asks names.coinos.io/lnurlp-fetch (coinosv3-server, live) for the same address and carries on with its pay parameters; speed's invoice callback itself allows any origin, so the payment completes from the browser. A host's own error isn't retried elsewhere, other lnurl paths aren't sent to the registrar, and if the registrar can't reach it either the original "couldn't reach <host>" stands. New lnurl-cors-fallback-test passes; lnurl-withdraw and features-smoke pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar
Diffstat (limited to 'tools')
-rw-r--r--tools/lnurl-cors-fallback-test.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/lnurl-cors-fallback-test.js b/tools/lnurl-cors-fallback-test.js
new file mode 100644
index 0000000..bc3923c
--- /dev/null
+++ b/tools/lnurl-cors-fallback-test.js
@@ -0,0 +1,44 @@
+// A Lightning address whose host the browser can't fetch (speed.app answers
+// with a redirect that has no CORS header, so fetch throws a TypeError) is
+// fetched through the registrar's /lnurlp-fetch instead; any other failure
+// stays as it was. Run: bun tools/lnurl-cors-fallback-test.js
+import assert from 'node:assert/strict';
+import { fetchPayParams } from '../src/lnurl.js';
+
+const pay = { tag: 'payRequest', callback: 'https://api.example/cb', minSendable: 1000, maxSendable: 1e9, metadata: '[]' };
+let calls = [];
+const install = (handler) => { calls = []; globalThis.fetch = async (url) => { calls.push(String(url)); return handler(String(url)); }; };
+
+// the browser can't follow the host's redirect → the registrar's copy
+install((u) => {
+ if (u.startsWith('https://speed.example/')) throw new TypeError('Failed to fetch');
+ if (u.startsWith('https://names.coinos.io/lnurlp-fetch?url=')) {
+ assert.equal(decodeURIComponent(u.split('url=')[1]), 'https://speed.example/.well-known/lnurlp/bob');
+ return Response.json(pay);
+ }
+ throw new Error('unexpected ' + u);
+});
+const p = await fetchPayParams('https://speed.example/.well-known/lnurlp/bob');
+assert.equal(p.callback, 'https://api.example/cb');
+assert.equal(calls.length, 2);
+
+// a host that works is fetched directly, once
+install(() => Response.json(pay));
+await fetchPayParams('https://ok.example/.well-known/lnurlp/bob');
+assert.deepEqual(calls, ['https://ok.example/.well-known/lnurlp/bob']);
+
+// the host's own error isn't retried elsewhere
+install(() => Response.json({ status: 'ERROR', reason: 'no such user' }, { status: 404 }));
+await assert.rejects(fetchPayParams('https://ok.example/.well-known/lnurlp/nobody'), /no such user/);
+assert.equal(calls.length, 1);
+
+// unreachable both ways: the original "couldn't reach" stands
+install((u) => { if (u.includes('names.coinos.io')) return Response.json({ status: 'ERROR', reason: "couldn't reach that address" }, { status: 502 }); throw new TypeError('Failed to fetch'); });
+await assert.rejects(fetchPayParams('https://down.example/.well-known/lnurlp/bob'), /couldn’t reach down\.example/);
+
+// an lnurl1 that isn't a Lightning address path isn't sent to the registrar
+install(() => { throw new TypeError('Failed to fetch'); });
+await assert.rejects(fetchPayParams('https://down.example/lnurl/pay/abc'), /couldn’t reach/);
+assert.equal(calls.length, 1);
+
+console.log('lnurl-cors-fallback-test: ok');