eventMatchesTemplate: drop `nonce` tags before comparison

This commit is contained in:
Alex Gleason 2023-11-20 19:57:03 -06:00
parent f4e334b5ff
commit e55ddbd8e6
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 14 additions and 0 deletions

View File

@ -107,8 +107,22 @@ function dedupeEvents<K extends number>(events: Event<K>[]): Event<K>[] {
return [...new Map(events.map((event) => [event.id, event])).values()];
}
/** Return a copy of the event with the given tags removed. */
function stripTags<E extends EventTemplate>(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 });
}