UNPKG

@iden3/js-jwz

Version:

JS implementation of JWZ

33 lines (32 loc) 1.21 kB
import { ProvingMethodAlg } from './proving'; import { Id } from '@iden3/js-iden3-core'; import { AuthCircuit, Groth16, prove, verify } from './common'; // ProvingMethodGroth16Auth defines proofs family and specific circuit class ProvingMethodGroth16Auth { constructor(methodAlg) { this.methodAlg = methodAlg; } get alg() { return this.methodAlg.alg; } get circuitId() { return this.methodAlg.circuitId; } unmarshall(pubsignals) { const outputs = {}; if (pubsignals.length != 3) { throw new Error(`invalid number of Output values expected ${3} got ${pubsignals.length}`); } outputs.challenge = BigInt(pubsignals[0]); outputs.userState = BigInt(pubsignals[1]); outputs.userId = Id.fromBigInt(BigInt(pubsignals[2])); return outputs; } async verify(messageHash, proof, verificationKey) { return verify(messageHash, proof, verificationKey, this.unmarshall); } prove(inputs, provingKey, wasm) { return prove(inputs, provingKey, wasm); } } export const provingMethodGroth16AuthInstance = new ProvingMethodGroth16Auth(new ProvingMethodAlg(Groth16, AuthCircuit));