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