diff options
| author | Adam Soltys <[email protected]> | 2024-10-31 09:29:04 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-31 09:34:42 -0700 |
| commit | aa4cd39c943b67169def224e224bd07b815b70ec (patch) | |
| tree | 2af857ac971705f4d20eb017864f0365d0b57ea6 /routes/lnurl.ts | |
| parent | bc9c04f6519f32d3b444d4df0b276eba960480a9 (diff) | |
| download | coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.tar.gz coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.zip | |
biome lint
Diffstat (limited to 'routes/lnurl.ts')
| -rw-r--r-- | routes/lnurl.ts | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/routes/lnurl.ts b/routes/lnurl.ts index fec516c1..a93e63e4 100644 --- a/routes/lnurl.ts +++ b/routes/lnurl.ts @@ -8,36 +8,36 @@ import { bech32 } from "bech32"; import { types } from "$lib/payments"; import { serverPubkey } from "$lib/nostr"; -let { URL } = process.env; -let host = URL.split("/").at(-1); +const { URL } = process.env; +const host = URL.split("/").at(-1); export default { async encode(req, res) { - let { + const { query: { address }, } = req; - let [name, domain] = address.split("@"); - let url = `https://${domain}/.well-known/lnurlp/${name}`; + const [name, domain] = address.split("@"); + const url = `https://${domain}/.well-known/lnurlp/${name}`; try { - let r = await got(url).json(); + const r = await got(url).json(); if (r.tag !== "payRequest") fail("not an ln address"); } catch (e) { - let m = `failed to lookup lightning address ${address}`; + const m = `failed to lookup lightning address ${address}`; warn(m); return bail(res, m); } - let enc = bech32.encode("lnurl", bech32.toWords(Buffer.from(url)), 20000); + const enc = bech32.encode("lnurl", bech32.toWords(Buffer.from(url)), 20000); res.send(enc); }, async decode(req, res) { - let { + const { query: { text }, } = req; try { - let url = Buffer.from( + const url = Buffer.from( bech32.fromWords(bech32.decode(text, 20000).words), ).toString(); @@ -48,19 +48,19 @@ export default { }, async lnurlp(req, res) { - let { + const { params: { username }, query: { minSendable = 1000, maxSendable = 100000000000 }, } = req; try { - let { id: uid } = await getUser(username); + const { id: uid } = await getUser(username); - let metadata = JSON.stringify([ + const metadata = JSON.stringify([ ["text/plain", `Paying ${username}@${host}`], ["text/identifier", `${username}@${host}`], ]); - let id = v4(); + const id = v4(); await s(`lnurl:${id}`, uid); res.send({ @@ -80,18 +80,18 @@ export default { }, async lnurl(req, res) { - let { + const { params: { id }, query: { amount, comment, nostr }, } = req; try { - let uid = await g(`lnurl:${id}`); - let user = await getUser(uid); + const uid = await g(`lnurl:${id}`); + const user = await getUser(uid); if (!user) fail("user not found"); let { username } = user; username = username.replace(/\s/g, "").toLowerCase(); - let memo = `Paying ${username}@${host}`; + const memo = `Paying ${username}@${host}`; let metadata = JSON.stringify([ ["text/plain", memo], ["text/identifier", `${username}@${host}`], @@ -99,7 +99,7 @@ export default { if (nostr) { try { - let event = JSON.parse(decodeURIComponent(nostr)); + const event = JSON.parse(decodeURIComponent(nostr)); // TODO: validate the event await s(`zap:${id}`, event); metadata = nostr; @@ -108,7 +108,7 @@ export default { } } - let { id: iid, text: pr } = await generate({ + const { id: iid, text: pr } = await generate({ invoice: { amount: Math.round(amount / 1000), memo: metadata, @@ -124,15 +124,15 @@ export default { }, async verify(req, res) { - let { + const { params: { id }, } = req; - let inv = await g(`invoice:${id}`); + const inv = await g(`invoice:${id}`); if (!inv) return res.send({ status: "ERROR", reason: "Not found" }); - let { received, amount, preimage } = inv; - let settled = received >= amount; + const { received, amount, preimage } = inv; + const settled = received >= amount; res.send({ status: "OK", settled, preimage }); }, |
