Skip to content

Commit

Permalink
Fix crash when importing wallets from private key. (trustwallet#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma510 authored and vikmeup committed Sep 18, 2018
1 parent 5f0b79d commit 55ea679
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Trust/EtherClient/EtherKeystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,25 @@ class EtherKeystore: Keystore {
}
}
case .privateKey(let privateKey):
let privateKeyData = PrivateKey(data: Data(hexString: privateKey)!)!
DispatchQueue.global(qos: .userInitiated).async {
do {
let wallet = try self.keyStore.import(privateKey: privateKeyData, password: newPassword, coin: coin)
self.setPassword(newPassword, for: wallet)
DispatchQueue.main.async {
completion(.success(WalletInfo(type: .privateKey(wallet))))
}
} catch {
DispatchQueue.main.async {
completion(.failure(KeystoreError.failedToImportPrivateKey))
if let data = Data(hexString: privateKey),
let privateKeyData = PrivateKey(data: data) {
DispatchQueue.global(qos: .userInitiated).async {
do {
let wallet = try self.keyStore.import(privateKey: privateKeyData, password: newPassword, coin: coin)
self.setPassword(newPassword, for: wallet)
DispatchQueue.main.async {
completion(.success(WalletInfo(type: .privateKey(wallet))))
}
} catch {
DispatchQueue.main.async {
completion(.failure(KeystoreError.failedToImportPrivateKey))
}
}
}
} else {
DispatchQueue.main.async {
completion(.failure(KeystoreError.failedToImportPrivateKey))
}
}
case .mnemonic(let words, let passphrase, let derivationPath):
let string = words.map { String($0) }.joined(separator: " ")
Expand Down

0 comments on commit 55ea679

Please sign in to comment.