Skip to content

Commit

Permalink
[WIP] Export Private Key (trustwallet#345)
Browse files Browse the repository at this point in the history
* add func for exporting private key

* change return type to Data

* add error case for exporting private key
  • Loading branch information
MillerApps authored and vikmeup committed Feb 15, 2018
1 parent e600cc8 commit 5e9d7fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Trust/EtherClient/EtherKeystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,26 @@ open class EtherKeystore: Keystore {
guard let account = getAccount(for: account.address) else {
return .failure(.accountNotFound)
}

do {
let data = try keyStore.export(account: account, password: password, newPassword: newPassword)
return (.success(data))
} catch {
return (.failure(.failedToDecryptKey))
}

}

func exportPrivateKey(account: Account) -> Result<Data, KeystoreError> {
guard let password = getPassword(for: account) else {
return .failure(KeystoreError.accountNotFound)
}
do {
let privateKey = try keyStore.exportPrivateKey(account: account, password: password)
return .success(privateKey)
} catch {
return .failure(KeystoreError.failedToExportPrivateKey)
}

}

func delete(wallet: Wallet) -> Result<Void, KeystoreError> {
Expand Down
3 changes: 3 additions & 0 deletions Trust/EtherClient/KeyStoreError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum KeystoreError: LocalizedError {
case failedToParseJSON
case accountNotFound
case failedToSignMessage
case failedToExportPrivateKey

var errorDescription: String? {
switch self {
Expand All @@ -39,6 +40,8 @@ enum KeystoreError: LocalizedError {
return "Account not found"
case .failedToSignMessage:
return "Failed to sign message"
case .failedToExportPrivateKey:
return "Failed to export private key"
}
}
}

0 comments on commit 5e9d7fa

Please sign in to comment.