mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
27 lines
554 B
JavaScript
27 lines
554 B
JavaScript
import fetch from 'cross-fetch'
|
|
|
|
export async function searchDomain(domain, 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) {
|
|
try {
|
|
let [name, domain] = fullname.split('@')
|
|
let res = await (
|
|
await fetch(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
|
).json()
|
|
|
|
return res.names && res.names[name]
|
|
} catch (_) {
|
|
return null
|
|
}
|
|
}
|