Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cocoapod dependencies #425

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 21 additions & 93 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -68,125 +50,71 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
"version" : "1.1.2"
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
"identity" : "swift-docc-plugin",
"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"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "a0224f3d20438635dd59c9fcc593520d80d131d0",
"version" : "1.33.0"
"revision" : "eaa71bb6ae082eee5a07407b1ad0cbd8f48f9dca",
"version" : "1.34.1"
}
},
{
"identity" : "swift-nio-ssl",
"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"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "d57a5aecf24a25b32ec4a74be2f5d0a995a47c4b",
"version" : "1.27.0"
"revision" : "ebc7251dd5b37f627c93698e4374084d98409633",
"version" : "1.28.2"
}
},
{
"identity" : "swift-system",
"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"
}
}
],
Expand Down
13 changes: 3 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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: "CryptoSwift", package: "CryptoSwift")
]
),
.target(
Expand Down
1 change: 0 additions & 1 deletion Sources/XMTPTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if canImport(XCTest)
import Combine
import CryptoKit
import XCTest
@testable import XMTPiOS
import LibXMTP
Expand Down
1 change: 0 additions & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import LibXMTP
import web3

public typealias PreEventCallback = () async throws -> Void

Expand Down
15 changes: 2 additions & 13 deletions Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions Sources/XMTPiOS/Crypto.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Crypto.swift
//

import CryptoKit
import Foundation

Expand Down
11 changes: 2 additions & 9 deletions Sources/XMTPiOS/Extensions/String.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

17 changes: 6 additions & 11 deletions Sources/XMTPiOS/KeyUtil.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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<secp256k1_ecdsa_recoverable_signature>.allocate(capacity: 1)
Expand All @@ -64,20 +59,20 @@ 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)

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 {
Expand Down
1 change: 0 additions & 1 deletion Sources/XMTPiOS/Messages/PrivateKey.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import CryptoKit
import Foundation
import LibXMTP

Expand Down
5 changes: 1 addition & 4 deletions Sources/XMTPiOS/Messages/PublicKey.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import CryptoKit
import Foundation
import LibXMTP
import web3

typealias PublicKey = Xmtp_MessageContents_PublicKey

Expand All @@ -11,7 +9,6 @@ enum PublicKeyError: String, Error {

extension PublicKey {
var walletAddress: String {
KeyUtilx.generateAddress(from: secp256K1Uncompressed.bytes)
.toChecksumAddress()
KeyUtilx.generateAddress(from: secp256K1Uncompressed.bytes).lowercased()
}
}
3 changes: 2 additions & 1 deletion Sources/XMTPiOS/Messages/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import LibXMTP
import CryptoSwift

/// Represents a secp256k1 compact recoverable signature.
public typealias Signature = Xmtp_MessageContents_Signature
Expand Down Expand Up @@ -42,7 +43,7 @@ extension Signature {
static func ethHash(_ message: String) throws -> Data {
let data = try ethPersonalMessage(message)

return Util.keccak256(data)
return data.sha3(.keccak256)
}

static func createIdentityText(key: Data) -> String {
Expand Down
Loading
Loading