Skip to content

Commit d16ec63

Browse files
authored
Merge pull request #164 from BANKEX/develop
Fix keystoreV3 init from external JSON file
2 parents 984cf79 + ad3b3a7 commit d16ec63

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<img align="left" width="25" height="25" src="https://user-images.githubusercontent.com/28599454/41086111-af4bc3b0-6a41-11e8-9f9f-2d642b12666e.png">[Ask questions](https://stackoverflow.com/questions/tagged/web3swift)
44
## Important notices
5-
With the version 0.3.0 API should be less volatile. All public functions should return a [Result](https://github.com/antitypical/Result) instead of `nil` or throwing.
5+
With the version 0.3.0 the API should be less volatile. All public functions should return a [Result](https://github.com/antitypical/Result) instead of `nil` or throwing.
66

77
Example is updated for 0.5.0, although please prefer to use tests as an example for your code.
88

@@ -20,7 +20,7 @@ Example is updated for 0.5.0, although please prefer to use tests as an example
2020
- RLP encoding
2121
- Interactions (read/write to Smart contracts) :arrows_counterclockwise:
2222
- Local keystore management (geth compatible)
23-
- Literally following the standarts:
23+
- Literally following the standards:
2424
- [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) HD Wallets: Deterministic Wallet
2525
- [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases)
2626
- [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)
@@ -29,18 +29,18 @@ Example is updated for 0.5.0, although please prefer to use tests as an example
2929

3030
## Check this out
3131

32-
- Private key and transaction were created directly on the iOS device and sent directly to [Infura](https://infura.io) node
32+
- Private key and transaction were created directly on an iOS device and sent directly to [Infura](https://infura.io) node
3333
- Native API
34-
- Security (as cool as hard wallet! Right out-of-the-box! :box: )
35-
- No unnecessary dependencies
34+
- Security (as cool as a hard wallet! Right out-of-the-box! :box: )
35+
- No unnecessary dependencies
3636
- Possibility to work with all existing smart contracts
3737
- Referencing the newest features introduced in Solidity
3838

3939
## Design decisions
4040

41-
- Not every JSON RPC function is exposed yet, priority is gives to ones required for mobile devices
42-
- Functionality was focused on serializing and signing transactions locally on device to send raw transaction to Ethereum network
43-
- Requirements for password input on every transactions are indeed a design decision. Interface designers can save user passwords given user's consent
41+
- Not every JSON RPC function is exposed yet, priority is given to the ones required for mobile devices
42+
- Functionality was focused on serializing and signing transactions locally on the device to send raw transactions to Ethereum network
43+
- Requirements for password input on every transaction are indeed a design decision. Interface designers can save user passwords with the user's consent
4444
- Public function for private key export is exposed for user convenience, but marked as UNSAFE_ :) Normal workflow takes care of EIP155 compatibility and proper clearing of private key data from memory
4545

4646
### Here it is
@@ -67,7 +67,7 @@ On Rinkeby TXid = 0xc6eca60ecac004a1501a4323a10edb7fa4cd1a0896675f6b51704c84deda
6767

6868
## Example
6969

70-
You can try it by yourself by running the example project:
70+
You can try it yourself by running the example project:
7171

7272
- Clone the repo
7373
- `cd Example/web3swiftExample`
@@ -76,7 +76,7 @@ You can try it by yourself by running the example project:
7676

7777
## Requirements
7878

79-
Web3swift requires Swift 4.1 and iOS 9.0 or macOS 10.13 although we recommend to use the latest iOS and MacOS versions for your own safety. Don't forget to set iOS version in a Podfile, otherwise you get an error if deployment target is less than the latest SDK.
79+
Web3swift requires Swift 4.1 and iOS 9.0 or macOS 10.13 although we recommend to use the latest iOS and MacOS versions for your own safety. Don't forget to set the iOS version in a Podfile, otherwise you get an error if the deployment target is less than the latest SDK.
8080

8181
## Communication
8282

@@ -119,7 +119,7 @@ $ pod install
119119

120120
- [x] Create Account
121121
- [x] Import Account
122-
- [x] Sign transictions
122+
- [x] Sign transactions
123123
- [x] Send transactions, call functions of smart-contracts, estimate gas costs
124124
- [x] Serialize and deserialize transactions and results to native Swift types
125125
- [x] Convenience functions for chain state: block number, gas price
@@ -130,7 +130,7 @@ $ pod install
130130

131131
## Usage
132132

133-
Here you can see a few examples of use of our library
133+
Here's a few use cases of our library
134134
### Initializing Ethereum address
135135
```bash
136136
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")
@@ -213,13 +213,13 @@ If you've used this project in a live app, please let us know!
213213
## Special thanks to
214214
215215
- Gnosis team and their library [Bivrost-swift](https://github.com/gnosis/bivrost-swift) for inspiration for the ABI decoding approach
216-
- [Trust iOS Wallet](https://github.com/TrustWallet/trust-wallet-ios) for collaboration and discussion for initial idea
216+
- [Trust iOS Wallet](https://github.com/TrustWallet/trust-wallet-ios) for the collaboration and discussion of the initial idea
217217
- Official Ethereum and Solidity docs, everything was written from ground truth standards
218218
219219
## Contribution
220220
221221
For the latest version, please check [develop](https://github.com/BANKEX/web3swift/tree/develop) branch.
222-
Changes from this branch will be merged into the [master](https://github.com/BANKEX/web3swift/tree/master) branch at some point.
222+
Changes made to this branch will be merged into the [master](https://github.com/BANKEX/web3swift/tree/master) branch at some point.
223223
224224
- If you want to contribute, submit a [pull request](https://github.com/BANKEX/web3swift/pulls) against a development `develop` branch.
225225
- If you found a bug, [open an issue](https://github.com/BANKEX/web3swift/issues).
@@ -228,7 +228,7 @@ Changes from this branch will be merged into the [master](https://github.com/BAN
228228
229229
## Appreciation
230230
231-
When using this pod references to this repo, [BANKEX](http://bankex.com) and [BANKEX Foundation](http://bankexfoundation.org) are appreciated.
231+
When using this pod, references to this repo, [BANKEX](http://bankex.com) and [BANKEX Foundation](http://bankexfoundation.org) are appreciated.
232232
233233
## Authors
234234

web3swift/KeystoreManager/Classes/EthereumAddress.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ public struct EthereumAddress: Equatable {
7979
case .normal:
8080
guard let data = Data.fromHex(addressString) else {return nil}
8181
guard data.count == 20 else {return nil}
82-
if (!ignoreChecksum && data.toHexString().addHexPrefix() != addressString) {
82+
if !addressString.hasHexPrefix() {
83+
return nil
84+
}
85+
if (!ignoreChecksum && data.toHexString().uppercased() != addressString.stripHexPrefix()) { // cover edge case if address is not completely UPPERCASED and potentially missing 0x prefix
86+
let checksummedAddress = EthereumAddress.toChecksumAddress(data.toHexString().addHexPrefix())
87+
guard checksummedAddress == addressString else {return nil}
88+
}
89+
if (!ignoreChecksum && data.toHexString().addHexPrefix() != addressString.stripHexPrefix()) { // cover edge case if address not completely lowercased and potentially missing 0x prefix
8390
let checksummedAddress = EthereumAddress.toChecksumAddress(data.toHexString().addHexPrefix())
8491
guard checksummedAddress == addressString else {return nil}
8592
}

web3swift/KeystoreManager/Classes/EthereumKeystoreV3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class EthereumKeystoreV3: AbstractKeystore {
5959
if (keystoreParams.crypto.version != nil && keystoreParams.crypto.version != "1") {return nil}
6060
self.keystoreParams = keystoreParams
6161
if keystoreParams.address != nil {
62-
self.address = EthereumAddress(keystoreParams.address!)
62+
self.address = EthereumAddress(keystoreParams.address!.addHexPrefix())
6363
} else {
6464
return nil
6565
}

web3swiftTests/web3swiftTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class web3swiftTests: XCTestCase {
124124
let keystore = try! EthereumKeystoreV3(password: "");
125125
XCTAssertNotNil(keystore)
126126
let account = keystore!.addresses![0]
127+
print(account)
128+
let data = try! keystore!.serialize()
129+
print(try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue:0)))
127130
let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account)
128131
XCTAssertNotNil(key)
129132
}

0 commit comments

Comments
 (0)