diff options
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) => { |
