How to use the snarkjs.isValid 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
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
                PROOF_AND_SIGNALS_DIR + '/' + i.toString() + '.json',
                    stringifyBigInts({ proof, publicSignals }),

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

            if (!isValid) {
                throw new Error('Invalid proof')
            } else {
                console.log('Valid proof')

            console.log('correctNumBlacks calculated by circuit:', witness[circuit.getSignalIdx('main.correctNumBlacks')])
            console.log('correctNumWhites calculated by circuit:', witness[circuit.getSignalIdx('main.correctNumWhites')])
            console.log('Hash calculated by JS     :', testInput.pubSolnHash)
            console.log('Hash calculated by circuit:', witness[circuit.getSignalIdx('main.solnHashOut')])
        } catch (e) {