Skip to content

Commit

Permalink
nip46: fix bunker url parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Feb 12, 2024
1 parent 566a2de commit 9d78c90
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nip46.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useFetchImplementation(fetchImplementation: any) {
_fetch = fetchImplementation
}

export const BUNKER_REGEX = /^bunker:\/\/[0-9a-f]{64}\??[?\/\w:.=&%]*$/
export const BUNKER_REGEX = /^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$/
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

export type BunkerPointer = {
Expand All @@ -31,11 +31,12 @@ export async function parseBunkerInput(input: string): Promise<BunkerPointer | n
let match = input.match(BUNKER_REGEX)
if (match) {
try {
const bunkerURL = new URL(input)
const pubkey = match[1]
const qs = new URLSearchParams(match[2])
return {
pubkey: bunkerURL.host,
relays: bunkerURL.searchParams.getAll('relay'),
secret: bunkerURL.searchParams.get('secret'),
pubkey,
relays: qs.getAll('relay'),
secret: qs.get('secret'),
}
} catch (_err) {
/* just move to the next case */
Expand Down

0 comments on commit 9d78c90

Please sign in to comment.