diff options
Diffstat (limited to 'src/lnurl.js')
| -rw-r--r-- | src/lnurl.js | 10 |
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); |
