aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-24 09:53:51 -0800
committerAdam Soltys <[email protected]>2023-01-24 09:53:51 -0800
commitf24aec1fb7dd4080d961c26ab5216fd2dfe5d971 (patch)
treed2ba4443b904431117a4939628cbf0ccbc3a7619 /routes
parentd8d07fac1cd3da8e128677c758d0c81ad1ba7a79 (diff)
downloadcoinos-server-f24aec1fb7dd4080d961c26ab5216fd2dfe5d971.tar.gz
coinos-server-f24aec1fb7dd4080d961c26ab5216fd2dfe5d971.zip
lnurl endpoints
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 3ec196cd..53bb6e4d 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -7,6 +7,8 @@ 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 got from "got";
import bc from "$lib/bitcoin";
import ln from "$lib/ln";
@@ -217,5 +219,33 @@ export default {
await bc.sendRawTransaction(hex);
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);
+ console.log(enc);
+ 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 lnurl({ params: { code }, query: { amount } }, res) {
+ let { uid } = await g(`code:${code}`);
+
+ let url = Buffer.from(
+ bech32.fromWords(bech32.decode(text, 20000).words)
+ ).toString();
+
+ res.send(await got(url).json());
}
};