fix: handle invalid client tag

This commit is contained in:
2025-04-30 12:22:18 +01:00
parent 992d7f19be
commit 3d778f7ec7
2 changed files with 15 additions and 1 deletions

View File

@ -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<string>, author?: string, kind?: number) {
try {
return NostrLink.fromTag(tag, author, kind);
} catch (e) {
// ignored
}
}
static fromTags(tags: ReadonlyArray<Array<string>>) {
return removeUndefined(
tags.map(a => {