zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
62 lines • 3.19 kB
JavaScript
import { RegisterKeyBuilder } from '../../builders/register/index.js';
import { ProofType, } from '../../../config/index.js';
import { registerVk } from '../../../api/register/index.js';
import { checkReadOnly } from '../../../utils/helpers/index.js';
import { validateProofTypeOptions } from '../../validator/index.js';
export 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 ProofType) {
if (Object.prototype.hasOwnProperty.call(ProofType, proofType)) {
Object.defineProperty(builderMethods, proofType, {
value: (proofConfig) => {
const validatedOptions = 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 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) {
checkReadOnly(this.connectionManager.connectionDetails);
return registerVk(this.connectionManager.connectionDetails, options, verificationKey);
}
}
//# sourceMappingURL=index.js.map