nip05: add debugging output

This commit is contained in:
Alex Gleason 2023-10-14 16:26:50 -05:00
parent 7ed34a0906
commit d2a4862a2a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -18,14 +18,26 @@ async function lookup(value: string, opts: LookupOpts = {}): Promise<string | nu
const [_, name = '_', domain] = match; const [_, name = '_', domain] = match;
const handleAbort = () => {
console.log(`NIP-05 lookup aborted for @${name}@${domain}`);
};
const signal = AbortSignal.timeout(timeout);
signal.addEventListener('abort', handleAbort);
try { try {
const res = await fetch(`https://${domain}/.well-known/nostr.json?name=${name}`, { const url = `https://${domain}/.well-known/nostr.json?name=${name}`;
signal: AbortSignal.timeout(timeout), console.log(`Fetching ${url}`);
});
const res = await fetch(url, { signal });
signal.removeEventListener('abort', handleAbort);
console.log(`NIP-05: successfully fetched @${name}@${domain}}`);
const { names } = nostrJsonSchema.parse(await res.json()); const { names } = nostrJsonSchema.parse(await res.json());
const pubkey = names[name] || null;
console.log(`NIP-05: @${name}@${domain} is ${pubkey}`);
return names[name] || null; return pubkey;
} catch (_e) { } catch (_e) {
return null; return null;
} }