Skip to content

Commit 1e75f98

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 2bbb2f2 + c85e063 commit 1e75f98

File tree

63 files changed

+1411
-512
lines changed

Some content is hidden

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

63 files changed

+1411
-512
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
runs-on: macos-latest
1111
steps:
1212
- uses: actions/checkout@v3
13-
- name: Lint
14-
run: ./scripts/runSwiftFormat.sh -l
13+
# - name: Lint
14+
# run: ./scripts/runSwiftFormat.sh -l
1515
macos:
16-
needs: lint
16+
# needs: lint
1717
runs-on: macos-latest
1818
env:
1919
TESTS_PRIVATEKEY: ${{ secrets.TESTS_PRIVATEKEY }}
@@ -26,10 +26,10 @@ jobs:
2626
- name: Tests
2727
run: swift test -v
2828
linux:
29-
needs: lint
29+
# needs: lint
3030
runs-on: ubuntu-latest
3131
container:
32-
image: swift:5.5-bionic
32+
image: swift:5.7-bionic
3333
env:
3434
TESTS_PRIVATEKEY: ${{ secrets.TESTS_PRIVATEKEY }}
3535
steps:

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GEM
33
specs:
44
CFPropertyList (3.0.5)
55
rexml
6-
activesupport (6.1.7.2)
6+
activesupport (6.1.7.6)
77
concurrent-ruby (~> 1.0, >= 1.0.2)
88
i18n (>= 1.6, < 2)
99
minitest (>= 5.1)
@@ -54,7 +54,7 @@ GEM
5454
netrc (~> 0.11)
5555
cocoapods-try (1.2.0)
5656
colored2 (3.1.2)
57-
concurrent-ruby (1.2.0)
57+
concurrent-ruby (1.2.2)
5858
escape (0.0.4)
5959
ethon (0.15.0)
6060
ffi (>= 1.15.0)
@@ -63,10 +63,10 @@ GEM
6363
fuzzy_match (2.0.4)
6464
gh_inspector (1.1.3)
6565
httpclient (2.8.3)
66-
i18n (1.12.0)
66+
i18n (1.14.1)
6767
concurrent-ruby (~> 1.0)
6868
json (2.6.1)
69-
minitest (5.17.0)
69+
minitest (5.19.0)
7070
molinillo (0.8.0)
7171
nanaimo (0.3.0)
7272
nap (1.1.0)
@@ -85,7 +85,7 @@ GEM
8585
colored2 (~> 3.1)
8686
nanaimo (~> 0.3.0)
8787
rexml (~> 3.2.4)
88-
zeitwerk (2.6.6)
88+
zeitwerk (2.6.11)
8989

9090
PLATFORMS
9191
ruby

Package.resolved

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

Package.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ let package = Package(
99
.watchOS(.v7)
1010
],
1111
products: [
12-
.library(name: "web3.swift", targets: ["web3"])
12+
.library(name: "web3.swift", targets: ["web3"]),
13+
.library(name: "web3-zksync.swift", targets: ["web3-zksync"])
1314
],
1415
dependencies: [
15-
.package(name: "BigInt", url: "https://github.com/attaswift/BigInt", from: "5.0.0"),
16+
.package(name: "BigInt", url: "https://github.com/attaswift/BigInt", from: "5.3.0"),
1617
.package(name: "GenericJSON", url: "https://github.com/iwill/generic-json-swift", .upToNextMajor(from: "2.0.0")),
1718
.package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", .upToNextMajor(from: "0.6.0")),
1819
.package(url: "https://github.com/vapor/websocket-kit.git", from: "2.0.0"),
@@ -32,7 +33,16 @@ let package = Package(
3233
.product(name: "WebSocketKit", package: "websocket-kit"),
3334
.product(name: "Logging", package: "swift-log")
3435
],
35-
path: "web3swift/src"
36+
path: "web3swift/src",
37+
exclude: ["ZKSync"]
38+
),
39+
.target(
40+
name: "web3-zksync",
41+
dependencies:
42+
[
43+
.target(name: "web3")
44+
],
45+
path: "web3swift/src/ZKSync"
3646
),
3747
.target(
3848
name: "keccaktiny",
@@ -53,7 +63,7 @@ let package = Package(
5363
),
5464
.testTarget(
5565
name: "web3swiftTests",
56-
dependencies: ["web3"],
66+
dependencies: ["web3", "web3-zksync"],
5767
path: "web3sTests",
5868
resources: [
5969
.copy("Resources/rlptests.json"),

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ We support querying ERC721 token data via the `ERC721` struct. Including:
162162
- Retrieve `Transfer` events
163163
- Decode standard JSON for NFT metadata. Please be aware some smart contracts are not 100% compliant with standard.
164164

165+
166+
### ZKSync Era
167+
168+
We also include additional helpers to interact with [ZKSync Era](https://zksync.io/), by importing `web3_zksync`.
169+
170+
Take a look at [ZKSyncTransaction](https://github.com/argentlabs/web3.swift/blob/develop/web3swift/src/ZKSync/ZKSyncTransaction.swift) or use directly
171+
[ZKSyncClient](https://github.com/argentlabs/web3.swift/blob/develop/web3swift/src/ZKSync/ZKSyncProvider.swift) which has similar API as the `EthereumClient`
172+
165173
### Running Tests
166174

167175
Some of the tests require a private key, which is not stored in the repository. You can ignore these while testing locally, as CI will use the encrypted secret key from Github.
@@ -183,7 +191,7 @@ Package dependencies:
183191
- [Vapor Websocket](https://github.com/vapor/websocket-kit.git)
184192
- [Apple Swift-log](https://github.com/apple/swift-log.git)
185193

186-
Also for Linux build, we can't se Apple crypto APIs, so we embedded a small subset of CryptoSwift (instead of importing the whole library). Credit to [Marcin Krzyżanowski](https://github.com/krzyzanowskim/CryptoSwift)
194+
Also for Linux build, we can't use Apple crypto APIs, so we embedded a small subset of CryptoSwift (instead of importing the whole library). Credit to [Marcin Krzyżanowski](https://github.com/krzyzanowskim/CryptoSwift)
187195

188196
## Contributors
189197

scripts/swiftformat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@
7575
--wraptypealiases preserve
7676
--xcodeindentation disabled
7777
--yodaswap always
78-
--disable enumNamespaces,extensionAccessControl,fileHeader,genericExtensions,modifierOrder,numberFormatting,opaqueGenericParameters,preferKeyPath,redundantBackticks,redundantExtensionACL,redundantFileprivate,redundantPattern,redundantRawValues,redundantSelf,sortDeclarations,spaceAroundGenerics,strongOutlets,trailingClosures,trailingCommas,unusedArguments,wrap,wrapMultilineStatementBraces,wrapSingleLineComments,yodaConditions
78+
--disable enumNamespaces,extensionAccessControl,fileHeader,genericExtensions,modifierOrder,numberFormatting,opaqueGenericParameters,preferKeyPath,redundantBackticks,redundantExtensionACL,redundantFileprivate,redundantPattern,redundantRawValues,redundantSelf,sortDeclarations,spaceAroundGenerics,strongOutlets,trailingClosures,trailingCommas,unusedArguments,wrap,wrapMultilineStatementBraces,wrapSingleLineComments,yodaConditions,consecutiveSpaces
7979
--enable blankLineAfterImports,blankLinesBetweenImports,isEmpty,wrapConditionalBodies

web3.swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'web3.swift'
3-
s.version = '1.5.0'
3+
s.version = '1.6.1'
44
s.license = 'MIT'
55
s.summary = 'Ethereum API for Swift'
66
s.homepage = 'https://github.com/argentlabs/web3.swift'

web3sTests/Account/EthereumAccount+SignTransactionTests.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,11 @@ class EthereumAccount_SignTransactionTests: XCTestCase {
4949
let gasLimit = BigUInt(hex: "0x5208")!
5050
let to = EthereumAddress("0x3535353535353535353535353535353535353535")
5151
let value = BigUInt(hex: "0x0")!
52-
let v = Int(hex: "0x25")!
53-
let r = Data(hex: "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d")!
54-
let s = Data(hex: "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d")!
55-
56-
var chainId = v
57-
if chainId >= 37 {
58-
chainId = (chainId - 35) / 2
59-
}
60-
61-
let tx = EthereumTransaction(from: nil, to: to, value: value, data: nil, nonce: nonce, gasPrice: gasPrice, gasLimit: gasLimit, chainId: chainId)
62-
let signed = SignedTransaction(transaction: tx, v: v, r: r, s: s)
63-
52+
let signature = "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d25".web3.hexData!
53+
54+
let tx = EthereumTransaction(from: nil, to: to, value: value, data: nil, nonce: nonce, gasPrice: gasPrice, gasLimit: gasLimit, chainId: 37)
55+
let signed = SignedTransaction(transaction: tx, signature: signature)
56+
6457
let raw = signed.raw!.web3.hexString
6558
let hash = signed.hash!.web3.hexString
6659

web3sTests/Account/EthereumAccountTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class EthereumAccountTests: XCTestCase {
1717

1818
func testLoadAccountAndAddress() {
1919
let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: TestConfig.privateKey))
20-
XCTAssertEqual(account.address.value.lowercased(), TestConfig.publicKey.lowercased(), "Failed to load private key. Ensure key is valid in TestConfig.swift")
20+
XCTAssertEqual(account.address, EthereumAddress(TestConfig.publicKey), "Failed to load private key. Ensure key is valid in TestConfig.swift")
2121
}
2222

2323
func testLoadAccountAndAddressMultiple() {
2424
let storage = TestEthereumMultipleKeyStorage(privateKey: TestConfig.privateKey)
2525
let account = try! EthereumAccount(addressString: TestConfig.publicKey, keyStorage: storage)
26-
XCTAssertEqual(account.address.value.lowercased(), TestConfig.publicKey.lowercased(), "Failed to load private key. Ensure key is valid in TestConfig.swift")
26+
XCTAssertEqual(account.address, EthereumAddress(TestConfig.publicKey), "Failed to load private key. Ensure key is valid in TestConfig.swift")
2727
}
2828

2929
func testCreateAccount() {
@@ -42,14 +42,14 @@ class EthereumAccountTests: XCTestCase {
4242
let storage = EthereumKeyLocalStorage()
4343
let account = try! EthereumAccount.importAccount(replacing: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD")
4444

45-
XCTAssertEqual(account.address.value, "0x675f5810feb3b09528e5cd175061b4eb8de69075")
45+
XCTAssertEqual(account.address, "0x675f5810feb3b09528e5cd175061b4eb8de69075")
4646
}
4747

4848
func testImportAccountMultiple() {
4949
let storage = EthereumKeyLocalStorage()
5050
let account = try! EthereumAccount.importAccount(addingTo: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD")
5151

52-
XCTAssertEqual(account.address.value, "0x675f5810feb3b09528e5cd175061b4eb8de69075")
52+
XCTAssertEqual(account.address, "0x675f5810feb3b09528e5cd175061b4eb8de69075")
5353
}
5454

5555
func testFetchAccounts() {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// web3.swift
3+
// Copyright © 2023 Argent Labs Limited. All rights reserved.
4+
//
5+
6+
import XCTest
7+
@testable import web3
8+
9+
class EthereumAddressTests: XCTestCase {
10+
private var values: Set<EthereumAddress>!
11+
private let addr1 = EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41")
12+
private let addr1Padded = EthereumAddress("0x0162142f0508F557C02bEB7C473682D7C91Bcef41")
13+
private let addr2 = EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef42")
14+
15+
func testGivenAddress_WhenComparingWithSameAddressString_AddressIsEqual() {
16+
XCTAssertEqual(addr1, addr1)
17+
}
18+
19+
func testGivenAddress_WhenHashingWithSameAddressString_AddressIsEqual() {
20+
values = [addr1]
21+
XCTAssertTrue(values.contains(addr1))
22+
}
23+
24+
func testGivenAddress_WhenComparingWithDifferentAddressString_AddressNotEqual() {
25+
XCTAssertNotEqual(addr1, addr2)
26+
}
27+
28+
func testGivenAddress_WhenComparingWith0PaddedAddress_AddressIsEqual() {
29+
XCTAssertEqual(addr1, addr1Padded)
30+
}
31+
32+
func testGivenAddress_WhenHashingWith0PaddedAddress_AddressIsEqual() {
33+
values = [addr1]
34+
XCTAssertTrue(values.contains(addr1Padded))
35+
}
36+
37+
func testGiven0PaddedAddress_WhenHashingWithNotPaddedAddress_AddressIsEqual() {
38+
values = [addr1Padded]
39+
XCTAssertTrue(values.contains(addr1))
40+
}
41+
42+
func testGivenAddress_WhenHashing_EqualToSameAddressHash() {
43+
XCTAssertEqual(addr1.hashValue, addr1.hashValue)
44+
}
45+
46+
func testGivenAddress_WhenHashing_EqualToPaddedAddressHash() {
47+
XCTAssertEqual(addr1.hashValue, addr1Padded.hashValue)
48+
}
49+
}

0 commit comments

Comments
 (0)