UNPKG

zkverifyjs

Version:

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

115 lines 6.15 kB
import { ConnectionManager } from './managers/connection/index.js'; import { VerificationManager } from './managers/verification/index.js'; import { VerificationKeyRegistrationManager } from './managers/register/index.js'; import { EventManager } from './managers/events/index.js'; import { ExtrinsicManager } from './managers/extrinsic/index.js'; import { DomainManager } from './managers/domain/index.js'; import { SupportedNetwork, SupportedNetworkConfig } from '../config/index.js'; import { NetworkBuilder, } from './builders/network/index.js'; import { FormatManager } from './managers/format/index.js'; import { RpcManager } from './managers/rpc/index.js'; export 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 VerificationManager(connectionManager); this.vkRegistrationManager = new VerificationKeyRegistrationManager(connectionManager); this.eventManager = new EventManager(connectionManager); this.extrinsicManager = new ExtrinsicManager(connectionManager); this.domainManager = new DomainManager(connectionManager); this.formatManager = new FormatManager(); this.rpcManager = new 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(SupportedNetworkConfig)) { const network = key; if (network === SupportedNetwork.Custom) { map[network] = (partialConfig) => new NetworkBuilder(zkVerifySession._startSession.bind(zkVerifySession), { ...partialConfig, host: SupportedNetwork.Custom, }); } else { map[network] = () => new 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 ConnectionManager.createSession(options); return new zkVerifySession(connectionManager); } catch (error) { console.debug(`❌ Failed to start session for network: ${options.networkConfig.host}`, error); throw error; } } } //# sourceMappingURL=index.js.map