mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-08-08 23:34:41 +00:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user