zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
37 lines (36 loc) • 1.36 kB
JavaScript
import { ProofType } from '../../config';
import { isGroth16Config, isPlonky2Config, isRisc0Config, } from '../../utils/helpers';
/**
* Validates the options provided for a given proof type.
* @throws {Error} - If the validation fails.
*/
export function validateProofTypeOptions(options) {
const { proofType } = options;
if (!proofType) {
throw new Error('Proof type is required.');
}
switch (proofType) {
case ProofType.groth16:
if (!isGroth16Config(options)) {
throw new Error(`Proof type '${proofType}' requires both 'library' and 'curve' options.`);
}
break;
case ProofType.plonky2:
if (!isPlonky2Config(options)) {
throw new Error(`Proof type '${proofType}' requires 'compressed' (boolean) and 'hashFunction' options.`);
}
break;
case ProofType.risc0:
if (!isRisc0Config(options)) {
throw new Error(`Proof type '${proofType}' requires a 'version' option.`);
}
break;
case ProofType.ultraplonk:
case ProofType.proofofsql:
// No specific options required for these proof types
break;
default:
void options;
throw new Error(`Unsupported proof type: ${options.proofType}`);
}
}