UNPKG

@nori-zk/proof-conversion

Version:

Verifying zkVM proofs inside o1js circuits, to generate Mina compatible proof

34 lines (33 loc) 1.52 kB
import { type SchemaObject, type InferSchemaType } from './guards/index.js'; /** * Validates that an object exactly matches a schema definition. * Uses TypeScript assertion signature to narrow the type on success. * * This function: * 1. Checks that the value is an object (not array, null, or primitive) * 2. Validates all required keys are present * 3. Validates all values match their schema rules (validators or literals) * 4. Rejects any unexpected extra keys * 5. Recursively validates nested objects * * For validator functions (ValidatorFn), uses the diagnose function to provide * detailed path-aware error messages. For literal values, checks exact equality. * * @template S - The schema object type * @param obj - The value to validate * @param schema - The schema definition (object with validators, literals, or nested schemas) * @param context - Human-readable context for error messages (e.g., "Groth16 proof") * @param pathPrefix - Internal parameter for recursive path tracking * @throws {ValidationError} If validation fails, with detailed error messages * * @example * const schema = { * name: isString, * age: isNumber, * role: "admin" // literal value * }; * * assertExactStructure(data, schema, "User"); * // After this line, data is narrowed to: { name: string; age: number; role: "admin" } */ export declare function assertExactStructure<S extends SchemaObject>(obj: unknown, schema: S, context: string, pathPrefix?: string): asserts obj is InferSchemaType<S>;