@unirep/circuits
Version:
Client library for circuit related functions which are used in UniRep protocol.
64 lines (63 loc) • 2.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EpochKeyProof = void 0;
const type_1 = require("./type");
const BaseProof_1 = require("./BaseProof");
const utils_1 = require("./utils");
/**
* A class representing an [epoch key proof](https://developer.unirep.io/docs/circuits-api/classes/src.EpochKeyProof). Each of the following properties are public signals for the proof.
*/
class EpochKeyProof extends BaseProof_1.BaseProof {
/**
* @param publicSignals The public signals of the epoch key proof that can be verified by the prover
* @param proof The proof that can be verified by the prover
* @param prover The prover that can verify the public signals and the proof
* @example
* ```ts
* import { EpochKeyProof } from '@unirep/circuits'
* const data = new EpochKeyProof(publicSignals, proof)
* ```
*/
constructor(publicSignals, proof, prover) {
super(publicSignals, proof, prover);
/**
* The index of the data in the public signals
*/
this.idx = {
epochKey: 0,
stateTreeRoot: 1,
control: 2,
data: 3,
};
this.epochKey = this.publicSignals[this.idx.epochKey];
this.stateTreeRoot = this.publicSignals[this.idx.stateTreeRoot];
this.control = this.publicSignals[this.idx.control];
const { nonce, epoch, attesterId, revealNonce, chainId } = (0, utils_1.decodeEpochKeyControl)(this.control);
this.nonce = nonce;
this.epoch = epoch;
this.attesterId = attesterId;
this.revealNonce = revealNonce;
this.chainId = chainId;
this.data = this.publicSignals[this.idx.data];
this.circuit = type_1.Circuit.epochKey;
}
/**
* Pack several variables into one `bigint` variable.
* @param config The variables that will be packed.
* @returns The control
* @example
* ```ts
* EpochKeyProof.buildControl({
* epoch,
* nonce,
* attesterId,
* revealNonce,
* chainId
* })
* ```
*/
static buildControl(config) {
return (0, utils_1.buildEpochKeyControl)(config);
}
}
exports.EpochKeyProof = EpochKeyProof;