@@ -129,6 +148,7 @@ export function profilePageHtml(profile: Profile, articles: Article[]): string {
${profile.name}
+ ${nip05Html}
${profile.about}
diff --git a/models/profile.ts b/models/profile.ts
index fcb9b8d..05e5415 100644
--- a/models/profile.ts
+++ b/models/profile.ts
@@ -1,4 +1,5 @@
import { nip19, NostrEvent as NEvent } from "@nostr/tools";
+import { verifyNip05Address } from "../nostr.ts";
import { getImageMagickCommand } from "../utils.ts";
import config from "../config.ts";
@@ -43,7 +44,7 @@ export default class Profile {
}
get nip05(): string | undefined {
- return this.data.nip05;
+ return this.data.nip05?.replace("_@", "");
}
get lud16(): string | undefined {
@@ -69,4 +70,12 @@ export default class Profile {
return this.picture || "";
}
}
+
+ verifyNip05(): Promise
{
+ if (typeof this.data.nip05 !== "undefined") {
+ return verifyNip05Address(this.data.nip05, this.pubkey);
+ } else {
+ return Promise.resolve(false);
+ }
+ }
}
diff --git a/nostr.ts b/nostr.ts
index 6c7eb5b..49606c8 100644
--- a/nostr.ts
+++ b/nostr.ts
@@ -113,3 +113,25 @@ export async function replaceNostrUris(markdown: string): Promise {
return markdown;
}
+
+export async function verifyNip05Address(
+ address: string,
+ pubkey: string,
+): Promise {
+ 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;
+ }
+}