Skip to content

Commit b5e25f5

Browse files
authored
Merge pull request #71 from BANKEX/develop
improve BIP32 serialization to disk
2 parents 49c569f + e63debd commit b5e25f5

File tree

9 files changed

+57
-20
lines changed

9 files changed

+57
-20
lines changed

Example/web3swiftExample/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ EXTERNAL SOURCES:
3838

3939
CHECKOUT OPTIONS:
4040
web3swift:
41-
:commit: 0314336d8c0ba9c9b0b0303d3f1cf73d149fcda1
41+
:commit: 49c569f76f135efa31f545a63a8599e5c9f6ec13
4242
:git: https://github.com/bankex/web3swift.git
4343

4444
SPEC CHECKSUMS:

Example/web3swiftExample/Pods/Manifest.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftExample/Pods/web3swift/web3swift/Convenience/Classes/LibSecp256k1Extension.swift

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftExample/Pods/web3swift/web3swift/KeystoreManager/Classes/BIP32Keystore.swift

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftExample/Pods/web3swift/web3swift/KeystoreManager/Classes/KeystoreManager.swift

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftExample/Pods/web3swift/web3swift/Web3/Classes/Web3+Utils.swift

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftExample/web3swiftExample/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ViewController: UIViewController {
3434
print(sender)
3535

3636
//create BIP32 keystore
37-
let bip32keystoreManager = KeystoreManager.managerForPath(userDir + "/bip32_keystore")
37+
let bip32keystoreManager = KeystoreManager.managerForPath(userDir + "/bip32_keystore", scanForHDwallets: true)
3838
var bip32ks: BIP32Keystore?
3939
if (bip32keystoreManager?.addresses?.count == 0) {
4040
bip32ks = try! BIP32Keystore.init(mnemonics: "normal dune pole key case cradle unfold require tornado mercy hospital buyer", password: "BANKEXFOUNDATION", mnemonicsPassword: "", language: .english)

web3swift/KeystoreManager/Classes/BIP32Keystore.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BIP32Keystore: AbstractKeystore {
2727
}
2828
}
2929

30-
public var isHDKeystore: Bool = false
30+
public var isHDKeystore: Bool = true
3131

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

72-
// public init? (mnemonics: String, password: String = "BANKEXFOUNDATION", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english) throws {
73-
// guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {throw AbstractKeystoreError.noEntropyError}
74-
// guard let prefixNode = HDNode(seed: seed)?.derive(path: HDNode.defaultPathPrefix, derivePrivateKey: true) else {return nil}
75-
// defer{ Data.zero(&seed) }
76-
// self.mnemonics = mnemonics
77-
// try createNewAccount(parentNode: prefixNode, password: password)
78-
// }
79-
8072
public init? (mnemonics: String, password: String = "BANKEXFOUNDATION", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathPrefix) throws {
8173
guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {throw AbstractKeystoreError.noEntropyError}
8274
guard let prefixNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else {return nil}
@@ -182,6 +174,7 @@ public class BIP32Keystore: AbstractKeystore {
182174
}
183175
var keystorePars = KeystoreParamsBIP32(crypto: crypto, id: UUID().uuidString.lowercased(), version: 3)
184176
keystorePars.pathToAddress = pathToAddress
177+
keystorePars.rootPath = self.rootPrefix
185178
keystoreParams = keystorePars
186179
}
187180

web3swift/KeystoreManager/Classes/KeystoreManager.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public class KeystoreManager: AbstractKeystore {
2020
toReturn.append(key)
2121
}
2222
}
23+
for keystore in _bip32keystores {
24+
guard let allAddresses = keystore.addresses else {continue}
25+
for addr in allAddresses {
26+
if addr.isValid {
27+
toReturn.append(addr)
28+
}
29+
}
30+
}
2331
return toReturn
2432
}
2533
}
@@ -138,10 +146,6 @@ public class KeystoreManager: AbstractKeystore {
138146
}
139147
}
140148
}
141-
149+
142150
}
143151
}
144-
145-
146-
147-

0 commit comments

Comments
 (0)