From e55ddbd8e644cbfd4509be766ca0ac07741077b0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Nov 2023 19:57:03 -0600 Subject: [PATCH] eventMatchesTemplate: drop `nonce` tags before comparison --- src/utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 11ef0ea..2b258fc 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 }); }