diff options
| author | Adam Soltys <[email protected]> | 2024-12-01 09:23:48 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-01 09:23:48 -0800 |
| commit | d16675345757dc7bf180f4aa51ccb0d124ea7e12 (patch) | |
| tree | e0bde47b82ea88ecb78c0dc078365667969a2724 | |
| parent | 05c582f6d0577596bbf079187b14d1fa28d35f75 (diff) | |
| download | coinos-server-d16675345757dc7bf180f4aa51ccb0d124ea7e12.tar.gz coinos-server-d16675345757dc7bf180f4aa51ccb0d124ea7e12.zip | |
send nwc info event
| -rw-r--r-- | lib/nwc.ts | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -12,6 +12,7 @@ import type { UnsignedEvent } from "nostr-tools"; const result = (result) => ({ result }); const error = (error) => ({ error }); +const sk = nip19.decode(config.nostrKey).data as Uint8Array; const methods = [ "pay_invoice", @@ -25,17 +26,25 @@ const methods = [ const week = 7 * 24 * 60 * 60; export default () => { - const r = new Relay("ws://strfry:7777"); + const r = new Relay("ws://sf:7777"); - r.on("open", (_) => { + r.on("open", async (_) => { r.subscribe("nwc", { kinds: [23194], "#p": [serverPubkey] }); + let info: UnsignedEvent = { + created_at: Math.floor(Date.now() / 1000), + kind: 13194, + tags: [["p", serverPubkey]], + pubkey: serverPubkey, + content: methods.join(" "), + }; + info = await finalizeEvent(info, sk); + r.send(["EVENT", info]); }); r.on("event", async (sub, ev) => { try { if (sub !== "nwc") return; let { content, pubkey } = ev; - const sk = nip19.decode(config.nostrKey).data as Uint8Array; const { params, method } = JSON.parse( await nip04.decrypt(sk, pubkey, content), ); @@ -63,10 +72,16 @@ export default () => { response = await finalizeEvent(response, sk); r.send(["EVENT", response]); - } catch(e) { - err("problem with nwc", user.username, JSON.stringify(params), e.message); + } catch (e) { + err( + "problem with nwc", + user.username, + JSON.stringify(params), + e.message, + ); } } catch (e) { + console.log(e); err("problem with nwc", e.message); } }); |
