From 1a8431aff912004f8a8b36049393669fd255880d Mon Sep 17 00:00:00 2001 From: elnosh Date: Thu, 18 Apr 2024 11:06:40 -0500 Subject: [PATCH] nwc keysend requests --- src/components/NWC.tsx | 76 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/components/NWC.tsx b/src/components/NWC.tsx index 2bb21e8..09c9432 100644 --- a/src/components/NWC.tsx +++ b/src/components/NWC.tsx @@ -99,13 +99,12 @@ async function publishMultiInvoiceRequest(invoices: string[], nwc: NWCInfo) { event.tags = [["p", nwc.npubHex]]; await event.encrypt(undefined, signer); - await event.sign(); - console.log("publishing zap request", event.rawEvent()); - + console.log("publishing multi zap request", event.rawEvent()); await event.publish(); } + async function fetchBolt11(): Promise<{ bolt11: string }> { const res = await fetch(`${FAUCET_API_URL}/api/bolt11`, { method: "POST", @@ -153,6 +152,71 @@ function Zapper(props: { nwc: NWCInfo }) { } setLoading(false); } + + async function handleKeysend() { + setLoading(true); + + const signer = new NDKPrivateKeySigner(props.nwc.secret); + const ndk = new NDK({ explicitRelayUrls: [props.nwc.relay], signer }); + + console.log("connecting to ndk"); + await ndk.connect(); + + const event = new NDKEvent(ndk); + event.kind = 23194; + event.content = JSON.stringify({ + method: "pay_keysend", + params: { + amount: 42 * 1000, + pubkey: "02465ed5be53d04fde66c9418ff14a5f2267723810176c9212b722e542dc1afb1b" + }, + }); + event.tags = [["p", props.nwc.npubHex]]; + + await event.encrypt(undefined, signer); + await event.sign(); + console.log("publishing keysend request", event.rawEvent()); + await event.publish(); + + setLoading(false); + } + + async function handleMultiKeysend() { + setLoading(true); + + const signer = new NDKPrivateKeySigner(props.nwc.secret); + const ndk = new NDK({ explicitRelayUrls: [props.nwc.relay], signer }); + + console.log("connecting to ndk"); + await ndk.connect(); + + let keysendParams = []; + for (let i = 0; i < 3; i++) { + let keysendParam = { + id: String(Math.floor(Math.random() * 10000000)), + pubkey: "02465ed5be53d04fde66c9418ff14a5f2267723810176c9212b722e542dc1afb1b", + amount: 42 * 1000 + } + keysendParams.push(keysendParam) + } + + const event = new NDKEvent(ndk); + event.kind = 23194; + event.content = JSON.stringify({ + method: "multi_pay_keysend", + params: { + keysends: keysendParams + }, + }); + event.tags = [["p", props.nwc.npubHex]]; + + await event.encrypt(undefined, signer); + await event.sign(); + console.log("publishing multi keysend request", event.rawEvent()); + await event.publish(); + + setLoading(false); + } return (
@@ -172,6 +236,12 @@ function Zapper(props: { nwc: NWCInfo }) { + +