yarn add @unirep/circuits
import * as snarkjs from 'snarkjs'
import { Circuit, Prover } from '@unirep/circuits'
import { SnarkProof, SnarkPublicSignals } from '@unirep/crypto'
const buildPath = 'PATH/TO/CIRCUIT/FOLDER/'
const prover: Prover = {
genProofAndPublicSignals: async (
proofType: string | Circuit,
inputs: any
): Promise<{
proof: any,
publicSignals: any
}> => {
const circuitWasmPath = buildPath + `${proofType}.wasm`
const zkeyPath = buildPath + `${proofType}.zkey`
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
inputs,
circuitWasmPath,
zkeyPath
)
return { proof, publicSignals }
},
verifyProof: async (
name: string | Circuit,
publicSignals: SnarkPublicSignals,
proof: SnarkProof
): Promise<boolean> => {
const vkey = require(buildPath + `${name}.vkey.json`)
return snarkjs.groth16.verify(vkey, publicSignals, proof)
},
}
import { Circuit } from '@unirep/circuits'
// See ./test/verifyEpochKey.test.ts for generating circuit inputs
const circuitInputs = {
identity_nullifier: ...,
identity_trapdoor: ...,
user_tree_root: ...,
...
}
const { proof, publicSignals } = await prover.genProofAndPublicSignals(
Circuit.verifyEpochKey,
circuitInputs
)
const isValid = await prover.verifyProof(
Circuit.verifyEpochKey,
publicSignals,
proof
)