Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

improve BIP32 serialization to disk #71

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/web3swiftExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EXTERNAL SOURCES:

CHECKOUT OPTIONS:
web3swift:
:commit: 0314336d8c0ba9c9b0b0303d3f1cf73d149fcda1
:commit: 49c569f76f135efa31f545a63a8599e5c9f6ec13
:git: https://github.com/bankex/web3swift.git

SPEC CHECKSUMS:
Expand Down
2 changes: 1 addition & 1 deletion Example/web3swiftExample/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ViewController: UIViewController {
print(sender)

//create BIP32 keystore
let bip32keystoreManager = KeystoreManager.managerForPath(userDir + "/bip32_keystore")
let bip32keystoreManager = KeystoreManager.managerForPath(userDir + "/bip32_keystore", scanForHDwallets: true)
var bip32ks: BIP32Keystore?
if (bip32keystoreManager?.addresses?.count == 0) {
bip32ks = try! BIP32Keystore.init(mnemonics: "normal dune pole key case cradle unfold require tornado mercy hospital buyer", password: "BANKEXFOUNDATION", mnemonicsPassword: "", language: .english)
Expand Down
11 changes: 2 additions & 9 deletions web3swift/KeystoreManager/Classes/BIP32Keystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BIP32Keystore: AbstractKeystore {
}
}

public var isHDKeystore: Bool = false
public var isHDKeystore: Bool = true

public func UNSAFE_getPrivateKeyData(password: String, account: EthereumAddress) throws -> Data {
if let key = self.paths.keyForValue(value: account) {
Expand Down Expand Up @@ -69,14 +69,6 @@ public class BIP32Keystore: AbstractKeystore {
rootPrefix = keystoreParams!.rootPath!
}

// public init? (mnemonics: String, password: String = "BANKEXFOUNDATION", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english) throws {
// guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {throw AbstractKeystoreError.noEntropyError}
// guard let prefixNode = HDNode(seed: seed)?.derive(path: HDNode.defaultPathPrefix, derivePrivateKey: true) else {return nil}
// defer{ Data.zero(&seed) }
// self.mnemonics = mnemonics
// try createNewAccount(parentNode: prefixNode, password: password)
// }

public init? (mnemonics: String, password: String = "BANKEXFOUNDATION", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathPrefix) throws {
guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {throw AbstractKeystoreError.noEntropyError}
guard let prefixNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else {return nil}
Expand Down Expand Up @@ -182,6 +174,7 @@ public class BIP32Keystore: AbstractKeystore {
}
var keystorePars = KeystoreParamsBIP32(crypto: crypto, id: UUID().uuidString.lowercased(), version: 3)
keystorePars.pathToAddress = pathToAddress
keystorePars.rootPath = self.rootPrefix
keystoreParams = keystorePars
}

Expand Down
14 changes: 9 additions & 5 deletions web3swift/KeystoreManager/Classes/KeystoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public class KeystoreManager: AbstractKeystore {
toReturn.append(key)
}
}
for keystore in _bip32keystores {
guard let allAddresses = keystore.addresses else {continue}
for addr in allAddresses {
if addr.isValid {
toReturn.append(addr)
}
}
}
return toReturn
}
}
Expand Down Expand Up @@ -138,10 +146,6 @@ public class KeystoreManager: AbstractKeystore {
}
}
}

}
}