Handle multi-relay NWC URIs

This commit is contained in:
thePR0M3TH3AN committed 2025-10-05 19:49:22 -04:00
1 parent 8dd4b40b5a
commit e76107c8b2
2 files changed
+108 -11

No files matched your search

+40 -2
View File
@@ -4,8 +4,9 @@ if (typeof globalThis.window === "undefined") {
globalThis.window = {};
}
const { __TESTING__ } = await import("../js/payments/nwcClient.js");
const { buildPayInvoiceParams } = __TESTING__;
const nwcModule = await import("../js/payments/nwcClient.js");
const { __TESTING__, resetWalletClient } = nwcModule;
const { buildPayInvoiceParams, ensureActiveState, parseNwcUri, getActiveState } = __TESTING__;
await (async () => {
const params = buildPayInvoiceParams({
@@ -40,4 +41,41 @@ await (async () => {
assert.equal(params.amount, 43_000);
})();
await (async () => {
resetWalletClient();
window.NostrTools = {
getPublicKey() {
return "c".repeat(64);
},
};
const walletPubkey = "b".repeat(64);
const secretKey = "a".repeat(64);
const relays = ["wss://relay.one.example", "wss://relay.two.example"];
const lud16 = "[email protected]";
const uri =
`nostr+walletconnect://${walletPubkey}` +
`?relay=${encodeURIComponent(relays[0])}` +
`&relay=${encodeURIComponent(relays[1])}` +
`&secret=${secretKey}` +
`&lud16=${encodeURIComponent(lud16)}`;
const context = ensureActiveState({ nwcUri: uri });
assert.deepEqual(context.relayUrls, relays);
assert.equal(context.relayUrl, relays[0]);
assert.equal(context.uri.split("?")[0], `nostr+walletconnect://${walletPubkey}`);
const state = getActiveState();
assert.ok(state?.settings?.nwcUri);
const reparsed = parseNwcUri(state.settings.nwcUri);
assert.deepEqual(reparsed.relays, relays);
assert.equal(reparsed.secretKey, secretKey);
assert.equal(reparsed.queryParams.lud16, lud16);
resetWalletClient();
})();
process.exit(0);