Skip to content

Commit b9c771b

Browse files
Merge branch 'develop'
2 parents 8275d1e + 4aa968a commit b9c771b

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

Sources/Web3Core/KeystoreManager/BIP32HDNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class HDNode {
8484
}
8585
depth = data[4..<5].bytes[0]
8686
parentFingerprint = data[5..<9]
87-
childNumber = data[9..<13].bytes.withUnsafeBytes { $0.load(as: UInt32.self) }
87+
childNumber = Array(data.dropFirst(9).prefix(4)).withUnsafeBytes { $0.load(as: UInt32.self) }
8888
chaincode = data[13..<45]
8989
if serializePrivate {
9090
privateKey = data[46..<78]

Sources/Web3Core/Utility/Utilities.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public struct Utilities {
239239
/// Takes a hash of some message. What message is hashed should be checked by user separately.
240240
public static func hashECRecover(hash: Data, signature: Data) -> EthereumAddress? {
241241
if signature.count != 65 { return nil }
242-
let rData = signature[0..<32].bytes
243-
let sData = signature[32..<64].bytes
242+
let rData: [UInt8] = Array(signature.prefix(32))
243+
let sData: [UInt8] = Array(signature.dropFirst(32).prefix(32))
244244
var vData = signature[64]
245245
if vData >= 27 && vData <= 30 {
246246
vData -= 27
@@ -274,11 +274,11 @@ public struct Utilities {
274274

275275
/// Unmarshals a 65 byte recoverable EC signature into internal structure.
276276
static func unmarshalSignature(signatureData: Data) -> SECP256K1.UnmarshaledSignature? {
277-
if signatureData.count != 65 { return nil }
278-
let bytes = signatureData.bytes
279-
let r = Array(bytes[0..<32])
280-
let s = Array(bytes[32..<64])
281-
return SECP256K1.UnmarshaledSignature(v: bytes[64], r: Data(r), s: Data(s))
277+
guard signatureData.count == 65 else { return nil }
278+
let rSlice = signatureData.prefix(32)
279+
let sSlice = signatureData.dropFirst(32).prefix(32)
280+
let v = signatureData[64]
281+
return SECP256K1.UnmarshaledSignature(v: v, r: Data(rSlice), s: Data(sSlice))
282282
}
283283

284284
/// Marshals the V, R and S signature parameters into a 65 byte recoverable EC signature.

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ extension Web3.BrowserFunctions {
5353

5454
public func personalECRecover(_ personalMessage: Data, signature: Data) -> String? {
5555
if signature.count != 65 { return nil }
56-
let rData = signature[0..<32].bytes
57-
let sData = signature[32..<64].bytes
56+
let rData = Array(signature.prefix(32))
57+
let sData = Array(signature.dropFirst(32).prefix(32))
5858
var vData = signature[64]
5959
if vData >= 27 && vData <= 30 {
6060
vData -= 27

Tests/web3swiftTests/remoteTests/EIP1559Tests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ import Web3Core
1212

1313
// swiftlint:disable force_unwrapping
1414
final class EIP1559Tests: XCTestCase {
15-
func testEIP1159MainnetTransaction() async throws {
16-
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
17-
var tx = try CodableTransaction(
18-
type: .eip1559,
19-
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
20-
chainID: web3.provider.network!.chainID,
21-
value: XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
22-
)
23-
// Vitalik's address
24-
tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
25-
// Should fail if there would be something wrong with the tx
26-
let res = try await web3.eth.estimateGas(for: tx)
27-
XCTAssertGreaterThan(res, 0)
28-
}
15+
// func testEIP1159MainnetTransaction() async throws {
16+
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
17+
// var tx = try CodableTransaction(
18+
// type: .eip1559,
19+
// to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
20+
// chainID: web3.provider.network!.chainID,
21+
// value: XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
22+
// )
23+
// // Vitalik's address
24+
// tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
25+
// // Should fail if there would be something wrong with the tx
26+
// let res = try await web3.eth.estimateGas(for: tx)
27+
// XCTAssertGreaterThan(res, 0)
28+
// }
2929

3030
// func testEIP1159GoerliTransaction() async throws {
3131
// let web3 = try await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken)

0 commit comments

Comments
 (0)