Skip to content

Commit 94e6e5b

Browse files
authored
Merge pull request #34 from matterinc/develop
Fix ethereum address parsing, add readme
2 parents f1f2e09 + 474d549 commit 94e6e5b

File tree

13 files changed

+45
-41
lines changed

13 files changed

+45
-41
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,20 @@ Here's a few use cases of our library:
132132
Create keystore and account with password.
133133

134134
```
135-
//TODO
135+
let keystore = try! EthereumKeystoreV3(password: "changeme"); // generates a private key internally if node "privateKey" parameter supplied
136+
let account = keystore!.addresses![0]
137+
print(account)
138+
let data = try! keystore!.serialize() // internally serializes to JSON
139+
print(try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue:0)))
140+
let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "changeme", account: account) // you should rarely use this and expose a key manually
136141
```
137142

138143
### Initializing Ethereum address
139144
```
140145
let coldWalletAddress = EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")
141-
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")
146+
let constractAddress = EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b", ignoreChecksum: true)
142147
```
143-
Ethereum addresses are checksum checked if they are not lowercased and always length checked
144-
148+
Ethereum addresses are checksum checked if they are not lowercased or uppercased and always length checked
145149

146150
### Setting options
147151

web3swift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@
14981498
MODULEMAP_PRIVATE_FILE = "";
14991499
OTHER_LDFLAGS = "$(inherited)";
15001500
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES;
1501-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-iOS";
1501+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-iOS";
15021502
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
15031503
SDKROOT = iphoneos;
15041504
SKIP_INSTALL = NO;
@@ -1537,7 +1537,7 @@
15371537
MODULEMAP_PRIVATE_FILE = "";
15381538
OTHER_LDFLAGS = "$(inherited)";
15391539
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES;
1540-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-iOS";
1540+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-iOS";
15411541
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
15421542
SDKROOT = iphoneos;
15431543
SKIP_INSTALL = NO;
@@ -1613,7 +1613,7 @@
16131613
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
16141614
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
16151615
MACOSX_DEPLOYMENT_TARGET = 10.11;
1616-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-macOS";
1616+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-macOS";
16171617
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
16181618
SDKROOT = macosx;
16191619
SKIP_INSTALL = YES;
@@ -1639,7 +1639,7 @@
16391639
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
16401640
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
16411641
MACOSX_DEPLOYMENT_TARGET = 10.11;
1642-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-macOS";
1642+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-macOS";
16431643
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
16441644
SDKROOT = macosx;
16451645
SKIP_INSTALL = YES;
@@ -1658,7 +1658,7 @@
16581658
DEVELOPMENT_TEAM = 62V9CKQN89;
16591659
INFOPLIST_FILE = "web3swift-macOS_Tests/Info.plist";
16601660
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
1661-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-macOS-Tests";
1661+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-macOS-Tests";
16621662
PRODUCT_NAME = "$(TARGET_NAME)";
16631663
SDKROOT = macosx;
16641664
SWIFT_VERSION = 4.0;
@@ -1676,7 +1676,7 @@
16761676
DEVELOPMENT_TEAM = 62V9CKQN89;
16771677
INFOPLIST_FILE = "web3swift-macOS_Tests/Info.plist";
16781678
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
1679-
PRODUCT_BUNDLE_IDENTIFIER = "org.bankexfoundation.web3swift-macOS-Tests";
1679+
PRODUCT_BUNDLE_IDENTIFIER = "io.thematter.web3swift-macOS-Tests";
16801680
PRODUCT_NAME = "$(TARGET_NAME)";
16811681
SDKROOT = macosx;
16821682
SWIFT_VERSION = 4.0;

web3swift/HookedFunctions/Classes/Web3+BrowserFunctions.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ extension web3.BrowserFunctions {
2727
return addresses[0]
2828
}
2929

30-
public func personalSign(_ personalMessage: String, account: String, password: String = "BANKEXFOUNDATION") -> String? {
30+
public func personalSign(_ personalMessage: String, account: String, password: String = "web3swift") -> String? {
3131
return self.sign(personalMessage, account: account, password: password)
3232
}
3333

34-
public func sign(_ personalMessage: String, account: String, password: String = "BANKEXFOUNDATION") -> String? {
34+
public func sign(_ personalMessage: String, account: String, password: String = "web3swift") -> String? {
3535
guard let data = Data.fromHex(personalMessage) else {return nil}
3636
return self.sign(data, account: account, password: password)
3737
}
3838

39-
public func sign(_ personalMessage: Data, account: String, password: String = "BANKEXFOUNDATION") -> String? {
39+
public func sign(_ personalMessage: Data, account: String, password: String = "web3swift") -> String? {
4040
do {
4141
guard let keystoreManager = self.web3.provider.attachedKeystoreManager else {return nil}
4242

@@ -74,13 +74,13 @@ extension web3.BrowserFunctions {
7474
}
7575

7676

77-
public func sendTransaction(_ transactionJSON: [String: Any], password: String = "BANKEXFOUNDATION") -> [String:Any]? {
77+
public func sendTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> [String:Any]? {
7878
guard let transaction = EthereumTransaction.fromJSON(transactionJSON) else {return nil}
7979
guard let options = Web3Options.fromJSON(transactionJSON) else {return nil}
8080
return self.sendTransaction(transaction, options: options, password: password)
8181
}
8282

83-
public func sendTransaction(_ transaction: EthereumTransaction, options: Web3Options, password: String = "BANKEXFOUNDATION") -> [String:Any]? {
83+
public func sendTransaction(_ transaction: EthereumTransaction, options: Web3Options, password: String = "web3swift") -> [String:Any]? {
8484
let result = self.web3.eth.sendTransaction(transaction, options: options, password: password)
8585
switch result {
8686
case .failure(_):
@@ -129,13 +129,13 @@ extension web3.BrowserFunctions {
129129
return (transaction, options)
130130
}
131131

132-
public func signTransaction(_ transactionJSON: [String: Any], password: String = "BANKEXFOUNDATION") -> String? {
132+
public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> String? {
133133
guard let transaction = EthereumTransaction.fromJSON(transactionJSON) else {return nil}
134134
guard let options = Web3Options.fromJSON(transactionJSON) else {return nil}
135135
return self.signTransaction(transaction, options: options, password: password)
136136
}
137137

138-
public func signTransaction(_ trans: EthereumTransaction, options: Web3Options, password: String = "BANKEXFOUNDATION") -> String? {
138+
public func signTransaction(_ trans: EthereumTransaction, options: Web3Options, password: String = "web3swift") -> String? {
139139
do {
140140
var transaction = trans
141141
guard let from = options.from else {return nil}

web3swift/HookedFunctions/Classes/Web3+Wallet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension web3.Web3Wallet {
3434
}
3535
}
3636

37-
public func signTX(transaction:inout EthereumTransaction, account: EthereumAddress, password: String = "BANKEXFOUNDATION") -> Result<Bool, Web3Error> {
37+
public func signTX(transaction:inout EthereumTransaction, account: EthereumAddress, password: String = "web3swift") -> Result<Bool, Web3Error> {
3838
do {
3939
guard let keystoreManager = self.web3.provider.attachedKeystoreManager else {
4040
return Result.failure(Web3Error.walletError)
@@ -50,15 +50,15 @@ extension web3.Web3Wallet {
5050
}
5151
}
5252

53-
public func signPersonalMessage(_ personalMessage: String, account: EthereumAddress, password: String = "BANKEXFOUNDATION") -> Result<Data, Web3Error> {
53+
public func signPersonalMessage(_ personalMessage: String, account: EthereumAddress, password: String = "web3swift") -> Result<Data, Web3Error> {
5454
guard let data = Data.fromHex(personalMessage) else
5555
{
5656
return Result.failure(Web3Error.dataError)
5757
}
5858
return self.signPersonalMessage(data, account: account, password: password)
5959
}
6060

61-
public func signPersonalMessage(_ personalMessage: Data, account: EthereumAddress, password: String = "BANKEXFOUNDATION") -> Result<Data, Web3Error> {
61+
public func signPersonalMessage(_ personalMessage: Data, account: EthereumAddress, password: String = "web3swift") -> Result<Data, Web3Error> {
6262
do {
6363
guard let keystoreManager = self.web3.provider.attachedKeystoreManager else
6464
{

web3swift/KeystoreManager/Classes/BIP32Keystore.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ public class BIP32Keystore: AbstractKeystore {
7070
rootPrefix = keystoreParams!.rootPath!
7171
}
7272

73-
public convenience init? (mnemonics: String, password: String = "BANKEXFOUNDATION", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathMetamaskPrefix) throws {
73+
public convenience init? (mnemonics: String, password: String = "web3swift", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathMetamaskPrefix) throws {
7474
guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {throw AbstractKeystoreError.noEntropyError}
7575
defer{ Data.zero(&seed) }
7676
try self.init(seed: seed, password: password, prefixPath: prefixPath)
7777
}
7878

79-
public init? (seed: Data, password: String = "BANKEXFOUNDATION", prefixPath: String = HDNode.defaultPathMetamaskPrefix) throws {
79+
public init? (seed: Data, password: String = "web3swift", prefixPath: String = HDNode.defaultPathMetamaskPrefix) throws {
8080
guard let prefixNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else {return nil}
8181
self.rootPrefix = prefixPath
8282
try createNewAccount(parentNode: prefixNode, password: password)
8383
}
8484

85-
public func createNewChildAccount(password: String = "BANKEXFOUNDATION") throws {
85+
public func createNewChildAccount(password: String = "web3swift") throws {
8686
guard let decryptedRootNode = try? self.getPrefixNodeData(password), decryptedRootNode != nil else {throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")}
8787
guard let rootNode = HDNode(decryptedRootNode!) else {throw AbstractKeystoreError.encryptionError("Failed to deserialize a root node")}
8888
let prefixPath = self.rootPrefix
8989
guard rootNode.depth == prefixPath.components(separatedBy: "/").count - 1 else {throw AbstractKeystoreError.encryptionError("Derivation depth mismatch")}
9090
try createNewAccount(parentNode: rootNode, password: password)
9191
}
9292

93-
public func createNewAccount(parentNode: HDNode, password: String = "BANKEXFOUNDATION", aesMode: String = "aes-128-cbc") throws {
93+
public func createNewAccount(parentNode: HDNode, password: String = "web3swift", aesMode: String = "aes-128-cbc") throws {
9494
var newIndex = UInt32(0)
9595
for (p, _) in paths {
9696
guard let idx = UInt32(p.components(separatedBy: "/").last!) else {continue}
@@ -112,7 +112,7 @@ public class BIP32Keystore: AbstractKeystore {
112112
try encryptDataToStorage(password, data: serializedRootNode, aesMode: aesMode)
113113
}
114114

115-
public func createNewCustomChildAccount(password: String = "BANKEXFOUNDATION", path: String) throws {
115+
public func createNewCustomChildAccount(password: String = "web3swift", path: String) throws {
116116
guard let decryptedRootNode = try? self.getPrefixNodeData(password), decryptedRootNode != nil else {throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")}
117117
guard let rootNode = HDNode(decryptedRootNode!) else {throw AbstractKeystoreError.encryptionError("Failed to deserialize a root node")}
118118
let prefixPath = self.rootPrefix
@@ -268,7 +268,7 @@ public class BIP32Keystore: AbstractKeystore {
268268
return data
269269
}
270270

271-
public func serializeRootNodeToString(password: String = "BANKEXFOUNDATION") throws -> String {
271+
public func serializeRootNodeToString(password: String = "web3swift") throws -> String {
272272
guard let decryptedRootNode = try? self.getPrefixNodeData(password), decryptedRootNode != nil else {throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")}
273273
guard let rootNode = HDNode(decryptedRootNode!) else {throw AbstractKeystoreError.encryptionError("Failed to deserialize a root node")}
274274
guard let string = rootNode.serializeToString(serializePublic: false) else {throw AbstractKeystoreError.encryptionError("Failed to deserialize a root node")}

web3swift/KeystoreManager/Classes/EthereumKeystoreV3.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public class EthereumKeystoreV3: AbstractKeystore {
6565
}
6666
}
6767

68-
public init? (password: String = "BANKEXFOUNDATION", aesMode: String = "aes-128-cbc") throws {
68+
public init? (password: String = "web3swift", aesMode: String = "aes-128-cbc") throws {
6969
guard var newPrivateKey = SECP256K1.generatePrivateKey() else {return nil}
7070
defer {Data.zero(&newPrivateKey)}
7171
try encryptDataToStorage(password, keyData: newPrivateKey, aesMode: aesMode)
7272
}
7373

74-
public init? (privateKey: Data, password: String = "BANKEXFOUNDATION", aesMode: String = "aes-128-cbc") throws {
74+
public init? (privateKey: Data, password: String = "web3swift", aesMode: String = "aes-128-cbc") throws {
7575
guard privateKey.count == 32 else {return nil}
7676
guard SECP256K1.verifyPrivateKey(privateKey: privateKey) else {return nil}
7777
try encryptDataToStorage(password, keyData: privateKey, aesMode: aesMode)

web3swift/Promises/Classes/Promise+Web3+Eth+SendTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import PromiseKit
1212

1313
extension web3.Eth {
1414

15-
func sendTransactionPromise(_ transaction: EthereumTransaction, options: Web3Options, password:String = "BANKEXFOUNDATION") -> Promise<TransactionSendingResult> {
15+
func sendTransactionPromise(_ transaction: EthereumTransaction, options: Web3Options, password:String = "web3swift") -> Promise<TransactionSendingResult> {
1616
// print(transaction)
1717
var assembledTransaction : EthereumTransaction = transaction.mergedWithOptions(options)
1818
let queue = web3.requestDispatcher.queue

web3swift/Promises/Classes/Promise+Web3+Personal+Sign.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import PromiseKit
1212

1313
extension web3.Personal {
1414

15-
func signPersonalMessagePromise(message: Data, from: EthereumAddress, password:String = "BANKEXFOUNDATION") -> Promise<Data> {
15+
func signPersonalMessagePromise(message: Data, from: EthereumAddress, password:String = "web3swift") -> Promise<Data> {
1616
let queue = web3.requestDispatcher.queue
1717
do {
1818
if self.web3.provider.attachedKeystoreManager == nil {

web3swift/Promises/Classes/Promise+Web3+Personal+UnlockAccount.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import BigInt
1111
import PromiseKit
1212

1313
extension web3.Personal {
14-
func unlockAccountPromise(account: EthereumAddress, password:String = "BANKEXFOUNDATION", seconds: UInt64 = 300) -> Promise<Bool> {
14+
func unlockAccountPromise(account: EthereumAddress, password:String = "web3swift", seconds: UInt64 = 300) -> Promise<Bool> {
1515
let addr = account.address
1616
return unlockAccountPromise(account: addr, password: password, seconds: seconds)
1717
}
1818

1919

20-
func unlockAccountPromise(account: String, password:String = "BANKEXFOUNDATION", seconds: UInt64 = 300) -> Promise<Bool> {
20+
func unlockAccountPromise(account: String, password:String = "web3swift", seconds: UInt64 = 300) -> Promise<Bool> {
2121
let queue = web3.requestDispatcher.queue
2222
do {
2323
if self.web3.provider.attachedKeystoreManager == nil {

web3swift/Web3/Classes/Web3+Eth.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension web3.Eth {
2121
/// This function is synchronous!
2222
///
2323
/// Returns the Result object that indicates either success of failure.
24-
public func sendTransaction(_ transaction: EthereumTransaction, options: Web3Options, password:String = "BANKEXFOUNDATION") -> Result<TransactionSendingResult, Web3Error> {
24+
public func sendTransaction(_ transaction: EthereumTransaction, options: Web3Options, password:String = "web3swift") -> Result<TransactionSendingResult, Web3Error> {
2525
do {
2626
let result = try self.sendTransactionPromise(transaction, options: options, password: password).wait()
2727
return Result(result)

0 commit comments

Comments
 (0)