This is the repository for the JavaScript SDK for zkWasm. You can use this library client or server-side as long as the runtime supports Wasm, Workers, and IndexedDB. To get started, bootstrap an AssemblyScript project with create-zkwasm-app:
npx create-zkwasm-app your-project-nameWarning You have to set a couple headers (see below) on your server because of our use of
SharedArrayBuffer. This library does not work otherwise.
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
import { Module, verify } from 'zkwasm';
let wasmBinary = { ... }; // This can be acquired in any way
let module = await Module.fromBinary(wasmBinary);
let { result, proof } = module.invokeExport('test', [...serializedArguments]);
console.log(result);
console.log(verify(proof)); // Check if a proof is validThe SDK has two exports. The Module class which is used to create a Wasm module and invoke exports on it, and the verify function which is used to verify any proofs from the SDK.
It's not recommended to use this. Always prefer to use Module.fromBinary instead. If you do use the constructor you must call Module.prototype.init before invoking any exports.
Initializes the module and sets up the internal worker.
Way to check if the module has been initialized or not. This is used internally and methods throw if it returns false.
The recommended way to create a Module object. Both constructs and initialized the object internally so it's ready to use.
Invokes a public export on the Wasm module and returns the result of execution and a verifiable proof.
type Proof = {
bytes: Uint8Array;
inputs: Uint8Array;
};
type InvocationResult = {
proof: Proof;
result: Uint8Array;
};Verifies a proof of execution and returns whether the provided proof is valid or not.