eventSchema: ensure the event ID matches its hash

This commit is contained in:
Alex Gleason 2023-09-02 19:40:28 -05:00
parent 7595dfa2e5
commit 007565b513
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { verifySignature, z } from '@/deps.ts'; import { getEventHash, verifySignature, z } from '@/deps.ts';
import { jsonSchema, safeUrlSchema } from '../schema.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. */ /** 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. */ /** Nostr relay filter schema. */
const filterSchema = z.object({ const filterSchema = z.object({