aboutsummaryrefslogtreecommitdiffstats
path: root/src
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 /src
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 'src')
-rw-r--r--src/lnurl.js10
1 files changed, 9 insertions, 1 deletions
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);