diff --git a/src/utils.ts b/src/utils.ts index 11ef0ea5..2b258fc3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,8 +107,22 @@ function dedupeEvents(events: Event[]): Event[] { return [...new Map(events.map((event) => [event.id, event])).values()]; } +/** Return a copy of the event with the given tags removed. */ +function stripTags(event: E, tags: string[] = []): E { + if (!tags.length) return event; + return { + ...event, + tags: event.tags.filter(([name]) => !tags.includes(name)), + }; +} + /** Ensure the template and event match on their shared keys. */ function eventMatchesTemplate(event: Event, template: EventTemplate): boolean { + const whitelist = ['nonce']; + + event = stripTags(event, whitelist); + template = stripTags(template, whitelist); + return getEventHash(event) === getEventHash({ pubkey: event.pubkey, ...template }); }