diff --git a/zokrates_book/src/zokrates_js.md b/zokrates_book/src/zokrates_js.md index 726449c0..134edeae 100644 --- a/zokrates_book/src/zokrates_js.md +++ b/zokrates_book/src/zokrates_js.md @@ -6,34 +6,25 @@ You can get JavaScript bindings for ZoKrates by running npm install zokrates-js ``` -## API +## Importing -| Function | Description | -| ------ | ------ | -| initialize | Loads binding wasm module and returns a promise with ZoKrates provider | -| 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 - -### Importing - -Bundlers +##### Bundlers +**Note:** As this library uses a model where the wasm module itself is natively an ES module, you will need a bundler of some form. +Currently the only known bundler known to be fully compatible with `zokrates-js` is [Webpack](https://webpack.js.org/). +The choice of this default was done to reflect the trends of the JS ecosystem. ```js import { initialize } from 'zokrates-js'; ``` -Node +##### Node ```js const { initialize } = require('zokrates-js/node'); ``` -### Example +## Example ```js function importResolver(currentLocation, importLocation) { + console.log(currentLocation + ' is importing ' + importLocation); // implement your resolving logic here return { source: "def main() -> (): return", @@ -60,3 +51,57 @@ initialize().then((zokratesProvider) => { const verifier = zokratesProvider.exportSolidityVerifier(keypair.vk, "v1"); }); ``` + +## API + +##### initialize() +Loads binding wasm module and returns a promise with ZoKrates provider. + +Returns: `Promise` + +##### compile(source, location, resolveCallback[, config]) +Compiles source code into ZoKrates internal representation of arithmetic circuits. + +Parameters: +* `source` - Source code to compile +* `location` - Root location of the module which is being compiled +* `resolveCallback` - User-defined callback used to resolve imports +* `config` - Compilation config + +Returns: `CompilationArtifacts` + +##### computeWitness(artifacts, args) +Computes a valid assignment of the variables, which include the results of the computation. + +Parameters: +* `artifacts` - Compilation artifacts +* `args` - Array of arguments (eg. `["1", "2", true]`) + +Returns: `ComputationResult` + +##### setup(program) +Generates a trusted setup for the compiled program. + +Parameters: +* `program` - Compiled program + +Returns: `SetupKeypair` + +##### exportSolidityVerifier(verificationKey, abi) +Generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program. + +Parameters: +* `verificationKey` - Verification key from the setup keypair +* `abi` - Abi version (`"v1"` | `"v2"`) + +Returns: `string` + +##### generateProof(program, witness, provingKey) +Generates a proof for a computation of the compiled program. + +Parameters: +* `program` - Compiled program +* `witness` - Witness (valid assignment of the variables) +* `provingKey` - Proving key from the setup keypair + +Returns: `Proof` \ No newline at end of file diff --git a/zokrates_js/README.md b/zokrates_js/README.md index 2863185f..c1944a33 100644 --- a/zokrates_js/README.md +++ b/zokrates_js/README.md @@ -6,34 +6,25 @@ JavaScript bindings for [ZoKrates](https://github.com/Zokrates/ZoKrates) project npm install zokrates-js ``` -## API +## Importing -| Function | Description | -| ------ | ------ | -| initialize | Loads binding wasm module and returns a promise with ZoKrates provider | -| 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 - -### Importing - -Bundlers +##### Bundlers +**Note:** As this library uses a model where the wasm module itself is natively an ES module, you will need a bundler of some form. +Currently the only known bundler known to be fully compatible with `zokrates-js` is [Webpack](https://webpack.js.org/). +The choice of this default was done to reflect the trends of the JS ecosystem. ```js import { initialize } from 'zokrates-js'; ``` -Node +##### Node ```js const { initialize } = require('zokrates-js/node'); ``` -### Example +## Example ```js function importResolver(currentLocation, importLocation) { + console.log(currentLocation + ' is importing ' + importLocation); // implement your resolving logic here return { source: "def main() -> (): return", @@ -59,4 +50,58 @@ initialize().then((zokratesProvider) => { // export solidity verifier const verifier = zokratesProvider.exportSolidityVerifier(keypair.vk, "v1"); }); -``` \ No newline at end of file +``` + +## API + +##### initialize() +Loads binding wasm module and returns a promise with ZoKrates provider. + +Returns: `Promise` + +##### compile(source, location, resolveCallback[, config]) +Compiles source code into ZoKrates internal representation of arithmetic circuits. + +Parameters: +* `source` - Source code to compile +* `location` - Root location of the module which is being compiled +* `resolveCallback` - User-defined callback used to resolve imports +* `config` - Compilation config + +Returns: `CompilationArtifacts` + +##### computeWitness(artifacts, args) +Computes a valid assignment of the variables, which include the results of the computation. + +Parameters: +* `artifacts` - Compilation artifacts +* `args` - Array of arguments (eg. `["1", "2", true]`) + +Returns: `ComputationResult` + +##### setup(program) +Generates a trusted setup for the compiled program. + +Parameters: +* `program` - Compiled program + +Returns: `SetupKeypair` + +##### exportSolidityVerifier(verificationKey, abi) +Generates a Solidity contract which contains the generated verification key and a public function to verify a solution to the compiled program. + +Parameters: +* `verificationKey` - Verification key from the setup keypair +* `abi` - Abi version (`"v1"` | `"v2"`) + +Returns: `string` + +##### generateProof(program, witness, provingKey) +Generates a proof for a computation of the compiled program. + +Parameters: +* `program` - Compiled program +* `witness` - Witness (valid assignment of the variables) +* `provingKey` - Proving key from the setup keypair + +Returns: `Proof` \ No newline at end of file