diff --git a/packages/test/index.ts b/packages/test/index.ts index 61bc4f3..29600cb 100644 --- a/packages/test/index.ts +++ b/packages/test/index.ts @@ -1,30 +1,20 @@ import { Project } from '@zk-kit/artifacts' -import { generate, type PoseidonProof } from '@zk-kit/poseidon-proof' +import type { PoseidonProof } from '@zk-kit/poseidon-proof' import { unpackGroth16Proof } from '@zk-kit/utils' import { keccak256, toBeHex } from 'ethers' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { groth16 } from 'snarkjs' -const SCOPE = 'scope' -const hash = (message: string) => (BigInt(keccak256(toBeHex(message, 32))) >> BigInt(8)).toString() - -const generateProof = (project: Project) => async (preimages: number[]) => { - const numParams = preimages.length +export const SCOPE = 'scope' - return generate(preimages, SCOPE, { - wasm: join(__dirname, '..', project, `${project}-${numParams}.wasm`), - zkey: join(__dirname, '..', project, `${project}-${numParams}.zkey`), - }) -} +const hash = (message: string) => (BigInt(keccak256(toBeHex(message, 32))) >> BigInt(8)).toString() -const verifyProof = (project: Project) => -async ( +export const verifyPoseidonProof = ( { digest, numberOfInputs, proof, scope }: PoseidonProof, ) => { - const verifKey = JSON.parse(readFileSync(join(__dirname, '..', project, `${project}-${numberOfInputs}.json`), 'utf8')) + const verifKey = JSON.parse( + readFileSync(join(__dirname, '..', Project.POSEIDON, `${Project.POSEIDON}-${numberOfInputs}.json`), 'utf8'), + ) return groth16.verify(verifKey, [digest, hash(scope)], unpackGroth16Proof(proof)) } - -export const generatePoseidonProof = generateProof(Project.POSEIDON) -export const verifyPoseidonProof = verifyProof(Project.POSEIDON)