aboutsummaryrefslogtreecommitdiffstats
path: root/routes/payments.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-24 14:46:46 -0800
committerAdam Soltys <[email protected]>2023-01-24 14:46:46 -0800
commitadf35d736de2cd870e363abc28a0989158ea0b5b (patch)
tree3f5b6f1cea7a1db0aafe9b707f8fff8bff1f1c36 /routes/payments.js
parentdcec2c0656d4fcb4e7713a46e39b1fccae915f2f (diff)
downloadcoinos-server-adf35d736de2cd870e363abc28a0989158ea0b5b.tar.gz
coinos-server-adf35d736de2cd870e363abc28a0989158ea0b5b.zip
move lnurl routes
Diffstat (limited to 'routes/payments.js')
-rw-r--r--routes/payments.js59
1 files changed, 0 insertions, 59 deletions
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 });
- }
};