nip05 typescript fixes.

This commit is contained in:
fiatjaf 2022-12-20 15:50:01 -03:00
parent bf120c1348
commit 72781e0eab
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
1 changed files with 12 additions and 14 deletions

View File

@ -4,7 +4,10 @@ export function useFetchImplementation(fetchImplementation: any) {
_fetch = fetchImplementation
}
export async function searchDomain(domain: string, query = '') {
export async function searchDomain(
domain: string,
query = ''
): Promise<{[name: string]: string}> {
try {
let res = await (
await _fetch(`https://${domain}/.well-known/nostr.json?name=${query}`)
@ -12,22 +15,17 @@ export async function searchDomain(domain: string, query = '') {
return res.names
} catch (_) {
return []
return {}
}
}
export async function queryName(fullname: string) {
try {
export async function queryName(fullname: string): Promise<string> {
let [name, domain] = fullname.split('@')
if (!domain) return null
if (!domain) throw new Error('invalid identifier, must contain an @')
let res = await (
await _fetch(`https://${domain}/.well-known/nostr.json?name=${name}`)
).json()
return res.names && res.names[name]
} catch (e) {
console.error(`${e}`)
return null
}
}