UNPKG

zkverifyjs

Version:

Submit proofs to zkVerify and query proof state with ease using our npm package.

67 lines (66 loc) 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VerificationKeyRegistrationManager = void 0; const register_1 = require("../../builders/register"); const config_1 = require("../../../config"); const register_2 = require("../../../api/register"); const helpers_1 = require("../../../utils/helpers"); const validator_1 = require("../../validator"); class VerificationKeyRegistrationManager { constructor(connectionManager) { this.connectionManager = connectionManager; } /** * Creates a builder map for different proof types that can be used for registering verification keys. * Each proof type returns a `RegisterKeyBuilder` that allows you to chain methods for setting options * and finally executing the registration process. * * @returns {RegisterKeyMethodMap} A map of proof types to their corresponding builder methods. */ registerVerificationKey(accountAddress) { const builderMethods = {}; for (const proofType in config_1.ProofType) { if (Object.prototype.hasOwnProperty.call(config_1.ProofType, proofType)) { Object.defineProperty(builderMethods, proofType, { value: (proofConfig) => { const proofOptions = { proofType: proofType, config: proofConfig || {}, }; (0, validator_1.validateProofTypeOptions)(proofOptions, this.connectionManager.connectionDetails.runtimeSpec); return this.createRegisterKeyBuilder(proofOptions, accountAddress); }, writable: false, configurable: false, enumerable: true, }); } } return builderMethods; } /** * Factory method to create a `RegisterKeyBuilder` for the given proof type. * The builder allows for chaining options and finally executing the key registration process. * * @returns {RegisterKeyBuilder} A new instance of `RegisterKeyBuilder`. * @private */ createRegisterKeyBuilder(proofOptions, accountAddress) { return new register_1.RegisterKeyBuilder(this.executeRegisterVerificationKey.bind(this), proofOptions, accountAddress); } /** * Executes the verification key registration process with the provided options and verification key. * This method is intended to be called by the `RegisterKeyBuilder`. * * @param {VerifyOptions} options - The options for the key registration process, including proof type and other optional settings. * @param {unknown} verificationKey - The verification key to be registered. * @returns {Promise<{events: EventEmitter, transactionResult: Promise<VKRegistrationTransactionInfo>}>} * A promise that resolves with an object containing an `EventEmitter` for real-time events and the final transaction result. * @private */ async executeRegisterVerificationKey(options, verificationKey) { (0, helpers_1.checkReadOnly)(this.connectionManager.connectionDetails); return (0, register_2.registerVk)(this.connectionManager.connectionDetails, options, verificationKey); } } exports.VerificationKeyRegistrationManager = VerificationKeyRegistrationManager;