From ef28b2eb7375b8004a06a2e0be322d18b52c4c4c Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 21 Apr 2025 23:40:15 -0300 Subject: [PATCH] nip46: toBunkerURL() function. --- nip46.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nip46.ts b/nip46.ts index ed4dcde..ff287ba 100644 --- a/nip46.ts +++ b/nip46.ts @@ -26,6 +26,17 @@ export type BunkerPointer = { secret: null | string } +export function toBunkerURL(bunkerPointer: BunkerPointer): string { + let bunkerURL = new URL(`bunker://${bunkerPointer.pubkey}`) + bunkerPointer.relays.forEach(relay => { + bunkerURL.searchParams.append('relay', relay) + }) + if (bunkerPointer.secret) { + bunkerURL.searchParams.set('secret', bunkerPointer.secret) + } + return bunkerURL.toString() +} + /** This takes either a bunker:// URL or a name@domain.com NIP-05 identifier and returns a BunkerPointer -- or null in case of error */ export async function parseBunkerInput(input: string): Promise {