UNPKG

mind-hubs-sdk

Version:

Typescript SDK to interact with MIND Hub Framework

60 lines (59 loc) 2.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchFheKeySet = fetchFheKeySet; const ethers_1 = require("ethers"); const context_1 = require("../context"); const FheKeyRegistry_json_1 = __importDefault(require("../abi/FheKeyRegistry.json")); const logger_1 = __importDefault(require("../logger")); /** * A singleton instance of the FheKeyRegistry contract. * It will be initialized lazily upon the first access. */ let fheKeyRegistryContract = null; /** * Ensures that the FheKeyRegistry contract is initialized * This must be called after the CoreContextManager has been initialized * * @returns The initialized FheKeyRegistry contract instance */ function ensureFheKeyRegistryContract() { if (!fheKeyRegistryContract) { const config = context_1.CoreContextManager.getConfiguration(); const context = context_1.CoreContextManager.getContext(); fheKeyRegistryContract = new ethers_1.Contract(config.fheKeyRegistryAddress, FheKeyRegistry_json_1.default, context.jsonRpcProvider); logger_1.default.info({ msg: 'FheKeyRegistry contract initialized', address: config.fheKeyRegistryAddress }); } return fheKeyRegistryContract; } /** * Fetches the FHE key set from the FheKeyRegistry contract * * @param keyId - The unique identifier of the FHE key set * @returns A promise resolving to the FHE key set associated with the provided keyId * @throws {Error} If there is an issue fetching the key set */ async function fetchFheKeySet(keyId) { try { const contract = ensureFheKeyRegistryContract(); const result = await contract.fheKeySets(keyId); logger_1.default.info({ msg: 'Fetched FHE key set successfully', keyId: keyId.toString() }); return result; } catch (error) { logger_1.default.error({ msg: 'Error fetching FHE key set', keyId: keyId.toString(), error }); throw new Error(`Failed to fetch FHE key set for keyId ${keyId}`); } }