mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
fix typescript types everywhere, delete pool.js and refactor relay.js to use event listeners everywhere.
This commit is contained in:
33
nip05.ts
Normal file
33
nip05.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user