diff options
| author | Adam Soltys <[email protected]> | 2026-02-11 17:51:24 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-11 17:51:24 -0800 |
| commit | 13466248004327e9a026cb89f94926f9b060d1c1 (patch) | |
| tree | 47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/lib/bip21.ts | |
| parent | 3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff) | |
| download | coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip | |
linting
Diffstat (limited to 'src/lib/bip21.ts')
| -rw-r--r-- | src/lib/bip21.ts | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/lib/bip21.ts b/src/lib/bip21.ts index 4689246e..842782a5 100644 --- a/src/lib/bip21.ts +++ b/src/lib/bip21.ts @@ -1,50 +1,50 @@ export function decode(uri, allowedSchemes = ["bitcoin", "liquidnetwork"]) { - // Determine the scheme from the URI - const split = uri.indexOf(":"); - if (split === -1) { - throw new Error("Invalid URI: Missing scheme"); - } + // Determine the scheme from the URI + const split = uri.indexOf(":"); + if (split === -1) { + throw new Error("Invalid URI: Missing scheme"); + } - const urnScheme = uri.slice(0, split).toLowerCase(); - if (!allowedSchemes.includes(urnScheme)) { - throw new Error(`Invalid scheme: ${urnScheme}`); - } + const urnScheme = uri.slice(0, split).toLowerCase(); + if (!allowedSchemes.includes(urnScheme)) { + throw new Error(`Invalid scheme: ${urnScheme}`); + } - // Extract address and query string - const queryStart = uri.indexOf("?"); - const address = uri.slice( - split + 1, - queryStart === -1 ? undefined : queryStart, - ); - const query = queryStart === -1 ? "" : uri.slice(queryStart + 1); - const options = Object.fromEntries(new URLSearchParams(query)); + // Extract address and query string + const queryStart = uri.indexOf("?"); + const address = uri.slice( + split + 1, + queryStart === -1 ? undefined : queryStart, + ); + const query = queryStart === -1 ? "" : uri.slice(queryStart + 1); + const options = Object.fromEntries(new URLSearchParams(query)); - if (options.amount) { - const n = Number(options.amount); - if (!Number.isFinite(n)) throw new Error("Invalid amount"); - if (n < 0) throw new Error("Invalid amount"); - } + if (options.amount) { + const n = Number(options.amount); + if (!Number.isFinite(n)) throw new Error("Invalid amount"); + if (n < 0) throw new Error("Invalid amount"); + } - return { scheme: urnScheme, address, options }; + return { scheme: urnScheme, address, options }; } export function encode( - address, - options = { amount: "" }, - urnScheme = "bitcoin", + address, + options = { amount: "" }, + urnScheme = "bitcoin", ) { - if (!address || typeof address !== "string") { - throw new TypeError("Invalid address"); - } + if (!address || typeof address !== "string") { + throw new TypeError("Invalid address"); + } - if (!["bitcoin", "liquidnetwork"].includes(urnScheme)) { - throw new Error(`Unsupported scheme: ${urnScheme}`); - } + if (!["bitcoin", "liquidnetwork"].includes(urnScheme)) { + throw new Error(`Unsupported scheme: ${urnScheme}`); + } - const n = Number(options?.amount); - if (!Number.isFinite(n)) throw new Error("Invalid amount"); - if (n < 0) throw new Error("Invalid amount"); + const n = Number(options?.amount); + if (!Number.isFinite(n)) throw new Error("Invalid amount"); + if (n < 0) throw new Error("Invalid amount"); - const query = new URLSearchParams(options).toString(); - return `${urnScheme}:${address}${query ? `?${query}` : ""}`; + const query = new URLSearchParams(options).toString(); + return `${urnScheme}:${address}${query ? `?${query}` : ""}`; } |
