only render hyperlink if link is valid

This commit is contained in:
Sam Samskies
2023-04-19 19:29:37 -05:00
parent 9b2fb3b6bf
commit 74bfa03227
2 changed files with 30 additions and 2 deletions

View File

@ -491,6 +491,20 @@ export interface NostrLink {
encode(): string;
}
export function validateNostrLink(link: string): boolean {
try {
const parsedLink = parseNostrLink(link);
if (!parsedLink) {
return false;
}
return parsedLink.id.length === 64;
} catch {
return false;
}
}
export function parseNostrLink(link: string): NostrLink | undefined {
const entity = link.startsWith("web+nostr:") || link.startsWith("nostr:") ? link.split(":")[1] : link;