Skip to content

Commit f5334ac

Browse files
committed
Bump BIP32 keystore version and get rid of magic constant
1 parent 9e59d57 commit f5334ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/web3swift/KeystoreManager/BIP32Keystore.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class BIP32Keystore: AbstractKeystore {
4040

4141
// --------------
4242

43+
private static let KeystoreParamsBIP32Version = 4
44+
4345
public var keystoreParams: KeystoreParamsBIP32?
4446
public var rootPrefix: String
4547

@@ -53,7 +55,7 @@ public class BIP32Keystore: AbstractKeystore {
5355

5456
public init?(_ jsonData: Data) {
5557
guard var keystorePars = try? JSONDecoder().decode(KeystoreParamsBIP32.self, from: jsonData) else {return nil}
56-
if (keystorePars.version != 3) {return nil}
58+
if (keystorePars.version != Self.KeystoreParamsBIP32Version) {return nil}
5759
if (keystorePars.crypto.version != nil && keystorePars.crypto.version != "1") {return nil}
5860
if (!keystorePars.isHDWallet) {return nil}
5961
addressStorage = PathAddressStorage(pathAddressPairs: keystorePars.pathAddressPairs)
@@ -181,7 +183,7 @@ public class BIP32Keystore: AbstractKeystore {
181183
let kdfparams = KdfParamsV3(salt: saltData.toHexString(), dklen: dkLen, n: N, p: P, r: R, c: nil, prf: nil)
182184
let cipherparams = CipherParamsV3(iv: IV.toHexString())
183185
let crypto = CryptoParamsV3(ciphertext: encryptedKeyData.toHexString(), cipher: aesMode, cipherparams: cipherparams, kdf: "scrypt", kdfparams: kdfparams, mac: mac.toHexString(), version: nil)
184-
var keystorePars = KeystoreParamsBIP32(crypto: crypto, id: UUID().uuidString.lowercased(), version: 3)
186+
var keystorePars = KeystoreParamsBIP32(crypto: crypto, id: UUID().uuidString.lowercased(), version: Self.KeystoreParamsBIP32Version)
185187
keystorePars.pathAddressPairs = addressStorage.toPathAddressPairs()
186188
keystorePars.rootPath = self.rootPrefix
187189
keystoreParams = keystorePars

0 commit comments

Comments
 (0)