From ef3679051214a9b3047b68f236eac656edcf8d38 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 18 Jan 2023 23:14:48 -0800 Subject: bitcoin invoices --- lib/utils.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/utils.js') diff --git a/lib/utils.js b/lib/utils.js index 92b34be5..e653f235 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -28,3 +28,12 @@ export const toSats = n => Math.round(n * SATS); export const uniq = (a, k) => [...new Map(a.map(x => [k(x), x])).values()]; export const pick = (O, K) => K.reduce((o, k) => (typeof O[k] !== "undefined" && (o[k] = O[k]), o), {}); + +export const bip21 = (address, { amount, memo, tip }) => { + let url = amount || memo ? `bitcoin:${address}?` : address; + if (amount) + url += `amount=${((amount + tip) / SATS).toFixed(8)}${memo ? "&" : ""}`; + if (memo) url += `message=${memo}`; + + return url; +}; -- cgit v1.2.3