@@ -60,6 +60,7 @@ Could not find key in storage please use Castor instead and provide the private
60
60
/// - services: an array of services associated to the DID
61
61
/// - Returns: The new created DID
62
62
func createNewPrismDID(
63
+ masterPrivateKey: PrivateKey ? = nil ,
63
64
keyPathIndex: Int ? = nil ,
64
65
alias: String ? = nil ,
65
66
services: [ DIDDocument . Service ] = [ ]
@@ -68,31 +69,38 @@ Could not find key in storage please use Castor instead and provide the private
68
69
let apollo = self . apollo
69
70
let castor = self . castor
70
71
71
- let lastKeyPairIndex = try await pluto
72
- . getPrismLastKeyPairIndex ( )
73
- . first ( )
74
- . await ( )
72
+ let usingPrivateKey : PrivateKey
75
73
76
- // If the user provided a key path index use it, if not use the last + 1
77
- let index = keyPathIndex ?? ( lastKeyPairIndex + 1 )
78
- // Create the key pair
79
- let privateKey = try apollo. createPrivateKey ( parameters: [
80
- KeyProperties . type. rawValue: " EC " ,
81
- KeyProperties . seed. rawValue: seed. value. base64Encoded ( ) ,
82
- KeyProperties . curve. rawValue: KnownKeyCurves . secp256k1. rawValue,
83
- KeyProperties . derivationPath. rawValue: EdgeAgentDerivationPath (
84
- keyPurpose: . master,
85
- keyIndex: index
86
- ) . derivationPath. keyPathString ( )
87
- ] )
74
+ if let masterPrivateKey {
75
+ usingPrivateKey = masterPrivateKey
76
+ }
77
+ else {
78
+ let lastKeyPairIndex = try await pluto
79
+ . getPrismLastKeyPairIndex ( )
80
+ . first ( )
81
+ . await ( )
82
+
83
+ // If the user provided a key path index use it, if not use the last + 1
84
+ let index = keyPathIndex ?? ( lastKeyPairIndex + 1 )
85
+ // Create the key pair
86
+ usingPrivateKey = try apollo. createPrivateKey ( parameters: [
87
+ KeyProperties . type. rawValue: " EC " ,
88
+ KeyProperties . seed. rawValue: seed. value. base64Encoded ( ) ,
89
+ KeyProperties . curve. rawValue: KnownKeyCurves . secp256k1. rawValue,
90
+ KeyProperties . derivationPath. rawValue: EdgeAgentDerivationPath (
91
+ keyPurpose: . master,
92
+ keyIndex: index
93
+ ) . derivationPath. keyPathString ( )
94
+ ] )
95
+ }
88
96
89
- let newDID = try castor. createPrismDID ( masterPublicKey: privateKey . publicKey ( ) , services: services)
97
+ let newDID = try castor. createPrismDID ( masterPublicKey: usingPrivateKey . publicKey ( ) , services: services)
90
98
logger. debug ( message: " Created new Prism DID " , metadata: [
91
99
. maskedMetadataByLevel( key: " DID " , value: newDID. string, level: . debug) ,
92
100
. maskedMetadataByLevel( key: " keyPathIndex " , value: " \( index) " , level: . debug)
93
101
] )
94
102
95
- try await registerPrismDID ( did: newDID, privateKey: privateKey , alias: alias)
103
+ try await registerPrismDID ( did: newDID, privateKey: usingPrivateKey , alias: alias)
96
104
return newDID
97
105
}
98
106
0 commit comments