UNPKG

@iden3/js-jwz

Version:

JS implementation of JWZ

39 lines (38 loc) 1.24 kB
export class ProvingMethodAlg { constructor(alg, circuitId) { this.alg = alg; this.circuitId = circuitId; } toString() { return `${this.alg}:${this.circuitId}`; } } const provingMethods = new Map(); // map[string]func() ProvingMethod{} // RegisterProvingMethod registers the "alg" name and a factory function for proving method. // This is typically done during init() in the method's implementation export function registerProvingMethod(alg, f) { return new Promise((res) => { provingMethods.set(alg.toString(), f); res(); }); } // GetProvingMethod retrieves a proving method from an "alg" string export function getProvingMethod(alg) { return new Promise((res, rej) => { const func = provingMethods.get(alg.toString()); if (func) { const method = func(); res(method); } else { rej('unknown alg'); } }); } export function getAlgorithms() { return Promise.resolve(Array.from(provingMethods.keys()).map((k) => k.split(':')[0])); } // Prepare function is responsible to call provided handler for inputs preparation export function prepare(f, hash, circuitId) { return f(hash, circuitId); }