UNPKG

zkverifyjs

Version:

Submit proofs to zkVerify and query proof state with ease using our npm package.

116 lines 5.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateProofTypeOptions = validateProofTypeOptions; const index_js_1 = require("../../config/index.js"); const index_js_2 = require("../../utils/helpers/index.js"); const enums_js_1 = require("../../enums.js"); /** * Validates the options provided for a given proof type. * * @param options - The proof options to validate. * @param runtimeSpec - Runtime spec for version-dependent validation. * @returns The validated options, with runtime-version defaults applied. * @throws {Error} - If validation fails. */ function validateProofTypeOptions(options, runtimeSpec) { const { proofType } = options; if (!proofType) { throw new Error('Proof type is required.'); } switch (proofType) { case index_js_1.ProofType.groth16: if (!(0, index_js_2.isGroth16Config)(options)) { throw new Error(`Proof type '${proofType}' requires both 'library' and 'curve' options.`); } return options; case index_js_1.ProofType.plonky2: if (!(0, index_js_2.isPlonky2Config)(options)) { throw new Error(`Proof type '${proofType}' requires a 'hashFunction' option.`); } return options; case index_js_1.ProofType.risc0: if (!(0, index_js_2.isRisc0Config)(options)) { throw new Error(`Proof type '${proofType}' requires a 'version' option.`); } return options; case index_js_1.ProofType.ultraplonk: if (!(0, index_js_2.isUltraplonkConfig)(options)) { throw new Error(`Proof type '${proofType}' requires a 'numberOfPublicInputs' option.`); } return options; case index_js_1.ProofType.ultrahonk: { if ((0, index_js_2.isVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_6_0)) { const defaulted = withDefaultedUltrahonkVersion(options, runtimeSpec); if (!(0, index_js_2.isVersionedUltrahonkConfig)(defaulted)) { throw new Error(`Proof type '${proofType}' requires 'version' and 'variant' options for runtime version 1.6.0 or later.`); } return defaulted; } const config = options.config; if (config?.version !== undefined) { throw new Error(`Proof type '${proofType}' does not support a 'version' option before runtime version 1.6.0.`); } if (!(0, index_js_2.isVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_3_0)) { return options; } if (!(0, index_js_2.isUltrahonkConfig)(options)) { throw new Error(`Proof type '${proofType}' requires a 'variant' option for runtime version 1.3.0 or later.`); } return options; } case index_js_1.ProofType.ezkl: (0, index_js_2.requireVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_3_0, 'EZKL proof type'); return options; case index_js_1.ProofType.fflonk: case index_js_1.ProofType.sp1: return options; case index_js_1.ProofType.tee: { (0, index_js_2.requireVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_5_0, 'TEE proof type'); if ((0, index_js_2.isVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_6_0)) { return withDefaultedTeeVariant(options); } const config = options.config; if (config?.variant !== undefined) { throw new Error(`Proof type '${proofType}' does not support a 'variant' option before runtime version 1.6.0.`); } return options; } // ADD_NEW_PROOF_TYPE config validation per proof type // ADD RUNTIME SPECIFIC RULE IF NEEDED USING requireVersionAtLeast default: void options; throw new Error(`Unsupported proof type: ${options.proofType}`); } } function withDefaultedUltrahonkVersion(options, runtimeSpec) { const config = options.config; if (config?.variant === undefined || config.version !== undefined) { return options; } const defaultVersion = (0, index_js_2.isVersionAtLeast)(runtimeSpec, enums_js_1.RuntimeVersion.V1_6_1) ? enums_js_1.UltrahonkVersion.Legacy : enums_js_1.UltrahonkVersion.V0_84; console.warn(`zkverifyjs: Proof type '${index_js_1.ProofType.ultrahonk}' now supports versioned proofs on runtime version 1.6.0 or later. Defaulting missing 'version' to '${defaultVersion}' for backwards compatibility. Pass 'version' explicitly to silence this warning.`); return { ...options, config: { ...config, version: defaultVersion, }, }; } function withDefaultedTeeVariant(options) { const config = options.config; if (config?.variant !== undefined) { return options; } console.warn(`zkverifyjs: Proof type '${index_js_1.ProofType.tee}' now supports variant verification keys on runtime version 1.6.0 or later. Defaulting missing 'variant' to '${enums_js_1.TeeVariant.Intel}' for backwards compatibility. Pass 'variant' explicitly to silence this warning.`); return { ...options, config: { ...config, variant: enums_js_1.TeeVariant.Intel, }, }; } //# sourceMappingURL=index.js.map