diff options
| author | Adam Soltys <[email protected]> | 2024-08-25 21:55:01 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-25 21:55:26 -0700 |
| commit | 5269deaa617dae61cdb97aca80269bf311e8dc4b (patch) | |
| tree | 882faa6b4346abec49338fedf421c7eacfae8681 /lib/utils.js | |
| parent | c5c201b441e0b1ef7d0df19bd936d0ccfa9e601c (diff) | |
| download | coinos-server-5269deaa617dae61cdb97aca80269bf311e8dc4b.tar.gz coinos-server-5269deaa617dae61cdb97aca80269bf311e8dc4b.zip | |
add nwc field to user
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/utils.js b/lib/utils.js index dfc9f3c1..f53b76d2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,6 +1,7 @@ +import { randomBytes, bytesToHex } from "@noble/hashes/utils"; import migrate from "$lib/migrate"; import store from "$lib/store"; -import { g } from "$lib/db"; +import { g, s } from "$lib/db"; import config from "$config"; export let fail = (msg) => { @@ -37,7 +38,7 @@ export let bip21 = (address, { amount, memo, tip, type }) => { let url = new URLSearchParams(); if (amount) { - url.append("amount", btc(amount+tip)); + url.append("amount", btc(amount + tip)); if (type === "liquid") url.append("assetid", config.liquid.btc); } @@ -68,7 +69,13 @@ export let fields = [ export let getUser = async (username) => { if (username === "undefined") fail("invalid user"); - return migrate(username); + let user = await migrate(username); + if (!user.nwc) { + user.nwc = bytesToHex(randomBytes(32)); + s(`user:${user.id}`, user); + } + + return user; }; export let getInvoice = async (hash) => { |
