fix typescript types everywhere, delete pool.js and refactor relay.js to use event listeners everywhere.

This commit is contained in:
fiatjaf
2022-12-18 17:02:19 -03:00
parent 46a0a342db
commit de8bdd8370
16 changed files with 446 additions and 762 deletions

33
nip05.ts Normal file
View File

@@ -0,0 +1,33 @@
var _fetch = fetch
export function useFetchImplementation(fetchImplementation: any) {
_fetch = fetchImplementation
}
export async function searchDomain(domain: string, query = '') {
try {
let res = await (
await _fetch(`https://${domain}/.well-known/nostr.json?name=${query}`)
).json()
return res.names
} catch (_) {
return []
}
}
export async function queryName(fullname: string) {
try {
let [name, domain] = fullname.split('@')
if (!domain) return null
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
}
}