From 2581d5655632ba3dbe59a20a5d8be6e8a1433717 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 7 Nov 2024 19:26:32 -0800 Subject: [PATCH] try and remove the bad dependencies --- Package.resolved | 114 ++++-------------- Package.swift | 13 +- Sources/XMTPTestHelpers/TestHelpers.swift | 1 - Sources/XMTPiOS/Client.swift | 1 - .../Codecs/RemoteAttachmentCodec.swift | 15 +-- Sources/XMTPiOS/Crypto.swift | 4 - Sources/XMTPiOS/Extensions/String.swift | 11 +- Sources/XMTPiOS/KeyUtil.swift | 17 +-- Sources/XMTPiOS/Messages/PrivateKey.swift | 1 - Sources/XMTPiOS/Messages/PublicKey.swift | 2 - Sources/XMTPiOS/SigningKey.swift | 8 -- Sources/XMTPiOS/Util.swift | 23 ---- Tests/XMTPTests/DmTests.swift | 1 - Tests/XMTPTests/GroupPermissionsTests.swift | 1 - Tests/XMTPTests/GroupTests.swift | 1 - XMTP.podspec | 26 +--- .../Account/WalletConnection.swift | 7 -- 17 files changed, 36 insertions(+), 210 deletions(-) delete mode 100644 Sources/XMTPiOS/Util.swift diff --git a/Package.resolved b/Package.resolved index 5a21bff4..c4f4f90c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,14 +1,5 @@ { "pins" : [ - { - "identity" : "bigint", - "kind" : "remoteSourceControl", - "location" : "https://github.com/attaswift/BigInt", - "state" : { - "revision" : "793a7fac0bfc318e85994bf6900652e827aef33e", - "version" : "5.4.1" - } - }, { "identity" : "connect-swift", "kind" : "remoteSourceControl", @@ -19,12 +10,12 @@ } }, { - "identity" : "generic-json-swift", + "identity" : "cryptoswift", "kind" : "remoteSourceControl", - "location" : "https://github.com/iwill/generic-json-swift", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", "state" : { - "revision" : "0a06575f4038b504e78ac330913d920f1630f510", - "version" : "2.0.2" + "revision" : "678d442c6f7828def400a70ae15968aef67ef52d", + "version" : "1.8.3" } }, { @@ -41,17 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift.git", "state" : { - "revision" : "abd4f896f539e5bb090c85022177d775ad08dcb1", - "version" : "0.5.8-beta4" - } - }, - { - "identity" : "secp256k1.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", - "state" : { - "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", - "version" : "0.10.0" + "revision" : "91653cdaf999119f99189178867e32dcc53b11e8", + "version" : "0.6.0" } }, { @@ -68,8 +50,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d", - "version" : "1.1.2" + "revision" : "671108c96644956dddcd89dd59c203dcdb36cec7", + "version" : "1.1.4" } }, { @@ -77,53 +59,26 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-docc-plugin.git", "state" : { - "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", - "version" : "1.3.0" + "revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64", + "version" : "1.4.3" } }, { "identity" : "swift-docc-symbolkit", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-docc-symbolkit", + "location" : "https://github.com/swiftlang/swift-docc-symbolkit", "state" : { "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", "version" : "1.0.0" } }, - { - "identity" : "swift-http-types", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-http-types", - "state" : { - "revision" : "1ddbea1ee34354a6a2532c60f98501c35ae8edfa", - "version" : "1.2.0" - } - }, - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "9cb486020ebf03bfa5b5df985387a14a98744537", - "version" : "1.6.1" - } - }, { "identity" : "swift-nio", "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "fc79798d5a150d61361a27ce0c51169b889e23de", - "version" : "2.68.0" - } - }, - { - "identity" : "swift-nio-extras", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-extras.git", - "state" : { - "revision" : "05c36b57453d23ea63785d58a7dbc7b70ba1745e", - "version" : "1.23.0" + "revision" : "914081701062b11e3bb9e21accc379822621995e", + "version" : "2.76.1" } }, { @@ -131,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-http2.git", "state" : { - "revision" : "a0224f3d20438635dd59c9fcc593520d80d131d0", - "version" : "1.33.0" + "revision" : "eaa71bb6ae082eee5a07407b1ad0cbd8f48f9dca", + "version" : "1.34.1" } }, { @@ -140,17 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "2b09805797f21c380f7dc9bedaab3157c5508efb", - "version" : "2.27.0" - } - }, - { - "identity" : "swift-nio-transport-services", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-transport-services.git", - "state" : { - "revision" : "38ac8221dd20674682148d6451367f89c2652980", - "version" : "1.21.0" + "revision" : "c7e95421334b1068490b5d41314a50e70bab23d1", + "version" : "2.29.0" } }, { @@ -158,8 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "d57a5aecf24a25b32ec4a74be2f5d0a995a47c4b", - "version" : "1.27.0" + "revision" : "ebc7251dd5b37f627c93698e4374084d98409633", + "version" : "1.28.2" } }, { @@ -167,26 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "6a9e38e7bd22a3b8ba80bddf395623cf68f57807", - "version" : "1.3.1" - } - }, - { - "identity" : "web3.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/argentlabs/web3.swift", - "state" : { - "revision" : "1e75f98a5738c470b23bbfffa9314e9f788df76b", - "version" : "1.6.1" - } - }, - { - "identity" : "websocket-kit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/vapor/websocket-kit.git", - "state" : { - "revision" : "4232d34efa49f633ba61afde365d3896fc7f8740", - "version" : "2.15.0" + "revision" : "c8a44d836fe7913603e246acab7c528c2e780168", + "version" : "1.4.0" } } ], diff --git a/Package.swift b/Package.swift index 3e78edad..a7840d2b 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,6 @@ let package = Package( name: "XMTPiOS", platforms: [.iOS(.v14), .macOS(.v11)], products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "XMTPiOS", targets: ["XMTPiOS"] @@ -18,26 +17,20 @@ let package = Package( ), ], dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", exact: "0.10.0"), - .package(url: "https://github.com/argentlabs/web3.swift", from: "1.1.0"), .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "0.12.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "3.0.0"), + .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", exact: "1.8.3") ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "XMTPiOS", dependencies: [ - .product(name: "secp256k1", package: "secp256k1.swift"), - "web3.swift", .product(name: "Gzip", package: "GzipSwift"), .product(name: "Connect", package: "connect-swift"), - .product(name: "LibXMTP", package: "libxmtp-swift") + .product(name: "LibXMTP", package: "libxmtp-swift"), + .product(name: "Crypto", package: "CryptoSwift") ] ), .target( diff --git a/Sources/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index d32a1462..f5feb8f3 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -1,6 +1,5 @@ #if canImport(XCTest) import Combine - import CryptoKit import XCTest @testable import XMTPiOS import LibXMTP diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 3ac2bab9..56caa5c9 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -1,6 +1,5 @@ import Foundation import LibXMTP -import web3 public typealias PreEventCallback = () async throws -> Void diff --git a/Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift b/Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift index 19fe5d95..3d58c2e0 100644 --- a/Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift +++ b/Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift @@ -1,13 +1,6 @@ -// -// RemoteAttachmentCodec.swift -// -// -// Created by Pat Nakajima on 2/19/23. -// - import CryptoKit +import CryptoSwift import Foundation -import web3 public let ContentTypeRemoteAttachment = ContentTypeID(authorityID: "xmtp.org", typeID: "remoteStaticAttachment", versionMajor: 1, versionMinor: 0) @@ -217,11 +210,7 @@ public struct RemoteAttachmentCodec: ContentCodec { throw RemoteAttachmentError.invalidParameters("missing \(name) parameter") } - guard let parameterData = parameterHex.web3.hexData else { - throw RemoteAttachmentError.invalidParameters("invalid \(name) value") - } - - return Data(parameterData) + return Data(parameterHex.hexToData) } public func shouldPush(content: RemoteAttachment) throws -> Bool { diff --git a/Sources/XMTPiOS/Crypto.swift b/Sources/XMTPiOS/Crypto.swift index 04fe4f82..05e0b87f 100644 --- a/Sources/XMTPiOS/Crypto.swift +++ b/Sources/XMTPiOS/Crypto.swift @@ -1,7 +1,3 @@ -// -// Crypto.swift -// - import CryptoKit import Foundation diff --git a/Sources/XMTPiOS/Extensions/String.swift b/Sources/XMTPiOS/Extensions/String.swift index b6fc6d21..bfa1186e 100644 --- a/Sources/XMTPiOS/Extensions/String.swift +++ b/Sources/XMTPiOS/Extensions/String.swift @@ -1,16 +1,9 @@ -// -// String.swift -// -// -// Created by Naomi Plasterer on 7/1/24. -// - import Foundation - +import CryptoSwift extension String { public var hexToData: Data { - return Data(self.web3.bytesFromHex ?? []) + return Data(hex: self) } } diff --git a/Sources/XMTPiOS/KeyUtil.swift b/Sources/XMTPiOS/KeyUtil.swift index bd7048ff..2312ea5f 100644 --- a/Sources/XMTPiOS/KeyUtil.swift +++ b/Sources/XMTPiOS/KeyUtil.swift @@ -1,12 +1,8 @@ -// -// web3.swift -// Copyright © 2022 Argent Labs Limited. All rights reserved. -// import Foundation import Logging import secp256k1 -import web3 import LibXMTP +import CryptoSwift enum KeyUtilError: Error { case invalidContext @@ -18,7 +14,6 @@ enum KeyUtilError: Error { case parseError } -// Copied from web3.swift since its version is `internal` enum KeyUtilx { static func generatePublicKey(from data: Data) throws -> Data { let vec = try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: data) @@ -42,7 +37,7 @@ enum KeyUtilx { secp256k1_context_destroy(ctx) } - let msgData = hashing ? Util.keccak256(message) : message + let msgData = hashing ? message.sha3(.keccak256) : message let msg = (msgData as NSData).bytes.assumingMemoryBound(to: UInt8.self) let privateKeyPtr = (privateKey as NSData).bytes.assumingMemoryBound(to: UInt8.self) let signaturePtr = UnsafeMutablePointer.allocate(capacity: 1) @@ -64,7 +59,7 @@ enum KeyUtilx { defer { outputWithRecidPtr.deallocate() } - outputWithRecidPtr.assign(from: outputPtr, count: 64) + outputWithRecidPtr.update(from: outputPtr, count: 64) outputWithRecidPtr.advanced(by: 64).pointee = UInt8(recid) let signature = Data(bytes: outputWithRecidPtr, count: 65) @@ -72,12 +67,12 @@ enum KeyUtilx { return signature } - static func generateAddress(from publicKey: Data) -> EthereumAddress { + static func generateAddress(from publicKey: Data) -> String { let publicKeyData = publicKey.count == 64 ? publicKey : publicKey[1 ..< publicKey.count] - let hash = Util.keccak256(publicKeyData) + let hash = publicKeyData.sha3(.keccak256) let address = hash.subdata(in: 12 ..< hash.count) - return EthereumAddress("0x" + address.toHex) + return "0x" + address.toHex } static func recoverPublicKey(message: Data, signature: Data) throws -> Data { diff --git a/Sources/XMTPiOS/Messages/PrivateKey.swift b/Sources/XMTPiOS/Messages/PrivateKey.swift index 53475b0d..396041d2 100644 --- a/Sources/XMTPiOS/Messages/PrivateKey.swift +++ b/Sources/XMTPiOS/Messages/PrivateKey.swift @@ -1,4 +1,3 @@ -import CryptoKit import Foundation import LibXMTP diff --git a/Sources/XMTPiOS/Messages/PublicKey.swift b/Sources/XMTPiOS/Messages/PublicKey.swift index f83ddc7e..4a724c3f 100644 --- a/Sources/XMTPiOS/Messages/PublicKey.swift +++ b/Sources/XMTPiOS/Messages/PublicKey.swift @@ -1,7 +1,5 @@ -import CryptoKit import Foundation import LibXMTP -import web3 typealias PublicKey = Xmtp_MessageContents_PublicKey diff --git a/Sources/XMTPiOS/SigningKey.swift b/Sources/XMTPiOS/SigningKey.swift index ddfc2ec9..dd12b57e 100644 --- a/Sources/XMTPiOS/SigningKey.swift +++ b/Sources/XMTPiOS/SigningKey.swift @@ -1,12 +1,4 @@ -// -// SigningKey.swift -// -// -// Created by Pat Nakajima on 11/17/22. -// - import Foundation -import web3 import LibXMTP public enum WalletType { diff --git a/Sources/XMTPiOS/Util.swift b/Sources/XMTPiOS/Util.swift deleted file mode 100644 index d8d88dba..00000000 --- a/Sources/XMTPiOS/Util.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// Util.swift -// -// -// Created by Pat Nakajima on 11/20/22. -// - -import Foundation -import web3 - -enum Util { - static func keccak256(_ data: Data) -> Data { - return data.web3.keccak256 - } -} - -extension Array { - func chunks(_ chunkSize: Int) -> [[Element]] { - return stride(from: 0, to: self.count, by: chunkSize).map { - Array(self[$0..