From 273afd10bb321c1ac23ce14aba9f61b6ffe1e910 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 15 Jan 2025 12:45:31 -0800 Subject: sign endpoint --- index.ts | 1 + lib/invoices.ts | 7 ++++--- routes/invoices.ts | 10 ++++++++++ routes/nostr.ts | 6 +++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 8d12705f..e4212c0e 100644 --- a/index.ts +++ b/index.ts @@ -46,6 +46,7 @@ app.get("/locations", locations.list); app.get("/invoice/:id", invoices.get); app.get("/invoices", auth, invoices.list); app.post("/invoice", optional, invoices.create); +app.post("/sign", auth, invoices.sign); app.get("/nostr.json", nostr.identities); app.get("/profile/:profile", nostr.profile); diff --git a/lib/invoices.ts b/lib/invoices.ts index 0957231a..b158592c 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -13,6 +13,7 @@ const lq = rpc(config.liquid); export const generate = async ({ invoice, user }) => { let { + address_type = "bech32", bolt11, aid, currency, @@ -60,7 +61,7 @@ export const generate = async ({ invoice, user }) => { if (account.seed) { type = "bitcoin"; const node = rpc({ ...config[type], wallet: aid }); - hash = await node.getNewAddress(); + hash = await node.getNewAddress({ address_type }); text = bip21(hash, invoice); ({ hdkeypath: path } = await node.getAddressInfo(hash)); @@ -100,10 +101,10 @@ export const generate = async ({ invoice, user }) => { await s(`invoice:${r.offer_id}`, id); } else if (type === types.bitcoin) { - hash = await bc.getNewAddress(); + hash = await bc.getNewAddress({ address_type }); text = bip21(hash, invoice); } else if (type === types.liquid) { - hash = await lq.getNewAddress(); + hash = await lq.getNewAddress({ address_type }); text = bip21(hash, invoice); } else if (type === types.internal) { hash = id; diff --git a/routes/invoices.ts b/routes/invoices.ts index ead2284c..e7295b6e 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -1,7 +1,11 @@ +import config from "$config"; import { db, g } from "$lib/db"; import { generate } from "$lib/invoices"; import { err } from "$lib/logging"; import { bail, getInvoice, pick } from "$lib/utils"; +import rpc from "@coinos/rpc"; + +const bc = rpc(config.bitcoin); export default { async get(req, res) { @@ -48,4 +52,10 @@ export default { invoices = await Promise.all(invoices.map((i) => getInvoice(i))); res.send(invoices); }, + + async sign(req, res) { + const { address, message } = req.body; + const signature = await bc.signMessage({ address, message }); + res.send({ signature }); + }, }; diff --git a/routes/nostr.ts b/routes/nostr.ts index ae2be7e9..f43f3517 100644 --- a/routes/nostr.ts +++ b/routes/nostr.ts @@ -64,14 +64,14 @@ export default { if (!events.length) return res.send([]); const event = events[0]; - const pubkeys = event.tags + let pubkeys = event.tags .filter((tag) => tag[0] === "p") - .map((tag) => tag[1]) - .slice(offset, limit); + .map((tag) => tag[1]); let follows = []; if (pubkeysOnly) follows = pubkeys; else { + pubkeys = pubkeys.slice(limit, offset); const profiles = await scan({ authors: pubkeys, kinds: [0] }); for (const p of profiles) { const { content, pubkey } = p; -- cgit v1.2.3