Merge pull request #637 from dark64/update-book
Update zokrates.js docs
This commit is contained in:
commit
bf591d595a
2 changed files with 34 additions and 7 deletions
|
@ -19,19 +19,44 @@ npm install zokrates-js
|
|||
|
||||
## Usage
|
||||
|
||||
### Importing
|
||||
|
||||
Bundlers
|
||||
```js
|
||||
import { initialize } from 'zokrates-js';
|
||||
```
|
||||
|
||||
function importResolver(location, path) {
|
||||
Node
|
||||
```js
|
||||
const { initialize } = require('zokrates-js/node');
|
||||
```
|
||||
|
||||
### Example
|
||||
```js
|
||||
function importResolver(currentLocation, importLocation) {
|
||||
// implement your resolving logic here
|
||||
return {
|
||||
source: "def main() -> (): return",
|
||||
location: path
|
||||
return {
|
||||
source: "def main() -> (): return",
|
||||
location: importLocation
|
||||
};
|
||||
}
|
||||
|
||||
initialize().then((zokratesProvider) => {
|
||||
// we have to initialize the wasm module before calling api functions
|
||||
zokratesProvider.compile("def main(private field a) -> (field): return a", "main", importResolver)
|
||||
const source = "def main(private field a) -> (field): return a * a";
|
||||
|
||||
// compilation
|
||||
const artifacts = zokratesProvider.compile(source, "main", importResolver);
|
||||
|
||||
// computation
|
||||
const { witness, output } = zokratesProvider.computeWitness(artifacts, ["2"]);
|
||||
|
||||
// run setup
|
||||
const keypair = zokratesProvider.setup(artifacts.program);
|
||||
|
||||
// generate proof
|
||||
const proof = zokratesProvider.generateProof(artifacts.program, witness, keypair.pk);
|
||||
|
||||
// export solidity verifier
|
||||
const verifier = zokratesProvider.exportSolidityVerifier(keypair.vk, "v1");
|
||||
});
|
||||
```
|
||||
|
|
|
@ -42,8 +42,10 @@ function importResolver(currentLocation, importLocation) {
|
|||
}
|
||||
|
||||
initialize().then((zokratesProvider) => {
|
||||
const source = "def main(private field a) -> (field): return a * a";
|
||||
|
||||
// compilation
|
||||
const artifacts = zokratesProvider.compile("def main(private field a) -> (field): return a * a", "main", importResolver);
|
||||
const artifacts = zokratesProvider.compile(source, "main", importResolver);
|
||||
|
||||
// computation
|
||||
const { witness, output } = zokratesProvider.computeWitness(artifacts, ["2"]);
|
||||
|
|
Loading…
Reference in a new issue