substr/models/profile.ts
2024-10-21 15:43:58 +02:00

55 lines
994 B
TypeScript

import { nip19 } from "@nostr/tools";
import { NEvent } from "../nostr.ts";
export interface ProfileData {
name: string;
about?: string;
picture?: string;
nip05?: string;
lud16?: string;
}
export default class Profile {
event: NEvent;
private data: ProfileData;
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.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);
}
}