mind-hubs-sdk
Version:
Typescript SDK to interact with MIND Hub Framework
71 lines (70 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreContextManager = void 0;
const ethers_1 = require("ethers");
/**
* SdkContextManager module for the SDK
* Handles initialization and retrieval of core SDK configuration and runtime context
*/
exports.CoreContextManager = {
/**
* Private variable to store the SDK configuration
* This should only be modified during initialization
*/
_sdkConfig: null,
/**
* Private variable to store the runtime context, including providers and utilities
* This is populated during initialization
*/
_sdkContext: null,
/**
* Initializes the SDK configuration
* This must be called before accessing the configuration or context
*
* @param config - The CoreConfig object containing necessary configuration parameters
* @throws {Error} If any required configuration parameter is missing
*/
initialize(config) {
if (!config.fheKeyRegistryAddress) {
throw new Error('fheKeyRegistryAddress is required');
}
if (!config.memberPoolAddress) {
throw new Error('memberPoolAddress is required');
}
if (!config.rpc) {
throw new Error('rpc is required');
}
if (!config.chainID) {
throw new Error('chainID is required');
}
this._sdkConfig = config;
this._sdkContext = {
jsonRpcProvider: new ethers_1.JsonRpcProvider(config.rpc, config.chainID, { staticNetwork: ethers_1.Network.from(config.chainID) })
};
},
/**
* Retrieves the current SDK configuration
* Ensures the configuration has been initialized before access
*
* @returns A readonly CoreConfig object
* @throws {Error} If the configuration has not been initialized
*/
getConfiguration() {
if (!this._sdkConfig) {
throw new Error('Configuration has not been initialized. Call initialize() first.');
}
return this._sdkConfig;
},
/**
* Retrieves the current runtime context for the SDK
*
* @returns The CoreContext object containing utilities such as the JsonRpcProvider
* @throws {Error} If the context has not been initialized
*/
getContext() {
if (!this._sdkContext) {
throw new Error('Configuration has not been initialized. Call initialize() first.');
}
return this._sdkContext;
}
};