From 007565b513395d591002e5797943aa93c2e02c59 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 2 Sep 2023 19:40:28 -0500 Subject: [PATCH] eventSchema: ensure the event ID matches its hash --- src/schemas/nostr.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/schemas/nostr.ts b/src/schemas/nostr.ts index 6b5c30c..1294804 100644 --- a/src/schemas/nostr.ts +++ b/src/schemas/nostr.ts @@ -1,4 +1,4 @@ -import { verifySignature, z } from '@/deps.ts'; +import { getEventHash, verifySignature, z } from '@/deps.ts'; import { jsonSchema, safeUrlSchema } from '../schema.ts'; @@ -19,7 +19,9 @@ const eventSchema = z.object({ }); /** Nostr event schema that also verifies the event's signature. */ -const signedEventSchema = eventSchema.refine(verifySignature); +const signedEventSchema = eventSchema + .refine((event) => event.id === getEventHash(event), 'Event ID does not match hash') + .refine(verifySignature, 'Event signature is invalid'); /** Nostr relay filter schema. */ const filterSchema = z.object({