@@ -48,15 +48,12 @@ export interface SchemaCreateOptions {
4848
4949@injectable ( )
5050export class EthereumLedgerService {
51- public readonly rpcUrl : string
52- private readonly schemaManagerContractAddress : string
53- private readonly fileServerToken : string
54- private readonly fileServerUrl : string
51+ public readonly rpcUrl : string | undefined
52+ private readonly schemaManagerContractAddress : string | undefined
53+ private readonly fileServerToken : string | undefined
54+ private readonly fileServerUrl : string | undefined
5555 public readonly resolver : Resolver
5656 public constructor ( config : EthereumModuleConfig ) {
57- // Validate configuration
58- this . validateConfig ( config )
59-
6057 this . resolver = new Resolver ( getResolver ( config . config ) )
6158 this . rpcUrl = config . rpcUrl
6259 this . schemaManagerContractAddress = config . schemaManagerContractAddress
@@ -71,6 +68,11 @@ export class EthereumLedgerService {
7168 agentContext : AgentContext ,
7269 { did, schemaName, schema } : SchemaCreateOptions
7370 ) : Promise < SchemaCreationResult > {
71+ if ( ! this . schemaManagerContractAddress || ! this . rpcUrl || ! this . fileServerUrl || ! this . fileServerToken ) {
72+ throw new SchemaCreationError (
73+ 'schemaManagerContractAddress, rpcUrl, fileServeUrl and fileServerToken must be defined and not empty'
74+ )
75+ }
7476 // Validate inputs
7577 if ( ! did ?. trim ( ) ) {
7678 throw new SchemaCreationError ( 'DID is required and cannot be empty' )
@@ -166,6 +168,9 @@ export class EthereumLedgerService {
166168
167169 agentContext . config . logger . info ( `Getting schema from ledger: ${ did } and schemaId: ${ schemaId } ` )
168170 try {
171+ if ( ! this . schemaManagerContractAddress || ! this . rpcUrl ) {
172+ throw new SchemaCreationError ( 'schemaManagerContractAddress and rpcUrl must be defined and not empty' )
173+ }
169174 const ethSchemaRegistry = new EthereumSchemaRegistry ( {
170175 contractAddress : this . schemaManagerContractAddress ,
171176 rpcUrl : this . rpcUrl ,
@@ -239,22 +244,4 @@ export class EthereumLedgerService {
239244 public async resolveDID ( did : string ) {
240245 return await this . resolver . resolve ( did )
241246 }
242-
243- /**
244- * Validates the configuration object
245- */
246- private validateConfig ( config : EthereumModuleConfig ) : void {
247- if ( ! config . rpcUrl ?. trim ( ) ) {
248- throw new EthereumLedgerError ( 'RPC URL is required and cannot be empty' )
249- }
250- if ( ! config . schemaManagerContractAddress ?. trim ( ) ) {
251- throw new EthereumLedgerError ( 'Schema manager contract address is required' )
252- }
253- if ( ! config . fileServerToken ?. trim ( ) ) {
254- throw new EthereumLedgerError ( 'File server token is required' )
255- }
256- if ( ! config . serverUrl ?. trim ( ) ) {
257- throw new EthereumLedgerError ( 'Server URL is required' )
258- }
259- }
260247}
0 commit comments