diff --git a/packages/app/src/Components/Event/Note/ClientTag.tsx b/packages/app/src/Components/Event/Note/ClientTag.tsx index 8ecd486c..64e9d6f0 100644 --- a/packages/app/src/Components/Event/Note/ClientTag.tsx +++ b/packages/app/src/Components/Event/Note/ClientTag.tsx @@ -5,7 +5,7 @@ import { Link } from "react-router-dom"; export function ClientTag({ ev }: { ev: TaggedNostrEvent }) { const tag = ev.tags.find(a => a[0] === "client"); if (!tag) return; - const link = tag[2] && tag[2].includes(":") ? NostrLink.fromTag(["a", tag[2]]) : undefined; + const link = tag[2] && tag[2].includes(":") ? NostrLink.tryFromTag(["a", tag[2]]) : undefined; return ( {" "} diff --git a/packages/system/src/nostr-link.ts b/packages/system/src/nostr-link.ts index e4e22089..aead391c 100644 --- a/packages/system/src/nostr-link.ts +++ b/packages/system/src/nostr-link.ts @@ -235,16 +235,30 @@ export class NostrLink implements ToNostrEventTag { } case "A": { const [kind, author, dTag] = tag[1].split(":"); + if (!isHex(author)) { + throw new Error(`Invalid author in A tag: ${tag[1]}`); + } return new NostrLink(NostrPrefix.Address, dTag, Number(kind), author, relays, "root"); } case "a": { const [kind, author, dTag] = tag[1].split(":"); + if (!isHex(author)) { + throw new Error(`Invalid author in a tag: ${tag[1]}`); + } return new NostrLink(NostrPrefix.Address, dTag, Number(kind), author, relays, tag[3]); } } throw new Error("Unknown tag!"); } + static tryFromTag(tag: Array, author?: string, kind?: number) { + try { + return NostrLink.fromTag(tag, author, kind); + } catch (e) { + // ignored + } + } + static fromTags(tags: ReadonlyArray>) { return removeUndefined( tags.map(a => {