mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
eventSchema: ensure the event ID matches its hash
This commit is contained in:
parent
7595dfa2e5
commit
007565b513
1 changed files with 4 additions and 2 deletions
|
|
@ -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({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue