From 8be6d08a43ae00a2ba11bbed3bb532672522ad48 Mon Sep 17 00:00:00 2001 From: Kai Date: Fri, 27 Mar 2026 03:04:51 +0100 Subject: [PATCH] fix(nip47): support multiple relays in parseConnectionString Addresses #494. The NIP-47 spec allows multiple relay parameters in connection strings, but parseConnectionString only returned the first one. Changes: - Add 'relays' field to NWCConnection interface (string array) - Use searchParams.getAll('relay') to capture all relays - Keep 'relay' field for backwards compatibility (returns first relay) This is backwards compatible - existing code using connection.relay will continue to work, while new code can use connection.relays to access all specified relays. --- nip47.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nip47.ts b/nip47.ts index c5fe461..7579ae3 100644 --- a/nip47.ts +++ b/nip47.ts @@ -5,20 +5,21 @@ import { encrypt } from './nip04.ts' interface NWCConnection { pubkey: string relay: string + relays: string[] secret: string } export function parseConnectionString(connectionString: string): NWCConnection { const { host, pathname, searchParams } = new URL(connectionString) const pubkey = pathname || host - const relay = searchParams.get('relay') + const relays = searchParams.getAll('relay') const secret = searchParams.get('secret') - if (!pubkey || !relay || !secret) { + if (!pubkey || relays.length === 0 || !secret) { throw new Error('invalid connection string') } - return { pubkey, relay, secret } + return { pubkey, relay: relays[0], relays, secret } } export async function makeNwcRequestEvent(