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

Commit 0f6d95f

Browse files
committed
Now we are using CommonCrypto instead of CryptoSwift (up to 1000 times faster now)
Optimized mnemonics generation (10 times faster) Added Transaction class (Work in progress) Added SignedTransaction class (Work in progress)
1 parent 8eb4e77 commit 0f6d95f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+784
-459
lines changed

Cartfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ github "mxcl/PromiseKit" ~> 6.0
22
github "attaswift/BigInt" ~> 3.1
33
github "krzyzanowskim/CryptoSwift"
44
github "Boilertalk/secp256k1.swift"
5+
github "v57/BlueCryptor" ~> 1.0

Cartfile.resolved

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
github "Boilertalk/secp256k1.swift" "0.1.4"
22
github "attaswift/BigInt" "v3.1.0"
33
github "attaswift/SipHash" "v1.2.2"
4-
github "krzyzanowskim/CryptoSwift" "0.13.0"
5-
github "mxcl/PromiseKit" "6.5.2"
4+
github "krzyzanowskim/CryptoSwift" "0.13.1"
5+
github "mxcl/PromiseKit" "6.6.1"
6+
github "v57/BlueCryptor" "1.0.22"

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let package = Package(
1414
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "0.12.0"),
1515
.package(url: "https://github.com/Boilertalk/secp256k1.swift.git", from: "0.1.1"),
1616
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.4.0"),
17+
.package(url: "https://github.com/v57/BlueCryptor.git", from: "1.0.0"),
1718
],
1819
targets: [
1920
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# We just released web3swift 2.0 [check it out](https://github.com/BANKEX/web3swift/releases/tag/2.0.0)
2-
### also check our [Discord Channel](https://discord.gg/3ETv2ST)
1+
2+
### You can ask for help in our [Discord Channel](https://discord.gg/3ETv2ST)
33
<p align="right">
44
<a href="https://brianmacdonald.github.io/Ethonate/address#0x47FC2e245b983A92EB3359F06E31F34B107B6EF6" target="_blank">
55
<img src="https://brianmacdonald.github.io/Ethonate/svg/eth-support-blue.svg" alt="Support">
@@ -57,7 +57,7 @@ Don't forget to set the iOS version in a Podfile, otherwise you get an error if
5757
Add this to the dependency section of your `Package.swift` manifest:
5858

5959
```Swift
60-
.package(url: "https://github.com/BANKEX/web3swift.git", from: "2.0.0")
60+
.package(url: "https://github.com/BANKEX/web3swift.git", from: "2.1.0")
6161
```
6262

6363
- **CocoaPods:** Put this in your `Podfile`:
@@ -69,7 +69,7 @@ Don't forget to set the iOS version in a Podfile, otherwise you get an error if
6969
- **Carthage:** Put this in your `Cartfile`:
7070

7171
```
72-
github "BANKEX/web3swift" ~> 2.0
72+
github "BANKEX/web3swift" ~> 2.1
7373
```
7474

7575

Sources/ABIv2/ABIv2Decoding.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct ABIv2Decoder {
3131
/// - data: Data to decode
3232
/// - Returns: Array of decoded types
3333
public static func decode(types: [ABIv2.Element.ParameterType], data: Data) -> [AnyObject]? {
34-
// print("Full data: \n" + data.toHexString())
34+
// print("Full data: \n" + data.hex)
3535
var toReturn = [AnyObject]()
3636
var consumed: UInt64 = 0
3737
for i in 0 ..< types.count {
@@ -59,30 +59,30 @@ public struct ABIv2Decoder {
5959
}
6060
switch type {
6161
case let .uint(bits):
62-
// print("Uint256 element itself: \n" + elementItself.toHexString())
62+
// print("Uint256 element itself: \n" + elementItself.hex)
6363
guard elementItself.count >= 32 else { break }
6464
let mod = BigUInt(1) << bits
6565
let dataSlice = elementItself[0 ..< 32]
6666
let v = BigUInt(dataSlice) % mod
6767
// print("Uint256 element is: \n" + String(v))
6868
return (v as AnyObject, type.memoryUsage)
6969
case let .int(bits):
70-
// print("Int256 element itself: \n" + elementItself.toHexString())
70+
// print("Int256 element itself: \n" + elementItself.hex)
7171
guard elementItself.count >= 32 else { break }
7272
let mod = BigInt(1) << bits
7373
let dataSlice = elementItself[0 ..< 32]
7474
let v = BigInt.fromTwosComplement(data: dataSlice) % mod
7575
// print("Int256 element is: \n" + String(v))
7676
return (v as AnyObject, type.memoryUsage)
7777
case .address:
78-
// print("Address element itself: \n" + elementItself.toHexString())
78+
// print("Address element itself: \n" + elementItself.hex)
7979
guard elementItself.count >= 32 else { break }
8080
let dataSlice = elementItself[12 ..< 32]
8181
let address = Address(dataSlice)
8282
// print("Address element is: \n" + String(address.address))
8383
return (address as AnyObject, type.memoryUsage)
8484
case .bool:
85-
// print("Bool element itself: \n" + elementItself.toHexString())
85+
// print("Bool element itself: \n" + elementItself.hex)
8686
guard elementItself.count >= 32 else { break }
8787
let dataSlice = elementItself[0 ..< 32]
8888
let v = BigUInt(dataSlice)
@@ -93,13 +93,13 @@ public struct ABIv2Decoder {
9393
return (false as AnyObject, type.memoryUsage)
9494
}
9595
case let .bytes(length):
96-
// print("Bytes32 element itself: \n" + elementItself.toHexString())
96+
// print("Bytes32 element itself: \n" + elementItself.hex)
9797
guard elementItself.count >= 32 else { break }
9898
let dataSlice = elementItself[0 ..< length]
99-
// print("Bytes32 element is: \n" + String(dataSlice.toHexString()))
99+
// print("Bytes32 element is: \n" + String(dataSlice.hex))
100100
return (dataSlice as AnyObject, type.memoryUsage)
101101
case .string:
102-
// print("String element itself: \n" + elementItself.toHexString())
102+
// print("String element itself: \n" + elementItself.hex)
103103
guard elementItself.count >= 32 else { break }
104104
var dataSlice = elementItself[0 ..< 32]
105105
let length = UInt64(BigUInt(dataSlice))
@@ -109,18 +109,18 @@ public struct ABIv2Decoder {
109109
// print("String element is: \n" + String(string))
110110
return (string as AnyObject, type.memoryUsage)
111111
case .dynamicBytes:
112-
// print("Bytes element itself: \n" + elementItself.toHexString())
112+
// print("Bytes element itself: \n" + elementItself.hex)
113113
guard elementItself.count >= 32 else { break }
114114
var dataSlice = elementItself[0 ..< 32]
115115
let length = UInt64(BigUInt(dataSlice))
116116
guard elementItself.count >= 32 + length else { break }
117117
dataSlice = elementItself[32 ..< 32 + length]
118-
// print("Bytes element is: \n" + String(dataSlice.toHexString()))
118+
// print("Bytes element is: \n" + String(dataSlice.hex))
119119
return (dataSlice as AnyObject, type.memoryUsage)
120120
case let .array(type: subType, length: length):
121121
switch type.arraySize {
122122
case .dynamicSize:
123-
// print("Dynamic array element itself: \n" + elementItself.toHexString())
123+
// print("Dynamic array element itself: \n" + elementItself.hex)
124124
if subType.isStatic {
125125
// uint[] like, expect length and elements
126126
guard elementItself.count >= 32 else { break }
@@ -146,7 +146,7 @@ public struct ABIv2Decoder {
146146
dataSlice = Data(elementItself[32 ..< elementItself.count])
147147
var subpointer: UInt64 = 0
148148
var toReturn = [AnyObject]()
149-
// print("Dynamic array sub element itself: \n" + dataSlice.toHexString())
149+
// print("Dynamic array sub element itself: \n" + dataSlice.hex)
150150
for _ in 0 ..< length {
151151
let (v, c) = decodeSignleType(type: subType, data: dataSlice, pointer: subpointer)
152152
guard let valueUnwrapped = v, let consumedUnwrapped = c else { break }
@@ -156,7 +156,7 @@ public struct ABIv2Decoder {
156156
return (toReturn as AnyObject, nextElementPointer)
157157
}
158158
case let .staticSize(staticLength):
159-
// print("Static array element itself: \n" + elementItself.toHexString())
159+
// print("Static array element itself: \n" + elementItself.hex)
160160
guard length == staticLength else { break }
161161
var toReturn = [AnyObject]()
162162
var consumed: UInt64 = 0
@@ -175,7 +175,7 @@ public struct ABIv2Decoder {
175175
break
176176
}
177177
case let .tuple(types: subTypes):
178-
// print("Tuple element itself: \n" + elementItself.toHexString())
178+
// print("Tuple element itself: \n" + elementItself.hex)
179179
var toReturn = [AnyObject]()
180180
var consumed: UInt64 = 0
181181
for i in 0 ..< subTypes.count {
@@ -191,23 +191,23 @@ public struct ABIv2Decoder {
191191
return (toReturn as AnyObject, nextElementPointer)
192192
}
193193
case .function:
194-
// print("Function element itself: \n" + elementItself.toHexString())
194+
// print("Function element itself: \n" + elementItself.hex)
195195
guard elementItself.count >= 32 else { break }
196196
let dataSlice = elementItself[8 ..< 32]
197-
// print("Function element is: \n" + String(dataSlice.toHexString()))
197+
// print("Function element is: \n" + String(dataSlice.hex))
198198
return (dataSlice as AnyObject, type.memoryUsage)
199199
}
200200
return (nil, nil)
201201
}
202202

203203
fileprivate static func followTheData(type: ABIv2.Element.ParameterType, data: Data, pointer: UInt64 = 0) -> (elementEncoding: Data?, nextElementPointer: UInt64?) {
204-
// print("Follow the data: \n" + data.toHexString())
204+
// print("Follow the data: \n" + data.hex)
205205
// print("At pointer: \n" + String(pointer))
206206
if type.isStatic {
207207
guard data.count >= pointer + type.memoryUsage else { return (nil, nil) }
208208
let elementItself = data[pointer ..< pointer + type.memoryUsage]
209209
let nextElement = pointer + type.memoryUsage
210-
// print("Got element itself: \n" + elementItself.toHexString())
210+
// print("Got element itself: \n" + elementItself.hex)
211211
// print("Next element pointer: \n" + String(nextElement))
212212
return (Data(elementItself), nextElement)
213213
} else {
@@ -230,7 +230,7 @@ public struct ABIv2Decoder {
230230
let elementPointer = UInt64(bn)
231231
let elementItself = data[elementPointer ..< UInt64(data.count)]
232232
let nextElement = pointer + type.memoryUsage
233-
// print("Got element itself: \n" + elementItself.toHexString())
233+
// print("Got element itself: \n" + elementItself.hex)
234234
// print("Next element pointer: \n" + String(nextElement))
235235
return (Data(elementItself), nextElement)
236236
}

Sources/ABIv2/ABIv2Encoding.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public struct ABIv2Encoder {
259259
toReturn.append(encoding)
260260
}
261261
let total = lengthEncoding + toReturn
262-
// print("Dynamic array of static types encoding :\n" + String(total.toHexString()))
262+
// print("Dynamic array of static types encoding :\n" + String(total.hex))
263263
return total
264264
} else {
265265
// create new context
@@ -292,7 +292,7 @@ public struct ABIv2Encoder {
292292
}
293293
}
294294
let total = lengthEncoding + headsConcatenated + tailsConcatenated
295-
// print("Dynamic array of dynamic types encoding :\n" + String(total.toHexString()))
295+
// print("Dynamic array of dynamic types encoding :\n" + String(total.hex))
296296
return total
297297
}
298298
case let .staticSize(staticLength):
@@ -307,7 +307,7 @@ public struct ABIv2Encoder {
307307
guard let encoding = enc else { break }
308308
toReturn.append(encoding)
309309
}
310-
// print("Static array of static types encoding :\n" + String(toReturn.toHexString()))
310+
// print("Static array of static types encoding :\n" + String(toReturn.hex))
311311
let total = toReturn
312312
return total
313313
} else {
@@ -335,7 +335,7 @@ public struct ABIv2Encoder {
335335
tailsPointer = tailsPointer + BigUInt(tail.count)
336336
}
337337
let total = headsConcatenated + tailsConcatenated
338-
// print("Static array of dynamic types encoding :\n" + String(total.toHexString()))
338+
// print("Static array of dynamic types encoding :\n" + String(total.hex))
339339
return total
340340
}
341341
case .notArray:

Sources/ABIv2/ABIv2ParameterTypes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ extension ABIv2.Element.Function {
179179

180180
/// Function hash in hex
181181
public var methodString: String {
182-
return String(signature.sha3(.keccak256).prefix(8))
182+
return signature.keccak256().hex
183183
}
184184

185185
/// Function hash
186186
public var methodEncoding: Data {
187-
return signature.data(using: .ascii)!.sha3(.keccak256)[0..<4]
187+
return signature.data(using: .ascii)!.keccak256()[0..<4]
188188
}
189189
}
190190

@@ -198,7 +198,7 @@ extension ABIv2.Element.Event {
198198

199199
/// Event hash
200200
public var topic: Data {
201-
return signature.data(using: .ascii)!.sha3(.keccak256)
201+
return signature.data(using: .ascii)!.keccak256()
202202
}
203203
}
204204

Sources/Contract/ComparisonExtensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ extension String: EventFilterComparable {
3939
public func isEqualTo(_ other: AnyObject) -> Bool {
4040
switch other {
4141
case let oth as String:
42-
return data.sha3(.keccak256) == oth.data.sha3(.keccak256)
42+
return data.keccak256() == oth.data.keccak256()
4343
case let oth as Data:
44-
return data.sha3(.keccak256) == oth.sha3(.keccak256)
44+
return data.keccak256() == oth.keccak256()
4545
default:
4646
return false
4747
}
@@ -56,13 +56,13 @@ extension Data: EventFilterComparable {
5656
if self == data {
5757
return true
5858
}
59-
let hash = data.sha3(.keccak256)
59+
let hash = data.keccak256()
6060
return self == hash
6161
case let oth as Data:
6262
if self == oth {
6363
return true
6464
}
65-
let hash = oth.sha3(.keccak256)
65+
let hash = oth.keccak256()
6666
return self == hash
6767
default:
6868
return false

Sources/Contract/EthereumFilterEncodingExtensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ import Foundation
1111

1212
extension BigUInt: EventFilterEncodable {
1313
public func eventFilterEncoded() -> String? {
14-
return abiEncode(bits: 256)?.toHexString().withHex
14+
return abiEncode(bits: 256)?.hex.withHex
1515
}
1616
}
1717

1818
extension BigInt: EventFilterEncodable {
1919
public func eventFilterEncoded() -> String? {
20-
return abiEncode(bits: 256)?.toHexString().withHex
20+
return abiEncode(bits: 256)?.hex.withHex
2121
}
2222
}
2323

2424
extension Data: EventFilterEncodable {
2525
public func eventFilterEncoded() -> String? {
2626
guard let padded = self.setLengthLeft(32) else { return nil }
27-
return padded.toHexString().withHex
27+
return padded.hex.withHex
2828
}
2929
}
3030

3131
extension Address: EventFilterEncodable {
3232
public func eventFilterEncoded() -> String? {
3333
guard let padded = self.addressData.setLengthLeft(32) else { return nil }
34-
return padded.toHexString().withHex
34+
return padded.hex.withHex
3535
}
3636
}
3737

3838
extension String: EventFilterEncodable {
3939
public func eventFilterEncoded() -> String? {
40-
return data.sha3(.keccak256).toHexString().withHex
40+
return data.keccak256().hex.withHex
4141
}
4242
}

Sources/Contract/EventFiltering.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal func encodeTopicToGetLogs(contract: ContractV2, eventName: String?, fil
6868
}
6969
var topics = [[String?]?]()
7070
if eventTopic != nil {
71-
topics.append([eventTopic!.toHexString().withHex])
71+
topics.append([eventTopic!.hex.withHex])
7272
} else {
7373
topics.append(nil as [String?]?)
7474
}

0 commit comments

Comments
 (0)