From f96edfab714011cc37f278ffec0ac1f3cb62dfc1 Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Wed, 30 Oct 2019 19:24:36 +0800 Subject: [PATCH] more semaphore wip --- zksnarks/semaphore/src/hello.js | 162 +++++++++++++++++++++++++++++--- 1 file changed, 147 insertions(+), 15 deletions(-) diff --git a/zksnarks/semaphore/src/hello.js b/zksnarks/semaphore/src/hello.js index 14f9d15..a78f860 100644 --- a/zksnarks/semaphore/src/hello.js +++ b/zksnarks/semaphore/src/hello.js @@ -1,8 +1,30 @@ +const crypto = require('crypto'); var fs = require('fs'); const zkSnark = require('snarkjs'); +const circomlib = require('circomlib'); + +const web3Utils = require('web3-utils'); + +const ethers = require('ethers'); + +const asciiToHex = web3Utils.asciiToHex; + +const bigInt = zkSnark.bigInt; + +const eddsa = circomlib.eddsa; +const mimcsponge = circomlib.mimcsponge; // Utils +beBuff2int = function(buff) { + let res = bigInt.zero; + for (let i=0; i true + +// What are the different types of signature fields? + +// loaded_identity.identity_nullifier? + +const inputs = { + 'identity_pk[0]': pubKey[0], + 'identity_pk[1]': pubKey[1], + 'auth_sig_r[0]': signature.R8[0], + 'auth_sig_r[1]': signature.R8[1], + auth_sig_s: signature.S, + signal_hash, + external_nullifier, + identity_nullifier, + identity_trapdoor, + identity_path_elements, + identity_path_index, + fake_zero: bigInt(0), +}; + +// const w = circuit.calculateWitness(inputs); +// assert(circuit.checkWitness(w)); + +//////////////////////////////////////////////////////////// + +//// 4. Generate proof +// const input = { +// "a": "3", +// "b": "11" +// } +// const witness = circuit.calculateWitness(input); +// const vk_proof = deserialize(fs.readFileSync("build/proving_key.json", "utf8")); + +// const {proof, publicSignals} = zkSnark.groth.genProof(vk_proof, witness); + +// // 5. Verify proof +// const vk_verifier = deserialize(fs.readFileSync("build/verification_key.json", "utf8")); + +// if (zkSnark.groth.isValid(vk_verifier, proof, publicSignals)) { +// console.log("The proof is valid"); +// } else { +// console.log("The proof is not valid"); +// }