How to use the snarkjs.genProof function in snarkjs

To help you get started, we’ve selected a few snarkjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github weijiekoh / zkmm / mastermind / src / old.ts View on Github external
pubGuessC: testCase.guess[2],
            pubGuessD: testCase.guess[3],
            privSolnA: testCase.soln[0],
            privSolnB: testCase.soln[1],
            privSolnC: testCase.soln[2],
            privSolnD: testCase.soln[3],
        }

        try {
            console.log('The codemaster calculates the witness')
            const witness = circuit.calculateWitness(testInput)

            console.log('The codemaster generates a proof', new Date())

            // Codemaster generates the proof and public signals
            const { proof, publicSignals } = snarkjs.genProof(provingKey, witness);

            // Save to file
            writeFileSync(
                PROOF_AND_SIGNALS_DIR + '/' + i.toString() + '.json',
                JSON.stringify(
                    stringifyBigInts({ proof, publicSignals }),
                ),
                'utf8'
            )

            console.log('Verifying proof', new Date())
            const isValid: boolean = snarkjs.isValid(verifyingKey, proof, publicSignals)

            if (!isValid) {
                throw new Error('Invalid proof')
            } else {