@unirep/circuits
Version:
Client library for circuit related functions which are used in UniRep protocol.
63 lines (62 loc) • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignupProof = void 0;
const type_1 = require("./type");
const BaseProof_1 = require("./BaseProof");
const utils_1 = require("./utils");
/**
* A class representing a [signup proof](https://developer.unirep.io/docs/circuits-api/classes/src.SignupProof). Each of the following properties are public signals for the proof.
*/
class SignupProof extends BaseProof_1.BaseProof {
/**
* @param publicSignals The public signals of the user sign up 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 { SignupProof } from '@unirep/circuits'
* const data = new SignupProof(publicSignals, proof)
* ```
*/
constructor(publicSignals, proof, prover) {
super(publicSignals, proof, prover);
/**
* The index of the data in the public signals
*/
this.idx = {
identityCommitment: 0,
stateTreeLeaf: 1,
control: 2,
};
this.identityCommitment = BigInt(this.publicSignals[this.idx.identityCommitment]);
this.stateTreeLeaf = BigInt(this.publicSignals[this.idx.stateTreeLeaf]);
this.control = BigInt(this.publicSignals[this.idx.control]);
const { chainId, epoch, attesterId } = (0, utils_1.decodeSignupControl)(this.control);
this.chainId = chainId;
this.epoch = epoch;
this.attesterId = attesterId;
this.circuit = type_1.Circuit.signup;
}
/**
* Pack several variables into one `bigint` variable.
* @param config The variables that will be packed.
* @returns The control
* @example
* ```ts
* SignupProof.buildControl({
* epoch,
* attesterId,
* chainId
* })
* ```
*/
static buildControl({ attesterId, epoch, chainId }) {
const control = (0, utils_1.buildSignupControl)({
attesterId: BigInt(attesterId),
epoch: BigInt(epoch),
chainId: BigInt(chainId),
});
return control;
}
}
exports.SignupProof = SignupProof;