mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
eventMatchesTemplate: drop nonce tags before comparison
This commit is contained in:
parent
f4e334b5ff
commit
e55ddbd8e6
1 changed files with 14 additions and 0 deletions
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 [...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. */
|
/** Ensure the template and event match on their shared keys. */
|
||||||
function eventMatchesTemplate(event: Event, template: EventTemplate): boolean {
|
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 });
|
return getEventHash(event) === getEventHash({ pubkey: event.pubkey, ...template });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue