Skip to content

Commit 7813b8c

Browse files
authored
Merge pull request #5 from Bhutan-NDI/fix/app-module-config
Set schema module config optional to allow using only the DID module
2 parents f881f6f + 0baac4e commit 7813b8c

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Usage
66

77
```ts
8-
import { EthereumDidResolver, EthereumDidRegistrar, EthereumModule } from 'credo-ethr-module'
8+
import { EthereumDidResolver, EthereumDidRegistrar, EthereumModule } from '@bhutan-ndi/ethr-credo-module'
99

1010
const agent = new Agent({
1111
config: {
@@ -26,5 +26,6 @@ const agent = new Agent({
2626
schemaManagerContractAddress: 'schemaManagerContractAddress' // ethereum schema manager contract address,
2727
serverUrl: 'serverUrl' // ethereum file server url,
2828
}),
29+
}
2930
})
3031
```

src/EthereumModuleConfig.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import type { ConfigurationOptions } from 'ethr-did-resolver/lib/configuration'
55
*/
66
export interface EthereumModuleConfigOptions {
77
config: ConfigurationOptions
8-
rpcUrl: string
9-
fileServerToken: string
10-
schemaManagerContractAddress: string
11-
serverUrl: string
8+
rpcUrl?: string
9+
fileServerToken?: string
10+
schemaManagerContractAddress?: string
11+
serverUrl?: string
1212
}
1313

1414
export class EthereumModuleConfig {
15-
public rpcUrl: string
16-
public fileServerToken: string
17-
public schemaManagerContractAddress: string
18-
public serverUrl: string
15+
public rpcUrl: string | undefined
16+
public fileServerToken: string | undefined
17+
public schemaManagerContractAddress: string | undefined
18+
public serverUrl: string | undefined
1919
public readonly config: ConfigurationOptions
2020

2121
public constructor({

src/ledger/EthereumLedgerService.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ export interface SchemaCreateOptions {
4848

4949
@injectable()
5050
export 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

Comments
 (0)