@lof-lang/toolkit-node
v0.1.2
Published
Node.js helpers for verifying Lof proofs with wasm-bindgen bindings.
Readme
@lof/toolkit-node
Node-focused helpers for loading verification keys and checking proofs using the wasm-bindgen bindings generated from the lofit crate.
The package wraps the lower-level WASM exports with a familiar, promise-based API. Pair it with the assets emitted by lof compile … --target wasm and the Node-targeted wasm-pack build of the prover/verifier.
Installation
npm install @lof/toolkit-nodeUsage
Simple (auto-discovery)
The easiest way is to specify bundlePath, which automatically discovers the verification key and verifier module:
import { loadVerifier, verifyProof } from '@lof-lang/toolkit-node';
import path from 'path';
const verifier = await loadVerifier({
bundlePath: path.resolve(__dirname, './dist/multiply/web/multiply')
});
const ok = await verifyProof(verifier, proofBytes, publicInputs);With bundlePath, the toolkit automatically discovers:
${bundlePath}/keys/${circuitName}_vk.bin${bundlePath}/prover-node/lofit.js
The circuit name is inferred from the basename of bundlePath (e.g., dist/multiply/web/multiply → multiply).
Explicit paths
For full control, you can specify each path individually:
import { pathToFileURL } from 'url';
const verifier = await loadVerifier({
verificationKeyPath: 'web/circuit/keys/circuit_vk.bin',
verifierModuleUrl: pathToFileURL('./prover-node/lofit.js').href
});
const ok = await verifyProof(verifier, proofBytes, publicSignals);Notes:
proofBytescan be aUint8Array, NodeBuffer, or array-like of numberspublicInputscan be:- An object:
{ a: '5', b: '7' }(field values as strings) - An array:
['5', '7'](ordered field elements as strings) - An iterable: Any iterable of field element strings
- An object:
API
loadVerifier(options)
Loads the WASM verifier module, reads the verification key, and returns a handle containing the instantiated WasmVerifier.
Options:
bundlePath?: string– Directory containing the circuit bundle (enables auto-discovery)artifactName?: string– Circuit name (defaults to basename ofbundlePath)verificationKeyPath?: string– Explicit path to verification key fileverifierModuleUrl?: string– Explicit file:// URL to verifier module (usepathToFileURL)verificationKey?: Uint8Array– Pre-loaded verification key bytesverifierModule?: VerifierModule– Pre-imported verifier moduleloadVerifierModule?: () => Promise<VerifierModule>– Custom module loaderfs?: { readFile }– Custom file reader (for testing)
Returns:
A VerifierHandle object containing the instantiated verifier.
verifyProof(verifier, proofBytes, publicInputs)
Verifies a Groth16 proof against public inputs.
Parameters:
verifier– The verifier handle fromloadVerifier()proofBytes– Proof asUint8Array,Buffer, or array of numberspublicInputs– Public inputs as:- Object:
{ signal1: 'value1', signal2: 'value2' } - Array:
['value1', 'value2'] - Iterable: Any iterable of field element strings
- Object:
Returns:
Promise<boolean> – true if the proof is valid, false otherwise.
