1
- import { IAgentContext , IIdentifier , IKeyManager } from '@veramo/core'
1
+ import { IAgentContext , IIdentifier , IKeyManager , MinimalImportableKey , TKeyType } from '@veramo/core'
2
2
import Debug from 'debug'
3
- import { AbstractIdentifierProvider } from '@veramo/did-manager/build/abstract-identifier-provider'
4
- import { DIDDocument } from 'did-resolver'
5
- import { IKey , IService } from '@veramo/core/build/types/IIdentifier'
3
+ import { AbstractIdentifierProvider } from '@veramo/did-manager/build/abstract-identifier-provider'
4
+ import { DIDDocument } from 'did-resolver'
5
+ import { IKey , IService } from '@veramo/core/build/types/IIdentifier'
6
6
import * as u8a from 'uint8arrays'
7
- import { ebsiDIDSpecInfo , IContext , ICreateIdentifierArgs } from './types'
8
- import { generateEbsiPrivateKeyHex , toMethodSpecificId } from './functions'
7
+ import { ebsiDIDSpecInfo , IContext , ICreateIdentifierArgs } from './types'
8
+ import { generateEbsiPrivateKeyHex , toMethodSpecificId } from './functions'
9
9
10
10
const debug = Debug ( 'sphereon:did-provider-ebsi' )
11
11
@@ -28,29 +28,15 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
28
28
context : IContext
29
29
) : Promise < Omit < IIdentifier , 'provider' > > {
30
30
if ( ! options ?. type || options . type === ebsiDIDSpecInfo . V1 ) {
31
- let privateKeyHex = generateEbsiPrivateKeyHex (
32
- ebsiDIDSpecInfo . V1 ,
33
- options ?. options ?. key ?. privateKeyHex ? u8a . fromString ( options . options . key . privateKeyHex , 'base16' ) : undefined
34
- )
35
- if ( privateKeyHex . startsWith ( '0x' ) ) {
36
- privateKeyHex = privateKeyHex . substring ( 2 )
37
- }
38
- if ( ! privateKeyHex || privateKeyHex . length !== 64 ) {
39
- throw Error ( 'Private key should be 32 bytes / 64 chars hex' )
40
- }
41
- const key = await context . agent . keyManagerImport ( {
42
- type : 'Secp256k1' ,
43
- kms : this . assertedKms ( kms ) ,
44
- // meta: options?.options?.meta,
45
- kid : options ?. options ?. key ?. kid ,
46
- privateKeyHex,
47
- } )
31
+ const { secp256k1, secp256r1 } = { ...options ?. options ?. keys }
32
+ const secp256k1ManagedKeyInfo = await this . generateEbsiKeyPair ( 'Secp256k1' , secp256k1 as Partial < MinimalImportableKey > , kms as string , context ) ;
33
+ const secp256r1ManagedKeyInfo = await this . generateEbsiKeyPair ( 'Secp256r1' , secp256r1 as Partial < MinimalImportableKey > , kms as string , context ) ;
48
34
49
35
const methodSpecificId = toMethodSpecificId ( ebsiDIDSpecInfo . V1 , options ?. options ?. methodSpecificId )
50
36
const identifier : Omit < IIdentifier , 'provider' > = {
51
37
did : ebsiDIDSpecInfo . V1 . method + methodSpecificId ,
52
- controllerKeyId : key . kid ,
53
- keys : [ key ] ,
38
+ controllerKeyId : secp256k1ManagedKeyInfo . kid ,
39
+ keys : [ secp256k1ManagedKeyInfo , secp256r1ManagedKeyInfo ] ,
54
40
services : [ ] ,
55
41
}
56
42
debug ( 'Created' , identifier . did )
@@ -61,6 +47,26 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
61
47
throw Error ( `Type ${ options . type } not supported` )
62
48
}
63
49
50
+ private async generateEbsiKeyPair ( keyType : TKeyType , key : Partial < MinimalImportableKey > , kms : string , context : IAgentContext < IKeyManager > ) {
51
+ let privateKeyHex = generateEbsiPrivateKeyHex (
52
+ ebsiDIDSpecInfo . V1 ,
53
+ key ?. privateKeyHex ? u8a . fromString ( key . privateKeyHex , 'base16' ) : undefined
54
+ )
55
+ if ( privateKeyHex . startsWith ( '0x' ) ) {
56
+ privateKeyHex = privateKeyHex . substring ( 2 )
57
+ }
58
+ if ( ! privateKeyHex || privateKeyHex . length !== 64 ) {
59
+ throw Error ( 'Private key should be 32 bytes / 64 chars hex' )
60
+ }
61
+
62
+ return await context . agent . keyManagerImport ( {
63
+ type : keyType ,
64
+ kms : this . assertedKms ( kms ) ,
65
+ kid : key ?. kid ,
66
+ privateKeyHex,
67
+ } )
68
+ }
69
+
64
70
addKey (
65
71
args : {
66
72
identifier : IIdentifier
0 commit comments