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
|
_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@]+$/
|
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||||
|
|
||||||
export type BunkerPointer = {
|
export type BunkerPointer = {
|
||||||
@@ -31,11 +31,12 @@ export async function parseBunkerInput(input: string): Promise<BunkerPointer | n
|
|||||||
let match = input.match(BUNKER_REGEX)
|
let match = input.match(BUNKER_REGEX)
|
||||||
if (match) {
|
if (match) {
|
||||||
try {
|
try {
|
||||||
const bunkerURL = new URL(input)
|
const pubkey = match[1]
|
||||||
|
const qs = new URLSearchParams(match[2])
|
||||||
return {
|
return {
|
||||||
pubkey: bunkerURL.host,
|
pubkey,
|
||||||
relays: bunkerURL.searchParams.getAll('relay'),
|
relays: qs.getAll('relay'),
|
||||||
secret: bunkerURL.searchParams.get('secret'),
|
secret: qs.get('secret'),
|
||||||
}
|
}
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
/* just move to the next case */
|
/* just move to the next case */
|
||||||
|
|||||||
Reference in New Issue
Block a user