diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..ca50d61ff --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,90 @@ +import { ethers } from 'ethers'; +import { AgentRegistry } from './contracts/AgentRegistry.mjs'; +import { ContentRegistry } from './contracts/ContentRegistry.mjs'; +import { ValidationEngine } from './validation/ValidationEngine.mjs'; +import { ChainConfig } from './config/ChainConfig.mjs'; +import { Logger } from './utils/Logger.mjs'; + +class SourceKeeperIndex { + constructor() { + this.logger = new Logger('SourceKeeperIndex'); + this.chainConfig = new ChainConfig(); + this.provider = new ethers.providers.JsonRpcProvider( + process.env.CHUNK_CHAIN_RPC_URL || this.chainConfig.getRpcUrl() + ); + } + + async initializeRegistries() { + try { + this.agentRegistry = new AgentRegistry(this.provider); + this.contentRegistry = new ContentRegistry(this.provider); + this.validationEngine = new ValidationEngine(this.provider); + + await Promise.all([ + this.agentRegistry.initialize(), + this.contentRegistry.initialize(), + this.validationEngine.initialize() + ]); + + this.logger.info('Core registries initialized successfully'); + } catch (error) { + this.logger.error('Registry initialization failed', error); + throw new Error(`Initialization Error: ${error.message}`); + } + } + + async validateContentSubmission(contentHash, agentAddress) { + if (!contentHash || !ethers.utils.isAddress(agentAddress)) { + throw new Error('Invalid content submission parameters'); + } + + const validationResult = await this.validationEngine.validateContent( + contentHash, + agentAddress + ); + + if (!validationResult.isValid) { + this.logger.warn('Content validation failed', { + contentHash, + reason: validationResult.reason + }); + return false; + } + + return true; + } + + async registerContent(contentHash, metadata) { + try { + const submissionResult = await this.contentRegistry.submitContent( + contentHash, + metadata + ); + + this.logger.info('Content registered successfully', { + contentHash, + transactionHash: submissionResult.transactionHash + }); + + return submissionResult; + } catch (error) { + this.logger.error('Content registration failed', error); + throw error; + } + } + + async run() { + try { + await this.initializeRegistries(); + this.logger.info('SourceKeeper research lab initialized'); + } catch (error) { + this.logger.critical('Startup sequence failed', error); + process.exit(1); + } + } +} + +const sourceKeeperIndex = new SourceKeeperIndex(); +sourceKeeperIndex.run(); + +export default sourceKeeperIndex; \ No newline at end of file