1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

Merge branch 'develop' of github.com:Zokrates/ZoKrates into remove-bellman-embeds

This commit is contained in:
schaeff 2020-07-16 11:26:47 +02:00
commit dd258f1e6a
4 changed files with 43 additions and 8 deletions

View file

@ -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");
});
```

View file

@ -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"]);

View file

@ -25,7 +25,12 @@ describe('tests', function() {
it('should resolve stdlib module', function() {
assert.doesNotThrow(() => {
const code = 'import "hashes/sha256/512bit" as sha256\ndef main() -> (): return';
const code = `
import "hashes/sha256/512bit" as sha256
import "ecc/edwardsAdd" as edwardsAdd
def main() -> ():
return
`;
this.zokrates.compile(code, "main");
})
});

View file

@ -1,4 +1,7 @@
const getAbsolutePath = (basePath, relativePath) => {
if (relativePath[0] !== '.') {
return relativePath;
}
var stack = basePath.split('/');
var chunks = relativePath.split('/');
stack.pop();