nip46: fix bunker url parsing.

This commit is contained in:
fiatjaf
2024-02-12 15:32:50 -03:00
parent 566a2deea3
commit 9d78c90a79

View File

@@ -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 = {
@@ -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 */