zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
35 lines • 1.16 kB
JavaScript
export class RegisterKeyBuilder {
constructor(executeRegisterVerificationKey, proofOptions, accountAddress) {
this.executeRegisterVerificationKey = executeRegisterVerificationKey;
this.nonceSet = false;
this.options = {
proofOptions,
accountAddress
};
}
/**
* Sets the nonce for the registration process.
* Can only be set once; subsequent calls will throw an error.
*
* @param {number} nonce - The nonce value to set.
* @returns {this} The builder instance for method chaining.
* @throws {Error} If the nonce is already set.
*/
nonce(nonce) {
if (this.nonceSet) {
throw new Error('Nonce can only be set once.');
}
this.nonceSet = true;
this.options.nonce = nonce;
return this;
}
/**
* Executes the registration process with the provided verification key.
*
* @param {unknown} verificationKey - The verification key to register.
* @returns {Promise<{ events: EventEmitter, transactionResult: Promise<VKRegistrationTransactionInfo> }>}
*/
async execute(verificationKey) {
return this.executeRegisterVerificationKey(this.options, verificationKey);
}
}