Utility Functions
Overview
The SDK exports several utility functions for initialization and verification operations.
Functions
initThreadPool
Initialize the thread pool for parallel WASM operations. This should be called before performing CPU-intensive operations like proof generation.
initThreadPool(num_threads) ► Promise<void>
| Param | Type | Description |
|---|---|---|
| num_threads | number | Number of threads to use in the thread pool |
| return | Promise<void> | Promise that resolves when initialization is complete |
Example
import { initThreadPool } from '@provablehq/sdk';
// Initialize with available CPU cores
await initThreadPool(navigator.hardwareConcurrency);
verifyFunctionExecution
Verify an execution. Executions with multiple transitions must have the program source code and verifying keys of imported functions supplied from outside to correctly verify. Note: this does not verify that the state root of the execution is included in the Aleo Network ledger.
verifyFunctionExecution(execution, verifying_key, program, function_id, imports, import_verifying_keys, block_height) ► boolean
| Param | Type | Description |
|---|---|---|
| execution | Execution | The function execution to verify |
| verifying_key | VerifyingKey | The verifying key for the function |
| program | Program | The program that the function execution belongs to |
| function_id | string | The name of the function that was executed |
| imports | Object | The imports for the program in the form of { "program_id.aleo": "source code", ... } |
| import_verifying_keys | Object | The verifying keys for the imports in the form of { "program_id.aleo": [["function", "verifying_key"], ...], ... } |
| block_height | number | The block height at which the execution occurred |
| return | boolean | True if the execution is valid, false otherwise |
Example
import { verifyFunctionExecution, Execution, VerifyingKey, Program } from '@provablehq/sdk';
const execution = Execution.fromString(executionJson);
const verifyingKey = VerifyingKey.fromString(vkString);
const program = Program.fromString(programSource);
const isValid = verifyFunctionExecution(
execution,
verifyingKey,
program,
"transfer_public",
{}, // imports
{}, // import_verifying_keys
1000000 // block_height
);
console.log("Execution valid:", isValid);
getOrInitConsensusVersionTestHeights
Get or initialize consensus version test heights. This is primarily used for testing network consensus version transitions.
getOrInitConsensusVersionTestHeights() ► Object
| Param | Type |
|---|---|
| return | Object |