diff --git a/nip46.ts b/nip46.ts index 26a7f35..d473aa1 100644 --- a/nip46.ts +++ b/nip46.ts @@ -93,6 +93,10 @@ export class BunkerSigner { * @param secretKey - An optional key pair. */ public constructor(clientSecretKey: Uint8Array, bp: BunkerPointer, params: BunkerSignerParams = {}) { + if (bp.relays.length === 0) { + throw new Error('no relays are specified for this bunker') + } + this.pool = params.pool || new SimplePool() this.secretKey = clientSecretKey this.relays = bp.relays @@ -242,25 +246,23 @@ export async function createAccount( } /** - * Fetches info on available signers (nsecbunkers) using NIP-89 events. - * + * Fetches info on available providers that announce themselves using NIP-89 events. * @returns A promise that resolves to an array of available bunker objects. */ export async function fetchCustodialbunkers(pool: AbstractSimplePool, relays: string[]): Promise { - const events = await pool.querySync(relays, { kinds: [Handlerinformation] }) - // filter for events that handle the connect event kind - const filteredEvents = events.filter(event => - event.tags.some(tag => tag[0] === 'k' && tag[1] === NostrConnect.toString()), - ) + const events = await pool.querySync(relays, { + kinds: [Handlerinformation], + '#k': [NostrConnect.toString()], + }) - // Validate bunkers by checking their NIP-05 and pubkey - // Map to a more useful object + // validate bunkers by checking their NIP-05 and pubkey + // map to a more useful object const validatedBunkers = await Promise.all( - filteredEvents.map(async event => { + events.map(async event => { try { const content = JSON.parse(event.content) const bp = await queryBunkerProfile(content.nip05) - if (bp && bp.pubkey === event.pubkey) { + if (bp && bp.pubkey === event.pubkey && bp.relays.length) { return { bunkerPointer: bp, nip05: content.nip05,