UNPKG

zkverifyjs

Version:

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

65 lines (64 loc) 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtrinsicManager = void 0; const extrinsic_1 = require("../../../api/extrinsic"); const estimate_1 = require("../../../api/estimate"); const helpers_1 = require("../../../utils/helpers"); 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. * @returns {SubmittableExtrinsic<'promise'>} The generated SubmittableExtrinsic for submission. * @throws {Error} - Throws an error if the extrinsic creation fails. */ async createSubmitProofExtrinsic(proofType, params, domainId) { return (0, extrinsic_1.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. * @returns {string} Hex-encoded string of the SubmittableExtrinsic. * @throws {Error} - Throws an error if the hex generation fails. */ async createExtrinsicHex(proofType, params, domainId) { return (0, extrinsic_1.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 (0, extrinsic_1.createExtrinsicFromHex)(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) { (0, helpers_1.checkReadOnly)(this.connectionManager.connectionDetails); let selectedAccount; if (accountAddress !== undefined) { selectedAccount = this.connectionManager.getAccount(accountAddress); } else { selectedAccount = this.connectionManager.getAccount(); } return (0, estimate_1.estimateCost)(this.connectionManager.api, extrinsic, selectedAccount); } } exports.ExtrinsicManager = ExtrinsicManager;