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'
3
3
4
4
export class DIDWebvhCrypto extends AbstractCrypto {
5
- private agentContext ? : AgentContext
5
+ private agentContext : AgentContext
6
6
7
- public constructor ( agentContext ? : AgentContext ) {
7
+ public constructor ( agentContext : AgentContext ) {
8
8
super ( {
9
9
verificationMethod : {
10
10
id : 'did:webvh:123' ,
@@ -17,8 +17,7 @@ export class DIDWebvhCrypto extends AbstractCrypto {
17
17
this . agentContext = agentContext
18
18
}
19
19
20
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
21
- public async sign ( input : SigningInput ) : Promise < SigningOutput > {
20
+ public async sign ( ) : Promise < SigningOutput > {
22
21
throw new Error ( 'Not implemented' )
23
22
}
24
23
@@ -38,52 +37,13 @@ export class DIDWebvhCrypto extends AbstractCrypto {
38
37
} catch ( error ) {
39
38
// Log error in a non-production environment
40
39
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 )
43
41
}
44
42
return false
45
43
}
46
44
}
47
45
}
48
46
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 ( / ^ h t t p s ? : \/ \/ / , '' ) . 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
-
87
47
export interface IDidDocOptions {
88
48
verificationMethods : {
89
49
publicKeyMultibase : string
0 commit comments