How to use the snarkjs.unstringifyBigInts 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 iden3 / websnark / test / bn128_prover.js View on Github external
it("It should do a zkSnark test", async () => {
        const bn128 = await buildBn128();

        const signals = fs.readFileSync(path.join(__dirname, "data", "witness.bin"));
        const provingKey = fs.readFileSync(path.join(__dirname, "data", "proving_key.bin"));
        const proofS = await bn128.proof(signals.buffer, provingKey.buffer);

        const proof = snarkjs.unstringifyBigInts(proofS);
        const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
        const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8")));

        assert(snarkjs.groth.isValid(verifierKey, proof, pub));

        bn128.terminate();
    }).timeout(10000000);
github iden3 / websnark / test / bn128_prover.js View on Github external
it("It should do a zkSnark test", async () => {
        const bn128 = await buildBn128();

        const signals = fs.readFileSync(path.join(__dirname, "data", "witness.bin"));
        const provingKey = fs.readFileSync(path.join(__dirname, "data", "proving_key.bin"));
        const proofS = await bn128.proof(signals.buffer, provingKey.buffer);

        const proof = snarkjs.unstringifyBigInts(proofS);
        const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
        const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8")));

        assert(snarkjs.groth.isValid(verifierKey, proof, pub));

        bn128.terminate();
    }).timeout(10000000);
github iden3 / websnark / test / bn128_prover.js View on Github external
it("It should do a zkSnark test", async () => {
        const bn128 = await buildBn128();

        const signals = fs.readFileSync(path.join(__dirname, "data", "witness.bin"));
        const provingKey = fs.readFileSync(path.join(__dirname, "data", "proving_key.bin"));
        const proofS = await bn128.proof(signals.buffer, provingKey.buffer);

        const proof = snarkjs.unstringifyBigInts(proofS);
        const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
        const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8")));

        assert(snarkjs.groth.isValid(verifierKey, proof, pub));

        bn128.terminate();
    }).timeout(10000000);
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / verify-proof.js View on Github external
const run = async (signals, proof, vk) => {
	const publicSignals = require(`${process.cwd()}/${generatedProofPath}/${signals}`);
	const generatedProof = zkSnark.unstringifyBigInts((require(`${process.cwd()}/${generatedProofPath}/${proof}`)));
	const verifierKey = zkSnark.unstringifyBigInts(require(`${process.cwd()}/${trustedSetupPath}/${vk}`));

	createZKProofFolder(verifiedProof);

	await verifyProof(publicSignals, generatedProof, verifierKey);
	console.log('===== Verifying Completed. Please check output.json =====');
};
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / generate-verify.js View on Github external
const run = async (vk) => {
	console.log('===== Creating Smart Contract for OnChain verification =====');
	const verifierKey = zkSnark.unstringifyBigInts(require(`${process.cwd()}/${trustedSetupPath}/${vk}`));
	const template = zkSnark.generateVerifier(verifierKey);
	fs.writeFileSync(`${contractsPath}/Verifier.sol`, template);
	console.log('===== Smart Contract Created Successfully. Please check your contracts folder =====');
};
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / generate-call.js View on Github external
const run = async (signals, proof) => {
	const publicSignals = require(`${process.cwd()}/${generatedProofPath}/${signals}`);
	const generatedProof = zkSnark.unstringifyBigInts((require(`${process.cwd()}/${generatedProofPath}/${proof}`)));

	createGenerateCallFolder(generatedCallPath);

	const generatedCall = await zkSnark.generateCall(publicSignals, generatedProof);
	
	
	fs.writeFileSync(`${generatedCallPath}/generatedCall.json`, zkSnark.stringifyBigInts(generatedCall));
	console.log('===== Generated Call Complete! =====');
	console.log('===== Generated Call: =====')
	console.log(generatedCall)
};
github kobigurk / semaphore / semaphorejs / src / client / semaphore.js View on Github external
constructor(node_url, loaded_identity, semaphoreABI, cir_def, proving_key, verifier_key, external_nullifier, identity_index, semaphore_server_url, contract_address, from_private_key, from_address, chain_id, transaction_confirmation_blocks, server_broadcast, server_broadcast_address, logger_handler) {
        logger = logger_handler;
        this.cir_def = cir_def;

        const circuit = new snarkjs.Circuit(cir_def);
        this.circuit = circuit;

        this.vk_proof = proving_key;
        this.verifier_key = snarkjs.unstringifyBigInts(verifier_key);

        this.private_key = loaded_identity.private_key;
        this.external_nullifier = external_nullifier;
        this.node_url = node_url;
        this.semaphore_server_url = semaphore_server_url;
        this.identity_index = identity_index;

        const prvKey = Buffer.from(this.private_key, 'hex');
        const pubKey = eddsa.prv2pub(prvKey);

        this.identity_nullifier = loaded_identity.identity_nullifier;
        this.identity_trapdoor = loaded_identity.identity_trapdoor;

        this.identity_commitment = pedersenHash([bigInt(circomlib.babyJub.mulPointEscalar(pubKey, 8)[0]), bigInt(this.identity_nullifier), bigInt(this.identity_trapdoor)]);

        this.web3 = new Web3(node_url);
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / verify-proof.js View on Github external
const run = async (signals, proof, vk) => {
	const publicSignals = require(`${process.cwd()}/${generatedProofPath}/${signals}`);
	const generatedProof = zkSnark.unstringifyBigInts((require(`${process.cwd()}/${generatedProofPath}/${proof}`)));
	const verifierKey = zkSnark.unstringifyBigInts(require(`${process.cwd()}/${trustedSetupPath}/${vk}`));

	createZKProofFolder(verifiedProof);

	await verifyProof(publicSignals, generatedProof, verifierKey);
	console.log('===== Verifying Completed. Please check output.json =====');
};
github LimeChain / etherlime / packages / etherlime / cli-commands / zk-proof / generate-proof.js View on Github external
const run = async (signal, circuit, pk) => {
	const compiledCircuit = require(`${process.cwd()}/${compiledCircuitsPath}/${circuit}`);
	const inputSignal = require(`${process.cwd()}/${signalsInputPath}/${signal}`);
	const provingKey = zkSnark.unstringifyBigInts(require(`${process.cwd()}/${trustedSetupPath}/${pk}`));

	createZKProofFolder(generatedProofPath);

	const witness = calculateWitness(compiledCircuit, inputSignal);
	generateProof(provingKey, witness, circuit);
	console.log('===== Generation Finished =====');

};
github kobigurk / semaphore / semaphorejs / src / util / index.js View on Github external
async function prove(witness, provingKey) {
  const groth16 = await buildGroth16();
  const p = await groth16.groth16GenProof(witness, provingKey);
  //groth16.terminate();
  return snarkjs.unstringifyBigInts(p);
}