diff --git a/nip05.ts b/nip05.ts index 2922453..a1e11d6 100644 --- a/nip05.ts +++ b/nip05.ts @@ -12,20 +12,24 @@ export type Nip05 = `${string}@${string}` export const NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/ export const isNip05 = (value?: string | null): value is Nip05 => NIP05_REGEX.test(value || '') -var _fetch: any +// eslint-disable-next-line @typescript-eslint/no-explicit-any +let _fetch: any try { _fetch = fetch -} catch {} +} catch (_) {null} -export function useFetchImplementation(fetchImplementation: any) { +export function useFetchImplementation(fetchImplementation: unknown) { _fetch = fetchImplementation } export async function searchDomain(domain: string, query = ''): Promise<{ [name: string]: string }> { try { const url = `https://${domain}/.well-known/nostr.json?name=${query}` - const res = await _fetch(url, { redirect: 'error' }) + const res = await _fetch(url, { redirect: 'manual' }) + if (res.status !== 200) { + throw Error("Wrong response code") + } const json = await res.json() return json.names } catch (_) { @@ -37,20 +41,24 @@ export async function queryProfile(fullname: string): Promise { - let res = await queryProfile(nip05) + const res = await queryProfile(nip05) return res ? res.pubkey === pubkey : false }