Skip to content

Commit

Permalink
Update to fix HD wallets (trustwallet#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-isaza authored and vikmeup committed Mar 8, 2018
1 parent 3c43170 commit a24a01b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target 'Trust' do
pod 'Fabric'
pod 'Crashlytics'
pod 'Kingfisher', '~> 4.0'
pod 'TrustKeystore', '~> 0.2.1'
pod 'TrustKeystore', '~> 0.3.1'
pod 'Branch'
# pod 'web3swift', :git=>'https://github.com/BANKEX/web3swift', :branch=>'master'
pod 'SAMKeychain'
Expand Down
12 changes: 6 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ PODS:
- Realm (= 3.0.2)
- Result (3.2.4)
- SAMKeychain (1.5.3)
- secp256k1_ios (0.1.1)
- secp256k1_ios (0.1.2)
- SeedStackViewController (0.4.0)
- SipHash (1.2.0)
- StatefulViewController (3.0)
- SwiftLint (0.24.1)
- TrezorCrypto (0.0.4)
- TrustKeystore (0.2.1):
- TrustKeystore (0.3.1):
- BigInt
- CryptoSwift
- secp256k1_ios (~> 0.1.0)
Expand Down Expand Up @@ -71,7 +71,7 @@ DEPENDENCIES:
- SeedStackViewController
- StatefulViewController
- SwiftLint
- TrustKeystore (~> 0.2.1)
- TrustKeystore (~> 0.3.1)
- TrustWeb3Provider (from `https://github.com/TrustWallet/trust-web3-provider`, branch `master`)

EXTERNAL SOURCES:
Expand Down Expand Up @@ -124,15 +124,15 @@ SPEC CHECKSUMS:
RealmSwift: 695393add1b8f9d5fa75dd16e6355cf3935f71e2
Result: d2d07204ce72856f1fd9130bbe42c35a7b0fea10
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
secp256k1_ios: 3c94e6cce14ff03924cb6dc10c5017f17011b79d
secp256k1_ios: 168c6c49ed9771db51875f5255c8f9847e4cf554
SeedStackViewController: 45e88ca1493a610e74d661d3feced7098f72dbd3
SipHash: c6e9e43e9c531b5bc6602545130c26194a6d31ce
StatefulViewController: 4803bf900d44de26074344998e10e041113b5931
SwiftLint: 2e4b89feed5909c42c3735bbd6745f4345c4b772
TrezorCrypto: 7f87a2296cf13872b21565c29fd9f7882dd00803
TrustKeystore: b9fc8e0d72de3e8f9c97f46802172d6f14a004aa
TrustKeystore: a045fb57cb0a292ed5295134833d17cbcd6b922b
TrustWeb3Provider: ac0bdf19b4c6c4d6ec0f03ddb85b83e32bda3a9a

PODFILE CHECKSUM: f6ba1746f62eeaaabee0dc8db12e09eb1e17a0e8
PODFILE CHECKSUM: cd1a443fa86d2410d5f2f02ece1f03670e3c9ad7

COCOAPODS: 1.4.0
1 change: 0 additions & 1 deletion Trust/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class AppCoordinator: NSObject, Coordinator {
func inializers() {
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .allDomainsMask, true).flatMap { URL(fileURLWithPath: $0) }
paths.append(keystore.keysDirectory)
paths.append(keystore.walletsDirectory)

let initializers: [Initializer] = [
CrashReportInitializer(),
Expand Down
11 changes: 4 additions & 7 deletions Trust/EtherClient/EtherKeystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ open class EtherKeystore: Keystore {
let keyStore: KeyStore
private let defaultKeychainAccess: KeychainSwiftAccessOptions = .accessibleWhenUnlockedThisDeviceOnly
let keysDirectory: URL
let walletsDirectory: URL
let userDefaults: UserDefaults

public init(
keychain: KeychainSwift = KeychainSwift(keyPrefix: Constants.keychainKeyPrefix),
keysSubfolder: String = "/keystore",
walletsSubfolder: String = "/wallets",
userDefaults: UserDefaults = UserDefaults.standard
) throws {
if !UIApplication.shared.isProtectedDataAvailable {
throw EtherKeystoreError.protectionDisabled
}
self.keysDirectory = URL(fileURLWithPath: datadir + keysSubfolder)
self.walletsDirectory = URL(fileURLWithPath: datadir + walletsSubfolder)
self.keychain = keychain
self.keychain.synchronizable = false
self.keyStore = try KeyStore(keyDirectory: keysDirectory, walletDirectory: walletsDirectory)
self.keyStore = try KeyStore(keyDirectory: keysDirectory)
self.userDefaults = userDefaults
}

Expand Down Expand Up @@ -131,11 +128,11 @@ open class EtherKeystore: Keystore {
completion(.failure(error))
}
}
case .mnemonic(let words, let password):
case .mnemonic(let words, let passphrase):
let string = words.map { String($0) }.joined(separator: " ")
do {
let account = try keyStore.import(mnemonic: string, password: password)
setPassword(PasswordGenerator.generateRandom(), for: account)
let account = try keyStore.import(mnemonic: string, passphrase: passphrase, encryptPassword: newPassword)
setPassword(newPassword, for: account)
completion(.success(Wallet(type: .hd(account))))
} catch {
return completion(.failure(KeystoreError.accountNotFound))
Expand Down
1 change: 0 additions & 1 deletion Trust/EtherClient/Keystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ protocol Keystore {
var hasWallets: Bool { get }
var wallets: [Wallet] { get }
var keysDirectory: URL { get }
var walletsDirectory: URL { get }
var recentlyUsedWallet: Wallet? { get set }
static var current: Wallet? { get }
@available(iOS 10.0, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ImportWalletViewController: FormViewController {
$0.options = [
ImportSelectionType.keystore.title,
ImportSelectionType.privateKey.title,
//ImportSelectionType.mnemonic.title,
ImportSelectionType.mnemonic.title,
ImportSelectionType.watch.title,
]
$0.value = ImportSelectionType.keystore.title
Expand Down
38 changes: 19 additions & 19 deletions TrustTests/EtherClient/EtherKeystoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,25 +304,25 @@ class EtherKeystoreTests: XCTestCase {
XCTAssertEqual(0, keystore.wallets.count)
}

// func testDeleteHDWallet() {
// let keystore = FakeEtherKeystore()
//
// // TODO. Move this into sync calls
// keystore.importWallet(type: ImportType.mnemonic(words: ["often", "tobacco", "bread", "scare", "imitate", "song", "kind", "common", "bar", "forest", "yard", "wisdom"], password: "test123")) { result in
// switch result {
// case .success(let wallet):
// XCTAssertEqual(1, keystore.wallets.count)
//
// let _ = keystore.delete(wallet: wallet)
//
// XCTAssertEqual(0, keystore.wallets.count)
// case .failure:
// XCTFail()
// }
// }
//
// XCTAssertEqual(0, keystore.wallets.count)
// }
func testDeleteHDWallet() {
let keystore = FakeEtherKeystore()

// TODO. Move this into sync calls
keystore.importWallet(type: ImportType.mnemonic(words: ["often", "tobacco", "bread", "scare", "imitate", "song", "kind", "common", "bar", "forest", "yard", "wisdom"], password: "test123")) { result in
switch result {
case .success(let wallet):
XCTAssertEqual(1, keystore.wallets.count)

let _ = keystore.delete(wallet: wallet)

XCTAssertEqual(0, keystore.wallets.count)
case .failure:
XCTFail()
}
}

XCTAssertEqual(0, keystore.wallets.count)
}

func testKeychainKeyPrivateKey() {
let keystore = FakeEtherKeystore()
Expand Down
1 change: 0 additions & 1 deletion TrustTests/Factories/FakeEtherKeystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FakeEtherKeystore: EtherKeystore {
try! self.init(
keychain: KeychainSwift(keyPrefix: "fake" + uniqueString),
keysSubfolder: "/keys" + uniqueString,
walletsSubfolder: "/wallets" + uniqueString,
userDefaults: UserDefaults.test
)
}
Expand Down

0 comments on commit a24a01b

Please sign in to comment.