aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js9
1 files changed, 9 insertions, 0 deletions
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;
+};