UNPKG

@puzzlehq/aleo-wasm-nodejs

Version:
69 lines (62 loc) 1.5 kB
import { readFile } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; import initWasm from "./aleo_wasm.js"; const __dirname = dirname(fileURLToPath(import.meta.url)); const wasmPath = join(__dirname, 'aleo_wasm.wasm'); const wasmBuffer = await readFile(wasmPath); const { initThreadPool: wasmInitThreadPool, Address, BHP256, Execution, ExecutionResponse, Field, Metadata, OfflineQuery, Plaintext, PrivateKey, PrivateKeyCiphertext, Program, ProvingKey, RecordCiphertext, RecordPlaintext, ProgramManager, Signature, Transaction, ViewKey, VerifyingKey, verifyFunctionExecution, } = await initWasm(wasmBuffer); async function initThreadPool(threads) { if (threads == null) { const { cpus } = await import('node:os'); threads = cpus().length; } console.info(`Spawning ${threads} threads`); const { Worker } = await import('node:worker_threads'); await wasmInitThreadPool((_, options) => new Worker("./worker.js", options), threads); } export { initThreadPool, Address, BHP256, Execution, ExecutionResponse, Field, Metadata, OfflineQuery, Plaintext, PrivateKey, PrivateKeyCiphertext, Program, ProvingKey, RecordCiphertext, RecordPlaintext, ProgramManager, Signature, Transaction, ViewKey, VerifyingKey, verifyFunctionExecution, };