mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
nip05.queryProfile() and test.
This commit is contained in:
23
nip05.ts
23
nip05.ts
@@ -1,3 +1,5 @@
|
||||
import {ProfilePointer} from './nip19'
|
||||
|
||||
var _fetch = fetch
|
||||
|
||||
export function useFetchImplementation(fetchImplementation: any) {
|
||||
@@ -19,13 +21,28 @@ export async function searchDomain(
|
||||
}
|
||||
}
|
||||
|
||||
export async function queryName(fullname: string): Promise<string> {
|
||||
export async function queryProfile(
|
||||
fullname: string
|
||||
): Promise<ProfilePointer | null> {
|
||||
let [name, domain] = fullname.split('@')
|
||||
if (!domain) throw new Error('invalid identifier, must contain an @')
|
||||
|
||||
if (!domain) {
|
||||
// if there is no @, it is because it is just a domain, so assume the name is "_"
|
||||
domain = name
|
||||
name = '_'
|
||||
}
|
||||
|
||||
let res = await (
|
||||
await _fetch(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
||||
).json()
|
||||
|
||||
return res.names && res.names[name]
|
||||
if (!res?.names?.[name]) return null
|
||||
|
||||
let pubkey = res.names[name] as string
|
||||
let relays = (res.relays?.[pubkey] || []) as string[] // nip35
|
||||
|
||||
return {
|
||||
pubkey,
|
||||
relays
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user