
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@rarimo/bionetta-js-sdk-core
Advanced tools
Bionetta Core Tools is a foundational set of tools designed to integrate complex cryptographic computations, such as zk-SNARK proof generation and verification, into web applications or environments requiring high performance.
ProverWorker
ProverWorker
class, which facilitates the generation and verification of zk-SNARK proofs using a Web Worker. By offloading these computationally intensive tasks to a separate thread, it helps prevent the main thread from blocking, ensuring a smoother user experience.
The ProverWorker
class acts as a wrapper around a Web Worker. It provides a convenient API for interacting with the worker to perform two primary operations:
.zkey
file) and witness data.new ProverWorker(worker: Worker | string | URL)
Initializes a new instance of the ProverWorker
class.
This constructor is flexible and allows you to either:
Worker
instance (if already created elsewhere),Worker
by providing a file path (as a string or URL
) to the worker script (usually a module that uses snarkjs
under the hood).worker
is an instance of Worker
, it is used directly.worker
is a string
or a URL
, the constructor internally creates a new Worker
using:new Worker(worker, { type: 'module' })
generateProof
generateProof<TProof = Groth16Proof>(zkeyFileBytes: BufferLike, wtns: BufferLike): Promise<ZkProof<TProof>>
Generates a zero-knowledge proof by sending data to the web worker.
This method communicates with the worker to execute the groth16.prove
function using the provided .zkey
proving key and the witness file.
Name | Type | Description |
---|---|---|
zkeyFileBytes | BufferLike | The proving key file contents as a buffer (e.g., Uint8Array, ArrayBuffer). |
wtns | BufferLike | The witness buffer generated from circuit inputs. |
Promise<ZkProof<TProof>>
ZkProof<TProof>
. By default, this is expected to conform to the Groth16Proof
structure from snarkjs
.postMessage
with type 'prove'
, including the .zkey
and .wtns
buffers.import { ProverWorker } from '@rarimo/bionetta-js-sdk-core'
import proofWorkerUrl from './proofWorker?worker&inline'
// Load your .zkey and .wtns files (as ArrayBuffer or Uint8Array)
const zkeyBuffer = await fetch('/circuits/myCircuit.zkey').then(r => r.arrayBuffer())
const witnessBuffer = await fetch('/circuits/myCircuit.wtns').then(r => r.arrayBuffer())
const prover = new ProverWorker(proofWorkerUrl)
const proof = await prover.generateProof(zkeyBuffer, witnessBuffer)
generateVerification
generateVerification(vkVerifier: any, publicSignals: PublicSignals, proof: Groth16Proof, logger?: any): Promise<boolean>
Verifies a previously generated zk-SNARK proof using the worker thread.
This method sends verification data to the worker, which should use snarkjs.groth16.verify
internally to check the validity of the proof.
Name | Type | Description |
---|---|---|
vkVerifier | any | The verification key object (usually from .vkey.json ). |
publicSignals | PublicSignals | The public signals generated during witness calculation. |
proof | Groth16Proof | The zk-SNARK proof previously generated by generateProof . |
logger (optional) | any | Optional logger or debug object to pass into the worker (if supported). |
Promise<boolean>
true
if the proof is valid, false
otherwise. Will throw
if an error occurs in the worker.postMessage
of type 'verify'
to the worker.true
or false
based on verification result.import { ProverWorker } from '@rarimo/bionetta-js-sdk-core'
import proofWorkerUrl from './proofWorker?worker&inline'
import vkey from './vkey.json'
const prover = new ProverWorker(proofWorkerUrl)
const isValid = await prover.generateVerification(vkey, publicSignals, proof)
WitnessWorker
The WitnessWorker
class is responsible for computing the witness for a zero-knowledge proof in a separate web worker thread. It isolates heavy computation (like executing a WASM circuit) from the main thread, improving performance and responsiveness.
new WitnessWorker(data: Worker | string | URL)
Creates a new instance of the WitnessWorker
.
Name | Type | Description |
---|---|---|
data | Worker string URL | An already created Worker instance or a URL/path to a worker script. |
If data
is a Worker
instance, it will be used directly. Otherwise, a new Worker
is created from the given URL with { type: 'module' }
.
generateWitness
generateWitness<TInput>(wasmBytes: BufferLike, input: TInput, workerMessageType: string): Promise<BufferLike>
Sends the circuit's WebAssembly and input signals to the worker to compute the witness.
Name | Type | Description |
---|---|---|
wasmBytes | BufferLike | A binary buffer (e.g., ArrayBuffer , Uint8Array ) containing the WASM code of the circuit. |
input | TInput | The input object to the circuit. This must match the input signals expected by the circuit. |
workerMessageType | string | The type identifier for the message to instruct the worker on what to do. |
Promise<BufferLike>
Uint8Array
or ArrayBuffer
).type
, wasmBytes
, and input
.message
event with the resulting witness.error
event.import { WitnessWorker } from '@rarimo/bionetta-js-sdk-core'
import witnessWorkerUrl from './witnessWorker?worker&inline'
const wasmBytes = await fetch('/circuits/myCircuit.wasm').then(r => r.arrayBuffer())
const input = { a: 3, b: 9 }
const witnessWorker = new WitnessWorker(witnessWorkerUrl)
const witness = await witnessWorker.generateWitness(wasmBytes, input, 'init')
initFace
Initializes the camera-based face detection pipeline using a video stream and canvas layers.
This function sets up a CameraProcessor
and a FaceDetectorService
, loads the face detection model, and starts processing frames to detect and extract faces.
Takes an options
object with the following properties:
Name | Type | Description |
---|---|---|
videoElement | HTMLVideoElement | The video DOM element displaying the camera feed. |
videoCanvas | HTMLCanvasElement | Canvas used to render raw video frames for processing. |
overlayCanvas | HTMLCanvasElement | Canvas to draw detection overlays (e.g., face boxes, landmarks). |
faceCanvas | HTMLCanvasElement | Canvas where the resized detected face is drawn for later usage. |
resizeWidth | number | The target width to which the detected face should be resized. |
onFaceResized | (imageData: ImageData) => Promise<void> | Callback called with resized face image data after each detection. |
FaceDetectorService
and loads its model (TensorFlow.js).CameraProcessor
which:
videoElement
.videoCanvas
.faceDetector
.overlayCanvas
.resizeWidth
and draws it on faceCanvas
.onFaceResized
.Promise<CameraProcessor>
CameraProcessor
instance that you can control (e.g., stop or pause).import { initFace } from '@rarimo/bionetta-js-sdk-core'
const processor = await initFace({
videoElement: document.getElementById('video') as HTMLVideoElement,
videoCanvas: document.getElementById('video-canvas') as HTMLCanvasElement,
overlayCanvas: document.getElementById('overlay') as HTMLCanvasElement,
faceCanvas: document.getElementById('face') as HTMLCanvasElement,
resizeWidth: 224,
onFaceResized: async (imageData) => {
console.log('Received resized face data', imageData)
},
})
FAQs
Bionetta core tools
We found that @rarimo/bionetta-js-sdk-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.