1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_js
2019-11-22 15:40:32 +01:00
..
js add mocha tests 2019-11-22 15:40:32 +01:00
src cargo fmt 2019-11-21 17:54:07 +01:00
tests add mocha tests 2019-11-22 15:40:32 +01:00
.gitignore add zokrates_js crate 2019-11-21 17:17:00 +01:00
Cargo.lock add mocha tests 2019-11-22 15:40:32 +01:00
Cargo.toml move readme to zokrates_book, remove custom serializer on SetupKeypair, remove docker files 2019-11-22 14:53:16 +01:00
gulpfile.js move readme to zokrates_book, remove custom serializer on SetupKeypair, remove docker files 2019-11-22 14:53:16 +01:00
package-lock.json add mocha tests 2019-11-22 15:40:32 +01:00
package.json add mocha tests 2019-11-22 15:40:32 +01:00
README.md add zokrates_js crate 2019-11-21 17:17:00 +01:00

zokrates-js

JavaScript bindings for ZoKrates project. The goal of this project is to provide ZoKrates JavaScript API supporting both node.js and the web. ZoKrates is a toolbox for zkSNARKs on Ethereum that helps you use verifiable computation in your DApp, from the specification of your program in a high level language to generating proofs of computation and verifying those proofs in Solidity.

CircleCI

Package

Install zokrates-js with npm:

npm install zokrates-js

API

Function Description
initialize Loads binding wasm module and sets necessary callbacks
compile Compiles source code into ZoKrates internal representation of arithmetic circuits
computeWitness Computes a valid assignment of the variables, which include the results of the computation
setup Generates a trusted setup for the compiled program
exportSolidityVerifier Generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program
generateProof Generates a proof for a computation of the compiled program

Usage

import * as zokrates from 'zokrates-js'

function importResolver(location, path) {
  // implement your resolving logic here
  return { 
    source: "def main() -> (): return", 
    location: path 
  };
}

zokrates.initialize(importResolver).then(() => {
    // we have to initialize wasm module before calling api functions
    zokrates.compile("def main(private field a) -> (field): return a", "main")
});

Installation

Install rustup and wasm-pack:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

In order to compile this project you need the nightly version of Rust. You can install all of this by running:

rustup install nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly

Development

Anyone is welcome to help progress and improve this library. Tasks and issues can be found in the issues tab. If your problem/task is not in the tasks, feel free to create a new issue explaining your problem/task.