@iden3/js-jwz
Version:
JS implementation of JWZ
50 lines (49 loc) • 2.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.provingMethodGroth16AuthV2Instance = exports.ProvingMethodGroth16AuthV2 = exports.AuthV2Groth16Alg = void 0;
const js_iden3_core_1 = require("@iden3/js-iden3-core");
const proving_1 = require("./proving");
const common_1 = require("./common");
const js_merkletree_1 = require("@iden3/js-merkletree");
const ffjavascript_1 = require("ffjavascript");
exports.AuthV2Groth16Alg = new proving_1.ProvingMethodAlg(common_1.Groth16, common_1.AuthV2Circuit);
// ProvingMethodGroth16AuthV2 instance for Groth16 proving method with an authV2 circuit
class ProvingMethodGroth16AuthV2 {
constructor(methodAlg) {
this.methodAlg = methodAlg;
}
get alg() {
return this.methodAlg.alg;
}
get circuitId() {
return this.methodAlg.circuitId;
}
async verify(messageHash, proof, verificationKey) {
const verificationResult = await (0, common_1.verify)(messageHash, proof, verificationKey, this.unmarshall);
await this.terminateCurve();
return verificationResult;
}
async prove(inputs, provingKey, wasm) {
const zkProof = await (0, common_1.prove)(inputs, provingKey, wasm);
await this.terminateCurve();
return zkProof;
}
async terminateCurve() {
const curve = await (0, ffjavascript_1.getCurveFromName)(ProvingMethodGroth16AuthV2.curveName);
curve.terminate();
}
unmarshall(pubSignals) {
const len = 3;
if (pubSignals.length !== len) {
throw new Error(`invalid number of Output values expected ${len} got ${pubSignals.length}`);
}
return {
userID: js_iden3_core_1.Id.fromBigInt(BigInt(pubSignals[0])),
challenge: BigInt(pubSignals[1]),
GISTRoot: js_merkletree_1.Hash.fromString(pubSignals[2])
};
}
}
exports.ProvingMethodGroth16AuthV2 = ProvingMethodGroth16AuthV2;
ProvingMethodGroth16AuthV2.curveName = 'bn128';
exports.provingMethodGroth16AuthV2Instance = new ProvingMethodGroth16AuthV2(new proving_1.ProvingMethodAlg(common_1.Groth16, common_1.AuthV2Circuit));
;