fix: handle invalid client tag
This commit is contained in:
@ -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 => {
|
||||
|
Reference in New Issue
Block a user