eventMatchesTemplate: drop `nonce` tags before comparison
This commit is contained in:
parent
f4e334b5ff
commit
e55ddbd8e6
14
src/utils.ts
14
src/utils.ts
|
@ -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 });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue