sign: ensure the NIP-46 result matches the template

This commit is contained in:
Alex Gleason
2023-09-02 20:09:28 -05:00
parent 007565b513
commit c8a5da086e
2 changed files with 19 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { type Event, nip19, z } from '@/deps.ts';
import { type Event, type EventTemplate, getEventHash, nip19, z } from '@/deps.ts';
import { getAuthor } from '@/queries.ts';
import { lookupNip05Cached } from '@/utils/nip05.ts';
@@ -106,11 +106,17 @@ function dedupeEvents<K extends number>(events: Event<K>[]): Event<K>[] {
return [...new Map(events.map((event) => [event.id, event])).values()];
}
/** Ensure the template and event match on their shared keys. */
function eventMatchesTemplate(event: Event, template: EventTemplate): boolean {
return getEventHash(event) === getEventHash({ pubkey: event.pubkey, ...template });
}
export {
bech32ToPubkey,
dedupeEvents,
eventAge,
eventDateComparator,
eventMatchesTemplate,
findTag,
isFollowing,
isRelay,