zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
63 lines • 3.24 kB
JavaScript
import { createExtrinsicHex, createSubmitProofExtrinsic, createSubmittableExtrinsicFromHex, } from '../../../api/extrinsic/index.js';
import { estimateCost } from '../../../api/estimate/index.js';
import { checkReadOnly } from '../../../utils/helpers/index.js';
export class ExtrinsicManager {
constructor(connectionManager) {
this.connectionManager = connectionManager;
}
/**
* Creates a SubmittableExtrinsic using formatted proof details to enable submitting a proof.
*
* @param {ProofType} proofType - The type of proof, to decide which pallet to use.
* @param {FormattedProofData} params - Formatted Proof Parameters required by the extrinsic.
* @param domainId
* @returns {SubmittableExtrinsic<'promise'>} The generated SubmittableExtrinsic for submission.
* @throws {Error} - Throws an error if the extrinsic creation fails.
*/
async createSubmitProofExtrinsic(proofType, params, domainId) {
return createSubmitProofExtrinsic(this.connectionManager.api, proofType, params, domainId);
}
/**
* Generates the hex representation of a SubmittableExtrinsic using formatted proof details.
*
* @param {ProofType} proofType - The type of supported proof, used to select the correct pallet.
* @param {FormattedProofData} params - Formatted Proof Parameters required by the extrinsic.
* @param domainId
* @returns {string} Hex-encoded string of the SubmittableExtrinsic.
* @throws {Error} - Throws an error if the hex generation fails.
*/
async createExtrinsicHex(proofType, params, domainId) {
return createExtrinsicHex(this.connectionManager.api, proofType, params, domainId);
}
/**
* Recreates an extrinsic from its hex-encoded representation.
*
* @param {string} extrinsicHex - Hex-encoded string of the SubmittableExtrinsic.
* @returns {SubmittableExtrinsic<'promise'>} The reconstructed SubmittableExtrinsic.
* @throws {Error} - Throws an error if the reconstruction from hex fails.
*/
async createExtrinsicFromHex(extrinsicHex) {
return createSubmittableExtrinsicFromHex(this.connectionManager.api, extrinsicHex);
}
/**
* Estimates the cost of a given extrinsic.
*
* @param {SubmittableExtrinsic<'promise'>} extrinsic - The extrinsic to estimate.
* @param {string} [accountAddress] - The account address to use for estimation.
* If not provided, the first available account will be used.
* @returns {Promise<ExtrinsicCostEstimate>} A promise that resolves to an object containing the estimated fee and extrinsic details.
* @throws {Error} If the session is in read-only mode or no account is available.
*/
async estimateCost(extrinsic, accountAddress) {
checkReadOnly(this.connectionManager.connectionDetails);
let selectedAccount;
if (accountAddress !== undefined) {
selectedAccount = this.connectionManager.getAccount(accountAddress);
}
else {
selectedAccount = this.connectionManager.getAccount();
}
return estimateCost(this.connectionManager.api, extrinsic, selectedAccount);
}
}
//# sourceMappingURL=index.js.map