mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
nip46: fix bunker url parsing.
This commit is contained in:
11
nip46.ts
11
nip46.ts
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user