diff options
| author | Adam Soltys <[email protected]> | 2024-08-25 21:55:01 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-25 21:55:26 -0700 |
| commit | 5269deaa617dae61cdb97aca80269bf311e8dc4b (patch) | |
| tree | 882faa6b4346abec49338fedf421c7eacfae8681 | |
| parent | c5c201b441e0b1ef7d0df19bd936d0ccfa9e601c (diff) | |
| download | coinos-server-5269deaa617dae61cdb97aca80269bf311e8dc4b.tar.gz coinos-server-5269deaa617dae61cdb97aca80269bf311e8dc4b.zip | |
add nwc field to user
| -rwxr-xr-x | bun.lockb | bin | 213547 -> 213571 bytes | |||
| -rw-r--r-- | index.js | 1 | ||||
| -rw-r--r-- | lib/nostr.js | 9 | ||||
| -rw-r--r-- | lib/utils.js | 13 | ||||
| -rw-r--r-- | lib/whitelist.js | 1 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | routes/nostr.js | 4 | ||||
| -rw-r--r-- | routes/users.js | 1 |
8 files changed, 26 insertions, 4 deletions
| Binary files differ @@ -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 { |
