zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
66 lines • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerificationKeyRegistrationManager = void 0;
const index_js_1 = require("../../builders/register/index.js");
const index_js_2 = require("../../../config/index.js");
const index_js_3 = require("../../../api/register/index.js");
const index_js_4 = require("../../../utils/helpers/index.js");
const index_js_5 = require("../../validator/index.js");
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 index_js_2.ProofType) {
if (Object.prototype.hasOwnProperty.call(index_js_2.ProofType, proofType)) {
Object.defineProperty(builderMethods, proofType, {
value: (proofConfig) => {
const validatedOptions = (0, index_js_5.validateProofTypeOptions)({
proofType: proofType,
config: proofConfig ?? undefined,
}, this.connectionManager.connectionDetails.runtimeSpec);
return this.createRegisterKeyBuilder(validatedOptions, 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 index_js_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, index_js_4.checkReadOnly)(this.connectionManager.connectionDetails);
return (0, index_js_3.registerVk)(this.connectionManager.connectionDetails, options, verificationKey);
}
}
exports.VerificationKeyRegistrationManager = VerificationKeyRegistrationManager;
//# sourceMappingURL=index.js.map