diff options
| author | Adam Soltys <[email protected]> | 2023-01-24 14:46:46 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-24 14:46:46 -0800 |
| commit | adf35d736de2cd870e363abc28a0989158ea0b5b (patch) | |
| tree | 3f5b6f1cea7a1db0aafe9b707f8fff8bff1f1c36 | |
| parent | dcec2c0656d4fcb4e7713a46e39b1fccae915f2f (diff) | |
| download | coinos-server-adf35d736de2cd870e363abc28a0989158ea0b5b.tar.gz coinos-server-adf35d736de2cd870e363abc28a0989158ea0b5b.zip | |
move lnurl routes
| -rw-r--r-- | lib/invoices.js | 2 | ||||
| -rw-r--r-- | routes/invoices.js | 4 | ||||
| -rw-r--r-- | routes/lnurl.js | 4 | ||||
| -rw-r--r-- | routes/payments.js | 59 |
4 files changed, 5 insertions, 64 deletions
diff --git a/lib/invoices.js b/lib/invoices.js index 7a45b1c0..f17223aa 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -9,7 +9,7 @@ import { v4 } from "uuid"; import bc from "$lib/bitcoin"; import ln from "$lib/ln"; -export let invoice = async ({ invoice, user, sender }) => { +export let generate = async ({ invoice, user, sender }) => { let { currency, tip, amount, rate, request_id, type } = invoice; if (amount < 0) fail("amount out of range"); diff --git a/routes/invoices.js b/routes/invoices.js index a4155d94..d1ec5338 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -1,5 +1,5 @@ import { g, s } from "$lib/db"; -import { invoice } from "$lib/invoices"; +import { generate } from "$lib/invoices"; export default { async get({ query: { hash } }, res) { @@ -9,6 +9,6 @@ export default { }, async create({ body: { invoice, user }, user: sender }, res) { - res.send(await invoice({ invoice, user, sender })); + res.send(await generate({ invoice, user, sender })); } }; diff --git a/routes/lnurl.js b/routes/lnurl.js index cb1b75c5..63488033 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -3,7 +3,7 @@ import { l } from "$lib/logging"; import { fail } from "$lib/utils"; import { v4 } from "uuid"; import got from "got"; -import { invoice } from "$lib/invoices"; +import { generate } from "$lib/invoices"; import { bech32 } from "bech32"; export default { @@ -50,7 +50,7 @@ export default { let uid = await g(`lnurl:${id}`); let user = await g(`user:${uid}`); - ({ text: pr } = await invoice({ + ({ text: pr } = await generate({ invoice: { amount, type: types.lightning diff --git a/routes/payments.js b/routes/payments.js index b80d54f6..a060d90a 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -7,9 +7,6 @@ import { l, err } from "$lib/logging"; import { fail, btc, sats } from "$lib/utils"; import { requirePin } from "$lib/auth"; import { debit, credit, confirm, types } from "$lib/payments"; -import { bech32 } from "bech32"; -import { invoice } from "$lib/invoices"; -import got from "got"; import bc from "$lib/bitcoin"; import ln from "$lib/ln"; @@ -220,60 +217,4 @@ export default { res.send({ txid }); }, - async encode({ query: { address } }, res) { - let [name, domain] = address.split("@"); - let url = `https://${domain}/.well-known/lnurlp/${name}`; - let r = await got(url).json(); - if (r.tag !== "payRequest") fail("not an ln address"); - let enc = bech32.encode("lnurl", bech32.toWords(Buffer.from(url)), 20000); - res.send(enc); - }, - - async decode({ query: { text } }, res) { - let url = Buffer.from( - bech32.fromWords(bech32.decode(text, 20000).words) - ).toString(); - - res.send(await got(url).json()); - }, - - async lnurlp({ params: { username } }, res) { - let uid = await g(`user:${username}`); - if (!uid) fail("user not found"); - - let id = v4(); - await s(`lnurl:${id}`, uid); - let { URL } = process.env; - let host = URL.split("/").at(-1); - - res.send({ - metadata: [ - ["text/plain", `Paying ${username}@${host}`], - ["text/identifier", `${username}@${host}`] - ], - callback: `${host}/lnurl/${id}`, - tag: "payRequest" - }); - }, - - async lnurl({ params: { id }, query: { amount } }, res) { - let pr = await g(`lnurlp:${id}`); - - if (!pr) { - let uid = await g(`lnurl:${id}`); - let user = await g(`user:${uid}`); - - ({ text: pr } = await invoice({ - invoice: { - amount, - type: types.lightning - }, - user - })); - - await s(`lnurlp:${id}`, pr); - } - - res.send({ pr }); - } }; |
