micro-zk-proofs
Version:
Create & verify zero-knowledge SNARK proofs in parallel, using noble cryptography
39 lines • 1.73 kB
TypeScript
/**
* MSM - Multi Scalar Multiplication. Done in parallel using micro-wrkr.
* MSM is a fast algorithm to add & multiply many elliptic curve points at once.
* @module
*/
import { type IField } from '@noble/curves/abstract/modular.js';
import type { WeierstrassPointCons as ProjConstructor, WeierstrassPoint as ProjPointType } from '@noble/curves/abstract/weierstrass.js';
import { type MSMInput } from './msm-worker.ts';
/**
* Initializes batched MSM workers and reduction helpers.
* @returns Worker methods together with a `terminate()` hook.
* @example
* Create the bn254 worker pool and terminate it when the batch work is done.
* ```ts
* const ctx = initMSM();
* ctx.terminate();
* ```
*/
export declare function initMSM(): {
methods: any;
terminate: () => void;
};
/**
* Adapts a worker MSM function into the point-array/scalar-array shape used by Groth16.
* @param field - Scalar field used to drop zero scalars.
* @param point - Projective point constructor for normalization.
* @param fn - Worker-backed MSM implementation.
* @returns Helper that accepts separate point and scalar arrays.
* @example
* Wrap a worker MSM function so Groth16 can call it with separate point and scalar arrays.
* ```ts
* const { bn254 } = await import('@noble/curves/bn254.js');
* const workerMsm = async () => bn254.G1.Point.ZERO;
* const msm = modifyArgs(bn254.fields.Fr, bn254.G1.Point, workerMsm);
* await msm([bn254.G1.Point.BASE], [1n]);
* ```
*/
export declare function modifyArgs<T>(field: IField<bigint>, point: ProjConstructor<T>, fn: (input: MSMInput<T>[]) => Promise<ProjPointType<T>>): (points: ProjPointType<T>[], scalars: bigint[]) => Promise<ProjPointType<T>>;
//# sourceMappingURL=msm.d.ts.map