From 5269deaa617dae61cdb97aca80269bf311e8dc4b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 25 Aug 2024 21:55:01 -0700 Subject: add nwc field to user --- bun.lockb | Bin 213547 -> 213571 bytes index.js | 1 + lib/nostr.js | 9 +++++++++ lib/utils.js | 13 ++++++++++--- lib/whitelist.js | 1 + package.json | 1 + routes/nostr.js | 4 ++++ routes/users.js | 1 - 8 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bun.lockb b/bun.lockb index 15a724cd..4127249a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.js b/index.js index 65fb9368..a3f358a6 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,7 @@ app.post("/email", email.send); app.get("/rate", rates.last); app.get("/rates", rates.index); +app.get("/nostr/info", nostr.info); app.get("/nostr.json", nostr.identities); app.get("/:pubkey/followers", nostr.followers); app.get("/:pubkey/follows", nostr.follows); diff --git a/lib/nostr.js b/lib/nostr.js index 28fde6aa..6bb28595 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -265,3 +265,12 @@ export async function handleZap(invoice) { await Promise.allSettled(relays.map((r) => send(ev, r))); } + +let damus = new Relay("ws://strfry:7777"); +damus.on("open", (relay) => { + damus.subscribe("nwc", { limit: 1, kinds: [23194] }); +}); + +damus.on("event", async (sub, ev) => { + console.log("EV", ev); +}); diff --git a/lib/utils.js b/lib/utils.js index dfc9f3c1..f53b76d2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,6 +1,7 @@ +import { randomBytes, bytesToHex } from "@noble/hashes/utils"; import migrate from "$lib/migrate"; import store from "$lib/store"; -import { g } from "$lib/db"; +import { g, s } from "$lib/db"; import config from "$config"; export let fail = (msg) => { @@ -37,7 +38,7 @@ export let bip21 = (address, { amount, memo, tip, type }) => { let url = new URLSearchParams(); if (amount) { - url.append("amount", btc(amount+tip)); + url.append("amount", btc(amount + tip)); if (type === "liquid") url.append("assetid", config.liquid.btc); } @@ -68,7 +69,13 @@ export let fields = [ export let getUser = async (username) => { if (username === "undefined") fail("invalid user"); - return migrate(username); + let user = await migrate(username); + if (!user.nwc) { + user.nwc = bytesToHex(randomBytes(32)); + s(`user:${user.id}`, user); + } + + return user; }; export let getInvoice = async (hash) => { diff --git a/lib/whitelist.js b/lib/whitelist.js index 52bb466a..bf5b4eb9 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -27,6 +27,7 @@ export default [ "nip5", "notify", "nsec", + "nwc", "payments", "profile", "prompt", diff --git a/package.json b/package.json index 62756470..71898e55 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@fastify/secure-session": "^5.2.0", "@fastify/static": "^6.5.0", "@fastify/websocket": "^7.2.0", + "@noble/hashes": "^1.4.0", "bcrypt": "^5.0.0", "bech32": "^2.0.0", "buffer-crc32": "^0.2.13", diff --git a/routes/nostr.js b/routes/nostr.js index 1bd6ffff..fdfa2613 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -206,4 +206,8 @@ export default { res.send({ names }); }, + + async info(req, res) { + res.send({ pubkey: COINOS_PUBKEY }); + } }; diff --git a/routes/users.js b/routes/users.js index f46136c0..d875decd 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,5 +1,4 @@ import { g, s, db } from "$lib/db"; -import migrate from "$lib/migrate"; import config from "$config"; import store from "$lib/store"; import { -- cgit v1.2.3