|
| 1 | +import "websocket-polyfill"; |
| 2 | +import { NWCClient } from "../NWCClient"; |
| 3 | + |
| 4 | +// this has no funds on it, I think ;-) |
| 5 | +const exampleNwcUrl = |
| 6 | + "nostr+walletconnect://69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9?relay=wss://relay.getalby.com/v1&secret=e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b"; |
| 7 | + |
| 8 | +describe("parseWalletConnectUrl", () => { |
| 9 | + test("standard protocol", () => { |
| 10 | + const parsed = NWCClient.parseWalletConnectUrl(exampleNwcUrl); |
| 11 | + expect(parsed.walletPubkey).toBe( |
| 12 | + "69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9", |
| 13 | + ); |
| 14 | + expect(parsed.secret).toBe( |
| 15 | + "e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b", |
| 16 | + ); |
| 17 | + expect(parsed.relayUrl).toBe("wss://relay.getalby.com/v1"); |
| 18 | + }); |
| 19 | + test("protocol without double slash", () => { |
| 20 | + const parsed = NWCClient.parseWalletConnectUrl( |
| 21 | + exampleNwcUrl.replace("nostr+walletconnect://", "nostr+walletconnect:"), |
| 22 | + ); |
| 23 | + expect(parsed.walletPubkey).toBe( |
| 24 | + "69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9", |
| 25 | + ); |
| 26 | + expect(parsed.secret).toBe( |
| 27 | + "e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b", |
| 28 | + ); |
| 29 | + expect(parsed.relayUrl).toBe("wss://relay.getalby.com/v1"); |
| 30 | + }); |
| 31 | + test("legacy protocol without double slash", () => { |
| 32 | + const parsed = NWCClient.parseWalletConnectUrl( |
| 33 | + exampleNwcUrl.replace("nostr+walletconnect://", "nostrwalletconnect:"), |
| 34 | + ); |
| 35 | + expect(parsed.walletPubkey).toBe( |
| 36 | + "69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9", |
| 37 | + ); |
| 38 | + expect(parsed.secret).toBe( |
| 39 | + "e839faf78693765b3833027fefa5a305c78f6965d0a5d2e47a3fcb25aa7cc45b", |
| 40 | + ); |
| 41 | + expect(parsed.relayUrl).toBe("wss://relay.getalby.com/v1"); |
| 42 | + }); |
| 43 | +}); |
0 commit comments