Verify nip05 address, display status

This commit is contained in:
2024-10-25 17:50:59 +02:00
parent a6517c61a4
commit 4c68be19fe
6 changed files with 85 additions and 4 deletions

View File

@@ -113,3 +113,25 @@ export async function replaceNostrUris(markdown: string): Promise<string> {
return markdown;
}
export async function verifyNip05Address(
address: string,
pubkey: string,
): Promise<boolean> {
const [username, host] = address.split("@");
const url = `https://${host}/.well-known/nostr.json?name=${username}`;
try {
const res = await fetch(url);
if (res.status === 404 || !res.ok) return false;
const data = await res.json();
if (data.names && data.names[username] === pubkey) {
return true;
} else {
return false;
}
} catch (_e) {
return false;
}
}