UNPKG

zkverifyjs

Version:

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

95 lines (94 loc) 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zkVerifySession = void 0; const connection_1 = require("./managers/connection"); const verification_1 = require("./managers/verification"); const register_1 = require("./managers/register"); const events_1 = require("./managers/events"); const extrinsic_1 = require("./managers/extrinsic"); const domain_1 = require("./managers/domain"); const config_1 = require("../config"); const network_1 = require("./builders/network"); const format_1 = require("./managers/format"); const rpc_1 = require("./managers/rpc"); const helpers_1 = require("../utils/helpers"); class zkVerifySession { constructor(connectionManager) { this.connectionManager = connectionManager; const managers = [ new verification_1.VerificationManager(connectionManager), new register_1.VerificationKeyRegistrationManager(connectionManager), new events_1.EventManager(connectionManager), new extrinsic_1.ExtrinsicManager(connectionManager), new domain_1.DomainManager(connectionManager), new format_1.FormatManager(), new rpc_1.RpcManager(connectionManager), connectionManager, ]; managers.forEach((manager) => (0, helpers_1.bindMethods)(this, manager)); } /** * 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(config_1.SupportedNetworkConfig)) { const network = key; if (network === config_1.SupportedNetwork.Custom) { map[network] = (partialConfig) => new network_1.NetworkBuilder(zkVerifySession._startSession.bind(zkVerifySession), { ...partialConfig, host: config_1.SupportedNetwork.Custom, }); } else { map[network] = () => new network_1.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; } /** * 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 connection_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;