Skip to content

Commit 1d09d4c

Browse files
refactor(webvh): remove WebvhDidRegistrar and clean up exports
- Removed WebvhDidRegistrar class and its related exports from the dids module. - Updated index.ts and WebvhModule.ts to reflect the removal of the registrar. - Adjusted DIDWebvhCrypto class to ensure agentContext is always defined. - Cleaned up unused functions and imports in didWebvhUtil.ts.
1 parent 8e5851d commit 1d09d4c

File tree

6 files changed

+8
-307
lines changed

6 files changed

+8
-307
lines changed

packages/webvh/src/WebvhModule.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { DependencyManager, Module } from '@credo-ts/core'
22

33
import { WebvhModuleConfig } from './WebvhModuleConfig'
4-
import { WebvhDidRegistrar } from './dids/WebvhDidRegistrar'
54
import { WebvhDidResolver } from './dids/WebvhDidResolver'
65

76
export class WebvhModule implements Module {
@@ -15,11 +14,7 @@ export class WebvhModule implements Module {
1514
* Registers the dependencies of the WebVH module on the dependency manager.
1615
*/
1716
public register(dependencyManager: DependencyManager) {
18-
// Register config
1917
dependencyManager.registerInstance(WebvhModuleConfig, this.config)
20-
21-
// Register did registrar and resolver
22-
dependencyManager.registerSingleton(WebvhDidRegistrar)
2318
dependencyManager.registerSingleton(WebvhDidResolver)
2419
}
2520
}

packages/webvh/src/dids/WebvhDidRegistrar.ts

Lines changed: 0 additions & 239 deletions
This file was deleted.

packages/webvh/src/dids/didWebvhUtil.ts

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { type AgentContext, Buffer, DidDocument, JsonTransformer, KeyType, Key } from '@credo-ts/core'
2-
import { createDID, AbstractCrypto, type SigningOutput, type SigningInput } from 'didwebvh-ts'
1+
import { type AgentContext, Buffer, KeyType, Key } from '@credo-ts/core'
2+
import { AbstractCrypto, type SigningOutput } from 'didwebvh-ts'
33

44
export class DIDWebvhCrypto extends AbstractCrypto {
5-
private agentContext?: AgentContext
5+
private agentContext: AgentContext
66

7-
public constructor(agentContext?: AgentContext) {
7+
public constructor(agentContext: AgentContext) {
88
super({
99
verificationMethod: {
1010
id: 'did:webvh:123',
@@ -17,8 +17,7 @@ export class DIDWebvhCrypto extends AbstractCrypto {
1717
this.agentContext = agentContext
1818
}
1919

20-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21-
public async sign(input: SigningInput): Promise<SigningOutput> {
20+
public async sign(): Promise<SigningOutput> {
2221
throw new Error('Not implemented')
2322
}
2423

@@ -38,52 +37,13 @@ export class DIDWebvhCrypto extends AbstractCrypto {
3837
} catch (error) {
3938
// Log error in a non-production environment
4039
if (process.env.NODE_ENV !== 'production') {
41-
// eslint-disable-next-line no-console
42-
console.error('Error verifying signature:', error)
40+
this.agentContext.config.logger.error('Error verifying signature:', error)
4341
}
4442
return false
4543
}
4644
}
4745
}
4846

49-
export function validateSpecCompliantPayload(didDocument: DidDocument): SpecValidationResult {
50-
// id is required, validated on both compile and runtime
51-
if (!didDocument.id || !didDocument.id.startsWith('did:webvh:')) return { valid: false, error: 'id is required' }
52-
53-
// verificationMethod is required
54-
if (!didDocument.verificationMethod) return { valid: false, error: 'verificationMethod is required' }
55-
56-
// verificationMethod must be an array
57-
if (!Array.isArray(didDocument.verificationMethod))
58-
return { valid: false, error: 'verificationMethod must be an array' }
59-
60-
// verificationMethod must be not be empty
61-
if (!didDocument.verificationMethod.length) return { valid: false, error: 'verificationMethod must be not be empty' }
62-
63-
return { valid: true }
64-
}
65-
66-
export interface SpecValidationResult {
67-
valid: boolean
68-
error?: string
69-
}
70-
71-
export async function generateDidDoc(options: IDidDocOptions, agentContext?: AgentContext) {
72-
const { verificationMethods, baseUrl, updateKeys } = options
73-
74-
const { doc } = await createDID({
75-
domain: baseUrl.replace(/^https?:\/\//, '').replace('/', ':'),
76-
updateKeys,
77-
signer: new DIDWebvhCrypto(agentContext),
78-
verificationMethods: verificationMethods.map((verificationMethod) => ({
79-
type: 'Multikey',
80-
publicKeyMultibase: verificationMethod.publicKeyMultibase,
81-
})),
82-
})
83-
84-
return JsonTransformer.fromJSON(doc, DidDocument)
85-
}
86-
8747
export interface IDidDocOptions {
8848
verificationMethods: {
8949
publicKeyMultibase: string

packages/webvh/src/dids/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
export {
2-
WebvhDidRegistrar,
3-
WebvhDidCreateOptions,
4-
WebvhDidDeactivateOptions,
5-
WebvhDidUpdateOptions,
6-
} from './WebvhDidRegistrar'
71
export { WebvhDidResolver } from './WebvhDidResolver'

packages/webvh/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
// Dids
2-
export {
3-
WebvhDidRegistrar,
4-
WebvhDidCreateOptions,
5-
WebvhDidDeactivateOptions,
6-
WebvhDidUpdateOptions,
7-
WebvhDidResolver,
8-
} from './dids'
1+
export { WebvhDidResolver } from './dids'
92

10-
// Module
113
export { WebvhModule } from './WebvhModule'
124
export { WebvhModuleConfig, WebvhModuleConfigOptions } from './WebvhModuleConfig'
135
export { WebvhApi } from './WebvhApi'
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DidsModule } from '@credo-ts/core'
22

3-
import { WebvhModule, WebvhDidRegistrar, WebvhDidResolver, WebvhModuleConfig } from '../src'
3+
import { WebvhModule, WebvhDidResolver, WebvhModuleConfig } from '../src'
44

55
export const getWebvhModules = (baseUrl?: string) => ({
66
webvhSdk: new WebvhModule(
@@ -9,7 +9,6 @@ export const getWebvhModules = (baseUrl?: string) => ({
99
})
1010
),
1111
dids: new DidsModule({
12-
registrars: [new WebvhDidRegistrar()],
1312
resolvers: [new WebvhDidResolver()],
1413
}),
1514
})

0 commit comments

Comments
 (0)