diff --git a/examples/nwc/client/nwa-accept.js b/examples/nwc/client/nwa-accept.js index 2714396..5751f87 100644 --- a/examples/nwc/client/nwa-accept.js +++ b/examples/nwc/client/nwa-accept.js @@ -33,7 +33,6 @@ const nwaOptions = nwa.NWAClient.parseWalletAuthUrl(nwaUrl); const createAppResponse = await client.createConnection({ pubkey: nwaOptions.appPubkey, - nwaSecret: nwaOptions.nwaSecret, // TODO: below should come from nwaOptions name: "NWA test " + new Date().toISOString(), methods: [ diff --git a/examples/nwc/client/nwa.js b/examples/nwc/client/nwa.js index 2247e13..86e1a00 100644 --- a/examples/nwc/client/nwa.js +++ b/examples/nwc/client/nwa.js @@ -27,7 +27,7 @@ console.info("Waiting for connection..."); await nwaClient.subscribe({ onSuccess: async (nwcClient) => { - console.info("NWA successful"); + console.info("NWA successful", nwcClient.options); const response = await nwcClient.getInfo(); console.info(response); diff --git a/src/NWAClient.test.ts b/src/NWAClient.test.ts index b6fd93a..2a446ed 100644 --- a/src/NWAClient.test.ts +++ b/src/NWAClient.test.ts @@ -8,7 +8,7 @@ describe("NWA URI", () => { }); expect(nwaClient.connectionUri).toEqual( - `nostr+walletauth://${nwaClient.options.appPubkey}?relay=${encodeURIComponent(nwaClient.options.relayUrl)}&secret=${nwaClient.options.nwaSecret}`, + `nostr+walletauth://${nwaClient.options.appPubkey}?relay=${encodeURIComponent(nwaClient.options.relayUrl)}`, ); }); @@ -21,8 +21,5 @@ describe("NWA URI", () => { "e73575d76c731102aefd4eb6fb0ddfaaf335eabe60255a22e6ca5e7074eb4992", ); expect(nwaOptions.relayUrl).toEqual("wss://relay.getalby.com/v1"); - expect(nwaOptions.nwaSecret).toEqual( - "1d7d477e495e26851ec0a01d633ceb74fe3cee78a850186a3a978f0e63b285d4", - ); }); }); diff --git a/src/NWAClient.ts b/src/NWAClient.ts index 2ec3765..c06b02e 100644 --- a/src/NWAClient.ts +++ b/src/NWAClient.ts @@ -1,12 +1,11 @@ import { bytesToHex, hexToBytes } from "@noble/hashes/utils"; -import { generateSecretKey, getPublicKey, nip44, Relay } from "nostr-tools"; +import { generateSecretKey, getPublicKey, Relay } from "nostr-tools"; import { Nip47NetworkError, NWCClient } from "./NWCClient"; export type NWAOptions = { relayUrl: string; appSecretKey?: string; appPubkey: string; - nwaSecret: string; }; export type NewNWAClientOptions = { @@ -25,7 +24,6 @@ export class NWAClient { relayUrl: options.relayUrl, appSecretKey, appPubkey: getPublicKey(hexToBytes(appSecretKey)), - nwaSecret: bytesToHex(generateSecretKey()), }; if (!this.options.relayUrl) { @@ -47,7 +45,7 @@ export class NWAClient { * returns the NWA connection URI which should be given to the wallet */ get connectionUri() { - return `nostr+walletauth://${this.options.appPubkey}?relay=${encodeURIComponent(this.options.relayUrl)}&secret=${this.options.nwaSecret}`; + return `nostr+walletauth://${this.options.appPubkey}?relay=${encodeURIComponent(this.options.relayUrl)}`; } static parseWalletAuthUrl(walletAuthUrl: string): NWAOptions { @@ -68,17 +66,11 @@ export class NWAClient { throw new Error("No relay URL found in connection string"); } - const nwaSecret = url.searchParams.get("secret"); - if (!nwaSecret) { - throw new Error("No secret found in connection string"); - } - // TODO: support other params (commands/methods, budgets, limits etc.) return { relayUrl, appPubkey, - nwaSecret, }; } @@ -97,9 +89,8 @@ export class NWAClient { const sub = this.relay.subscribe( [ { - // kinds: [33194], // NIP-04 - kinds: [33195], // NIP-44 - "#d": [this.options.appPubkey], + kinds: [13194], // NIP-47 info event + "#p": [this.options.appPubkey], }, ], { @@ -114,34 +105,13 @@ export class NWAClient { sub.onevent = async (event) => { try { - if ( - event.tags.find((t) => t[0] === "d")?.[1] !== this.options.appPubkey - ) { - throw new Error("Event with incorrect d tag"); - } - - const decryptedContent = await this.decrypt( - event.pubkey, - event.content, - ); - - type NWAContent = { - secret: string; - // TODO: should commands be included here? they can be fetched from get_info or the info event? - // commands: Nip47Method[]; - lud16: string; - }; - - const nwaContent = JSON.parse(decryptedContent) as NWAContent; - if (nwaContent.secret !== this.options.nwaSecret) { - throw new Error("Incorrect secret for this app"); - } + const lud16 = event.tags.find((t) => t[0] === "lud16")?.[1]; args.onSuccess( new NWCClient({ relayUrl: this.options.relayUrl, secret: this.options.appSecretKey, walletPubkey: event.pubkey, - lud16: nwaContent.lud16, + lud16, }), ); unsub(); @@ -155,18 +125,6 @@ export class NWAClient { }; } - private decrypt(walletServicePubkey: string, content: string) { - if (!this.options.appSecretKey) { - throw new Error("No app secret key set"); - } - - const key = nip44.getConversationKey( - hexToBytes(this.options.appSecretKey), - walletServicePubkey, - ); - return nip44.decrypt(content, key); - } - private async _checkConnected() { if (!this.options.appSecretKey) { throw new Error("Missing secret key");