diff options
| author | Adam Soltys <[email protected]> | 2023-01-18 23:14:48 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-18 23:14:48 -0800 |
| commit | ef3679051214a9b3047b68f236eac656edcf8d38 (patch) | |
| tree | 426eda7cf7e36026c60da2ae28ce7c61804518f8 /lib/utils.js | |
| parent | 90ddef9f0dd93e8f980eb728cf0519d9215163f0 (diff) | |
| download | coinos-server-ef3679051214a9b3047b68f236eac656edcf8d38.tar.gz coinos-server-ef3679051214a9b3047b68f236eac656edcf8d38.zip | |
bitcoin invoices
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 9 |
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; +}; |
