UNPKG

zkverifyjs

Version:

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

119 lines 6.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zkVerifySession = void 0; const index_js_1 = require("./managers/connection/index.js"); const index_js_2 = require("./managers/verification/index.js"); const index_js_3 = require("./managers/register/index.js"); const index_js_4 = require("./managers/events/index.js"); const index_js_5 = require("./managers/extrinsic/index.js"); const index_js_6 = require("./managers/domain/index.js"); const index_js_7 = require("../config/index.js"); const index_js_8 = require("./builders/network/index.js"); const index_js_9 = require("./managers/format/index.js"); const index_js_10 = require("./managers/rpc/index.js"); class zkVerifySession { constructor(connectionManager) { this.verify = (...args) => this.verificationManager.verify(...args); this.optimisticVerify = (...args) => this.verificationManager.optimisticVerify(...args); this.batchVerify = (...args) => this.verificationManager.batchVerify(...args); this.batchOptimisticVerify = (...args) => this.verificationManager.batchOptimisticVerify(...args); this.registerVerificationKey = (...args) => this.vkRegistrationManager.registerVerificationKey(...args); this.format = (...args) => this.formatManager.format(...args); this.formatVk = (...args) => this.formatManager.formatVk(...args); this.subscribe = (...args) => this.eventManager.subscribe(...args); this.unsubscribe = (...args) => this.eventManager.unsubscribe(...args); this.waitForAggregationReceipt = (...args) => this.eventManager.waitForAggregationReceipt(...args); this.estimateCost = (...args) => this.extrinsicManager.estimateCost(...args); this.createSubmitProofExtrinsic = (...args) => this.extrinsicManager.createSubmitProofExtrinsic(...args); this.createExtrinsicHex = (...args) => this.extrinsicManager.createExtrinsicHex(...args); this.createExtrinsicFromHex = (...args) => this.extrinsicManager.createExtrinsicFromHex(...args); this.close = (...args) => this.connectionManager.close(...args); this.addAccount = (...args) => this.connectionManager.addAccount(...args); this.addAccounts = (...args) => this.connectionManager.addAccounts(...args); this.addDerivedAccounts = (...args) => this.connectionManager.addDerivedAccounts(...args); this.removeAccount = (...args) => this.connectionManager.removeAccount(...args); this.getAccount = (...args) => this.connectionManager.getAccount(...args); this.getAccountInfo = (...args) => this.connectionManager.getAccountInfo(...args); this.registerDomain = (...args) => this.domainManager.registerDomain(...args); this.unregisterDomain = (...args) => this.domainManager.unregisterDomain(...args); this.holdDomain = (...args) => this.domainManager.holdDomain(...args); this.aggregate = (...args) => this.domainManager.aggregate(...args); this.addDomainSubmitters = (...args) => this.domainManager.addDomainSubmitters(...args); this.removeDomainSubmitters = (...args) => this.domainManager.removeDomainSubmitters(...args); this.getAggregateStatementPath = (...args) => this.rpcManager.getAggregateStatementPath(...args); this.getVkHash = (...args) => this.rpcManager.getVkHash(...args); this.connectionManager = connectionManager; this.verificationManager = new index_js_2.VerificationManager(connectionManager); this.vkRegistrationManager = new index_js_3.VerificationKeyRegistrationManager(connectionManager); this.eventManager = new index_js_4.EventManager(connectionManager); this.extrinsicManager = new index_js_5.ExtrinsicManager(connectionManager); this.domainManager = new index_js_6.DomainManager(connectionManager); this.formatManager = new index_js_9.FormatManager(); this.rpcManager = new index_js_10.RpcManager(connectionManager); } /** * Starts a session for the specified network. * @returns {SupportedNetworkMap} A map of supported networks. */ static start() { const map = {}; for (const [key, config] of Object.entries(index_js_7.SupportedNetworkConfig)) { const network = key; if (network === index_js_7.SupportedNetwork.Custom) { map[network] = (partialConfig) => new index_js_8.NetworkBuilder(zkVerifySession._startSession.bind(zkVerifySession), { ...partialConfig, host: index_js_7.SupportedNetwork.Custom, }); } else { map[network] = () => new index_js_8.NetworkBuilder(zkVerifySession._startSession.bind(zkVerifySession), config); } } return map; } /** * Getter for the Polkadot.js API instance. * @returns {ApiPromise} The API instance. */ get api() { return this.connectionManager.api; } /** * Getter for the WebSocket provider. * @returns {WsProvider} The WebSocket provider. */ get provider() { return this.connectionManager.provider; } /** * Getter for connection details. * @returns {AccountConnection | WalletConnection | EstablishedConnection} The connection details. */ get connection() { return this.connectionManager.connectionDetails; } /** * Checks if the session is in read-only mode. * @returns {boolean} True if read-only, otherwise false. */ get readOnly() { return this.connectionManager.readOnly; } /** * Initializes a new zkVerifySession instance. * @param {zkVerifySessionOptions} options - The session configuration options. * @returns {Promise<zkVerifySession>} A promise resolving to the zkVerifySession instance. */ static async _startSession(options) { try { const connectionManager = await index_js_1.ConnectionManager.createSession(options); return new zkVerifySession(connectionManager); } catch (error) { console.debug(`❌ Failed to start session for network: ${options.networkConfig.host}`, error); throw error; } } } exports.zkVerifySession = zkVerifySession; //# sourceMappingURL=index.js.map