import { nip19, NostrEvent as NEvent } from "@nostr/tools"; import config from "../config.ts"; export interface ProfileData { name?: string; display_name?: string; displayName?: string; about?: string; picture?: string; nip05?: string; lud16?: string; } export default class Profile { private data: ProfileData; event: NEvent; username?: string; constructor(event: NEvent, username?: string) { this.event = event; this.data = JSON.parse(event.content); this.username = username; } get updatedAt(): number { return this.event.created_at; } get name(): string { return this.data.display_name || this.data.displayName || this.data.name || "Anonymous"; } get about(): string { return this.data.about || ""; } get picture(): string | undefined { return this.data.picture; } get nip05(): string | undefined { return this.data.nip05; } get lud16(): string | undefined { return this.data.lud16; } get pubkey(): string { return this.event.pubkey; } get npub(): string { return nip19.npubEncode(this.pubkey); } get profileUrl(): string { return `${config.base_url}/@${this.username}`; } get ogImageUrl(): string { return `${config.base_url}/assets/g/img/og-p-${this.event.id}.png`; } }