@@ -19,7 +19,18 @@ public class BIP32Keystore: AbstractKeystore {
19
19
public var keystoreParams : KeystoreParamsBIP32 ?
20
20
21
21
@available ( * , deprecated, message: " Please use addressStorage instead " )
22
- public var paths : [ String : EthereumAddress ] = [ String: EthereumAddress] ( )
22
+ public var paths : [ String : EthereumAddress ] {
23
+ get {
24
+ return self . addressStorage. toPathAddressPairs ( ) . reduce ( into: [ String: EthereumAddress] ( ) ) {
25
+ $0 [ $1. path] = EthereumAddress ( $1. address) !
26
+ }
27
+ }
28
+ set {
29
+ for pair in newValue {
30
+ self . addressStorage. add ( address: pair. value, for: pair. key)
31
+ }
32
+ }
33
+ }
23
34
24
35
public var rootPrefix : String
25
36
@@ -73,9 +84,6 @@ public class BIP32Keystore: AbstractKeystore {
73
84
if ( keystorePars. crypto. version != nil && keystorePars. crypto. version != " 1 " ) { return nil }
74
85
if ( !keystorePars. isHDWallet) { return nil }
75
86
76
- for (p, ad) in keystorePars. pathToAddress {
77
- paths [ p] = EthereumAddress ( ad)
78
- }
79
87
addressStorage = PathAddressStorage ( pathAddressPairs: keystorePars. pathAddressPairs)
80
88
81
89
if keystorePars. rootPath == nil {
@@ -195,7 +203,6 @@ public class BIP32Keystore: AbstractKeystore {
195
203
} else {
196
204
newPath = prefixPath + " / " + pathAppendix!
197
205
}
198
- paths [ newPath] = newAddress
199
206
addressStorage. add ( address: newAddress, for: newPath)
200
207
guard let serializedRootNode = rootNode. serialize ( serializePublic: false ) else { throw AbstractKeystoreError . keyDerivationError}
201
208
try encryptDataToStorage ( password, data: serializedRootNode, aesMode: self . keystoreParams!. crypto. cipher)
@@ -244,10 +251,7 @@ public class BIP32Keystore: AbstractKeystore {
244
251
let kdfparams = KdfParamsV3 ( salt: saltData. toHexString ( ) , dklen: dkLen, n: N, p: P, r: R, c: nil , prf: nil )
245
252
let cipherparams = CipherParamsV3 ( iv: IV . toHexString ( ) )
246
253
let crypto = CryptoParamsV3 ( ciphertext: encryptedKeyData. toHexString ( ) , cipher: aesMode, cipherparams: cipherparams, kdf: " scrypt " , kdfparams: kdfparams, mac: mac. toHexString ( ) , version: nil )
247
- var pathToAddress = [ String: String] ( )
248
- for (path, address) in paths {
249
- pathToAddress [ path] = address. address
250
- }
254
+
251
255
var keystorePars = KeystoreParamsBIP32 ( crypto: crypto, id: UUID ( ) . uuidString. lowercased ( ) , version: Self . KeystoreParamsBIP32Version)
252
256
keystorePars. pathAddressPairs = addressStorage. toPathAddressPairs ( )
253
257
keystorePars. rootPath = self . rootPrefix
0 commit comments