@@ -19,7 +19,18 @@ public class BIP32Keystore: AbstractKeystore {
1919 public var keystoreParams : KeystoreParamsBIP32 ?
2020
2121 @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+ }
2334
2435 public var rootPrefix : String
2536
@@ -73,9 +84,6 @@ public class BIP32Keystore: AbstractKeystore {
7384 if ( keystorePars. crypto. version != nil && keystorePars. crypto. version != " 1 " ) { return nil }
7485 if ( !keystorePars. isHDWallet) { return nil }
7586
76- for (p, ad) in keystorePars. pathToAddress {
77- paths [ p] = EthereumAddress ( ad)
78- }
7987 addressStorage = PathAddressStorage ( pathAddressPairs: keystorePars. pathAddressPairs)
8088
8189 if keystorePars. rootPath == nil {
@@ -195,7 +203,6 @@ public class BIP32Keystore: AbstractKeystore {
195203 } else {
196204 newPath = prefixPath + " / " + pathAppendix!
197205 }
198- paths [ newPath] = newAddress
199206 addressStorage. add ( address: newAddress, for: newPath)
200207 guard let serializedRootNode = rootNode. serialize ( serializePublic: false ) else { throw AbstractKeystoreError . keyDerivationError}
201208 try encryptDataToStorage ( password, data: serializedRootNode, aesMode: self . keystoreParams!. crypto. cipher)
@@ -244,10 +251,7 @@ public class BIP32Keystore: AbstractKeystore {
244251 let kdfparams = KdfParamsV3 ( salt: saltData. toHexString ( ) , dklen: dkLen, n: N, p: P, r: R, c: nil , prf: nil )
245252 let cipherparams = CipherParamsV3 ( iv: IV . toHexString ( ) )
246253 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+
251255 var keystorePars = KeystoreParamsBIP32 ( crypto: crypto, id: UUID ( ) . uuidString. lowercased ( ) , version: Self . KeystoreParamsBIP32Version)
252256 keystorePars. pathAddressPairs = addressStorage. toPathAddressPairs ( )
253257 keystorePars. rootPath = self . rootPrefix
0 commit comments