From 9f55be849bbac1aa5071fa5a93289fda6fe08e08 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 3 Dec 2026 21:38:31 -0700 Subject: 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/ 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 " stands. New lnurl-cors-fallback-test passes; lnurl-withdraw and features-smoke pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar --- src/lnurl.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/lnurl.js') diff --git a/src/lnurl.js b/src/lnurl.js index 134edcf..53b98df 100644 --- a/src/lnurl.js +++ b/src/lnurl.js @@ -75,6 +75,8 @@ export function zapTargetFromProfile(profile, pk) { return null; } +const LNURLP_FETCH = 'https://names.coinos.io/lnurlp-fetch'; + function safeEncode(url) { try { return encodeLnurl(url); } catch { return null; } } // Errors name the server: the recipient's Lightning address lives on THEIR @@ -104,7 +106,13 @@ async function fetchJson(url, ms = 8000) { // An lnurl that turns out to be a withdraw (LUD-03) is not an error here: // the thrown error carries its terms (`withdraw`) for the caller to take up. export async function fetchPayParams(url) { - const d = await fetchJson(url); + let d; + try { d = await fetchJson(url); } catch (e) { + // A host the browser can't follow, e.g. speed.app's redirect to its API + // carries no CORS header: ask the registrar to fetch the same address. + if (!/^couldn’t reach /.test(e.message) || !/^https:\/\/[^/]+\/\.well-known\/lnurlp\//.test(url)) throw e; + d = await fetchJson(`${LNURLP_FETCH}?url=${encodeURIComponent(url)}`, 12000).catch(() => { throw e; }); + } if (!d || d.tag !== 'payRequest' || !d.callback) { if (d && d.status === 'ERROR') throw new Error(d.reason || 'LNURL error'); const w = withdrawParamsOf(d); -- cgit v1.2.3