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.
This commit is contained in:
Kai
2026-03-27 07:02:47 -03:00
committed by fiatjaf_
parent 1b955bdbcb
commit 8be6d08a43
+4 -3
View File
@@ -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(