Closed zhaojiewen closed 6 years ago
Replacing this Method in KeyStore.swift file with below code,this bug will disappear.
/// Imports an encrypted JSON key. /// /// - Parameters: /// - key: key to import /// - password: key password /// - newPassword: password to use for the imported key /// - Returns: new account public func import(json: Data, password: String, newPassword: String) throws -> Account { let key = try JSONDecoder().decode(KeystoreKey.self, from: json) if self.account(for: key.address) != nil { throw Error.accountAlreadyExists }
import
var privateKey = try key.decrypt(password: password) print(privateKey.hexString) defer { privateKey.resetBytes(in: 0..<privateKey.count) } var newKey : KeystoreKey switch key.type { case .encryptedKey: newKey = try KeystoreKey(password: newPassword, key: privateKey) case .hierarchicalDeterministicWallet: guard let mnemonic = String(data: privateKey, encoding: .ascii) else { throw EncryptError.invalidMnemonic } newKey = try KeystoreKey(password: newPassword, mnemonic: mnemonic) } keysByAddress[key.address] = newKey let url = makeAccountURL(for: key.address) let account = Account(address: newKey.address, type: key.type, url: url) try save(account: account, in: keyDirectory) accountsByAddress[newKey.address] = account return account }
Replacing this Method in KeyStore.swift file with below code,this bug will disappear.
/// Imports an encrypted JSON key. /// /// - Parameters: /// - key: key to import /// - password: key password /// - newPassword: password to use for the imported key /// - Returns: new account public func
import
(json: Data, password: String, newPassword: String) throws -> Account { let key = try JSONDecoder().decode(KeystoreKey.self, from: json) if self.account(for: key.address) != nil { throw Error.accountAlreadyExists }