UNPKG

@unirep/circuits

Version:

Client library for circuit related functions which are used in UniRep protocol.

96 lines (95 loc) 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReputationProof = void 0; const type_1 = require("./type"); const BaseProof_1 = require("./BaseProof"); const utils_1 = require("./utils"); /** * The reputation proof structure that helps to query the public signals */ class ReputationProof extends BaseProof_1.BaseProof { /** * @param publicSignals The public signals of the reputation 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 { ReputationProof } from '@unirep/circuits' * const data = new ReputationProof(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, control0: 2, control1: 3, graffiti: 4, data: 5, }; this.epochKey = BigInt(this.publicSignals[this.idx.epochKey]); this.stateTreeRoot = BigInt(this.publicSignals[this.idx.stateTreeRoot]); this.control0 = BigInt(this.publicSignals[this.idx.control0]); this.control1 = BigInt(this.publicSignals[this.idx.control1]); const { nonce, epoch, attesterId, revealNonce, chainId } = (0, utils_1.decodeEpochKeyControl)(this.control0); this.nonce = nonce; this.epoch = epoch; this.attesterId = attesterId; this.revealNonce = revealNonce; this.chainId = chainId; const { minRep, maxRep, proveMinRep, proveMaxRep, proveZeroRep, proveGraffiti, } = (0, utils_1.decodeReputationControl)(this.control1); this.minRep = minRep; this.maxRep = maxRep; this.proveMinRep = proveMinRep; this.proveMaxRep = proveMaxRep; this.proveZeroRep = proveZeroRep; this.proveGraffiti = proveGraffiti; this.graffiti = this.publicSignals[this.idx.graffiti]; this.data = this.publicSignals[this.idx.data]; this.circuit = type_1.Circuit.reputation; } /** * Pack several variables into one `bigint` variable. * @param config The variables that will be packed. * @returns The controls * @example * ```ts * ReputationProof.buildControl({ * attesterId, * epoch, * nonce, * revealNonce, * chainId, * proveGraffiti, * minRep, * maxRep, * proveMinRep, * proveMaxRep, * proveZeroRep, * }) * ``` */ static buildControl({ attesterId, epoch, nonce, revealNonce = BigInt(0), chainId, proveGraffiti = BigInt(0), minRep = BigInt(0), maxRep = BigInt(0), proveMinRep = BigInt(0), proveMaxRep = BigInt(0), proveZeroRep = BigInt(0), }) { let control0 = (0, utils_1.buildEpochKeyControl)({ attesterId: BigInt(attesterId), epoch: BigInt(epoch), nonce: BigInt(nonce), revealNonce: BigInt(revealNonce), chainId: BigInt(chainId), }); let control1 = (0, utils_1.buildReputationControl)({ minRep: BigInt(minRep), maxRep: BigInt(maxRep), proveMinRep: BigInt(proveMinRep), proveMaxRep: BigInt(proveMaxRep), proveZeroRep: BigInt(proveZeroRep), proveGraffiti: BigInt(proveGraffiti), }); return [control0, control1]; } } exports.ReputationProof = ReputationProof;