From 7dc3cac024e5b408d53695edd982df14ed3fa6f7 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 12 Apr 2023 17:34:23 -0700 Subject: [PATCH 01/47] feat: crappy XMTPRustSwift usage --- Package.swift | 2 ++ Sources/XMTP/Client.swift | 7 ++++++- Sources/XMTP/KeyUtil.swift | 2 +- Sources/XMTP/Messages/PrivateKey.swift | 2 +- Tests/XMTPTests/ClientTests.swift | 4 ++++ Tests/XMTPTests/MessageTests.swift | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index 62975c5f..51f9b57c 100644 --- a/Package.swift +++ b/Package.swift @@ -27,6 +27,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", from: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), + .package(url: "https://github.com/xmtp/xmtp-rust-swift.git", branch: "main"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -39,6 +40,7 @@ let package = Package( "web3.swift", .product(name: "Gzip", package: "GzipSwift"), .product(name: "Connect", package: "connect-swift"), + .product(name: "XMTPRustSwift", package: "xmtp-rust-swift") ] ), .target( diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 9111ab8e..342c94c6 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -9,6 +9,7 @@ import Foundation import GRPC import web3 import XMTPProto +import XMTPRustSwift /// Specify configuration options for creating a ``Client``. public struct ClientOptions { @@ -78,9 +79,13 @@ public class Client { environment: options.api.env, secure: options.api.isSecure ) - + return try await create(account: account, apiClient: apiClient) } + + public static func testAdd() -> Int32 { + return XMTPRustSwift.add(5, 6) + } static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { let privateKeyBundleV1 = try await loadOrCreateKeys(for: account, apiClient: apiClient) diff --git a/Sources/XMTP/KeyUtil.swift b/Sources/XMTP/KeyUtil.swift index 9dcf40f6..e046feeb 100644 --- a/Sources/XMTP/KeyUtil.swift +++ b/Sources/XMTP/KeyUtil.swift @@ -23,7 +23,7 @@ enum KeyUtil { Logger(label: "web3.swift.key-util") } - static func generatePublicKey(from privateKeyData: Data) throws -> Data { + static func xmtpGeneratePublicKey(from privateKeyData: Data) throws -> Data { let privateKey = try secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyData, format: .uncompressed) return privateKey.publicKey.rawRepresentation } diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 282f61e5..2aa9a94b 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -54,7 +54,7 @@ public extension PrivateKey { timestamp = UInt64(Date().millisecondsSinceEpoch) secp256K1.bytes = privateKeyData - let publicData = try KeyUtil.generatePublicKey(from: privateKeyData) + let publicData = try KeyUtil.xmtpGeneratePublicKey(from: privateKeyData) publicKey.secp256K1Uncompressed.bytes = publicData publicKey.timestamp = timestamp } diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 26aba8c9..0fc71bd3 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -17,6 +17,10 @@ class ClientTests: XCTestCase { let fakeWallet = try PrivateKey.generate() _ = try await Client.create(account: fakeWallet) } + + func testXMTPRustSwift() async throws { + XCTAssertEqual(11, Client.testAdd()) + } func testCanMessage() async throws { let fixtures = await fixtures() diff --git a/Tests/XMTPTests/MessageTests.swift b/Tests/XMTPTests/MessageTests.swift index c3a5a8de..01948d6b 100644 --- a/Tests/XMTPTests/MessageTests.swift +++ b/Tests/XMTPTests/MessageTests.swift @@ -114,7 +114,7 @@ class MessageTests: XCTestCase { 140, 247, 221, 172, 14, 188, 52, 88, ]) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.generatePublicKey(from: key.secp256K1.bytes) + key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.xmtpGeneratePublicKey(from: key.secp256K1.bytes) } let keyBundleData = Data( From 0f753204a2e8650e007d19abbd69e62ccbce8153 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Thu, 13 Apr 2023 14:32:53 -0700 Subject: [PATCH 02/47] feat: get Rust networking selftest in --- Package.swift | 22 +++---- Sources/XMTP/Client.swift | 9 ++- Tests/XMTPTests/ClientTests.swift | 105 ++++++++++++++++-------------- 3 files changed, 73 insertions(+), 63 deletions(-) diff --git a/Package.swift b/Package.swift index 51f9b57c..d5282e66 100644 --- a/Package.swift +++ b/Package.swift @@ -41,15 +41,15 @@ let package = Package( .product(name: "Gzip", package: "GzipSwift"), .product(name: "Connect", package: "connect-swift"), .product(name: "XMTPRustSwift", package: "xmtp-rust-swift") - ] - ), - .target( - name: "XMTPTestHelpers", - dependencies: ["XMTP"] - ), - .testTarget( - name: "XMTPTests", - dependencies: ["XMTP", "XMTPTestHelpers"] - ), - ] + ] + ), + .target( + name: "XMTPTestHelpers", + dependencies: ["XMTP"] + ), + .testTarget( + name: "XMTPTests", + dependencies: ["XMTP", "XMTPTestHelpers"] + ), + ] ) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 342c94c6..3807a618 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -83,8 +83,13 @@ public class Client { return try await create(account: account, apiClient: apiClient) } - public static func testAdd() -> Int32 { - return XMTPRustSwift.add(5, 6) + public static func runSelfTests() -> Bool { + return XMTPRustSwift.encryption_selftest() + } + + public static func runNetworkingSelftest() -> String { + let statusCode = XMTPRustSwift.networking_selftest() + return "\(statusCode)" } static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 0fc71bd3..85e2087b 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -13,57 +13,62 @@ import XMTPTestHelpers @available(iOS 15, *) class ClientTests: XCTestCase { - func testTakesAWallet() async throws { - let fakeWallet = try PrivateKey.generate() - _ = try await Client.create(account: fakeWallet) - } + func testTakesAWallet() async throws { + let fakeWallet = try PrivateKey.generate() + _ = try await Client.create(account: fakeWallet) + } func testXMTPRustSwift() async throws { - XCTAssertEqual(11, Client.testAdd()) + XCTAssertTrue(Client.runSelfTests()) + } + + func testXMTPRustNetworking() async throws { + let str_result = Client.runNetworkingSelftest() + XCTAssertEqual(str_result, "200") + } + + func testCanMessage() async throws { + let fixtures = await fixtures() + let notOnNetwork = try PrivateKey.generate() + + let canMessage = try await fixtures.aliceClient.canMessage(fixtures.bobClient.address) + let cannotMessage = try await fixtures.aliceClient.canMessage(notOnNetwork.address) + XCTAssertTrue(canMessage) + XCTAssertFalse(cannotMessage) + } + + func testHasPrivateKeyBundleV1() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet) + + XCTAssertEqual(1, client.privateKeyBundleV1.preKeys.count) + + let preKey = client.privateKeyBundleV1.preKeys[0] + + XCTAssert(preKey.publicKey.hasSignature, "prekey not signed") + } + + func testCanBeCreatedWithBundle() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet) + + let bundle = client.privateKeyBundle + let clientFromV1Bundle = try Client.from(bundle: bundle) + + XCTAssertEqual(client.address, clientFromV1Bundle.address) + XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) + XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) + } + + func testCanBeCreatedWithV1Bundle() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet) + + let bundleV1 = client.v1keys + let clientFromV1Bundle = try Client.from(v1Bundle: bundleV1) + + XCTAssertEqual(client.address, clientFromV1Bundle.address) + XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) + XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) } - - func testCanMessage() async throws { - let fixtures = await fixtures() - let notOnNetwork = try PrivateKey.generate() - - let canMessage = try await fixtures.aliceClient.canMessage(fixtures.bobClient.address) - let cannotMessage = try await fixtures.aliceClient.canMessage(notOnNetwork.address) - XCTAssertTrue(canMessage) - XCTAssertFalse(cannotMessage) - } - - func testHasPrivateKeyBundleV1() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - XCTAssertEqual(1, client.privateKeyBundleV1.preKeys.count) - - let preKey = client.privateKeyBundleV1.preKeys[0] - - XCTAssert(preKey.publicKey.hasSignature, "prekey not signed") - } - - func testCanBeCreatedWithBundle() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - let bundle = client.privateKeyBundle - let clientFromV1Bundle = try Client.from(bundle: bundle) - - XCTAssertEqual(client.address, clientFromV1Bundle.address) - XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) - XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) - } - - func testCanBeCreatedWithV1Bundle() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - let bundleV1 = client.v1keys - let clientFromV1Bundle = try Client.from(v1Bundle: bundleV1) - - XCTAssertEqual(client.address, clientFromV1Bundle.address) - XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) - XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) - } } From b8a9b91b4f311250200ab1542f55d377df92c49e Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Thu, 13 Apr 2023 21:48:37 -0700 Subject: [PATCH 03/47] feat: add gRPC selftest --- Sources/XMTP/Client.swift | 5 +++++ Tests/XMTPTests/ClientTests.swift | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 3807a618..06976630 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -91,6 +91,11 @@ public class Client { let statusCode = XMTPRustSwift.networking_selftest() return "\(statusCode)" } + + public static func runGrpcTest() -> Bool { + let code = XMTPRustSwift.grpc_selftest() + return true + } static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { let privateKeyBundleV1 = try await loadOrCreateKeys(for: account, apiClient: apiClient) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 85e2087b..39834a31 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -27,6 +27,10 @@ class ClientTests: XCTestCase { XCTAssertEqual(str_result, "200") } + func testXMTPgRPC() async throws { + XCTAssertTrue(Client.runGrpcTest()) + } + func testCanMessage() async throws { let fixtures = await fixtures() let notOnNetwork = try PrivateKey.generate() From 085de71ee3becc0afb62736f9ef3a007c5906ab9 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Fri, 14 Apr 2023 09:54:53 -0700 Subject: [PATCH 04/47] test: grpc test --- Sources/XMTP/Client.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 06976630..ec6a96c8 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -94,7 +94,8 @@ public class Client { public static func runGrpcTest() -> Bool { let code = XMTPRustSwift.grpc_selftest() - return true + print("grpc test code: \(code)") + return code == 0 } static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { From 2174f24b03d91d9de5fa2a522ff4c5c9486d7723 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Fri, 14 Apr 2023 17:14:31 -0700 Subject: [PATCH 05/47] feat: cleaned up Swift package to use local reference, works great --- Sources/XMTP/ApiClient.swift | 9 +++++++++ Sources/XMTP/Client.swift | 17 +---------------- Tests/XMTPTests/ClientTests.swift | 12 ++---------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index c3c8ab73..1bdc7d18 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -7,6 +7,7 @@ import GRPC import XMTPProto +import XMTPRust typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse @@ -125,4 +126,12 @@ class GRPCApiClient: ApiClient { return try await client.publish(request, callOptions: options) } + + public static func runGrpcTest() async throws -> Int { + let service = XMTPRust.ApiService(environment: "http://localhost:15555", secure: false) + let response = try await service.query(topic: "test", json_paging_info: "") + // Try to parse the response JSON into a QueryResponse + let queryResponse = try QueryResponse(jsonString: response) + return queryResponse.envelopes.count + } } diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index ec6a96c8..93665ae8 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -9,7 +9,6 @@ import Foundation import GRPC import web3 import XMTPProto -import XMTPRustSwift /// Specify configuration options for creating a ``Client``. public struct ClientOptions { @@ -82,21 +81,7 @@ public class Client { return try await create(account: account, apiClient: apiClient) } - - public static func runSelfTests() -> Bool { - return XMTPRustSwift.encryption_selftest() - } - - public static func runNetworkingSelftest() -> String { - let statusCode = XMTPRustSwift.networking_selftest() - return "\(statusCode)" - } - - public static func runGrpcTest() -> Bool { - let code = XMTPRustSwift.grpc_selftest() - print("grpc test code: \(code)") - return code == 0 - } + static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { let privateKeyBundleV1 = try await loadOrCreateKeys(for: account, apiClient: apiClient) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 39834a31..63f4bef1 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -18,17 +18,9 @@ class ClientTests: XCTestCase { _ = try await Client.create(account: fakeWallet) } - func testXMTPRustSwift() async throws { - XCTAssertTrue(Client.runSelfTests()) - } - - func testXMTPRustNetworking() async throws { - let str_result = Client.runNetworkingSelftest() - XCTAssertEqual(str_result, "200") - } - func testXMTPgRPC() async throws { - XCTAssertTrue(Client.runGrpcTest()) + let numEnvelopes = try await GRPCApiClient.runGrpcTest() + XCTAssertEqual(numEnvelopes, 0) } func testCanMessage() async throws { From 6cf43f8af8beabcd6daaab594902694a83c40a72 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sun, 16 Apr 2023 13:43:42 -0700 Subject: [PATCH 06/47] feat: query using gRPC library works --- Package.swift | 74 ++++++++++++++++++------------------ Sources/XMTP/ApiClient.swift | 22 ++++++++--- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/Package.swift b/Package.swift index d5282e66..0518136a 100644 --- a/Package.swift +++ b/Package.swift @@ -4,43 +4,43 @@ import PackageDescription let package = Package( - name: "XMTP", - platforms: [.iOS(.v14), .macOS(.v11)], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "XMTP", - targets: ["XMTP"] - ), - .library( - name: "XMTPTestHelpers", - targets: ["XMTPTestHelpers"] - ), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - - .package(url: "https://github.com/xmtp/proto", branch: "main"), - .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", from: "0.3.0"), - .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/xmtp-rust-swift.git", branch: "main"), - ], - 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: "XMTP", - dependencies: [ - .product(name: "XMTPProto", package: "proto"), - .product(name: "secp256k1", package: "secp256k1.swift"), - "web3.swift", - .product(name: "Gzip", package: "GzipSwift"), - .product(name: "Connect", package: "connect-swift"), - .product(name: "XMTPRustSwift", package: "xmtp-rust-swift") + name: "XMTP", + platforms: [.iOS(.v14), .macOS(.v11)], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "XMTP", + targets: ["XMTP"] + ), + .library( + name: "XMTPTestHelpers", + targets: ["XMTPTestHelpers"] + ), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + + .package(url: "https://github.com/xmtp/proto", branch: "main"), + .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", branch: "main"), + .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", from: "0.3.0"), + .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), + .package(url: "../xmtp_rust_swift/", branch: "local_only_test_001") + ], + 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: "XMTP", + dependencies: [ + .product(name: "XMTPProto", package: "proto"), + .product(name: "secp256k1", package: "secp256k1.swift"), + "web3.swift", + .product(name: "Gzip", package: "GzipSwift"), + .product(name: "Connect", package: "connect-swift"), + .product(name: "XMTPRust", package: "xmtp_rust_swift") ] ), .target( diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 1bdc7d18..2cf6290b 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -32,6 +32,7 @@ class GRPCApiClient: ApiClient { var authToken = "" private var client: Xmtp_MessageApi_V1_MessageApiAsyncClient! + private var rustClient: XMTPRust.ApiService! required init(environment: XMTPEnvironment, secure: Bool = true) throws { self.environment = environment @@ -45,6 +46,7 @@ class GRPCApiClient: ApiClient { ) client = Xmtp_MessageApi_V1_MessageApiAsyncClient(channel: channel) + rustClient = XMTPRust.ApiService(environment:"http://localhost:5556", secure:false) } func setAuthToken(_ token: String) { @@ -73,11 +75,19 @@ class GRPCApiClient: ApiClient { request.pagingInfo.cursor = cursor } - var options = CallOptions() - options.customMetadata.add(name: "authorization", value: "Bearer \(authToken)") - options.timeLimit = .timeout(.seconds(5)) - - return try await client.query(request, callOptions: options) +// var options = CallOptions() +// options.customMetadata.add(name: "authorization", value: "Bearer \(authToken)") +// options.timeLimit = .timeout(.seconds(5)) +// +// return try await client.query(request, callOptions: options) + var encodedPaging = "" + if request.hasPagingInfo { + encodedPaging = try request.pagingInfo.jsonString() + } + let responseJson = try await rustClient.query(topic: topic, json_paging_info: encodedPaging) + // Decode the response as a QueryResponse + let decodedQueryResponse = try QueryResponse(jsonString: responseJson) + return decodedQueryResponse } func envelopes(topic: String, pagination: Pagination? = nil) async throws -> [Envelope] { @@ -128,7 +138,7 @@ class GRPCApiClient: ApiClient { } public static func runGrpcTest() async throws -> Int { - let service = XMTPRust.ApiService(environment: "http://localhost:15555", secure: false) + let service = XMTPRust.ApiService(environment: "http://localhost:5556", secure: false) let response = try await service.query(topic: "test", json_paging_info: "") // Try to parse the response JSON into a QueryResponse let queryResponse = try QueryResponse(jsonString: response) From d39550fa6c3e9c98d446d9bb2820e7a2d3af7628 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sun, 16 Apr 2023 13:46:49 -0700 Subject: [PATCH 07/47] fix: refactor a bit but query still works --- Sources/XMTP/ApiClient.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 2cf6290b..6bbd8196 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -46,8 +46,17 @@ class GRPCApiClient: ApiClient { ) client = Xmtp_MessageApi_V1_MessageApiAsyncClient(channel: channel) - rustClient = XMTPRust.ApiService(environment:"http://localhost:5556", secure:false) + // Secure flag is useless for now, XMTPRust checks the URL scheme to see if it's https + rustClient = XMTPRust.ApiService(environment:envToUrl(env: environment), secure:true) } + + func envToUrl(env: XMTPEnvironment) -> String { + switch (env) { + case XMTPEnvironment.local: return "http://localhost:5556"; + case XMTPEnvironment.dev: return "https://dev.xmtp.network:5556"; + case XMTPEnvironment.production: return "https://xmtp.network:5556"; + } + } func setAuthToken(_ token: String) { authToken = token From 3101d4d55973aa91c1cd756d07c6309f4f97bb34 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sun, 16 Apr 2023 14:40:11 -0700 Subject: [PATCH 08/47] feat: with local_test_only_005 branch, publish/query pass --- Package.swift | 2 +- Sources/XMTP/ApiClient.swift | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 0518136a..80e84edc 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", from: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "../xmtp_rust_swift/", branch: "local_only_test_001") + .package(url: "../xmtp_rust_swift/", branch: "local_only_test_005") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 6bbd8196..7f2c8d87 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -9,6 +9,7 @@ import GRPC import XMTPProto import XMTPRust + typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest @@ -143,10 +144,19 @@ class GRPCApiClient: ApiClient { options.customMetadata.add(name: AppVersionHeaderKey, value: Constants.version) options.timeLimit = .timeout(.seconds(5)) - return try await client.publish(request, callOptions: options) + // return try await client.publish(request, callOptions: options) + // Use the JSON encoding api for rustClient to publish + let encodedEnvelopes = try envelopes.map { try $0.jsonString() } + let responseJson = try await rustClient.publish(token: authToken, envelopes: encodedEnvelopes) + // Decode the response as a PublishResponse + let decodedPublishResponse = try PublishResponse(jsonString: responseJson) + return decodedPublishResponse } public static func runGrpcTest() async throws -> Int { + + let json = "{\"contentTopic\":\"/xmtp/0/privatestore-0x144a87F6dB31445B916BF4d896A425C91DbA7f84/key_bundle/proto\",\"timestampNs\":\"1681678277321011968\",\"message\":\"CvYDCiBPVY2cN8BNkvA2Ypoh0GvaMKNKmAtUsaPMNMwsRDRsmhLRAwrOAwogJ2zn2csOlNN6h2Llb9H4sAvp2Qs6x2L8Dra4ZTG9OvoSDIXSSqfFBhJgYMPSuxqbA68nOkGUPsV1WKjzs2LBuktCdGAEt3tWAbW1jNSF3KaA8XBkbhmM5zwSIbv69vszBzBp9/cYXxW4/rAJtkOuyNlsX04x/i+hswL4T6EkpTl/SGgzRfAHZs+SKbfhwsdcVC577r0u5mm7a9C/DOrsdo42zXDL1cKv8DGSmLzIMGQTrryo6bOH+6JhHUu0bVdXC8KF13zhQxnbdnjg5NMN7PRfUZWP5iz/bfv2H3FZC7fFfmkxIM+yn4y0XQCPjhrygAZyzMhiUC2cPWBj+iTX/lDRed3qy5RmvHhBiOVwumtzkSCy2kreZ2Kd6xMBk+mfKnjLU9cDd2QDmlyJDjZ8FZlk83AeJr7rPCdRDPVPCxUhFNET605QBrx90HoTr6o+EK8N9KUgCHGuijqLen1aARBpqsWkit2zn371Poi3zQvGL/gEQuR7yGd+0Gi+sx/A/08jxcqKNtNOSO0XbtWzASYnEc8gDup+1CsEkMpvKJ/F5CbmQN2yAV0ZIHhsCpdIQ9uUe3C8lwVkns5oWlfZNX/FWKrqRMk6Nlvobg==\"}" + let envelope = try Envelope(jsonString: json) let service = XMTPRust.ApiService(environment: "http://localhost:5556", secure: false) let response = try await service.query(topic: "test", json_paging_info: "") // Try to parse the response JSON into a QueryResponse From 163537b302b78c45f027a93a9006a15fad7f6949 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sun, 16 Apr 2023 14:44:22 -0700 Subject: [PATCH 09/47] feat: all tests pass with rustClient --- Package.swift | 2 +- Sources/XMTP/ApiClient.swift | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 80e84edc..4a4afcc7 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", from: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "../xmtp_rust_swift/", branch: "local_only_test_005") + .package(url: "../xmtp_rust_swift/", branch: "local_only_test_006") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 7f2c8d87..7aa7a805 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -124,10 +124,8 @@ class GRPCApiClient: ApiClient { func subscribe(topics: [String]) -> AsyncThrowingStream { return AsyncThrowingStream { continuation in Task { - var request = SubscribeRequest() - request.contentTopics = topics - - for try await envelope in self.client.subscribe(request) { + for try await envelopeJson in self.rustClient.subscribe(topics: topics) { + let envelope = try Envelope(jsonString: envelopeJson) continuation.yield(envelope) } } From 393fd9dd6c5983e9ecbb2e6c3872bbdbd23e6239 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sun, 16 Apr 2023 14:50:18 -0700 Subject: [PATCH 10/47] feat: checkpoint - no more GRPC dependency --- Package.swift | 2 +- Sources/XMTP/ApiClient.swift | 23 ----------------------- Sources/XMTP/Client.swift | 1 - 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/Package.swift b/Package.swift index 4a4afcc7..4696caca 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(url: "https://github.com/xmtp/proto", branch: "main"), + .package(url: "https://github.com/xmtp/proto", branch: "ios_minus_grpc_keeping_messageapi"), .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", branch: "main"), .package(url: "https://github.com/argentlabs/web3.swift", from: "1.1.0"), .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 7aa7a805..7fbc8ebf 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -5,7 +5,6 @@ // Created by Pat Nakajima on 11/17/22. // -import GRPC import XMTPProto import XMTPRust @@ -32,21 +31,10 @@ class GRPCApiClient: ApiClient { var environment: XMTPEnvironment var authToken = "" - private var client: Xmtp_MessageApi_V1_MessageApiAsyncClient! private var rustClient: XMTPRust.ApiService! required init(environment: XMTPEnvironment, secure: Bool = true) throws { self.environment = environment - let group = PlatformSupport.makeEventLoopGroup(loopCount: 1) - - let config = GRPCTLSConfiguration.makeClientConfigurationBackedByNIOSSL() - let channel = try GRPCChannelPool.with( - target: .host(environment.rawValue, port: 5556), - transportSecurity: secure ? .tls(config) : .plaintext, - eventLoopGroup: group - ) - - client = Xmtp_MessageApi_V1_MessageApiAsyncClient(channel: channel) // Secure flag is useless for now, XMTPRust checks the URL scheme to see if it's https rustClient = XMTPRust.ApiService(environment:envToUrl(env: environment), secure:true) } @@ -85,11 +73,6 @@ class GRPCApiClient: ApiClient { request.pagingInfo.cursor = cursor } -// var options = CallOptions() -// options.customMetadata.add(name: "authorization", value: "Bearer \(authToken)") -// options.timeLimit = .timeout(.seconds(5)) -// -// return try await client.query(request, callOptions: options) var encodedPaging = "" if request.hasPagingInfo { encodedPaging = try request.pagingInfo.jsonString() @@ -136,12 +119,6 @@ class GRPCApiClient: ApiClient { var request = Xmtp_MessageApi_V1_PublishRequest() request.envelopes = envelopes - var options = CallOptions() - options.customMetadata.add(name: "authorization", value: "Bearer \(authToken)") - options.customMetadata.add(name: ClientVersionHeaderKey, value: Constants.version) - options.customMetadata.add(name: AppVersionHeaderKey, value: Constants.version) - options.timeLimit = .timeout(.seconds(5)) - // return try await client.publish(request, callOptions: options) // Use the JSON encoding api for rustClient to publish let encodedEnvelopes = try envelopes.map { try $0.jsonString() } diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 93665ae8..656312e2 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -6,7 +6,6 @@ // import Foundation -import GRPC import web3 import XMTPProto From c7ac973ab020f081d0ecb2c72b886486a4981d07 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar Date: Mon, 17 Apr 2023 10:27:01 -0700 Subject: [PATCH 11/47] Use remote package --- .../xcshareddata/xcschemes/XMTP.xcscheme | 14 ++- Package.swift | 4 +- .../xcshareddata/swiftpm/Package.resolved | 40 +++----- .../xcshareddata/xcschemes/Example.xcscheme | 77 +++++++++++++++ .../xcschemes/NotificationService.xcscheme | 96 +++++++++++++++++++ 5 files changed, 198 insertions(+), 33 deletions(-) create mode 100644 XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/Example.xcscheme create mode 100644 XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/NotificationService.xcscheme diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/XMTP.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/XMTP.xcscheme index e8eb1fcd..2a93911e 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/XMTP.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/XMTP.xcscheme @@ -70,14 +70,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/NotificationService.xcscheme b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/NotificationService.xcscheme new file mode 100644 index 00000000..63addb81 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/NotificationService.xcscheme @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 332eb0a613b4fb5dff7a4bd1c931c8f5b8c92d42 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Mon, 17 Apr 2023 17:18:41 -0700 Subject: [PATCH 12/47] checkpoint: Getting closer to building, need to fix secp256k1 issues --- .gitignore | 1 + Sources/XMTP/ApiClient.swift | 9 +- Sources/XMTP/KeyUtil.swift | 8 +- Sources/XMTP/Messages/PagingInfo.swift | 2 +- Sources/XMTP/Messages/PrivateKey.swift | 2 +- .../XMTP/Messages/PrivateKeyBundleV2.swift | 4 +- Sources/XMTP/Messages/PublicKey.swift | 2 +- Sources/XMTP/Messages/Signature.swift | 6 +- Sources/XMTP/Messages/SignedPrivateKey.swift | 2 +- Sources/XMTP/Messages/SignedPublicKey.swift | 2 +- Sources/XMTP/Messages/Topic.swift | 2 +- Sources/XMTP/Push/XMTPPush.swift | 2 +- Sources/XMTP/SigningKey.swift | 2 +- XMTP.podspec | 152 ++++++++++++++++++ XMTPiOSExample/Podfile | 37 +++++ XMTPiOSExample/Podfile.lock | 90 +++++++++++ .../XMTPiOSExample.xcodeproj/project.pbxproj | 110 +++++++++++-- .../contents.xcworkspacedata | 10 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 + 19 files changed, 414 insertions(+), 37 deletions(-) create mode 100644 XMTP.podspec create mode 100644 XMTPiOSExample/Podfile create mode 100644 XMTPiOSExample/Podfile.lock create mode 100644 XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata create mode 100644 XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/.gitignore b/.gitignore index 9a09962f..bbb46d66 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ DerivedData/ Package.resolved .vscode +XMTPiOSExample/Pods diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 7fbc8ebf..88713d1d 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -5,13 +5,12 @@ // Created by Pat Nakajima on 11/17/22. // -import XMTPProto import XMTPRust +import XMTPProto - -typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse -typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse -typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest +public typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse +public typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse +public typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest protocol ApiClient { var environment: XMTPEnvironment { get } diff --git a/Sources/XMTP/KeyUtil.swift b/Sources/XMTP/KeyUtil.swift index e046feeb..51030e71 100644 --- a/Sources/XMTP/KeyUtil.swift +++ b/Sources/XMTP/KeyUtil.swift @@ -23,10 +23,10 @@ enum KeyUtil { Logger(label: "web3.swift.key-util") } - static func xmtpGeneratePublicKey(from privateKeyData: Data) throws -> Data { - let privateKey = try secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyData, format: .uncompressed) - return privateKey.publicKey.rawRepresentation - } +// static func xmtpGeneratePublicKey(from privateKeyData: Data) throws -> Data { +// let privateKey = try secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyData, format: .uncompressed) +// return privateKey.publicKey.rawRepresentation +// } static func sign(message: Data, with privateKey: Data, hashing: Bool) throws -> Data { guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)) else { diff --git a/Sources/XMTP/Messages/PagingInfo.swift b/Sources/XMTP/Messages/PagingInfo.swift index cdde34d8..e8977f0f 100644 --- a/Sources/XMTP/Messages/PagingInfo.swift +++ b/Sources/XMTP/Messages/PagingInfo.swift @@ -12,7 +12,7 @@ typealias PagingInfo = Xmtp_MessageApi_V1_PagingInfo typealias PagingInfoCursor = Xmtp_MessageApi_V1_Cursor typealias PagingInfoSortDirection = Xmtp_MessageApi_V1_SortDirection -struct Pagination { +public struct Pagination { var limit: Int? var direction: PagingInfoSortDirection? var startTime: Date? diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 2aa9a94b..7542d2f6 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift index a1544568..0221b975 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto public typealias PrivateKeyBundleV2 = Xmtp_MessageContents_PrivateKeyBundleV2 @@ -35,7 +35,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - let publicKey = try secp256k1.Signing.PublicKey(rawRepresentation: publicData, format: .uncompressed) + let publicKey = try secp256k1.Signing.PublicKey(rawRepresentation: publicData.bytes, format: .uncompressed) let sharedSecret = try publicKey.multiply(privateData.bytes, format: .uncompressed) diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTP/Messages/PublicKey.swift index 6ea5d844..7b612ae7 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTP/Messages/PublicKey.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto typealias PublicKey = Xmtp_MessageContents_PublicKey diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 4faa5b23..5978cc55 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto /// Represents a secp256k1 compact recoverable signature. @@ -103,9 +103,9 @@ extension Signature { } func verify(signedBy: PublicKey, digest: Data) throws -> Bool { - let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes, recoveryId: Int32(ecdsaCompact.recovery)) + let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes.bytes, recoveryId: Int32(ecdsaCompact.recovery)) let ecdsaSignature = try recoverySignature.normalize - let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes, format: .uncompressed) + let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes.bytes, format: .uncompressed) return signingKey.ecdsa.isValidSignature(ecdsaSignature, for: digest) } diff --git a/Sources/XMTP/Messages/SignedPrivateKey.swift b/Sources/XMTP/Messages/SignedPrivateKey.swift index 13a8ba8b..e1865d70 100644 --- a/Sources/XMTP/Messages/SignedPrivateKey.swift +++ b/Sources/XMTP/Messages/SignedPrivateKey.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto public typealias SignedPrivateKey = Xmtp_MessageContents_SignedPrivateKey diff --git a/Sources/XMTP/Messages/SignedPublicKey.swift b/Sources/XMTP/Messages/SignedPublicKey.swift index 7d1eefbe..368ffbc5 100644 --- a/Sources/XMTP/Messages/SignedPublicKey.swift +++ b/Sources/XMTP/Messages/SignedPublicKey.swift @@ -7,7 +7,7 @@ import CryptoKit import Foundation -import secp256k1 +import secp256k1Swift import XMTPProto typealias SignedPublicKey = Xmtp_MessageContents_SignedPublicKey diff --git a/Sources/XMTP/Messages/Topic.swift b/Sources/XMTP/Messages/Topic.swift index 276ab3d1..c1ec7c5a 100644 --- a/Sources/XMTP/Messages/Topic.swift +++ b/Sources/XMTP/Messages/Topic.swift @@ -7,7 +7,7 @@ import XMTPProto -enum Topic { +public enum Topic { case userPrivateStoreKeyBundle(String), contact(String), userIntro(String), diff --git a/Sources/XMTP/Push/XMTPPush.swift b/Sources/XMTP/Push/XMTPPush.swift index c17aef90..005b1bfc 100644 --- a/Sources/XMTP/Push/XMTPPush.swift +++ b/Sources/XMTP/Push/XMTPPush.swift @@ -40,7 +40,7 @@ public struct XMTPPush { } if try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge]) { - await UIApplication.shared.registerForRemoteNotifications() +// await UIApplication.shared.registerForRemoteNotifications() return true } diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTP/SigningKey.swift index a0448096..f0699dd9 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTP/SigningKey.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1 +import secp256k1Swift /// Defines a type that is used by a ``Client`` to sign keys and messages. /// diff --git a/XMTP.podspec b/XMTP.podspec new file mode 100644 index 00000000..e038720d --- /dev/null +++ b/XMTP.podspec @@ -0,0 +1,152 @@ +# +# Be sure to run `pod spec lint XMTP.podspec' to ensure this is a +# valid spec and to remove all comments including this before submitting the spec. +# +# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html +# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ +# + +Pod::Spec.new do |spec| + + # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # These will help people to find your library, and whilst it + # can feel like a chore to fill in it's definitely to your advantage. The + # summary should be tweet-length, and the description more in depth. + # + + spec.name = "XMTP" + spec.version = "0.1.1" + spec.summary = "XMTP pod." + + # This description is used to generate tags and improve search results. + # * Think: What does it do? Why did you write it? What is the focus? + # * Try to keep it short, snappy and to the point. + # * Write the description between the DESC delimiters below. + # * Finally, don't worry about the indent, CocoaPods strips it! + spec.description = <<-DESC + TODO + DESC + + spec.homepage = "https://github.com/xmtp/xmtp-ios" + # spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" + + + # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Licensing your code is important. See https://choosealicense.com for more info. + # CocoaPods will detect a license file if there is a named LICENSE* + # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. + # + + spec.license = "MIT" + # spec.license = { :type => "MIT", :file => "FILE_LICENSE" } + + + # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Specify the authors of the library, with email addresses. Email addresses + # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also + # accepts just a name if you'd rather not provide an email address. + # + # Specify a social_media_url where others can refer to, for example a twitter + # profile URL. + # + + spec.author = { "Pat Nakajima" => "pat@xmtp.com" } + # Or just: spec.author = "Pat Nakajima" + # spec.authors = { "Pat Nakajima" => "patnakajima@gmail.com" } + # spec.social_media_url = "https://twitter.com/Pat Nakajima" + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If this Pod runs only on iOS or OS X, then specify the platform and + # the deployment target. You can optionally include the target after the platform. + # + + # spec.platform = :ios + spec.platform = :ios, "16.0" + + # When using multiple platforms + # spec.ios.deployment_target = "5.0" + # spec.osx.deployment_target = "10.7" + # spec.watchos.deployment_target = "2.0" + # spec.tvos.deployment_target = "9.0" + + + # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Specify the location from where the source should be retrieved. + # Supports git, hg, bzr, svn and HTTP. + # + + spec.source = { :git => "https://github.com/xmtp/xmtp-ios.git", :tag => "#{spec.version}" } + + + # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # CocoaPods is smart about how it includes source code. For source files + # giving a folder will include any swift, h, m, mm, c & cpp files. + # For header files it will include any header in the folder. + # Not including the public_header_files will make all headers public. + # + + spec.source_files = "Sources/**/*.swift" + + # spec.public_header_files = "Classes/**/*.h" + + + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # A list of resources included with the Pod. These are copied into the + # target bundle with a build phase script. Anything else will be cleaned. + # You can preserve files from being cleaned, please don't preserve + # non-essential files like tests, examples and documentation. + # + + # spec.resource = "icon.png" + # spec.resources = "Resources/*.png" + + # spec.preserve_paths = "FilesToSave", "MoreFilesToSave" + + + # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Link your library with frameworks, or libraries. Libraries do not include + # the lib prefix of their name. + # + + # spec.framework = "SomeFramework" + spec.frameworks = "CryptoKit", "UIKit" + + # spec.library = "iconv" + # spec.libraries = "iconv", "xml2" + + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If your library depends on compiler flags you can set them in the xcconfig hash + # where they will only apply to your library. If you depend on other Podspecs + # you can include multiple dependencies to ensure it works. + + # spec.requires_arc = true + + # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } + spec.dependency "secp256k1Swift" + spec.dependency "web3.swift" + spec.dependency "GzipSwift" + spec.dependency "Connect-Swift" + + spec.subspec 'XMTPProto' do |subspec| + subspec.dependency "SwiftProtobuf" + subspec.source_files = "../proto/**/*.swift" + end + + spec.subspec 'XMTPRust' do |subspec| + subspec.source_files = "../xmtp-rust-swift/**/*.swift" + subspec.vendored_frameworks = 'XMTPRustSwift.xcframework' + end + + spec.dependency 'XMTPProto' + spec.dependency 'XMTPRust' +end diff --git a/XMTPiOSExample/Podfile b/XMTPiOSExample/Podfile new file mode 100644 index 00000000..caadb8b8 --- /dev/null +++ b/XMTPiOSExample/Podfile @@ -0,0 +1,37 @@ +# Uncomment the next line to define a global platform for your project +platform :ios, '16.0' + +target 'NotificationService' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + # Pods for NotificationService + # Pods for XMTPiOSExample + # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" + pod "web3.swift" + pod "XMTPProto", path: "../../proto" + pod "XMTPRust", path: '../../xmtp-rust-swift' + pod "XMTP", path: "../" +end + +target 'XMTPiOSExample' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + # Pods for XMTPiOSExample + # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" + pod "web3.swift" + pod "XMTPProto", path: "../../proto" + pod "XMTPRust", path: '../../xmtp-rust-swift' + pod "XMTP", path: "../" +end + +post_install do |installer| + installer.generated_projects.each do |project| + project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' + end + end + end +end diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock new file mode 100644 index 00000000..b42e710c --- /dev/null +++ b/XMTPiOSExample/Podfile.lock @@ -0,0 +1,90 @@ +PODS: + - BigInt (5.0.0) + - Connect-Swift (0.5.0): + - SwiftProtobuf (~> 1.21.0) + - GenericJSON (2.0.2) + - GzipSwift (5.1.1) + - Logging (1.0.0) + - secp256k1.swift (0.1.4) + - secp256k1Swift (0.7.4): + - secp256k1Wrapper (~> 0.0.5) + - secp256k1Wrapper (0.0.5) + - SwiftProtobuf (1.21.0) + - web3.swift (1.6.0): + - BigInt (~> 5.0.0) + - GenericJSON (~> 2.0) + - Logging (~> 1.0.0) + - secp256k1.swift (~> 0.1) + - XMTP (0.1.1): + - Connect-Swift + - GzipSwift + - secp256k1Swift + - web3.swift + - XMTP/XMTPProto (= 0.1.1) + - XMTP/XMTPRust (= 0.1.1) + - XMTPProto + - XMTPRust + - XMTP/XMTPProto (0.1.1): + - Connect-Swift + - GzipSwift + - secp256k1Swift + - SwiftProtobuf + - web3.swift + - XMTPProto + - XMTPRust + - XMTP/XMTPRust (0.1.1): + - Connect-Swift + - GzipSwift + - secp256k1Swift + - web3.swift + - XMTPProto + - XMTPRust + - XMTPProto (0.1.0): + - SwiftProtobuf + - XMTPRust (0.1.0) + +DEPENDENCIES: + - web3.swift + - XMTP (from `../`) + - XMTPProto (from `../../proto`) + - XMTPRust (from `../../xmtp-rust-swift`) + +SPEC REPOS: + trunk: + - BigInt + - Connect-Swift + - GenericJSON + - GzipSwift + - Logging + - secp256k1.swift + - secp256k1Swift + - secp256k1Wrapper + - SwiftProtobuf + - web3.swift + +EXTERNAL SOURCES: + XMTP: + :path: "../" + XMTPProto: + :path: "../../proto" + XMTPRust: + :path: "../../xmtp-rust-swift" + +SPEC CHECKSUMS: + BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 + Connect-Swift: a75380c30c1341e483012444044105ff49b6093a + GenericJSON: 79a840eeb77030962e8cf02a62d36bd413b67626 + GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa + Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 + secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 + secp256k1Swift: ea49d2b06724444a03cf7938a2d3fc7acc4c0f08 + secp256k1Wrapper: 0378417cd06d51187bbc9e178ec318e7902e2120 + SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 + web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 + XMTP: 05a334f36c98e8a05bef19c41372f87c1c487bdc + XMTPProto: 929b9d316e220ff9d321eea2318d8bdcb3d73991 + XMTPRust: 7809eb7e3fda3d095f1359fa86de041b4d55bb73 + +PODFILE CHECKSUM: a5714547991f401af3096df5f89f36fa1e550806 + +COCOAPODS: 1.11.3 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index b6e0eadf..6bf92874 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 6AEE396D29F330CD0027B657 /* secp256k1 */; }; + 32C62D213641651EBC32117E /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */; }; A60FC8BF293AD054001697E3 /* MessageComposerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8BE293AD054001697E3 /* MessageComposerView.swift */; }; A60FC8C1293AD171001697E3 /* ConversationDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */; }; A60FC8C3293AD18A001697E3 /* PreviewClientProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */; }; @@ -25,15 +26,14 @@ A687810729679BC700042FAB /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810629679BC700042FAB /* Account.swift */; }; A687810C29679BFC00042FAB /* WalletConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810B29679BFC00042FAB /* WalletConnection.swift */; }; A687810E29679C0D00042FAB /* WalletConnectionMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810D29679C0D00042FAB /* WalletConnectionMethod.swift */; }; - A69F33C6292DC992005A5556 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A69F33C5292DC992005A5556 /* XMTP */; }; A69F33CA292DD557005A5556 /* LoggedInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A69F33C9292DD557005A5556 /* LoggedInView.swift */; }; A69F33CC292DD568005A5556 /* QRCodeSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A69F33CB292DD568005A5556 /* QRCodeSheetView.swift */; }; A6AE5187297B61AE006FDD0F /* NotificationService.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A6AE5180297B61AE006FDD0F /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; A6AE518E297B6210006FDD0F /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AE518C297B6210006FDD0F /* NotificationService.swift */; }; - A6AE5191297B625F006FDD0F /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A6AE5190297B625F006FDD0F /* XMTP */; }; A6AE5192297B6270006FDD0F /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A6AE5193297B62C8006FDD0F /* KeychainAccess */; }; A6D192D0293A7B97006B49F2 /* ConversationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D192CF293A7B97006B49F2 /* ConversationListView.swift */; }; + B815305000C45E0BDC765F4E /* Pods_XMTPiOSExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -61,6 +61,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMTPiOSExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.release.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.release.xcconfig"; sourceTree = ""; }; + 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = ""; }; A60FC8BE293AD054001697E3 /* MessageComposerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView.swift; sourceTree = ""; }; A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationDetailView.swift; sourceTree = ""; }; A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewClientProvider.swift; sourceTree = ""; }; @@ -78,13 +81,15 @@ A687810629679BC700042FAB /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; A687810B29679BFC00042FAB /* WalletConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletConnection.swift; sourceTree = ""; }; A687810D29679C0D00042FAB /* WalletConnectionMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletConnectionMethod.swift; sourceTree = ""; }; - A69F33C7292DD3A9005A5556 /* xmtp-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "xmtp-ios"; path = ..; sourceTree = ""; }; A69F33C9292DD557005A5556 /* LoggedInView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggedInView.swift; sourceTree = ""; }; A69F33CB292DD568005A5556 /* QRCodeSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeSheetView.swift; sourceTree = ""; }; A6AE5180297B61AE006FDD0F /* NotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A6AE518B297B61C8006FDD0F /* NotificationService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationService.entitlements; sourceTree = ""; }; A6AE518C297B6210006FDD0F /* NotificationService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; A6D192CF293A7B97006B49F2 /* ConversationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationListView.swift; sourceTree = ""; }; + AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = ""; }; + B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.debug.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -96,6 +101,7 @@ 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */, A69F33C6292DC992005A5556 /* XMTP in Frameworks */, A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */, + B815305000C45E0BDC765F4E /* Pods_XMTPiOSExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -104,21 +110,32 @@ buildActionMask = 2147483647; files = ( A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */, - A6AE5191297B625F006FDD0F /* XMTP in Frameworks */, + 32C62D213641651EBC32117E /* Pods_NotificationService.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3F738A9EAAA632479874E954 /* Pods */ = { + isa = PBXGroup; + children = ( + 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */, + AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */, + B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */, + 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; A6281986292DC825004B9117 = { isa = PBXGroup; children = ( - A69F33C7292DD3A9005A5556 /* xmtp-ios */, A6281991292DC825004B9117 /* XMTPiOSExample */, A6AE5181297B61AE006FDD0F /* NotificationService */, A6281990292DC825004B9117 /* Products */, A69F33C4292DC992005A5556 /* Frameworks */, + 3F738A9EAAA632479874E954 /* Pods */, ); sourceTree = ""; }; @@ -168,6 +185,8 @@ A69F33C4292DC992005A5556 /* Frameworks */ = { isa = PBXGroup; children = ( + B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */, + 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */, ); name = Frameworks; sourceTree = ""; @@ -204,10 +223,12 @@ isa = PBXNativeTarget; buildConfigurationList = A628199E292DC826004B9117 /* Build configuration list for PBXNativeTarget "XMTPiOSExample" */; buildPhases = ( + C50343F196FCC7C930B85889 /* [CP] Check Pods Manifest.lock */, A628198B292DC825004B9117 /* Sources */, A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, A65F0701297B5BCC00C3C76E /* Embed Foundation Extensions */, + 00BCA10454D1CCB2B86AC7A0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -216,7 +237,6 @@ ); name = XMTPiOSExample; packageProductDependencies = ( - A69F33C5292DC992005A5556 /* XMTP */, A65F0706297B5E7600C3C76E /* WalletConnectSwift */, A65F0709297B5E8600C3C76E /* KeychainAccess */, 6AEE396D29F330CD0027B657 /* secp256k1 */, @@ -229,6 +249,7 @@ isa = PBXNativeTarget; buildConfigurationList = A6AE5188297B61AE006FDD0F /* Build configuration list for PBXNativeTarget "NotificationService" */; buildPhases = ( + F3EFD13DA11B8942E54F4C0B /* [CP] Check Pods Manifest.lock */, A6AE517C297B61AE006FDD0F /* Sources */, A6AE517D297B61AE006FDD0F /* Frameworks */, A6AE517E297B61AE006FDD0F /* Resources */, @@ -239,7 +260,6 @@ ); name = NotificationService; packageProductDependencies = ( - A6AE5190297B625F006FDD0F /* XMTP */, A6AE5193297B62C8006FDD0F /* KeychainAccess */, ); productName = NotificationService; @@ -307,6 +327,70 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 00BCA10454D1CCB2B86AC7A0 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + C50343F196FCC7C930B85889 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-XMTPiOSExample-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + F3EFD13DA11B8942E54F4C0B /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ A628198B292DC825004B9117 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -462,6 +546,7 @@ }; A628199F292DC826004B9117 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -502,6 +587,7 @@ }; A62819A0292DC826004B9117 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -541,6 +627,7 @@ }; A6AE5189297B61AE006FDD0F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -569,6 +656,7 @@ }; A6AE518A297B61AE006FDD0F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -671,14 +759,6 @@ package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; - A69F33C5292DC992005A5556 /* XMTP */ = { - isa = XCSwiftPackageProductDependency; - productName = XMTP; - }; - A6AE5190297B625F006FDD0F /* XMTP */ = { - isa = XCSwiftPackageProductDependency; - productName = XMTP; - }; A6AE5193297B62C8006FDD0F /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata b/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..157b58d4 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 44395a0ae95955143a7e564d039a6e19a3f23e24 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 18 Apr 2023 09:05:55 -0700 Subject: [PATCH 13/47] wip: commit code calling secp256k1 --- Package.swift | 2 +- Sources/XMTP/Messages/PrivateKey.swift | 4 +- .../XMTP/Messages/PrivateKeyBundleV2.swift | 8 +-- Sources/XMTP/Messages/PublicKey.swift | 4 +- Sources/XMTP/Messages/Signature.swift | 27 ++++----- Sources/XMTP/Messages/SignedPrivateKey.swift | 1 - Sources/XMTP/Messages/SignedPublicKey.swift | 1 - Sources/XMTP/SigningKey.swift | 1 - Tests/XMTPTests/AuthenticationTests.swift | 1 - Tests/XMTPTests/IntegrationTests.swift | 60 ++++++++++--------- 10 files changed, 51 insertions(+), 58 deletions(-) diff --git a/Package.swift b/Package.swift index 75aac444..8224ecac 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", from: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/xmtp-rust-swift/", branch: "local_only_test_008") + .package(url: "../xmtp-rust-swift/", branch: "michaelx_secp256k1_wip") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 7542d2f6..1acddbbd 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -6,8 +6,8 @@ // import Foundation -import secp256k1Swift import XMTPProto +import XMTPRust /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it /// to create a ``Client``. @@ -77,7 +77,7 @@ public extension PrivateKey { internal func sign(key: UnsignedPublicKey) async throws -> SignedPublicKey { let bytes = try key.serializedData() - let digest = SHA256.hash(data: bytes) + let digest = XMTPRust.CoreCrypto.sha256(data: bytes) let signature = try await sign(Data(digest.bytes)) var signedPublicKey = SignedPublicKey() diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift index 0221b975..d832529b 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1Swift +import XMTPRust import XMTPProto public typealias PrivateKeyBundleV2 = Xmtp_MessageContents_PrivateKeyBundleV2 @@ -35,11 +35,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - let publicKey = try secp256k1.Signing.PublicKey(rawRepresentation: publicData.bytes, format: .uncompressed) - - let sharedSecret = try publicKey.multiply(privateData.bytes, format: .uncompressed) - - return sharedSecret.rawRepresentation + return try XMTPRust.CoreCrypto.diffie_hellman_k256(privateKeyBytes: privateData, publicKeyBytes: publicData) } func findPreKey(_ myPreKey: SignedPublicKey) throws -> SignedPrivateKey { diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTP/Messages/PublicKey.swift index 7b612ae7..b5648a0a 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTP/Messages/PublicKey.swift @@ -6,8 +6,8 @@ // import Foundation -import secp256k1Swift import XMTPProto +import XMTPRust typealias PublicKey = Xmtp_MessageContents_PublicKey @@ -73,7 +73,7 @@ extension PublicKey { slimKey.timestamp = timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData) + let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(XMTPRust.CoreCrypto.sha256(data: bytesToSign)), signature: signature.rawData) return try PublicKey(pubKeyData) } diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 5978cc55..0d9633df 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -6,7 +6,7 @@ // import Foundation -import secp256k1Swift +import XMTPRust import XMTPProto /// Represents a secp256k1 compact recoverable signature. @@ -102,21 +102,16 @@ extension Signature { } } - func verify(signedBy: PublicKey, digest: Data) throws -> Bool { - let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes.bytes, recoveryId: Int32(ecdsaCompact.recovery)) - let ecdsaSignature = try recoverySignature.normalize - let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes.bytes, format: .uncompressed) - - return signingKey.ecdsa.isValidSignature(ecdsaSignature, for: digest) - } - - func verify(signedBy: PublicKey, digest: any Digest) throws -> Bool { - let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes, recoveryId: Int32(ecdsaCompact.recovery)) - let ecdsaSignature = try recoverySignature.normalize - let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes, format: .uncompressed) - - return signingKey.ecdsa.isValidSignature(ecdsaSignature, for: digest) - } + func verify(signedBy: PublicKey, digest: Data) throws -> Bool { + // let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes, recoveryId: Int32(ecdsaCompact.recovery)) + // let ecdsaSignature = try recoverySignature.normalize + // let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes, format: .uncompressed) + // + // return signingKey.ecdsa.isValidSignature(ecdsaSignature, for: digest) + // NOTE: it says "digest" in this function header but really it's the message. The verify_k256_sha256 function does + // the additional sha256 operation to convert the message into 32 bytes. + return try XMTPRust.CoreCrypto.verify_k256_sha256(publicKeyBytes: signedBy.secp256K1Uncompressed.bytes, message: digest, signature: ecdsaCompact.bytes, recoveryId: UInt8(ecdsaCompact.recovery)) + } } extension Signature: Codable { diff --git a/Sources/XMTP/Messages/SignedPrivateKey.swift b/Sources/XMTP/Messages/SignedPrivateKey.swift index e1865d70..0b2ce11d 100644 --- a/Sources/XMTP/Messages/SignedPrivateKey.swift +++ b/Sources/XMTP/Messages/SignedPrivateKey.swift @@ -6,7 +6,6 @@ // import Foundation -import secp256k1Swift import XMTPProto public typealias SignedPrivateKey = Xmtp_MessageContents_SignedPrivateKey diff --git a/Sources/XMTP/Messages/SignedPublicKey.swift b/Sources/XMTP/Messages/SignedPublicKey.swift index 368ffbc5..5d717a70 100644 --- a/Sources/XMTP/Messages/SignedPublicKey.swift +++ b/Sources/XMTP/Messages/SignedPublicKey.swift @@ -7,7 +7,6 @@ import CryptoKit import Foundation -import secp256k1Swift import XMTPProto typealias SignedPublicKey = Xmtp_MessageContents_SignedPublicKey diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTP/SigningKey.swift index f0699dd9..02d32d9e 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTP/SigningKey.swift @@ -6,7 +6,6 @@ // import Foundation -import secp256k1Swift /// Defines a type that is used by a ``Client`` to sign keys and messages. /// diff --git a/Tests/XMTPTests/AuthenticationTests.swift b/Tests/XMTPTests/AuthenticationTests.swift index 8ddd41f8..2cc76568 100644 --- a/Tests/XMTPTests/AuthenticationTests.swift +++ b/Tests/XMTPTests/AuthenticationTests.swift @@ -7,7 +7,6 @@ import Foundation -import secp256k1 import XCTest @testable import XMTP diff --git a/Tests/XMTPTests/IntegrationTests.swift b/Tests/XMTPTests/IntegrationTests.swift index 2f46efa6..1f2c0cb4 100644 --- a/Tests/XMTPTests/IntegrationTests.swift +++ b/Tests/XMTPTests/IntegrationTests.swift @@ -14,33 +14,39 @@ import XMTPTestHelpers @available(iOS 16, *) final class IntegrationTests: XCTestCase { - func testSaveKey() async throws { - throw XCTSkip("integration only (requires local node)") - - let alice = try PrivateKey.generate() - let identity = try PrivateKey.generate() - - let authorized = try await alice.createIdentity(identity) - - let authToken = try await authorized.createAuthToken() - - let api = try GRPCApiClient(environment: .local, secure: false) - api.setAuthToken(authToken) - - let encryptedBundle = try await authorized.toBundle.encrypted(with: alice) - - var envelope = Envelope() - envelope.contentTopic = Topic.userPrivateStoreKeyBundle(authorized.address).description - envelope.timestampNs = UInt64(Date().millisecondsSinceEpoch) * 1_000_000 - envelope.message = try encryptedBundle.serializedData() - - try await api.publish(envelopes: [envelope]) - - try await Task.sleep(nanoseconds: 2_000_000_000) - - let result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) - XCTAssert(result.envelopes.count == 1) - } + func testSaveKey() async throws { + for i in 1...1 { + let alice = try PrivateKey.generate() + let identity = try PrivateKey.generate() + + let authorized = try await alice.createIdentity(identity) + + let authToken = try await authorized.createAuthToken() + + let api = try GRPCApiClient(environment: .local, secure: false) + api.setAuthToken(authToken) + + let encryptedBundle = try await authorized.toBundle.encrypted(with: alice) + + var envelope = Envelope() + envelope.contentTopic = Topic.userPrivateStoreKeyBundle(authorized.address).description + envelope.timestampNs = UInt64(Date().millisecondsSinceEpoch) * 1_000_000 + envelope.message = try encryptedBundle.serializedData() + + try await api.publish(envelopes: [envelope]) + + try await Task.sleep(nanoseconds: 20_000_000) + var result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) + let starttime = Date().millisecondsSinceEpoch + + for u in 1...10000 { + result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) + } + XCTAssert(result.envelopes.count == 1) + let endtime = Date().millisecondsSinceEpoch + XCTAssertEqual(0.0, (endtime - starttime) / (10000000.0)) + } + } func testPublishingAndFetchingContactBundlesWithWhileGeneratingKeys() async throws { throw XCTSkip("integration only (requires local node)") From 35d56886406c4188183afe550bc32e19598c0ec0 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 12:55:14 -0700 Subject: [PATCH 14/47] wip --- Sources/XMTP/Client.swift | 2 ++ Sources/XMTP/Messages/PrivateKey.swift | 5 +++-- Sources/XMTP/Messages/PrivateKeyBundleV1.swift | 10 ++++++++++ Sources/XMTPTestHelpers/TestHelpers.swift | 2 ++ XMTPiOSExample/Podfile.lock | 18 ++++-------------- .../XMTPiOSExample/ContentView.swift | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 656312e2..20245690 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -113,6 +113,8 @@ public class Client { authorizedIdentity.address = account.address let authToken = try await authorizedIdentity.createAuthToken() + print("authToken: \(authToken)") + let apiClient = apiClient apiClient.setAuthToken(authToken) diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 1acddbbd..af0ea766 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -8,6 +8,7 @@ import Foundation import XMTPProto import XMTPRust +import web3 /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it /// to create a ``Client``. @@ -54,7 +55,7 @@ public extension PrivateKey { timestamp = UInt64(Date().millisecondsSinceEpoch) secp256K1.bytes = privateKeyData - let publicData = try KeyUtil.xmtpGeneratePublicKey(from: privateKeyData) + let publicData = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: privateKeyData) publicKey.secp256K1Uncompressed.bytes = publicData publicKey.timestamp = timestamp } @@ -78,7 +79,7 @@ public extension PrivateKey { internal func sign(key: UnsignedPublicKey) async throws -> SignedPublicKey { let bytes = try key.serializedData() let digest = XMTPRust.CoreCrypto.sha256(data: bytes) - let signature = try await sign(Data(digest.bytes)) + let signature = try await sign(digest) var signedPublicKey = SignedPublicKey() signedPublicKey.signature = signature diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift index 5185a510..8b64e64c 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift @@ -32,6 +32,16 @@ extension PrivateKeyBundleV1 { preKey.publicKey.signature = signedPublicKey.signature bundle.v1.preKeys = [preKey] + print("account private key: \(privateKey.secp256K1.bytes.toHex)") + print("account public key: \(privateKey.publicKey.secp256K1Uncompressed.bytes.toHex)") + print("identity private: \(bundle.v1.identityKey.secp256K1.bytes.toHex)") + print("identity public: \(bundle.v1.identityKey.publicKey.secp256K1Uncompressed.bytes.toHex)") + print("identity key signature: \(authorizedIdentity.identity.publicKey.signature.rawData.toHex)") + print("pre key private: \(preKey.secp256K1.bytes.toHex)") + print("pre key public: \(preKey.publicKey.secp256K1Uncompressed.bytes.toHex)") + + print("pre key signature: \(signedPublicKey.signature.rawData.toHex)") + return bundle.v1 } diff --git a/Sources/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index 4aac8d84..1b4e4dfe 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -5,6 +5,7 @@ // Created by Pat Nakajima on 12/6/22. // +#if canImport(XCTest) import Combine import XCTest @testable import XMTP @@ -234,3 +235,4 @@ public extension XCTestCase { return try! await Fixtures() } } +#endif diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index b42e710c..6c724d28 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -6,9 +6,6 @@ PODS: - GzipSwift (5.1.1) - Logging (1.0.0) - secp256k1.swift (0.1.4) - - secp256k1Swift (0.7.4): - - secp256k1Wrapper (~> 0.0.5) - - secp256k1Wrapper (0.0.5) - SwiftProtobuf (1.21.0) - web3.swift (1.6.0): - BigInt (~> 5.0.0) @@ -18,7 +15,6 @@ PODS: - XMTP (0.1.1): - Connect-Swift - GzipSwift - - secp256k1Swift - web3.swift - XMTP/XMTPProto (= 0.1.1) - XMTP/XMTPRust (= 0.1.1) @@ -27,7 +23,6 @@ PODS: - XMTP/XMTPProto (0.1.1): - Connect-Swift - GzipSwift - - secp256k1Swift - SwiftProtobuf - web3.swift - XMTPProto @@ -35,13 +30,12 @@ PODS: - XMTP/XMTPRust (0.1.1): - Connect-Swift - GzipSwift - - secp256k1Swift - web3.swift - XMTPProto - XMTPRust - XMTPProto (0.1.0): - SwiftProtobuf - - XMTPRust (0.1.0) + - XMTPRust (0.1.1) DEPENDENCIES: - web3.swift @@ -57,8 +51,6 @@ SPEC REPOS: - GzipSwift - Logging - secp256k1.swift - - secp256k1Swift - - secp256k1Wrapper - SwiftProtobuf - web3.swift @@ -77,13 +69,11 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 - secp256k1Swift: ea49d2b06724444a03cf7938a2d3fc7acc4c0f08 - secp256k1Wrapper: 0378417cd06d51187bbc9e178ec318e7902e2120 SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 05a334f36c98e8a05bef19c41372f87c1c487bdc - XMTPProto: 929b9d316e220ff9d321eea2318d8bdcb3d73991 - XMTPRust: 7809eb7e3fda3d095f1359fa86de041b4d55bb73 + XMTP: 5a89e947bcfbf6f8dfb1f8e2dc708fa30753f3ee + XMTPProto: 8e329d4a799e6c5dea2e8c3988ec48d54571809b + XMTPRust: d7c7f090e9993bb8cf5517f11e1622ff3a0c29af PODFILE CHECKSUM: a5714547991f401af3096df5f89f36fa1e550806 diff --git a/XMTPiOSExample/XMTPiOSExample/ContentView.swift b/XMTPiOSExample/XMTPiOSExample/ContentView.swift index 785ac15a..6ba08b98 100644 --- a/XMTPiOSExample/XMTPiOSExample/ContentView.swift +++ b/XMTPiOSExample/XMTPiOSExample/ContentView.swift @@ -105,7 +105,7 @@ struct ContentView: View { Task { do { let wallet = try PrivateKey.generate() - let client = try await Client.create(account: wallet) + let client = try! await Client.create(account: wallet) let keysData = try client.privateKeyBundle.serializedData() Persistence().saveKeys(keysData) From 58e893c8dcf821f35c74f5bf44e87c7b6727421a Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 14:34:58 -0700 Subject: [PATCH 15/47] wip --- Sources/XMTP/AuthorizedIdentity.swift | 2 ++ Sources/XMTP/Client.swift | 2 -- Sources/XMTP/Messages/MessageV2.swift | 8 +++++++- Sources/XMTP/Messages/PrivateKey.swift | 8 +++++--- Sources/XMTP/Messages/PrivateKeyBundleV1.swift | 5 +++++ Sources/XMTP/Messages/PublicKey.swift | 16 ++++++++++++++-- Sources/XMTP/SigningKey.swift | 4 +++- XMTPiOSExample/XMTPiOSExample/ContentView.swift | 2 +- dev/local/docker-compose.yml | 4 +++- script/local | 2 +- 10 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Sources/XMTP/AuthorizedIdentity.swift b/Sources/XMTP/AuthorizedIdentity.swift index a4ff3e31..4cdc97c3 100644 --- a/Sources/XMTP/AuthorizedIdentity.swift +++ b/Sources/XMTP/AuthorizedIdentity.swift @@ -17,6 +17,8 @@ struct AuthorizedIdentity { let authDataBytes = try authData.serializedData() let signature = try await identity.sign(Util.keccak256(authDataBytes)) + print("SIG: \(signature.rawData.toHex)") + var token = Token() token.identityKey = authorized diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 20245690..656312e2 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -113,8 +113,6 @@ public class Client { authorizedIdentity.address = account.address let authToken = try await authorizedIdentity.createAuthToken() - print("authToken: \(authToken)") - let apiClient = apiClient apiClient.setAuthToken(authToken) diff --git a/Sources/XMTP/Messages/MessageV2.swift b/Sources/XMTP/Messages/MessageV2.swift index a905c20c..9c044b54 100644 --- a/Sources/XMTP/Messages/MessageV2.swift +++ b/Sources/XMTP/Messages/MessageV2.swift @@ -8,6 +8,8 @@ import CryptoKit import Foundation import XMTPProto +import XMTPRust +import web3 typealias MessageV2 = Xmtp_MessageContents_MessageV2 @@ -44,7 +46,11 @@ extension MessageV2 { let digest = SHA256.hash(data: message.headerBytes + signed.payload) let key = try PublicKey.with { key in - key.secp256K1Uncompressed.bytes = try KeyUtil.recoverPublicKey(message: Data(digest.bytes), signature: signed.signature.rawData) + guard let bytes = try KeyUtil.recoverPublicKey(message: Data(digest), signature: signed.signature.rawData).web3.bytesFromHex else { + throw MessageV2Error.decodeError("invalid bytes") + } + + key.secp256K1Uncompressed.bytes = Data(bytes) } if key.walletAddress != (try PublicKey(signed.sender.preKey).walletAddress) { diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index af0ea766..7a4d57f0 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -8,6 +8,7 @@ import Foundation import XMTPProto import XMTPRust +import CryptoKit import web3 /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it @@ -68,7 +69,8 @@ public extension PrivateKey { } static func generate() throws -> PrivateKey { - let data = Data(try Crypto.secureRandomBytes(count: 32)) +// let data = Data(try Crypto.secureRandomBytes(count: 32)) + let data = "7ec7bca44abcf7aefac9d6d0c99e532590a3478114a11759303cf72a72544473".web3.hexData! return try PrivateKey(data) } @@ -78,8 +80,8 @@ public extension PrivateKey { internal func sign(key: UnsignedPublicKey) async throws -> SignedPublicKey { let bytes = try key.serializedData() - let digest = XMTPRust.CoreCrypto.sha256(data: bytes) - let signature = try await sign(digest) + let digest = SHA256.hash(data: bytes) + let signature = try await sign(Data(digest)) var signedPublicKey = SignedPublicKey() signedPublicKey.signature = signature diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift index 8b64e64c..d2f407fe 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift @@ -7,6 +7,8 @@ import CryptoKit import Foundation +import web3 +import XMTPRust import XMTPProto public typealias PrivateKeyBundleV1 = Xmtp_MessageContents_PrivateKeyBundleV1 @@ -32,6 +34,9 @@ extension PrivateKeyBundleV1 { preKey.publicKey.signature = signedPublicKey.signature bundle.v1.preKeys = [preKey] + + print("authorized identity address: \(authorizedIdentity.address)") + print("wallet address: \(wallet.address)") print("account private key: \(privateKey.secp256K1.bytes.toHex)") print("account public key: \(privateKey.publicKey.secp256K1Uncompressed.bytes.toHex)") print("identity private: \(bundle.v1.identityKey.secp256K1.bytes.toHex)") diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTP/Messages/PublicKey.swift index b5648a0a..3c873dbd 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTP/Messages/PublicKey.swift @@ -8,11 +8,13 @@ import Foundation import XMTPProto import XMTPRust +import web3 +import CryptoKit typealias PublicKey = Xmtp_MessageContents_PublicKey enum PublicKeyError: String, Error { - case noSignature, invalidPreKey, addressNotFound + case noSignature, invalidPreKey, addressNotFound, invalidKeyString } extension PublicKey { @@ -46,6 +48,16 @@ extension PublicKey { secp256K1Uncompressed.bytes = data } + init(_ string: String) throws { + self.init() + + guard let bytes = string.web3.bytesFromHex else { + throw PublicKeyError.invalidKeyString + } + + try self.init(Data(bytes)) + } + func recoverWalletSignerPublicKey() throws -> PublicKey { if !hasSignature { throw PublicKeyError.noSignature @@ -73,7 +85,7 @@ extension PublicKey { slimKey.timestamp = timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(XMTPRust.CoreCrypto.sha256(data: bytesToSign)), signature: signature.rawData) + let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData) return try PublicKey(pubKeyData) } diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTP/SigningKey.swift index 02d32d9e..bc1ff25f 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTP/SigningKey.swift @@ -6,6 +6,8 @@ // import Foundation +import web3 +import XMTPRust /// Defines a type that is used by a ``Client`` to sign keys and messages. /// @@ -37,7 +39,7 @@ extension SigningKey { let digest = try Signature.ethHash(signatureText) let recoveredKey = try KeyUtil.recoverPublicKey(message: digest, signature: signature.rawData) - let address = KeyUtil.generateAddress(from: recoveredKey).toChecksumAddress() + let address = KeyUtil.generateAddress(from: Data(recoveredKey.web3.bytesFromHex ?? [])).toChecksumAddress() var authorized = PublicKey() authorized.secp256K1Uncompressed = slimKey.secp256K1Uncompressed diff --git a/XMTPiOSExample/XMTPiOSExample/ContentView.swift b/XMTPiOSExample/XMTPiOSExample/ContentView.swift index 6ba08b98..ffda7b1a 100644 --- a/XMTPiOSExample/XMTPiOSExample/ContentView.swift +++ b/XMTPiOSExample/XMTPiOSExample/ContentView.swift @@ -105,7 +105,7 @@ struct ContentView: View { Task { do { let wallet = try PrivateKey.generate() - let client = try! await Client.create(account: wallet) + let client = try! await Client.create(account: wallet, options: .init(api: .init(env: .local, isSecure: false))) let keysData = try client.privateKeyBundle.serializedData() Persistence().saveKeys(keysData) diff --git a/dev/local/docker-compose.yml b/dev/local/docker-compose.yml index ebd2112a..87736f21 100644 --- a/dev/local/docker-compose.yml +++ b/dev/local/docker-compose.yml @@ -2,12 +2,14 @@ version: "3.8" services: wakunode: image: xmtp/node-go + platform: linux/arm64 environment: - GOWAKU-NODEKEY=8a30dcb604b0b53627a5adc054dbf434b446628d4bd1eccc681d223f0550ce67 command: - --ws - --store - --message-db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable + - --message-db-reader-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable - --lightpush - --filter - --ws-port=9001 @@ -20,7 +22,7 @@ services: depends_on: - db healthcheck: - test: ["CMD", "lsof", "-i", ":5556"] + test: [ "CMD", "lsof", "-i", ":5556" ] interval: 3s timeout: 10s retries: 5 diff --git a/script/local b/script/local index 10df4142..67a03a6b 100755 --- a/script/local +++ b/script/local @@ -1,3 +1,3 @@ #!/usr/bin/env sh -docker-compose -p xmtp-ios-swift -f dev/local/docker-compose.yml up +docker-compose -p xmtp-ios-swiftxx -f dev/local/docker-compose.yml up From c3c35faa892573605bab60a00850ce46e86d74eb Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 16:37:13 -0700 Subject: [PATCH 16/47] Bring in the proto types for now --- Sources/XMTP/ApiClient.swift | 1 - Sources/XMTP/Client.swift | 1 - Sources/XMTP/Codecs/AttachmentCodec.swift | 1 - Sources/XMTP/Codecs/Composite.swift | 2 - Sources/XMTP/Codecs/ContentCodec.swift | 1 - Sources/XMTP/Codecs/ContentTypeID.swift | 2 - .../XMTP/Codecs/RemoteAttachmentCodec.swift | 1 - Sources/XMTP/Codecs/TextCodec.swift | 1 - Sources/XMTP/Conversation.swift | 1 - Sources/XMTP/ConversationExport.swift | 2 - Sources/XMTP/ConversationV2.swift | 1 - Sources/XMTP/Conversations.swift | 1 - Sources/XMTP/Crypto.swift | 1 - Sources/XMTP/KeyUtil.swift | 10 +- Sources/XMTP/Messages/AuthData.swift | 1 - Sources/XMTP/Messages/ContactBundle.swift | 7 +- .../Messages/EncryptedPrivateKeyBundle.swift | 2 - Sources/XMTP/Messages/Envelope.swift | 1 - Sources/XMTP/Messages/Invitation.swift | 1 - Sources/XMTP/Messages/Message.swift | 2 - Sources/XMTP/Messages/MessageHeaderV1.swift | 1 - Sources/XMTP/Messages/MessageHeaderV2.swift | 1 - Sources/XMTP/Messages/MessageV1.swift | 1 - Sources/XMTP/Messages/MessageV2.swift | 9 +- Sources/XMTP/Messages/PagingInfo.swift | 1 - Sources/XMTP/Messages/PrivateKey.swift | 6 +- Sources/XMTP/Messages/PrivateKeyBundle.swift | 2 +- .../XMTP/Messages/PrivateKeyBundleV1.swift | 22 +- .../XMTP/Messages/PrivateKeyBundleV2.swift | 2 +- Sources/XMTP/Messages/PublicKey.swift | 10 +- Sources/XMTP/Messages/PublicKeyBundle.swift | 2 +- Sources/XMTP/Messages/SealedInvitation.swift | 2 +- .../Messages/SealedInvitationHeaderV1.swift | 2 +- .../XMTP/Messages/SealedInvitationV1.swift | 2 +- Sources/XMTP/Messages/Signature.swift | 2 +- Sources/XMTP/Messages/SignedContent.swift | 2 +- Sources/XMTP/Messages/SignedPrivateKey.swift | 2 +- Sources/XMTP/Messages/SignedPublicKey.swift | 10 +- .../XMTP/Messages/SignedPublicKeyBundle.swift | 2 +- Sources/XMTP/Messages/Token.swift | 2 +- Sources/XMTP/Messages/Topic.swift | 2 +- Sources/XMTP/Messages/UnsignedPublicKey.swift | 2 +- .../Proto/keystore_api/v1/keystore.pb.swift | 1864 +++++++++++++++++ .../XMTP/Proto/message_api/v1/authn.pb.swift | 177 ++ .../message_api/v1/message_api.grpc.swift | 744 +++++++ .../Proto/message_api/v1/message_api.pb.swift | 776 +++++++ .../message_contents/ciphertext.pb.swift | 331 +++ .../Proto/message_contents/composite.pb.swift | 201 ++ .../Proto/message_contents/contact.pb.swift | 278 +++ .../Proto/message_contents/content.pb.swift | 357 ++++ .../conversation_reference.pb.swift | 113 + .../message_contents/invitation.pb.swift | 506 +++++ .../Proto/message_contents/message.pb.swift | 600 ++++++ .../message_contents/private_key.pb.swift | 787 +++++++ .../message_contents/public_key.pb.swift | 562 +++++ .../Proto/message_contents/signature.pb.swift | 271 +++ Sources/XMTP/SigningKey.swift | 6 +- Sources/XMTPTestHelpers/TestHelpers.swift | 2 +- Tests/XMTPTests/IntegrationTests.swift | 9 +- Tests/XMTPTests/MessageTests.swift | 3 +- Tests/XMTPTests/SignatureTests.swift | 6 + XMTP.podspec | 14 +- XMTPiOSExample/Podfile | 8 +- XMTPiOSExample/Podfile.lock | 38 +- 64 files changed, 7640 insertions(+), 140 deletions(-) create mode 100644 Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift create mode 100644 Sources/XMTP/Proto/message_api/v1/authn.pb.swift create mode 100644 Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift create mode 100644 Sources/XMTP/Proto/message_api/v1/message_api.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/ciphertext.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/composite.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/contact.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/content.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/invitation.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/message.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/private_key.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/public_key.pb.swift create mode 100644 Sources/XMTP/Proto/message_contents/signature.pb.swift diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 88713d1d..5fc0217a 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -6,7 +6,6 @@ // import XMTPRust -import XMTPProto public typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse public typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 656312e2..968a2f3a 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -7,7 +7,6 @@ import Foundation import web3 -import XMTPProto /// Specify configuration options for creating a ``Client``. public struct ClientOptions { diff --git a/Sources/XMTP/Codecs/AttachmentCodec.swift b/Sources/XMTP/Codecs/AttachmentCodec.swift index aea24406..4bb8e1ab 100644 --- a/Sources/XMTP/Codecs/AttachmentCodec.swift +++ b/Sources/XMTP/Codecs/AttachmentCodec.swift @@ -5,7 +5,6 @@ // Created by Pat on 2/14/23. // import Foundation -import XMTPProto public let ContentTypeAttachment = ContentTypeID(authorityID: "xmtp.org", typeID: "attachment", versionMajor: 1, versionMinor: 0) diff --git a/Sources/XMTP/Codecs/Composite.swift b/Sources/XMTP/Codecs/Composite.swift index 8b5ad72e..044d8654 100644 --- a/Sources/XMTP/Codecs/Composite.swift +++ b/Sources/XMTP/Codecs/Composite.swift @@ -5,8 +5,6 @@ // Created by Pat Nakajima on 12/22/22. // -import XMTPProto - typealias Composite = Xmtp_MessageContents_Composite let ContentTypeComposite = ContentTypeID(authorityID: "xmtp.org", typeID: "composite", versionMajor: 1, versionMinor: 0) diff --git a/Sources/XMTP/Codecs/ContentCodec.swift b/Sources/XMTP/Codecs/ContentCodec.swift index c6512983..c8feac96 100644 --- a/Sources/XMTP/Codecs/ContentCodec.swift +++ b/Sources/XMTP/Codecs/ContentCodec.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto enum CodecError: String, Error { case invalidContent, codecNotFound diff --git a/Sources/XMTP/Codecs/ContentTypeID.swift b/Sources/XMTP/Codecs/ContentTypeID.swift index d7fa062a..e55cb16d 100644 --- a/Sources/XMTP/Codecs/ContentTypeID.swift +++ b/Sources/XMTP/Codecs/ContentTypeID.swift @@ -5,8 +5,6 @@ // Created by Pat Nakajima on 11/28/22. // -import XMTPProto - public typealias ContentTypeID = Xmtp_MessageContents_ContentTypeId public extension ContentTypeID { diff --git a/Sources/XMTP/Codecs/RemoteAttachmentCodec.swift b/Sources/XMTP/Codecs/RemoteAttachmentCodec.swift index e966a777..5ea0385f 100644 --- a/Sources/XMTP/Codecs/RemoteAttachmentCodec.swift +++ b/Sources/XMTP/Codecs/RemoteAttachmentCodec.swift @@ -8,7 +8,6 @@ import CryptoKit import Foundation import web3 -import XMTPProto public let ContentTypeRemoteAttachment = ContentTypeID(authorityID: "xmtp.org", typeID: "remoteStaticAttachment", versionMajor: 1, versionMinor: 0) diff --git a/Sources/XMTP/Codecs/TextCodec.swift b/Sources/XMTP/Codecs/TextCodec.swift index 4297dc62..5e5f7495 100644 --- a/Sources/XMTP/Codecs/TextCodec.swift +++ b/Sources/XMTP/Codecs/TextCodec.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto public let ContentTypeText = ContentTypeID(authorityID: "xmtp.org", typeID: "text", versionMajor: 1, versionMinor: 0) diff --git a/Sources/XMTP/Conversation.swift b/Sources/XMTP/Conversation.swift index a0943088..c8a20b24 100644 --- a/Sources/XMTP/Conversation.swift +++ b/Sources/XMTP/Conversation.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto public enum ConversationContainer: Codable { case v1(ConversationV1Container), v2(ConversationV2Container) diff --git a/Sources/XMTP/ConversationExport.swift b/Sources/XMTP/ConversationExport.swift index 61b072a0..f09450e0 100644 --- a/Sources/XMTP/ConversationExport.swift +++ b/Sources/XMTP/ConversationExport.swift @@ -5,8 +5,6 @@ // Created by Pat Nakajima on 2/1/23. // -import XMTPProto - enum ConversationImportError: Error { case invalidData } diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTP/ConversationV2.swift index a6524cb8..255c3277 100644 --- a/Sources/XMTP/ConversationV2.swift +++ b/Sources/XMTP/ConversationV2.swift @@ -7,7 +7,6 @@ import CryptoKit import Foundation -import XMTPProto // Save the non-client parts for a v2 conversation public struct ConversationV2Container: Codable { diff --git a/Sources/XMTP/Conversations.swift b/Sources/XMTP/Conversations.swift index 3c81dd3a..06841912 100644 --- a/Sources/XMTP/Conversations.swift +++ b/Sources/XMTP/Conversations.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto public enum ConversationError: Error { case recipientNotOnNetwork, recipientIsSender, v1NotSupported(String) diff --git a/Sources/XMTP/Crypto.swift b/Sources/XMTP/Crypto.swift index 4dc7af41..5fa41ff6 100644 --- a/Sources/XMTP/Crypto.swift +++ b/Sources/XMTP/Crypto.swift @@ -7,7 +7,6 @@ import CryptoKit import Foundation -import XMTPProto public typealias CipherText = Xmtp_MessageContents_Ciphertext diff --git a/Sources/XMTP/KeyUtil.swift b/Sources/XMTP/KeyUtil.swift index 51030e71..cdca6bcd 100644 --- a/Sources/XMTP/KeyUtil.swift +++ b/Sources/XMTP/KeyUtil.swift @@ -6,6 +6,7 @@ import Foundation import Logging import secp256k1 import web3 +import XMTPRust enum KeyUtilError: Error { case invalidContext @@ -18,15 +19,14 @@ enum KeyUtilError: Error { } // Copied from web3.swift since its version is `internal` -enum KeyUtil { +enum KeyUtilx { private static var logger: Logger { Logger(label: "web3.swift.key-util") } -// static func xmtpGeneratePublicKey(from privateKeyData: Data) throws -> Data { -// let privateKey = try secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyData, format: .uncompressed) -// return privateKey.publicKey.rawRepresentation -// } + static func generatePublicKey(from data: Data) throws -> Data { + try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: data) + } static func sign(message: Data, with privateKey: Data, hashing: Bool) throws -> Data { guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)) else { diff --git a/Sources/XMTP/Messages/AuthData.swift b/Sources/XMTP/Messages/AuthData.swift index dd5e4bdb..bc5207b7 100644 --- a/Sources/XMTP/Messages/AuthData.swift +++ b/Sources/XMTP/Messages/AuthData.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto typealias AuthData = Xmtp_MessageApi_V1_AuthData diff --git a/Sources/XMTP/Messages/ContactBundle.swift b/Sources/XMTP/Messages/ContactBundle.swift index ce364795..267ac63d 100644 --- a/Sources/XMTP/Messages/ContactBundle.swift +++ b/Sources/XMTP/Messages/ContactBundle.swift @@ -5,7 +5,8 @@ // Created by Pat Nakajima on 11/23/22. // -import XMTPProto +import web3 +import XMTPRust typealias ContactBundle = Xmtp_MessageContents_ContactBundle typealias ContactBundleV1 = Xmtp_MessageContents_ContactBundleV1 @@ -62,13 +63,13 @@ extension ContactBundle { switch version { case .v1: if let key = try? v1.keyBundle.identityKey.recoverWalletSignerPublicKey() { - return KeyUtil.generateAddress(from: key.secp256K1Uncompressed.bytes).toChecksumAddress() + return KeyUtilx.generateAddress(from: key.secp256K1Uncompressed.bytes).toChecksumAddress() } return nil case .v2: if let key = try? v2.keyBundle.identityKey.recoverWalletSignerPublicKey() { - return KeyUtil.generateAddress(from: key.secp256K1Uncompressed.bytes).toChecksumAddress() + return KeyUtilx.generateAddress(from: key.secp256K1Uncompressed.bytes).toChecksumAddress() } return nil diff --git a/Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift b/Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift index 448b10f2..54ab6a5a 100644 --- a/Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift +++ b/Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift @@ -5,8 +5,6 @@ // Created by Pat Nakajima on 11/17/22. // -import XMTPProto - typealias EncryptedPrivateKeyBundle = Xmtp_MessageContents_EncryptedPrivateKeyBundle extension EncryptedPrivateKeyBundle { diff --git a/Sources/XMTP/Messages/Envelope.swift b/Sources/XMTP/Messages/Envelope.swift index 1c7a799b..8b04e281 100644 --- a/Sources/XMTP/Messages/Envelope.swift +++ b/Sources/XMTP/Messages/Envelope.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto public typealias Envelope = Xmtp_MessageApi_V1_Envelope diff --git a/Sources/XMTP/Messages/Invitation.swift b/Sources/XMTP/Messages/Invitation.swift index ac5dd322..54d57722 100644 --- a/Sources/XMTP/Messages/Invitation.swift +++ b/Sources/XMTP/Messages/Invitation.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto /// Handles topic generation for conversations. public typealias InvitationV1 = Xmtp_MessageContents_InvitationV1 diff --git a/Sources/XMTP/Messages/Message.swift b/Sources/XMTP/Messages/Message.swift index 0fda2f65..ff2613b4 100644 --- a/Sources/XMTP/Messages/Message.swift +++ b/Sources/XMTP/Messages/Message.swift @@ -5,8 +5,6 @@ // Created by Pat Nakajima on 11/27/22. // -import XMTPProto - /// Handles encryption/decryption for communicating data in conversations public typealias Message = Xmtp_MessageContents_Message diff --git a/Sources/XMTP/Messages/MessageHeaderV1.swift b/Sources/XMTP/Messages/MessageHeaderV1.swift index 6b998f55..25c3682f 100644 --- a/Sources/XMTP/Messages/MessageHeaderV1.swift +++ b/Sources/XMTP/Messages/MessageHeaderV1.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto typealias MessageHeaderV1 = Xmtp_MessageContents_MessageHeaderV1 diff --git a/Sources/XMTP/Messages/MessageHeaderV2.swift b/Sources/XMTP/Messages/MessageHeaderV2.swift index ea707044..d967525e 100644 --- a/Sources/XMTP/Messages/MessageHeaderV2.swift +++ b/Sources/XMTP/Messages/MessageHeaderV2.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto typealias MessageHeaderV2 = Xmtp_MessageContents_MessageHeaderV2 diff --git a/Sources/XMTP/Messages/MessageV1.swift b/Sources/XMTP/Messages/MessageV1.swift index 6cc5928e..6a075ca7 100644 --- a/Sources/XMTP/Messages/MessageV1.swift +++ b/Sources/XMTP/Messages/MessageV1.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto typealias MessageV1 = Xmtp_MessageContents_MessageV1 diff --git a/Sources/XMTP/Messages/MessageV2.swift b/Sources/XMTP/Messages/MessageV2.swift index 9c044b54..369b5baf 100644 --- a/Sources/XMTP/Messages/MessageV2.swift +++ b/Sources/XMTP/Messages/MessageV2.swift @@ -7,7 +7,6 @@ import CryptoKit import Foundation -import XMTPProto import XMTPRust import web3 @@ -43,14 +42,8 @@ extension MessageV2 { } // Verify content signature - let digest = SHA256.hash(data: message.headerBytes + signed.payload) - let key = try PublicKey.with { key in - guard let bytes = try KeyUtil.recoverPublicKey(message: Data(digest), signature: signed.signature.rawData).web3.bytesFromHex else { - throw MessageV2Error.decodeError("invalid bytes") - } - - key.secp256K1Uncompressed.bytes = Data(bytes) + key.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(message.headerBytes + signed.payload), signature: signed.signature.rawData) } if key.walletAddress != (try PublicKey(signed.sender.preKey).walletAddress) { diff --git a/Sources/XMTP/Messages/PagingInfo.swift b/Sources/XMTP/Messages/PagingInfo.swift index e8977f0f..8d74e797 100644 --- a/Sources/XMTP/Messages/PagingInfo.swift +++ b/Sources/XMTP/Messages/PagingInfo.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto typealias PagingInfo = Xmtp_MessageApi_V1_PagingInfo typealias PagingInfoCursor = Xmtp_MessageApi_V1_Cursor diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 7a4d57f0..4bb38b3e 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -6,7 +6,6 @@ // import Foundation -import XMTPProto import XMTPRust import CryptoKit import web3 @@ -33,7 +32,7 @@ extension PrivateKey: SigningKey { } public func sign(_ data: Data) async throws -> Signature { - let signatureData = try KeyUtil.sign(message: data, with: secp256K1.bytes, hashing: false) + let signatureData = try KeyUtilx.sign(message: data, with: secp256K1.bytes, hashing: false) var signature = Signature() signature.ecdsaCompact.bytes = signatureData[0 ..< 64] @@ -69,8 +68,7 @@ public extension PrivateKey { } static func generate() throws -> PrivateKey { -// let data = Data(try Crypto.secureRandomBytes(count: 32)) - let data = "7ec7bca44abcf7aefac9d6d0c99e532590a3478114a11759303cf72a72544473".web3.hexData! + let data = Data(try Crypto.secureRandomBytes(count: 32)) return try PrivateKey(data) } diff --git a/Sources/XMTP/Messages/PrivateKeyBundle.swift b/Sources/XMTP/Messages/PrivateKeyBundle.swift index b1b785ca..96331dd9 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundle.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundle.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + public typealias PrivateKeyBundle = Xmtp_MessageContents_PrivateKeyBundle diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift index d2f407fe..3b35f599 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift @@ -9,7 +9,7 @@ import CryptoKit import Foundation import web3 import XMTPRust -import XMTPProto + public typealias PrivateKeyBundleV1 = Xmtp_MessageContents_PrivateKeyBundleV1 @@ -24,6 +24,13 @@ extension PrivateKeyBundleV1 { let bytesToSign = try UnsignedPublicKey(preKey.publicKey).serializedData() let signature = try await privateKey.sign(Data(SHA256.hash(data: bytesToSign))) + + print("Signature: \(signature.rawData)") + + print("KeyUtilx recovered: \(try KeyUtilx.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData).toHex)") + print("XMTPRust recovered: \(try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData).toHex)") + + bundle.v1.identityKey = authorizedIdentity.identity bundle.v1.identityKey.publicKey = authorizedIdentity.authorized preKey.publicKey.signature = signature @@ -34,19 +41,6 @@ extension PrivateKeyBundleV1 { preKey.publicKey.signature = signedPublicKey.signature bundle.v1.preKeys = [preKey] - - print("authorized identity address: \(authorizedIdentity.address)") - print("wallet address: \(wallet.address)") - print("account private key: \(privateKey.secp256K1.bytes.toHex)") - print("account public key: \(privateKey.publicKey.secp256K1Uncompressed.bytes.toHex)") - print("identity private: \(bundle.v1.identityKey.secp256K1.bytes.toHex)") - print("identity public: \(bundle.v1.identityKey.publicKey.secp256K1Uncompressed.bytes.toHex)") - print("identity key signature: \(authorizedIdentity.identity.publicKey.signature.rawData.toHex)") - print("pre key private: \(preKey.secp256K1.bytes.toHex)") - print("pre key public: \(preKey.publicKey.secp256K1Uncompressed.bytes.toHex)") - - print("pre key signature: \(signedPublicKey.signature.rawData.toHex)") - return bundle.v1 } diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift index d832529b..fb6b8fa2 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift @@ -7,7 +7,7 @@ import Foundation import XMTPRust -import XMTPProto + public typealias PrivateKeyBundleV2 = Xmtp_MessageContents_PrivateKeyBundleV2 diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTP/Messages/PublicKey.swift index 3c873dbd..6113bd1a 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTP/Messages/PublicKey.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + import XMTPRust import web3 import CryptoKit @@ -68,9 +68,9 @@ extension PublicKey { slimKey.secp256K1Uncompressed.bytes = secp256K1Uncompressed.bytes let sigText = Signature.createIdentityText(key: try slimKey.serializedData()) - let sigHash = try Signature.ethHash(sigText) + let message = try Signature.ethPersonalMessage(sigText) - let pubKeyData = try KeyUtil.recoverPublicKey(message: sigHash, signature: signature.rawData) + let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) return try PublicKey(pubKeyData) } @@ -85,11 +85,11 @@ extension PublicKey { slimKey.timestamp = timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData) + let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: bytesToSign, signature: signature.rawData) return try PublicKey(pubKeyData) } var walletAddress: String { - KeyUtil.generateAddress(from: secp256K1Uncompressed.bytes).toChecksumAddress() + KeyUtilx.generateAddress(from: secp256K1Uncompressed.bytes).toChecksumAddress() } } diff --git a/Sources/XMTP/Messages/PublicKeyBundle.swift b/Sources/XMTP/Messages/PublicKeyBundle.swift index 518f71b3..23691789 100644 --- a/Sources/XMTP/Messages/PublicKeyBundle.swift +++ b/Sources/XMTP/Messages/PublicKeyBundle.swift @@ -5,7 +5,7 @@ // Created by Pat Nakajima on 11/23/22. // -import XMTPProto + typealias PublicKeyBundle = Xmtp_MessageContents_PublicKeyBundle diff --git a/Sources/XMTP/Messages/SealedInvitation.swift b/Sources/XMTP/Messages/SealedInvitation.swift index c90d75a1..635df583 100644 --- a/Sources/XMTP/Messages/SealedInvitation.swift +++ b/Sources/XMTP/Messages/SealedInvitation.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + typealias SealedInvitation = Xmtp_MessageContents_SealedInvitation diff --git a/Sources/XMTP/Messages/SealedInvitationHeaderV1.swift b/Sources/XMTP/Messages/SealedInvitationHeaderV1.swift index 83bc3ca6..70bbafc2 100644 --- a/Sources/XMTP/Messages/SealedInvitationHeaderV1.swift +++ b/Sources/XMTP/Messages/SealedInvitationHeaderV1.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + public typealias SealedInvitationHeaderV1 = Xmtp_MessageContents_SealedInvitationHeaderV1 diff --git a/Sources/XMTP/Messages/SealedInvitationV1.swift b/Sources/XMTP/Messages/SealedInvitationV1.swift index 23c1000d..054274b0 100644 --- a/Sources/XMTP/Messages/SealedInvitationV1.swift +++ b/Sources/XMTP/Messages/SealedInvitationV1.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + typealias SealedInvitationV1 = Xmtp_MessageContents_SealedInvitationV1 diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 0d9633df..01cd1879 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -7,7 +7,7 @@ import Foundation import XMTPRust -import XMTPProto + /// Represents a secp256k1 compact recoverable signature. public typealias Signature = Xmtp_MessageContents_Signature diff --git a/Sources/XMTP/Messages/SignedContent.swift b/Sources/XMTP/Messages/SignedContent.swift index 329c6d38..42d4e3b8 100644 --- a/Sources/XMTP/Messages/SignedContent.swift +++ b/Sources/XMTP/Messages/SignedContent.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + typealias SignedContent = Xmtp_MessageContents_SignedContent diff --git a/Sources/XMTP/Messages/SignedPrivateKey.swift b/Sources/XMTP/Messages/SignedPrivateKey.swift index 0b2ce11d..102ce248 100644 --- a/Sources/XMTP/Messages/SignedPrivateKey.swift +++ b/Sources/XMTP/Messages/SignedPrivateKey.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + public typealias SignedPrivateKey = Xmtp_MessageContents_SignedPrivateKey diff --git a/Sources/XMTP/Messages/SignedPublicKey.swift b/Sources/XMTP/Messages/SignedPublicKey.swift index 5d717a70..574e4e24 100644 --- a/Sources/XMTP/Messages/SignedPublicKey.swift +++ b/Sources/XMTP/Messages/SignedPublicKey.swift @@ -7,7 +7,9 @@ import CryptoKit import Foundation -import XMTPProto + +import XMTPRust +import web3 typealias SignedPublicKey = Xmtp_MessageContents_SignedPublicKey @@ -62,15 +64,15 @@ extension SignedPublicKey { slimKey.timestamp = publicKey.timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try KeyUtil.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: publicKey.signature.rawData) + let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(SHA256.hash(data: bytesToSign)), signature: publicKey.signature.rawData) return try PublicKey(pubKeyData) } func recoverWalletSignerPublicKey() throws -> PublicKey { let sigText = Signature.createIdentityText(key: keyBytes) - let sigHash = try Signature.ethHash(sigText) + let message = try Signature.ethPersonalMessage(sigText) - let pubKeyData = try KeyUtil.recoverPublicKey(message: sigHash, signature: signature.rawData) + let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) return try PublicKey(pubKeyData) } diff --git a/Sources/XMTP/Messages/SignedPublicKeyBundle.swift b/Sources/XMTP/Messages/SignedPublicKeyBundle.swift index a67220bd..36cf81ce 100644 --- a/Sources/XMTP/Messages/SignedPublicKeyBundle.swift +++ b/Sources/XMTP/Messages/SignedPublicKeyBundle.swift @@ -5,7 +5,7 @@ // Created by Pat Nakajima on 11/23/22. // -import XMTPProto + typealias SignedPublicKeyBundle = Xmtp_MessageContents_SignedPublicKeyBundle diff --git a/Sources/XMTP/Messages/Token.swift b/Sources/XMTP/Messages/Token.swift index 1831a55d..5165e156 100644 --- a/Sources/XMTP/Messages/Token.swift +++ b/Sources/XMTP/Messages/Token.swift @@ -6,6 +6,6 @@ // import Foundation -import XMTPProto + typealias Token = Xmtp_MessageApi_V1_Token diff --git a/Sources/XMTP/Messages/Topic.swift b/Sources/XMTP/Messages/Topic.swift index c1ec7c5a..e0b9c0b6 100644 --- a/Sources/XMTP/Messages/Topic.swift +++ b/Sources/XMTP/Messages/Topic.swift @@ -5,7 +5,7 @@ // Created by Pat Nakajima on 11/17/22. // -import XMTPProto + public enum Topic { case userPrivateStoreKeyBundle(String), diff --git a/Sources/XMTP/Messages/UnsignedPublicKey.swift b/Sources/XMTP/Messages/UnsignedPublicKey.swift index 9b1111de..69e26afd 100644 --- a/Sources/XMTP/Messages/UnsignedPublicKey.swift +++ b/Sources/XMTP/Messages/UnsignedPublicKey.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPProto + typealias UnsignedPublicKey = Xmtp_MessageContents_UnsignedPublicKey diff --git a/Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift b/Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift new file mode 100644 index 00000000..586462ad --- /dev/null +++ b/Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift @@ -0,0 +1,1864 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: keystore_api/v1/keystore.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Message content encoding structures + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Application-specific error codes for the Keystore API. +public enum Xmtp_KeystoreApi_V1_ErrorCode: SwiftProtobuf.Enum { + public typealias RawValue = Int + case unspecified // = 0 + case invalidInput // = 1 + case noMatchingPrekey // = 2 + case UNRECOGNIZED(Int) + + public init() { + self = .unspecified + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .unspecified + case 1: self = .invalidInput + case 2: self = .noMatchingPrekey + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .unspecified: return 0 + case .invalidInput: return 1 + case .noMatchingPrekey: return 2 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Xmtp_KeystoreApi_V1_ErrorCode: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Xmtp_KeystoreApi_V1_ErrorCode] = [ + .unspecified, + .invalidInput, + .noMatchingPrekey, + ] +} + +#endif // swift(>=4.2) + +/// Wrapper class for errors from the Keystore API +public struct Xmtp_KeystoreApi_V1_KeystoreError { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var message: String = String() + + public var code: Xmtp_KeystoreApi_V1_ErrorCode = .unspecified + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Decrypt a batch of messages using X3DH key agreement +public struct Xmtp_KeystoreApi_V1_DecryptV1Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_KeystoreApi_V1_DecryptV1Request.Request] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single decryption request + public struct Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var payload: Xmtp_MessageContents_Ciphertext { + get {return _payload ?? Xmtp_MessageContents_Ciphertext()} + set {_payload = newValue} + } + /// Returns true if `payload` has been explicitly set. + public var hasPayload: Bool {return self._payload != nil} + /// Clears the value of `payload`. Subsequent reads from it will return its default value. + public mutating func clearPayload() {self._payload = nil} + + public var peerKeys: Xmtp_MessageContents_PublicKeyBundle { + get {return _peerKeys ?? Xmtp_MessageContents_PublicKeyBundle()} + set {_peerKeys = newValue} + } + /// Returns true if `peerKeys` has been explicitly set. + public var hasPeerKeys: Bool {return self._peerKeys != nil} + /// Clears the value of `peerKeys`. Subsequent reads from it will return its default value. + public mutating func clearPeerKeys() {self._peerKeys = nil} + + public var headerBytes: Data = Data() + + public var isSender: Bool = false + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _payload: Xmtp_MessageContents_Ciphertext? = nil + fileprivate var _peerKeys: Xmtp_MessageContents_PublicKeyBundle? = nil + } + + public init() {} +} + +/// Response type for both V1 and V2 decryption requests +public struct Xmtp_KeystoreApi_V1_DecryptResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var responses: [Xmtp_KeystoreApi_V1_DecryptResponse.Response] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single decryption response + public struct Response { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var response: Xmtp_KeystoreApi_V1_DecryptResponse.Response.OneOf_Response? = nil + + public var result: Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success { + get { + if case .result(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success() + } + set {response = .result(newValue)} + } + + public var error: Xmtp_KeystoreApi_V1_KeystoreError { + get { + if case .error(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_KeystoreError() + } + set {response = .error(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Response: Equatable { + case result(Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success) + case error(Xmtp_KeystoreApi_V1_KeystoreError) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response.OneOf_Response, rhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response.OneOf_Response) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.result, .result): return { + guard case .result(let l) = lhs, case .result(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.error, .error): return { + guard case .error(let l) = lhs, case .error(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + /// Wrapper object for success response + public struct Success { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var decrypted: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + } + + public init() {} +} + +/// Decrypt a batch of messages using the appropriate topic keys +public struct Xmtp_KeystoreApi_V1_DecryptV2Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_KeystoreApi_V1_DecryptV2Request.Request] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single decryption request + public struct Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var payload: Xmtp_MessageContents_Ciphertext { + get {return _payload ?? Xmtp_MessageContents_Ciphertext()} + set {_payload = newValue} + } + /// Returns true if `payload` has been explicitly set. + public var hasPayload: Bool {return self._payload != nil} + /// Clears the value of `payload`. Subsequent reads from it will return its default value. + public mutating func clearPayload() {self._payload = nil} + + public var headerBytes: Data = Data() + + public var contentTopic: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _payload: Xmtp_MessageContents_Ciphertext? = nil + } + + public init() {} +} + +/// Encrypt a batch of messages using X3DH key agreement +public struct Xmtp_KeystoreApi_V1_EncryptV1Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_KeystoreApi_V1_EncryptV1Request.Request] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single encryption request + public struct Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var recipient: Xmtp_MessageContents_PublicKeyBundle { + get {return _recipient ?? Xmtp_MessageContents_PublicKeyBundle()} + set {_recipient = newValue} + } + /// Returns true if `recipient` has been explicitly set. + public var hasRecipient: Bool {return self._recipient != nil} + /// Clears the value of `recipient`. Subsequent reads from it will return its default value. + public mutating func clearRecipient() {self._recipient = nil} + + public var payload: Data = Data() + + public var headerBytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _recipient: Xmtp_MessageContents_PublicKeyBundle? = nil + } + + public init() {} +} + +/// Response type for both V1 and V2 encryption requests +public struct Xmtp_KeystoreApi_V1_EncryptResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var responses: [Xmtp_KeystoreApi_V1_EncryptResponse.Response] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single encryption response + public struct Response { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var response: Xmtp_KeystoreApi_V1_EncryptResponse.Response.OneOf_Response? = nil + + public var result: Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success { + get { + if case .result(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success() + } + set {response = .result(newValue)} + } + + public var error: Xmtp_KeystoreApi_V1_KeystoreError { + get { + if case .error(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_KeystoreError() + } + set {response = .error(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Response: Equatable { + case result(Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success) + case error(Xmtp_KeystoreApi_V1_KeystoreError) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response.OneOf_Response, rhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response.OneOf_Response) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.result, .result): return { + guard case .result(let l) = lhs, case .result(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.error, .error): return { + guard case .error(let l) = lhs, case .error(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + /// Wrapper object for success response + public struct Success { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var encrypted: Xmtp_MessageContents_Ciphertext { + get {return _encrypted ?? Xmtp_MessageContents_Ciphertext()} + set {_encrypted = newValue} + } + /// Returns true if `encrypted` has been explicitly set. + public var hasEncrypted: Bool {return self._encrypted != nil} + /// Clears the value of `encrypted`. Subsequent reads from it will return its default value. + public mutating func clearEncrypted() {self._encrypted = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _encrypted: Xmtp_MessageContents_Ciphertext? = nil + } + + public init() {} + } + + public init() {} +} + +/// Encrypt a batch of messages using the appropriate topic keys +public struct Xmtp_KeystoreApi_V1_EncryptV2Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_KeystoreApi_V1_EncryptV2Request.Request] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single encryption request + public struct Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var payload: Data = Data() + + public var headerBytes: Data = Data() + + public var contentTopic: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} +} + +/// Request to create an invite payload, and store the topic keys in the Keystore +public struct Xmtp_KeystoreApi_V1_CreateInviteRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var context: Xmtp_MessageContents_InvitationV1.Context { + get {return _context ?? Xmtp_MessageContents_InvitationV1.Context()} + set {_context = newValue} + } + /// Returns true if `context` has been explicitly set. + public var hasContext: Bool {return self._context != nil} + /// Clears the value of `context`. Subsequent reads from it will return its default value. + public mutating func clearContext() {self._context = nil} + + public var recipient: Xmtp_MessageContents_SignedPublicKeyBundle { + get {return _recipient ?? Xmtp_MessageContents_SignedPublicKeyBundle()} + set {_recipient = newValue} + } + /// Returns true if `recipient` has been explicitly set. + public var hasRecipient: Bool {return self._recipient != nil} + /// Clears the value of `recipient`. Subsequent reads from it will return its default value. + public mutating func clearRecipient() {self._recipient = nil} + + public var createdNs: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _context: Xmtp_MessageContents_InvitationV1.Context? = nil + fileprivate var _recipient: Xmtp_MessageContents_SignedPublicKeyBundle? = nil +} + +/// Response to a CreateInviteRequest +public struct Xmtp_KeystoreApi_V1_CreateInviteResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var conversation: Xmtp_MessageContents_ConversationReference { + get {return _conversation ?? Xmtp_MessageContents_ConversationReference()} + set {_conversation = newValue} + } + /// Returns true if `conversation` has been explicitly set. + public var hasConversation: Bool {return self._conversation != nil} + /// Clears the value of `conversation`. Subsequent reads from it will return its default value. + public mutating func clearConversation() {self._conversation = nil} + + public var payload: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _conversation: Xmtp_MessageContents_ConversationReference? = nil +} + +/// Request to save a batch of invite messages to the Keystore +public struct Xmtp_KeystoreApi_V1_SaveInvitesRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_KeystoreApi_V1_SaveInvitesRequest.Request] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// Mirrors xmtp.envelope schema + public struct Request { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var contentTopic: String = String() + + public var timestampNs: UInt64 = 0 + + public var payload: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} +} + +/// Response to a SaveInvitesRequest +public struct Xmtp_KeystoreApi_V1_SaveInvitesResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var responses: [Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// A single response + public struct Response { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var response: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.OneOf_Response? = nil + + public var result: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success { + get { + if case .result(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success() + } + set {response = .result(newValue)} + } + + public var error: Xmtp_KeystoreApi_V1_KeystoreError { + get { + if case .error(let v)? = response {return v} + return Xmtp_KeystoreApi_V1_KeystoreError() + } + set {response = .error(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Response: Equatable { + case result(Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success) + case error(Xmtp_KeystoreApi_V1_KeystoreError) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.OneOf_Response, rhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.OneOf_Response) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.result, .result): return { + guard case .result(let l) = lhs, case .result(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.error, .error): return { + guard case .error(let l) = lhs, case .error(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + /// Wrapper object for success response + public struct Success { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var conversation: Xmtp_MessageContents_ConversationReference { + get {return _conversation ?? Xmtp_MessageContents_ConversationReference()} + set {_conversation = newValue} + } + /// Returns true if `conversation` has been explicitly set. + public var hasConversation: Bool {return self._conversation != nil} + /// Clears the value of `conversation`. Subsequent reads from it will return its default value. + public mutating func clearConversation() {self._conversation = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _conversation: Xmtp_MessageContents_ConversationReference? = nil + } + + public init() {} + } + + public init() {} +} + +/// CreateAuthTokenRequest is used to create an auth token for the XMTP API +public struct Xmtp_KeystoreApi_V1_CreateAuthTokenRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var timestampNs: UInt64 { + get {return _timestampNs ?? 0} + set {_timestampNs = newValue} + } + /// Returns true if `timestampNs` has been explicitly set. + public var hasTimestampNs: Bool {return self._timestampNs != nil} + /// Clears the value of `timestampNs`. Subsequent reads from it will return its default value. + public mutating func clearTimestampNs() {self._timestampNs = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _timestampNs: UInt64? = nil +} + +/// SignDigestRequest is used to sign a digest with either the identity key +/// or a prekey +public struct Xmtp_KeystoreApi_V1_SignDigestRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var digest: Data = Data() + + public var signer: Xmtp_KeystoreApi_V1_SignDigestRequest.OneOf_Signer? = nil + + public var identityKey: Bool { + get { + if case .identityKey(let v)? = signer {return v} + return false + } + set {signer = .identityKey(newValue)} + } + + public var prekeyIndex: UInt32 { + get { + if case .prekeyIndex(let v)? = signer {return v} + return 0 + } + set {signer = .prekeyIndex(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Signer: Equatable { + case identityKey(Bool) + case prekeyIndex(UInt32) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_KeystoreApi_V1_SignDigestRequest.OneOf_Signer, rhs: Xmtp_KeystoreApi_V1_SignDigestRequest.OneOf_Signer) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.identityKey, .identityKey): return { + guard case .identityKey(let l) = lhs, case .identityKey(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.prekeyIndex, .prekeyIndex): return { + guard case .prekeyIndex(let l) = lhs, case .prekeyIndex(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} +} + +/// A mapping of topics to their decrypted invitations +public struct Xmtp_KeystoreApi_V1_TopicMap { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var topics: Dictionary = [:] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// TopicData wraps the invitation and the timestamp it was created + public struct TopicData { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var createdNs: UInt64 = 0 + + public var peerAddress: String = String() + + public var invitation: Xmtp_MessageContents_InvitationV1 { + get {return _invitation ?? Xmtp_MessageContents_InvitationV1()} + set {_invitation = newValue} + } + /// Returns true if `invitation` has been explicitly set. + public var hasInvitation: Bool {return self._invitation != nil} + /// Clears the value of `invitation`. Subsequent reads from it will return its default value. + public mutating func clearInvitation() {self._invitation = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _invitation: Xmtp_MessageContents_InvitationV1? = nil + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_KeystoreApi_V1_ErrorCode: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_KeystoreError: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptV1Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptV1Request.Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptResponse: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptResponse.Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptResponse.Response.OneOf_Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptV2Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_DecryptV2Request.Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptV1Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptV1Request.Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptResponse: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptResponse.Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptResponse.Response.OneOf_Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptV2Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_EncryptV2Request.Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_CreateInviteRequest: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_CreateInviteResponse: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesRequest: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesRequest.Request: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.OneOf_Response: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_CreateAuthTokenRequest: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SignDigestRequest: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_SignDigestRequest.OneOf_Signer: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_TopicMap: @unchecked Sendable {} +extension Xmtp_KeystoreApi_V1_TopicMap.TopicData: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.keystore_api.v1" + +extension Xmtp_KeystoreApi_V1_ErrorCode: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "ERROR_CODE_UNSPECIFIED"), + 1: .same(proto: "ERROR_CODE_INVALID_INPUT"), + 2: .same(proto: "ERROR_CODE_NO_MATCHING_PREKEY"), + ] +} + +extension Xmtp_KeystoreApi_V1_KeystoreError: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".KeystoreError" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "message"), + 2: .same(proto: "code"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.message) }() + case 2: try { try decoder.decodeSingularEnumField(value: &self.code) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.message.isEmpty { + try visitor.visitSingularStringField(value: self.message, fieldNumber: 1) + } + if self.code != .unspecified { + try visitor.visitSingularEnumField(value: self.code, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_KeystoreError, rhs: Xmtp_KeystoreApi_V1_KeystoreError) -> Bool { + if lhs.message != rhs.message {return false} + if lhs.code != rhs.code {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptV1Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DecryptV1Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptV1Request, rhs: Xmtp_KeystoreApi_V1_DecryptV1Request) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptV1Request.Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_DecryptV1Request.protoMessageName + ".Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "payload"), + 2: .standard(proto: "peer_keys"), + 3: .standard(proto: "header_bytes"), + 4: .standard(proto: "is_sender"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._payload) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._peerKeys) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 4: try { try decoder.decodeSingularBoolField(value: &self.isSender) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._payload { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._peerKeys { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 3) + } + if self.isSender != false { + try visitor.visitSingularBoolField(value: self.isSender, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptV1Request.Request, rhs: Xmtp_KeystoreApi_V1_DecryptV1Request.Request) -> Bool { + if lhs._payload != rhs._payload {return false} + if lhs._peerKeys != rhs._peerKeys {return false} + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs.isSender != rhs.isSender {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DecryptResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "responses"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.responses) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.responses.isEmpty { + try visitor.visitRepeatedMessageField(value: self.responses, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptResponse, rhs: Xmtp_KeystoreApi_V1_DecryptResponse) -> Bool { + if lhs.responses != rhs.responses {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptResponse.Response: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_DecryptResponse.protoMessageName + ".Response" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "result"), + 2: .same(proto: "error"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .result(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .result(v) + } + }() + case 2: try { + var v: Xmtp_KeystoreApi_V1_KeystoreError? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .error(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .error(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.response { + case .result?: try { + guard case .result(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .error?: try { + guard case .error(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response, rhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response) -> Bool { + if lhs.response != rhs.response {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_DecryptResponse.Response.protoMessageName + ".Success" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "decrypted"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.decrypted) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.decrypted.isEmpty { + try visitor.visitSingularBytesField(value: self.decrypted, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success, rhs: Xmtp_KeystoreApi_V1_DecryptResponse.Response.Success) -> Bool { + if lhs.decrypted != rhs.decrypted {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptV2Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DecryptV2Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptV2Request, rhs: Xmtp_KeystoreApi_V1_DecryptV2Request) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_DecryptV2Request.Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_DecryptV2Request.protoMessageName + ".Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "payload"), + 2: .standard(proto: "header_bytes"), + 3: .standard(proto: "content_topic"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._payload) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 3: try { try decoder.decodeSingularStringField(value: &self.contentTopic) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._payload { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 2) + } + if !self.contentTopic.isEmpty { + try visitor.visitSingularStringField(value: self.contentTopic, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_DecryptV2Request.Request, rhs: Xmtp_KeystoreApi_V1_DecryptV2Request.Request) -> Bool { + if lhs._payload != rhs._payload {return false} + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs.contentTopic != rhs.contentTopic {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptV1Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncryptV1Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptV1Request, rhs: Xmtp_KeystoreApi_V1_EncryptV1Request) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptV1Request.Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_EncryptV1Request.protoMessageName + ".Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "recipient"), + 2: .same(proto: "payload"), + 3: .standard(proto: "header_bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._recipient) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._recipient { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 2) + } + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptV1Request.Request, rhs: Xmtp_KeystoreApi_V1_EncryptV1Request.Request) -> Bool { + if lhs._recipient != rhs._recipient {return false} + if lhs.payload != rhs.payload {return false} + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncryptResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "responses"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.responses) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.responses.isEmpty { + try visitor.visitRepeatedMessageField(value: self.responses, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptResponse, rhs: Xmtp_KeystoreApi_V1_EncryptResponse) -> Bool { + if lhs.responses != rhs.responses {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptResponse.Response: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_EncryptResponse.protoMessageName + ".Response" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "result"), + 2: .same(proto: "error"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .result(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .result(v) + } + }() + case 2: try { + var v: Xmtp_KeystoreApi_V1_KeystoreError? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .error(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .error(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.response { + case .result?: try { + guard case .result(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .error?: try { + guard case .error(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response, rhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response) -> Bool { + if lhs.response != rhs.response {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_EncryptResponse.Response.protoMessageName + ".Success" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "encrypted"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._encrypted) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._encrypted { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success, rhs: Xmtp_KeystoreApi_V1_EncryptResponse.Response.Success) -> Bool { + if lhs._encrypted != rhs._encrypted {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptV2Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncryptV2Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptV2Request, rhs: Xmtp_KeystoreApi_V1_EncryptV2Request) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_EncryptV2Request.Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_EncryptV2Request.protoMessageName + ".Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "payload"), + 2: .standard(proto: "header_bytes"), + 3: .standard(proto: "content_topic"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 3: try { try decoder.decodeSingularStringField(value: &self.contentTopic) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 1) + } + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 2) + } + if !self.contentTopic.isEmpty { + try visitor.visitSingularStringField(value: self.contentTopic, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_EncryptV2Request.Request, rhs: Xmtp_KeystoreApi_V1_EncryptV2Request.Request) -> Bool { + if lhs.payload != rhs.payload {return false} + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs.contentTopic != rhs.contentTopic {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_CreateInviteRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".CreateInviteRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "context"), + 2: .same(proto: "recipient"), + 3: .standard(proto: "created_ns"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._context) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._recipient) }() + case 3: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._context { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._recipient { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_CreateInviteRequest, rhs: Xmtp_KeystoreApi_V1_CreateInviteRequest) -> Bool { + if lhs._context != rhs._context {return false} + if lhs._recipient != rhs._recipient {return false} + if lhs.createdNs != rhs.createdNs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_CreateInviteResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".CreateInviteResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "conversation"), + 2: .same(proto: "payload"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._conversation) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._conversation { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_CreateInviteResponse, rhs: Xmtp_KeystoreApi_V1_CreateInviteResponse) -> Bool { + if lhs._conversation != rhs._conversation {return false} + if lhs.payload != rhs.payload {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SaveInvitesRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SaveInvitesRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesRequest, rhs: Xmtp_KeystoreApi_V1_SaveInvitesRequest) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SaveInvitesRequest.Request: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_SaveInvitesRequest.protoMessageName + ".Request" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "content_topic"), + 2: .standard(proto: "timestamp_ns"), + 3: .same(proto: "payload"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.contentTopic) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.timestampNs) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.contentTopic.isEmpty { + try visitor.visitSingularStringField(value: self.contentTopic, fieldNumber: 1) + } + if self.timestampNs != 0 { + try visitor.visitSingularUInt64Field(value: self.timestampNs, fieldNumber: 2) + } + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesRequest.Request, rhs: Xmtp_KeystoreApi_V1_SaveInvitesRequest.Request) -> Bool { + if lhs.contentTopic != rhs.contentTopic {return false} + if lhs.timestampNs != rhs.timestampNs {return false} + if lhs.payload != rhs.payload {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SaveInvitesResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "responses"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.responses) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.responses.isEmpty { + try visitor.visitRepeatedMessageField(value: self.responses, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse, rhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse) -> Bool { + if lhs.responses != rhs.responses {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_SaveInvitesResponse.protoMessageName + ".Response" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "result"), + 2: .same(proto: "error"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .result(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .result(v) + } + }() + case 2: try { + var v: Xmtp_KeystoreApi_V1_KeystoreError? + var hadOneofValue = false + if let current = self.response { + hadOneofValue = true + if case .error(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.response = .error(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.response { + case .result?: try { + guard case .result(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .error?: try { + guard case .error(let v)? = self.response else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response, rhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response) -> Bool { + if lhs.response != rhs.response {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.protoMessageName + ".Success" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "conversation"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._conversation) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._conversation { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success, rhs: Xmtp_KeystoreApi_V1_SaveInvitesResponse.Response.Success) -> Bool { + if lhs._conversation != rhs._conversation {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_CreateAuthTokenRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".CreateAuthTokenRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "timestamp_ns"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self._timestampNs) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._timestampNs { + try visitor.visitSingularUInt64Field(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_CreateAuthTokenRequest, rhs: Xmtp_KeystoreApi_V1_CreateAuthTokenRequest) -> Bool { + if lhs._timestampNs != rhs._timestampNs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_SignDigestRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignDigestRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "digest"), + 2: .standard(proto: "identity_key"), + 3: .standard(proto: "prekey_index"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.digest) }() + case 2: try { + var v: Bool? + try decoder.decodeSingularBoolField(value: &v) + if let v = v { + if self.signer != nil {try decoder.handleConflictingOneOf()} + self.signer = .identityKey(v) + } + }() + case 3: try { + var v: UInt32? + try decoder.decodeSingularUInt32Field(value: &v) + if let v = v { + if self.signer != nil {try decoder.handleConflictingOneOf()} + self.signer = .prekeyIndex(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.digest.isEmpty { + try visitor.visitSingularBytesField(value: self.digest, fieldNumber: 1) + } + switch self.signer { + case .identityKey?: try { + guard case .identityKey(let v)? = self.signer else { preconditionFailure() } + try visitor.visitSingularBoolField(value: v, fieldNumber: 2) + }() + case .prekeyIndex?: try { + guard case .prekeyIndex(let v)? = self.signer else { preconditionFailure() } + try visitor.visitSingularUInt32Field(value: v, fieldNumber: 3) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_SignDigestRequest, rhs: Xmtp_KeystoreApi_V1_SignDigestRequest) -> Bool { + if lhs.digest != rhs.digest {return false} + if lhs.signer != rhs.signer {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_TopicMap: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".TopicMap" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "topics"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: &self.topics) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.topics.isEmpty { + try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMessageMap.self, value: self.topics, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_TopicMap, rhs: Xmtp_KeystoreApi_V1_TopicMap) -> Bool { + if lhs.topics != rhs.topics {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_KeystoreApi_V1_TopicMap.TopicData: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_KeystoreApi_V1_TopicMap.protoMessageName + ".TopicData" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "created_ns"), + 2: .standard(proto: "peer_address"), + 3: .same(proto: "invitation"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.peerAddress) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._invitation) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 1) + } + if !self.peerAddress.isEmpty { + try visitor.visitSingularStringField(value: self.peerAddress, fieldNumber: 2) + } + try { if let v = self._invitation { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_KeystoreApi_V1_TopicMap.TopicData, rhs: Xmtp_KeystoreApi_V1_TopicMap.TopicData) -> Bool { + if lhs.createdNs != rhs.createdNs {return false} + if lhs.peerAddress != rhs.peerAddress {return false} + if lhs._invitation != rhs._invitation {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_api/v1/authn.pb.swift b/Sources/XMTP/Proto/message_api/v1/authn.pb.swift new file mode 100644 index 00000000..22361f7c --- /dev/null +++ b/Sources/XMTP/Proto/message_api/v1/authn.pb.swift @@ -0,0 +1,177 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_api/v1/authn.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Client authentication protocol + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Token is used by clients to prove to the nodes +/// that they are serving a specific wallet. +public struct Xmtp_MessageApi_V1_Token { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// identity key signed by a wallet + public var identityKey: Xmtp_MessageContents_PublicKey { + get {return _identityKey ?? Xmtp_MessageContents_PublicKey()} + set {_identityKey = newValue} + } + /// Returns true if `identityKey` has been explicitly set. + public var hasIdentityKey: Bool {return self._identityKey != nil} + /// Clears the value of `identityKey`. Subsequent reads from it will return its default value. + public mutating func clearIdentityKey() {self._identityKey = nil} + + /// encoded bytes of AuthData + public var authDataBytes: Data = Data() + + /// identity key signature of AuthData bytes + public var authDataSignature: Xmtp_MessageContents_Signature { + get {return _authDataSignature ?? Xmtp_MessageContents_Signature()} + set {_authDataSignature = newValue} + } + /// Returns true if `authDataSignature` has been explicitly set. + public var hasAuthDataSignature: Bool {return self._authDataSignature != nil} + /// Clears the value of `authDataSignature`. Subsequent reads from it will return its default value. + public mutating func clearAuthDataSignature() {self._authDataSignature = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _identityKey: Xmtp_MessageContents_PublicKey? = nil + fileprivate var _authDataSignature: Xmtp_MessageContents_Signature? = nil +} + +/// AuthData carries token parameters that are authenticated +/// by the identity key signature. +/// It is embedded in the Token structure as bytes +/// so that the bytes don't need to be reconstructed +/// to verify the token signature. +public struct Xmtp_MessageApi_V1_AuthData { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// address of the wallet + public var walletAddr: String = String() + + /// time when the token was generated/signed + public var createdNs: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageApi_V1_Token: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_AuthData: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_api.v1" + +extension Xmtp_MessageApi_V1_Token: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Token" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "identity_key"), + 2: .standard(proto: "auth_data_bytes"), + 3: .standard(proto: "auth_data_signature"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._identityKey) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.authDataBytes) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._authDataSignature) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._identityKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.authDataBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.authDataBytes, fieldNumber: 2) + } + try { if let v = self._authDataSignature { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_Token, rhs: Xmtp_MessageApi_V1_Token) -> Bool { + if lhs._identityKey != rhs._identityKey {return false} + if lhs.authDataBytes != rhs.authDataBytes {return false} + if lhs._authDataSignature != rhs._authDataSignature {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_AuthData: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".AuthData" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "wallet_addr"), + 2: .standard(proto: "created_ns"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.walletAddr) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.walletAddr.isEmpty { + try visitor.visitSingularStringField(value: self.walletAddr, fieldNumber: 1) + } + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_AuthData, rhs: Xmtp_MessageApi_V1_AuthData) -> Bool { + if lhs.walletAddr != rhs.walletAddr {return false} + if lhs.createdNs != rhs.createdNs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift b/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift new file mode 100644 index 00000000..ac098abb --- /dev/null +++ b/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift @@ -0,0 +1,744 @@ +// +// DO NOT EDIT. +// +// Generated by the protocol buffer compiler. +// Source: message_api/v1/message_api.proto +// + +// +// Copyright 2018, gRPC Authors All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if canImport(GRPC) +import GRPC +import NIO +import NIOConcurrencyHelpers +import SwiftProtobuf + + +/// RPC +/// +/// Usage: instantiate `Xmtp_MessageApi_V1_MessageApiClient`, then call methods of this protocol to make API calls. +public protocol Xmtp_MessageApi_V1_MessageApiClientProtocol: GRPCClient { + var serviceName: String { get } + var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { get } + + func publish( + _ request: Xmtp_MessageApi_V1_PublishRequest, + callOptions: CallOptions? + ) -> UnaryCall + + func subscribe( + _ request: Xmtp_MessageApi_V1_SubscribeRequest, + callOptions: CallOptions?, + handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void + ) -> ServerStreamingCall + + func subscribeAll( + _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, + callOptions: CallOptions?, + handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void + ) -> ServerStreamingCall + + func query( + _ request: Xmtp_MessageApi_V1_QueryRequest, + callOptions: CallOptions? + ) -> UnaryCall + + func batchQuery( + _ request: Xmtp_MessageApi_V1_BatchQueryRequest, + callOptions: CallOptions? + ) -> UnaryCall +} + +extension Xmtp_MessageApi_V1_MessageApiClientProtocol { + public var serviceName: String { + return "xmtp.message_api.v1.MessageApi" + } + + /// Publish messages to the network + /// + /// - Parameters: + /// - request: Request to send to Publish. + /// - callOptions: Call options. + /// - Returns: A `UnaryCall` with futures for the metadata, status and response. + public func publish( + _ request: Xmtp_MessageApi_V1_PublishRequest, + callOptions: CallOptions? = nil + ) -> UnaryCall { + return self.makeUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makePublishInterceptors() ?? [] + ) + } + + /// Subscribe to a stream of new envelopes matching a predicate + /// + /// - Parameters: + /// - request: Request to send to Subscribe. + /// - callOptions: Call options. + /// - handler: A closure called when each response is received from the server. + /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. + public func subscribe( + _ request: Xmtp_MessageApi_V1_SubscribeRequest, + callOptions: CallOptions? = nil, + handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void + ) -> ServerStreamingCall { + return self.makeServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], + handler: handler + ) + } + + /// Subscribe to a stream of all messages + /// + /// - Parameters: + /// - request: Request to send to SubscribeAll. + /// - callOptions: Call options. + /// - handler: A closure called when each response is received from the server. + /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. + public func subscribeAll( + _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, + callOptions: CallOptions? = nil, + handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void + ) -> ServerStreamingCall { + return self.makeServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], + handler: handler + ) + } + + /// Query the store for messages + /// + /// - Parameters: + /// - request: Request to send to Query. + /// - callOptions: Call options. + /// - Returns: A `UnaryCall` with futures for the metadata, status and response. + public func query( + _ request: Xmtp_MessageApi_V1_QueryRequest, + callOptions: CallOptions? = nil + ) -> UnaryCall { + return self.makeUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeQueryInterceptors() ?? [] + ) + } + + /// BatchQuery containing a set of queries to be processed + /// + /// - Parameters: + /// - request: Request to send to BatchQuery. + /// - callOptions: Call options. + /// - Returns: A `UnaryCall` with futures for the metadata, status and response. + public func batchQuery( + _ request: Xmtp_MessageApi_V1_BatchQueryRequest, + callOptions: CallOptions? = nil + ) -> UnaryCall { + return self.makeUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] + ) + } +} + +#if compiler(>=5.6) +@available(*, deprecated) +extension Xmtp_MessageApi_V1_MessageApiClient: @unchecked Sendable {} +#endif // compiler(>=5.6) + +@available(*, deprecated, renamed: "Xmtp_MessageApi_V1_MessageApiNIOClient") +public final class Xmtp_MessageApi_V1_MessageApiClient: Xmtp_MessageApi_V1_MessageApiClientProtocol { + private let lock = Lock() + private var _defaultCallOptions: CallOptions + private var _interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? + public let channel: GRPCChannel + public var defaultCallOptions: CallOptions { + get { self.lock.withLock { return self._defaultCallOptions } } + set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } + } + public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { + get { self.lock.withLock { return self._interceptors } } + set { self.lock.withLockVoid { self._interceptors = newValue } } + } + + /// Creates a client for the xmtp.message_api.v1.MessageApi service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self._defaultCallOptions = defaultCallOptions + self._interceptors = interceptors + } +} + +public struct Xmtp_MessageApi_V1_MessageApiNIOClient: Xmtp_MessageApi_V1_MessageApiClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? + + /// Creates a client for the xmtp.message_api.v1.MessageApi service. + /// + /// - Parameters: + /// - channel: `GRPCChannel` to the service host. + /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. + /// - interceptors: A factory providing interceptors for each RPC. + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#if compiler(>=5.6) +/// RPC +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol: GRPCClient { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { get } + + func makePublishCall( + _ request: Xmtp_MessageApi_V1_PublishRequest, + callOptions: CallOptions? + ) -> GRPCAsyncUnaryCall + + func makeSubscribeCall( + _ request: Xmtp_MessageApi_V1_SubscribeRequest, + callOptions: CallOptions? + ) -> GRPCAsyncServerStreamingCall + + func makeSubscribeAllCall( + _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, + callOptions: CallOptions? + ) -> GRPCAsyncServerStreamingCall + + func makeQueryCall( + _ request: Xmtp_MessageApi_V1_QueryRequest, + callOptions: CallOptions? + ) -> GRPCAsyncUnaryCall + + func makeBatchQueryCall( + _ request: Xmtp_MessageApi_V1_BatchQueryRequest, + callOptions: CallOptions? + ) -> GRPCAsyncUnaryCall +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { + public static var serviceDescriptor: GRPCServiceDescriptor { + return Xmtp_MessageApi_V1_MessageApiClientMetadata.serviceDescriptor + } + + public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { + return nil + } + + public func makePublishCall( + _ request: Xmtp_MessageApi_V1_PublishRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncUnaryCall { + return self.makeAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makePublishInterceptors() ?? [] + ) + } + + public func makeSubscribeCall( + _ request: Xmtp_MessageApi_V1_SubscribeRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncServerStreamingCall { + return self.makeAsyncServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [] + ) + } + + public func makeSubscribeAllCall( + _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncServerStreamingCall { + return self.makeAsyncServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [] + ) + } + + public func makeQueryCall( + _ request: Xmtp_MessageApi_V1_QueryRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncUnaryCall { + return self.makeAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeQueryInterceptors() ?? [] + ) + } + + public func makeBatchQueryCall( + _ request: Xmtp_MessageApi_V1_BatchQueryRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncUnaryCall { + return self.makeAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { + public func publish( + _ request: Xmtp_MessageApi_V1_PublishRequest, + callOptions: CallOptions? = nil + ) async throws -> Xmtp_MessageApi_V1_PublishResponse { + return try await self.performAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makePublishInterceptors() ?? [] + ) + } + + public func subscribe( + _ request: Xmtp_MessageApi_V1_SubscribeRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncResponseStream { + return self.performAsyncServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [] + ) + } + + public func subscribeAll( + _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, + callOptions: CallOptions? = nil + ) -> GRPCAsyncResponseStream { + return self.performAsyncServerStreamingCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [] + ) + } + + public func query( + _ request: Xmtp_MessageApi_V1_QueryRequest, + callOptions: CallOptions? = nil + ) async throws -> Xmtp_MessageApi_V1_QueryResponse { + return try await self.performAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeQueryInterceptors() ?? [] + ) + } + + public func batchQuery( + _ request: Xmtp_MessageApi_V1_BatchQueryRequest, + callOptions: CallOptions? = nil + ) async throws -> Xmtp_MessageApi_V1_BatchQueryResponse { + return try await self.performAsyncUnaryCall( + path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, + request: request, + callOptions: callOptions ?? self.defaultCallOptions, + interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] + ) + } +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public struct Xmtp_MessageApi_V1_MessageApiAsyncClient: Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { + public var channel: GRPCChannel + public var defaultCallOptions: CallOptions + public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? + + public init( + channel: GRPCChannel, + defaultCallOptions: CallOptions = CallOptions(), + interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil + ) { + self.channel = channel + self.defaultCallOptions = defaultCallOptions + self.interceptors = interceptors + } +} + +#endif // compiler(>=5.6) + +public protocol Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol: GRPCSendable { + + /// - Returns: Interceptors to use when invoking 'publish'. + func makePublishInterceptors() -> [ClientInterceptor] + + /// - Returns: Interceptors to use when invoking 'subscribe'. + func makeSubscribeInterceptors() -> [ClientInterceptor] + + /// - Returns: Interceptors to use when invoking 'subscribeAll'. + func makeSubscribeAllInterceptors() -> [ClientInterceptor] + + /// - Returns: Interceptors to use when invoking 'query'. + func makeQueryInterceptors() -> [ClientInterceptor] + + /// - Returns: Interceptors to use when invoking 'batchQuery'. + func makeBatchQueryInterceptors() -> [ClientInterceptor] +} + +public enum Xmtp_MessageApi_V1_MessageApiClientMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "MessageApi", + fullName: "xmtp.message_api.v1.MessageApi", + methods: [ + Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish, + Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe, + Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll, + Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query, + Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery, + ] + ) + + public enum Methods { + public static let publish = GRPCMethodDescriptor( + name: "Publish", + path: "/xmtp.message_api.v1.MessageApi/Publish", + type: GRPCCallType.unary + ) + + public static let subscribe = GRPCMethodDescriptor( + name: "Subscribe", + path: "/xmtp.message_api.v1.MessageApi/Subscribe", + type: GRPCCallType.serverStreaming + ) + + public static let subscribeAll = GRPCMethodDescriptor( + name: "SubscribeAll", + path: "/xmtp.message_api.v1.MessageApi/SubscribeAll", + type: GRPCCallType.serverStreaming + ) + + public static let query = GRPCMethodDescriptor( + name: "Query", + path: "/xmtp.message_api.v1.MessageApi/Query", + type: GRPCCallType.unary + ) + + public static let batchQuery = GRPCMethodDescriptor( + name: "BatchQuery", + path: "/xmtp.message_api.v1.MessageApi/BatchQuery", + type: GRPCCallType.unary + ) + } +} + +/// RPC +/// +/// To build a server, implement a class that conforms to this protocol. +public protocol Xmtp_MessageApi_V1_MessageApiProvider: CallHandlerProvider { + var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { get } + + /// Publish messages to the network + func publish(request: Xmtp_MessageApi_V1_PublishRequest, context: StatusOnlyCallContext) -> EventLoopFuture + + /// Subscribe to a stream of new envelopes matching a predicate + func subscribe(request: Xmtp_MessageApi_V1_SubscribeRequest, context: StreamingResponseCallContext) -> EventLoopFuture + + /// Subscribe to a stream of all messages + func subscribeAll(request: Xmtp_MessageApi_V1_SubscribeAllRequest, context: StreamingResponseCallContext) -> EventLoopFuture + + /// Query the store for messages + func query(request: Xmtp_MessageApi_V1_QueryRequest, context: StatusOnlyCallContext) -> EventLoopFuture + + /// BatchQuery containing a set of queries to be processed + func batchQuery(request: Xmtp_MessageApi_V1_BatchQueryRequest, context: StatusOnlyCallContext) -> EventLoopFuture +} + +extension Xmtp_MessageApi_V1_MessageApiProvider { + public var serviceName: Substring { + return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor.fullName[...] + } + + /// Determines, calls and returns the appropriate request handler, depending on the request's method. + /// Returns nil for methods not handled by this service. + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "Publish": + return UnaryServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makePublishInterceptors() ?? [], + userFunction: self.publish(request:context:) + ) + + case "Subscribe": + return ServerStreamingServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], + userFunction: self.subscribe(request:context:) + ) + + case "SubscribeAll": + return ServerStreamingServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], + userFunction: self.subscribeAll(request:context:) + ) + + case "Query": + return UnaryServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeQueryInterceptors() ?? [], + userFunction: self.query(request:context:) + ) + + case "BatchQuery": + return UnaryServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [], + userFunction: self.batchQuery(request:context:) + ) + + default: + return nil + } + } +} + +#if compiler(>=5.6) + +/// RPC +/// +/// To implement a server, implement an object which conforms to this protocol. +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +public protocol Xmtp_MessageApi_V1_MessageApiAsyncProvider: CallHandlerProvider { + static var serviceDescriptor: GRPCServiceDescriptor { get } + var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { get } + + /// Publish messages to the network + @Sendable func publish( + request: Xmtp_MessageApi_V1_PublishRequest, + context: GRPCAsyncServerCallContext + ) async throws -> Xmtp_MessageApi_V1_PublishResponse + + /// Subscribe to a stream of new envelopes matching a predicate + @Sendable func subscribe( + request: Xmtp_MessageApi_V1_SubscribeRequest, + responseStream: GRPCAsyncResponseStreamWriter, + context: GRPCAsyncServerCallContext + ) async throws + + /// Subscribe to a stream of all messages + @Sendable func subscribeAll( + request: Xmtp_MessageApi_V1_SubscribeAllRequest, + responseStream: GRPCAsyncResponseStreamWriter, + context: GRPCAsyncServerCallContext + ) async throws + + /// Query the store for messages + @Sendable func query( + request: Xmtp_MessageApi_V1_QueryRequest, + context: GRPCAsyncServerCallContext + ) async throws -> Xmtp_MessageApi_V1_QueryResponse + + /// BatchQuery containing a set of queries to be processed + @Sendable func batchQuery( + request: Xmtp_MessageApi_V1_BatchQueryRequest, + context: GRPCAsyncServerCallContext + ) async throws -> Xmtp_MessageApi_V1_BatchQueryResponse +} + +@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) +extension Xmtp_MessageApi_V1_MessageApiAsyncProvider { + public static var serviceDescriptor: GRPCServiceDescriptor { + return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor + } + + public var serviceName: Substring { + return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor.fullName[...] + } + + public var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { + return nil + } + + public func handle( + method name: Substring, + context: CallHandlerContext + ) -> GRPCServerHandlerProtocol? { + switch name { + case "Publish": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makePublishInterceptors() ?? [], + wrapping: self.publish(request:context:) + ) + + case "Subscribe": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], + wrapping: self.subscribe(request:responseStream:context:) + ) + + case "SubscribeAll": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], + wrapping: self.subscribeAll(request:responseStream:context:) + ) + + case "Query": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeQueryInterceptors() ?? [], + wrapping: self.query(request:context:) + ) + + case "BatchQuery": + return GRPCAsyncServerHandler( + context: context, + requestDeserializer: ProtobufDeserializer(), + responseSerializer: ProtobufSerializer(), + interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [], + wrapping: self.batchQuery(request:context:) + ) + + default: + return nil + } + } +} + +#endif // compiler(>=5.6) + +public protocol Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol { + + /// - Returns: Interceptors to use when handling 'publish'. + /// Defaults to calling `self.makeInterceptors()`. + func makePublishInterceptors() -> [ServerInterceptor] + + /// - Returns: Interceptors to use when handling 'subscribe'. + /// Defaults to calling `self.makeInterceptors()`. + func makeSubscribeInterceptors() -> [ServerInterceptor] + + /// - Returns: Interceptors to use when handling 'subscribeAll'. + /// Defaults to calling `self.makeInterceptors()`. + func makeSubscribeAllInterceptors() -> [ServerInterceptor] + + /// - Returns: Interceptors to use when handling 'query'. + /// Defaults to calling `self.makeInterceptors()`. + func makeQueryInterceptors() -> [ServerInterceptor] + + /// - Returns: Interceptors to use when handling 'batchQuery'. + /// Defaults to calling `self.makeInterceptors()`. + func makeBatchQueryInterceptors() -> [ServerInterceptor] +} + +public enum Xmtp_MessageApi_V1_MessageApiServerMetadata { + public static let serviceDescriptor = GRPCServiceDescriptor( + name: "MessageApi", + fullName: "xmtp.message_api.v1.MessageApi", + methods: [ + Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.publish, + Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.subscribe, + Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.subscribeAll, + Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.query, + Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.batchQuery, + ] + ) + + public enum Methods { + public static let publish = GRPCMethodDescriptor( + name: "Publish", + path: "/xmtp.message_api.v1.MessageApi/Publish", + type: GRPCCallType.unary + ) + + public static let subscribe = GRPCMethodDescriptor( + name: "Subscribe", + path: "/xmtp.message_api.v1.MessageApi/Subscribe", + type: GRPCCallType.serverStreaming + ) + + public static let subscribeAll = GRPCMethodDescriptor( + name: "SubscribeAll", + path: "/xmtp.message_api.v1.MessageApi/SubscribeAll", + type: GRPCCallType.serverStreaming + ) + + public static let query = GRPCMethodDescriptor( + name: "Query", + path: "/xmtp.message_api.v1.MessageApi/Query", + type: GRPCCallType.unary + ) + + public static let batchQuery = GRPCMethodDescriptor( + name: "BatchQuery", + path: "/xmtp.message_api.v1.MessageApi/BatchQuery", + type: GRPCCallType.unary + ) + } +} +#endif diff --git a/Sources/XMTP/Proto/message_api/v1/message_api.pb.swift b/Sources/XMTP/Proto/message_api/v1/message_api.pb.swift new file mode 100644 index 00000000..03ae0a3a --- /dev/null +++ b/Sources/XMTP/Proto/message_api/v1/message_api.pb.swift @@ -0,0 +1,776 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_api/v1/message_api.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Message API + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Sort direction +public enum Xmtp_MessageApi_V1_SortDirection: SwiftProtobuf.Enum { + public typealias RawValue = Int + case unspecified // = 0 + case ascending // = 1 + case descending // = 2 + case UNRECOGNIZED(Int) + + public init() { + self = .unspecified + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .unspecified + case 1: self = .ascending + case 2: self = .descending + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .unspecified: return 0 + case .ascending: return 1 + case .descending: return 2 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Xmtp_MessageApi_V1_SortDirection: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Xmtp_MessageApi_V1_SortDirection] = [ + .unspecified, + .ascending, + .descending, + ] +} + +#endif // swift(>=4.2) + +/// This is based off of the go-waku Index type, but with the +/// receiverTime and pubsubTopic removed for simplicity. +/// Both removed fields are optional +public struct Xmtp_MessageApi_V1_IndexCursor { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var digest: Data = Data() + + public var senderTimeNs: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Wrapper for potentially multiple types of cursor +public struct Xmtp_MessageApi_V1_Cursor { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Making the cursor a one-of type, as I would like to change the way we + /// handle pagination to use a precomputed sort field. + /// This way we can handle both methods + public var cursor: Xmtp_MessageApi_V1_Cursor.OneOf_Cursor? = nil + + public var index: Xmtp_MessageApi_V1_IndexCursor { + get { + if case .index(let v)? = cursor {return v} + return Xmtp_MessageApi_V1_IndexCursor() + } + set {cursor = .index(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// Making the cursor a one-of type, as I would like to change the way we + /// handle pagination to use a precomputed sort field. + /// This way we can handle both methods + public enum OneOf_Cursor: Equatable { + case index(Xmtp_MessageApi_V1_IndexCursor) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageApi_V1_Cursor.OneOf_Cursor, rhs: Xmtp_MessageApi_V1_Cursor.OneOf_Cursor) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.index, .index): return { + guard case .index(let l) = lhs, case .index(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + public init() {} +} + +/// This is based off of the go-waku PagingInfo struct, but with the direction +/// changed to our SortDirection enum format +public struct Xmtp_MessageApi_V1_PagingInfo { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Note: this is a uint32, while go-waku's pageSize is a uint64 + public var limit: UInt32 = 0 + + public var cursor: Xmtp_MessageApi_V1_Cursor { + get {return _cursor ?? Xmtp_MessageApi_V1_Cursor()} + set {_cursor = newValue} + } + /// Returns true if `cursor` has been explicitly set. + public var hasCursor: Bool {return self._cursor != nil} + /// Clears the value of `cursor`. Subsequent reads from it will return its default value. + public mutating func clearCursor() {self._cursor = nil} + + public var direction: Xmtp_MessageApi_V1_SortDirection = .unspecified + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _cursor: Xmtp_MessageApi_V1_Cursor? = nil +} + +/// Envelope encapsulates a message while in transit. +public struct Xmtp_MessageApi_V1_Envelope { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// The topic the message belongs to, + /// If the message includes the topic as well + /// it MUST be the same as the topic in the envelope. + public var contentTopic: String = String() + + /// Message creation timestamp + /// If the message includes the timestamp as well + /// it MUST be equivalent to the timestamp in the envelope. + public var timestampNs: UInt64 = 0 + + public var message: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Publish +public struct Xmtp_MessageApi_V1_PublishRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var envelopes: [Xmtp_MessageApi_V1_Envelope] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Empty message as a response for Publish +public struct Xmtp_MessageApi_V1_PublishResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Subscribe +public struct Xmtp_MessageApi_V1_SubscribeRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var contentTopics: [String] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// SubscribeAll +public struct Xmtp_MessageApi_V1_SubscribeAllRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Query +public struct Xmtp_MessageApi_V1_QueryRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var contentTopics: [String] = [] + + public var startTimeNs: UInt64 = 0 + + public var endTimeNs: UInt64 = 0 + + public var pagingInfo: Xmtp_MessageApi_V1_PagingInfo { + get {return _pagingInfo ?? Xmtp_MessageApi_V1_PagingInfo()} + set {_pagingInfo = newValue} + } + /// Returns true if `pagingInfo` has been explicitly set. + public var hasPagingInfo: Bool {return self._pagingInfo != nil} + /// Clears the value of `pagingInfo`. Subsequent reads from it will return its default value. + public mutating func clearPagingInfo() {self._pagingInfo = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _pagingInfo: Xmtp_MessageApi_V1_PagingInfo? = nil +} + +/// The response, containing envelopes, for a query +public struct Xmtp_MessageApi_V1_QueryResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var envelopes: [Xmtp_MessageApi_V1_Envelope] = [] + + public var pagingInfo: Xmtp_MessageApi_V1_PagingInfo { + get {return _pagingInfo ?? Xmtp_MessageApi_V1_PagingInfo()} + set {_pagingInfo = newValue} + } + /// Returns true if `pagingInfo` has been explicitly set. + public var hasPagingInfo: Bool {return self._pagingInfo != nil} + /// Clears the value of `pagingInfo`. Subsequent reads from it will return its default value. + public mutating func clearPagingInfo() {self._pagingInfo = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _pagingInfo: Xmtp_MessageApi_V1_PagingInfo? = nil +} + +/// BatchQuery +public struct Xmtp_MessageApi_V1_BatchQueryRequest { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var requests: [Xmtp_MessageApi_V1_QueryRequest] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Response containing a list of QueryResponse messages +public struct Xmtp_MessageApi_V1_BatchQueryResponse { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var responses: [Xmtp_MessageApi_V1_QueryResponse] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageApi_V1_SortDirection: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_IndexCursor: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_Cursor: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_Cursor.OneOf_Cursor: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_PagingInfo: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_Envelope: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_PublishRequest: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_PublishResponse: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_SubscribeRequest: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_SubscribeAllRequest: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_QueryRequest: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_QueryResponse: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_BatchQueryRequest: @unchecked Sendable {} +extension Xmtp_MessageApi_V1_BatchQueryResponse: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_api.v1" + +extension Xmtp_MessageApi_V1_SortDirection: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "SORT_DIRECTION_UNSPECIFIED"), + 1: .same(proto: "SORT_DIRECTION_ASCENDING"), + 2: .same(proto: "SORT_DIRECTION_DESCENDING"), + ] +} + +extension Xmtp_MessageApi_V1_IndexCursor: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".IndexCursor" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "digest"), + 2: .standard(proto: "sender_time_ns"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.digest) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.senderTimeNs) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.digest.isEmpty { + try visitor.visitSingularBytesField(value: self.digest, fieldNumber: 1) + } + if self.senderTimeNs != 0 { + try visitor.visitSingularUInt64Field(value: self.senderTimeNs, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_IndexCursor, rhs: Xmtp_MessageApi_V1_IndexCursor) -> Bool { + if lhs.digest != rhs.digest {return false} + if lhs.senderTimeNs != rhs.senderTimeNs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_Cursor: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Cursor" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "index"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageApi_V1_IndexCursor? + var hadOneofValue = false + if let current = self.cursor { + hadOneofValue = true + if case .index(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.cursor = .index(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if case .index(let v)? = self.cursor { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_Cursor, rhs: Xmtp_MessageApi_V1_Cursor) -> Bool { + if lhs.cursor != rhs.cursor {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_PagingInfo: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PagingInfo" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "limit"), + 2: .same(proto: "cursor"), + 3: .same(proto: "direction"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt32Field(value: &self.limit) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._cursor) }() + case 3: try { try decoder.decodeSingularEnumField(value: &self.direction) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.limit != 0 { + try visitor.visitSingularUInt32Field(value: self.limit, fieldNumber: 1) + } + try { if let v = self._cursor { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if self.direction != .unspecified { + try visitor.visitSingularEnumField(value: self.direction, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_PagingInfo, rhs: Xmtp_MessageApi_V1_PagingInfo) -> Bool { + if lhs.limit != rhs.limit {return false} + if lhs._cursor != rhs._cursor {return false} + if lhs.direction != rhs.direction {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_Envelope: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Envelope" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "content_topic"), + 2: .standard(proto: "timestamp_ns"), + 3: .same(proto: "message"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.contentTopic) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.timestampNs) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.message) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.contentTopic.isEmpty { + try visitor.visitSingularStringField(value: self.contentTopic, fieldNumber: 1) + } + if self.timestampNs != 0 { + try visitor.visitSingularUInt64Field(value: self.timestampNs, fieldNumber: 2) + } + if !self.message.isEmpty { + try visitor.visitSingularBytesField(value: self.message, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_Envelope, rhs: Xmtp_MessageApi_V1_Envelope) -> Bool { + if lhs.contentTopic != rhs.contentTopic {return false} + if lhs.timestampNs != rhs.timestampNs {return false} + if lhs.message != rhs.message {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_PublishRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PublishRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "envelopes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.envelopes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.envelopes.isEmpty { + try visitor.visitRepeatedMessageField(value: self.envelopes, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_PublishRequest, rhs: Xmtp_MessageApi_V1_PublishRequest) -> Bool { + if lhs.envelopes != rhs.envelopes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_PublishResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PublishResponse" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_PublishResponse, rhs: Xmtp_MessageApi_V1_PublishResponse) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_SubscribeRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SubscribeRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "content_topics"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedStringField(value: &self.contentTopics) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.contentTopics.isEmpty { + try visitor.visitRepeatedStringField(value: self.contentTopics, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_SubscribeRequest, rhs: Xmtp_MessageApi_V1_SubscribeRequest) -> Bool { + if lhs.contentTopics != rhs.contentTopics {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_SubscribeAllRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SubscribeAllRequest" + public static let _protobuf_nameMap = SwiftProtobuf._NameMap() + + public mutating func decodeMessage(decoder: inout D) throws { + while let _ = try decoder.nextFieldNumber() { + } + } + + public func traverse(visitor: inout V) throws { + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_SubscribeAllRequest, rhs: Xmtp_MessageApi_V1_SubscribeAllRequest) -> Bool { + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_QueryRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".QueryRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "content_topics"), + 2: .standard(proto: "start_time_ns"), + 3: .standard(proto: "end_time_ns"), + 4: .standard(proto: "paging_info"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedStringField(value: &self.contentTopics) }() + case 2: try { try decoder.decodeSingularUInt64Field(value: &self.startTimeNs) }() + case 3: try { try decoder.decodeSingularUInt64Field(value: &self.endTimeNs) }() + case 4: try { try decoder.decodeSingularMessageField(value: &self._pagingInfo) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.contentTopics.isEmpty { + try visitor.visitRepeatedStringField(value: self.contentTopics, fieldNumber: 1) + } + if self.startTimeNs != 0 { + try visitor.visitSingularUInt64Field(value: self.startTimeNs, fieldNumber: 2) + } + if self.endTimeNs != 0 { + try visitor.visitSingularUInt64Field(value: self.endTimeNs, fieldNumber: 3) + } + try { if let v = self._pagingInfo { + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_QueryRequest, rhs: Xmtp_MessageApi_V1_QueryRequest) -> Bool { + if lhs.contentTopics != rhs.contentTopics {return false} + if lhs.startTimeNs != rhs.startTimeNs {return false} + if lhs.endTimeNs != rhs.endTimeNs {return false} + if lhs._pagingInfo != rhs._pagingInfo {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_QueryResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".QueryResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "envelopes"), + 2: .standard(proto: "paging_info"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.envelopes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._pagingInfo) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.envelopes.isEmpty { + try visitor.visitRepeatedMessageField(value: self.envelopes, fieldNumber: 1) + } + try { if let v = self._pagingInfo { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_QueryResponse, rhs: Xmtp_MessageApi_V1_QueryResponse) -> Bool { + if lhs.envelopes != rhs.envelopes {return false} + if lhs._pagingInfo != rhs._pagingInfo {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_BatchQueryRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BatchQueryRequest" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "requests"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.requests) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.requests.isEmpty { + try visitor.visitRepeatedMessageField(value: self.requests, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_BatchQueryRequest, rhs: Xmtp_MessageApi_V1_BatchQueryRequest) -> Bool { + if lhs.requests != rhs.requests {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageApi_V1_BatchQueryResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".BatchQueryResponse" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "responses"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.responses) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.responses.isEmpty { + try visitor.visitRepeatedMessageField(value: self.responses, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageApi_V1_BatchQueryResponse, rhs: Xmtp_MessageApi_V1_BatchQueryResponse) -> Bool { + if lhs.responses != rhs.responses {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/ciphertext.pb.swift b/Sources/XMTP/Proto/message_contents/ciphertext.pb.swift new file mode 100644 index 00000000..6d057307 --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/ciphertext.pb.swift @@ -0,0 +1,331 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/ciphertext.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Ciphertext is a generic structure for encrypted payload. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Ciphertext represents encrypted payload. +/// It is definited as a union to support cryptographic algorithm agility. +/// The payload is accompanied by the cryptographic parameters +/// required by the chosen encryption scheme. +public struct Xmtp_MessageContents_Ciphertext { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var union: Xmtp_MessageContents_Ciphertext.OneOf_Union? = nil + + public var aes256GcmHkdfSha256: Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256 { + get { + if case .aes256GcmHkdfSha256(let v)? = union {return v} + return Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256() + } + set {union = .aes256GcmHkdfSha256(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Union: Equatable { + case aes256GcmHkdfSha256(Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_Ciphertext.OneOf_Union, rhs: Xmtp_MessageContents_Ciphertext.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.aes256GcmHkdfSha256, .aes256GcmHkdfSha256): return { + guard case .aes256GcmHkdfSha256(let l) = lhs, case .aes256GcmHkdfSha256(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// Encryption: AES256-GCM + /// Key derivation function: HKDF-SHA256 + public struct Aes256gcmHkdfsha256 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// 32 bytes + public var hkdfSalt: Data = Data() + + /// 12 bytes + public var gcmNonce: Data = Data() + + /// encrypted payload + public var payload: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} +} + +/// SignedEciesCiphertext represents an ECIES encrypted payload and a signature +public struct Xmtp_MessageContents_SignedEciesCiphertext { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// serialized Ecies message + public var eciesBytes: Data = Data() + + /// signature of sha256(ecies_bytes) signed with the IdentityKey + public var signature: Xmtp_MessageContents_Signature { + get {return _signature ?? Xmtp_MessageContents_Signature()} + set {_signature = newValue} + } + /// Returns true if `signature` has been explicitly set. + public var hasSignature: Bool {return self._signature != nil} + /// Clears the value of `signature`. Subsequent reads from it will return its default value. + public mutating func clearSignature() {self._signature = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// Ecies is ciphertext encrypted using ECIES with a MAC + public struct Ecies { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// 65 bytes + public var ephemeralPublicKey: Data = Data() + + /// 16 bytes + public var iv: Data = Data() + + /// 32 bytes + public var mac: Data = Data() + + /// encrypted payload with block size of 16 + public var ciphertext: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + + fileprivate var _signature: Xmtp_MessageContents_Signature? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_Ciphertext: @unchecked Sendable {} +extension Xmtp_MessageContents_Ciphertext.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedEciesCiphertext: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedEciesCiphertext.Ecies: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_Ciphertext: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Ciphertext" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "aes256_gcm_hkdf_sha256"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .aes256GcmHkdfSha256(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .aes256GcmHkdfSha256(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if case .aes256GcmHkdfSha256(let v)? = self.union { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Ciphertext, rhs: Xmtp_MessageContents_Ciphertext) -> Bool { + if lhs.union != rhs.union {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_Ciphertext.protoMessageName + ".Aes256gcmHkdfsha256" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "hkdf_salt"), + 2: .standard(proto: "gcm_nonce"), + 3: .same(proto: "payload"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.hkdfSalt) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.gcmNonce) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.hkdfSalt.isEmpty { + try visitor.visitSingularBytesField(value: self.hkdfSalt, fieldNumber: 1) + } + if !self.gcmNonce.isEmpty { + try visitor.visitSingularBytesField(value: self.gcmNonce, fieldNumber: 2) + } + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256, rhs: Xmtp_MessageContents_Ciphertext.Aes256gcmHkdfsha256) -> Bool { + if lhs.hkdfSalt != rhs.hkdfSalt {return false} + if lhs.gcmNonce != rhs.gcmNonce {return false} + if lhs.payload != rhs.payload {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedEciesCiphertext: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignedEciesCiphertext" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "ecies_bytes"), + 2: .same(proto: "signature"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.eciesBytes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._signature) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.eciesBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.eciesBytes, fieldNumber: 1) + } + try { if let v = self._signature { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedEciesCiphertext, rhs: Xmtp_MessageContents_SignedEciesCiphertext) -> Bool { + if lhs.eciesBytes != rhs.eciesBytes {return false} + if lhs._signature != rhs._signature {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedEciesCiphertext.Ecies: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_SignedEciesCiphertext.protoMessageName + ".Ecies" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "ephemeral_public_key"), + 2: .same(proto: "iv"), + 3: .same(proto: "mac"), + 4: .same(proto: "ciphertext"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.ephemeralPublicKey) }() + case 2: try { try decoder.decodeSingularBytesField(value: &self.iv) }() + case 3: try { try decoder.decodeSingularBytesField(value: &self.mac) }() + case 4: try { try decoder.decodeSingularBytesField(value: &self.ciphertext) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.ephemeralPublicKey.isEmpty { + try visitor.visitSingularBytesField(value: self.ephemeralPublicKey, fieldNumber: 1) + } + if !self.iv.isEmpty { + try visitor.visitSingularBytesField(value: self.iv, fieldNumber: 2) + } + if !self.mac.isEmpty { + try visitor.visitSingularBytesField(value: self.mac, fieldNumber: 3) + } + if !self.ciphertext.isEmpty { + try visitor.visitSingularBytesField(value: self.ciphertext, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedEciesCiphertext.Ecies, rhs: Xmtp_MessageContents_SignedEciesCiphertext.Ecies) -> Bool { + if lhs.ephemeralPublicKey != rhs.ephemeralPublicKey {return false} + if lhs.iv != rhs.iv {return false} + if lhs.mac != rhs.mac {return false} + if lhs.ciphertext != rhs.ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/composite.pb.swift b/Sources/XMTP/Proto/message_contents/composite.pb.swift new file mode 100644 index 00000000..015eba3b --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/composite.pb.swift @@ -0,0 +1,201 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/composite.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Composite ContentType + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Composite is used to implement xmtp.org/composite content type +public struct Xmtp_MessageContents_Composite { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var parts: [Xmtp_MessageContents_Composite.Part] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// Part represents one section of a composite message + public struct Part { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var element: Xmtp_MessageContents_Composite.Part.OneOf_Element? = nil + + public var part: Xmtp_MessageContents_EncodedContent { + get { + if case .part(let v)? = element {return v} + return Xmtp_MessageContents_EncodedContent() + } + set {element = .part(newValue)} + } + + public var composite: Xmtp_MessageContents_Composite { + get { + if case .composite(let v)? = element {return v} + return Xmtp_MessageContents_Composite() + } + set {element = .composite(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Element: Equatable { + case part(Xmtp_MessageContents_EncodedContent) + case composite(Xmtp_MessageContents_Composite) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_Composite.Part.OneOf_Element, rhs: Xmtp_MessageContents_Composite.Part.OneOf_Element) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.part, .part): return { + guard case .part(let l) = lhs, case .part(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.composite, .composite): return { + guard case .composite(let l) = lhs, case .composite(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_Composite: @unchecked Sendable {} +extension Xmtp_MessageContents_Composite.Part: @unchecked Sendable {} +extension Xmtp_MessageContents_Composite.Part.OneOf_Element: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_Composite: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Composite" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "parts"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeRepeatedMessageField(value: &self.parts) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.parts.isEmpty { + try visitor.visitRepeatedMessageField(value: self.parts, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Composite, rhs: Xmtp_MessageContents_Composite) -> Bool { + if lhs.parts != rhs.parts {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_Composite.Part: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_Composite.protoMessageName + ".Part" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "part"), + 2: .same(proto: "composite"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_EncodedContent? + var hadOneofValue = false + if let current = self.element { + hadOneofValue = true + if case .part(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.element = .part(v) + } + }() + case 2: try { + var v: Xmtp_MessageContents_Composite? + var hadOneofValue = false + if let current = self.element { + hadOneofValue = true + if case .composite(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.element = .composite(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.element { + case .part?: try { + guard case .part(let v)? = self.element else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .composite?: try { + guard case .composite(let v)? = self.element else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Composite.Part, rhs: Xmtp_MessageContents_Composite.Part) -> Bool { + if lhs.element != rhs.element {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/contact.pb.swift b/Sources/XMTP/Proto/message_contents/contact.pb.swift new file mode 100644 index 00000000..2795a424 --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/contact.pb.swift @@ -0,0 +1,278 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/contact.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Contact Bundles are used to advertise user's public keys on the network. +/// They are published in well known topics so that other participants +/// can find them when they wish to communicate with the user. +/// The public keys are used to sign messages and to derive encryption keys +/// for some meta-messages, e.g. invitations. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// LEGACY: User key bundle V1 using PublicKeys. +/// The PublicKeys MUST be signed. +public struct Xmtp_MessageContents_ContactBundleV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var keyBundle: Xmtp_MessageContents_PublicKeyBundle { + get {return _keyBundle ?? Xmtp_MessageContents_PublicKeyBundle()} + set {_keyBundle = newValue} + } + /// Returns true if `keyBundle` has been explicitly set. + public var hasKeyBundle: Bool {return self._keyBundle != nil} + /// Clears the value of `keyBundle`. Subsequent reads from it will return its default value. + public mutating func clearKeyBundle() {self._keyBundle = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _keyBundle: Xmtp_MessageContents_PublicKeyBundle? = nil +} + +/// User key bundle V2 using SignedPublicKeys. +public struct Xmtp_MessageContents_ContactBundleV2 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var keyBundle: Xmtp_MessageContents_SignedPublicKeyBundle { + get {return _keyBundle ?? Xmtp_MessageContents_SignedPublicKeyBundle()} + set {_keyBundle = newValue} + } + /// Returns true if `keyBundle` has been explicitly set. + public var hasKeyBundle: Bool {return self._keyBundle != nil} + /// Clears the value of `keyBundle`. Subsequent reads from it will return its default value. + public mutating func clearKeyBundle() {self._keyBundle = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _keyBundle: Xmtp_MessageContents_SignedPublicKeyBundle? = nil +} + +/// Versioned ContactBundle +public struct Xmtp_MessageContents_ContactBundle { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var version: Xmtp_MessageContents_ContactBundle.OneOf_Version? = nil + + public var v1: Xmtp_MessageContents_ContactBundleV1 { + get { + if case .v1(let v)? = version {return v} + return Xmtp_MessageContents_ContactBundleV1() + } + set {version = .v1(newValue)} + } + + public var v2: Xmtp_MessageContents_ContactBundleV2 { + get { + if case .v2(let v)? = version {return v} + return Xmtp_MessageContents_ContactBundleV2() + } + set {version = .v2(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Version: Equatable { + case v1(Xmtp_MessageContents_ContactBundleV1) + case v2(Xmtp_MessageContents_ContactBundleV2) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_ContactBundle.OneOf_Version, rhs: Xmtp_MessageContents_ContactBundle.OneOf_Version) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.v1, .v1): return { + guard case .v1(let l) = lhs, case .v1(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.v2, .v2): return { + guard case .v2(let l) = lhs, case .v2(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_ContactBundleV1: @unchecked Sendable {} +extension Xmtp_MessageContents_ContactBundleV2: @unchecked Sendable {} +extension Xmtp_MessageContents_ContactBundle: @unchecked Sendable {} +extension Xmtp_MessageContents_ContactBundle.OneOf_Version: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_ContactBundleV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ContactBundleV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "key_bundle"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._keyBundle) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._keyBundle { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_ContactBundleV1, rhs: Xmtp_MessageContents_ContactBundleV1) -> Bool { + if lhs._keyBundle != rhs._keyBundle {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_ContactBundleV2: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ContactBundleV2" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "key_bundle"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._keyBundle) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._keyBundle { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_ContactBundleV2, rhs: Xmtp_MessageContents_ContactBundleV2) -> Bool { + if lhs._keyBundle != rhs._keyBundle {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_ContactBundle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ContactBundle" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "v1"), + 2: .same(proto: "v2"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_ContactBundleV1? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v1(v) + } + }() + case 2: try { + var v: Xmtp_MessageContents_ContactBundleV2? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v2(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v2(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.version { + case .v1?: try { + guard case .v1(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .v2?: try { + guard case .v2(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_ContactBundle, rhs: Xmtp_MessageContents_ContactBundle) -> Bool { + if lhs.version != rhs.version {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/content.pb.swift b/Sources/XMTP/Proto/message_contents/content.pb.swift new file mode 100644 index 00000000..cf73da0d --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/content.pb.swift @@ -0,0 +1,357 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/content.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Message content encoding structures + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Recognized compression algorithms +/// protolint:disable ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH +public enum Xmtp_MessageContents_Compression: SwiftProtobuf.Enum { + public typealias RawValue = Int + case deflate // = 0 + case gzip // = 1 + case UNRECOGNIZED(Int) + + public init() { + self = .deflate + } + + public init?(rawValue: Int) { + switch rawValue { + case 0: self = .deflate + case 1: self = .gzip + default: self = .UNRECOGNIZED(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .deflate: return 0 + case .gzip: return 1 + case .UNRECOGNIZED(let i): return i + } + } + +} + +#if swift(>=4.2) + +extension Xmtp_MessageContents_Compression: CaseIterable { + // The compiler won't synthesize support with the UNRECOGNIZED case. + public static var allCases: [Xmtp_MessageContents_Compression] = [ + .deflate, + .gzip, + ] +} + +#endif // swift(>=4.2) + +/// ContentTypeId is used to identify the type of content stored in a Message. +public struct Xmtp_MessageContents_ContentTypeId { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// authority governing this content type + public var authorityID: String = String() + + /// type identifier + public var typeID: String = String() + + /// major version of the type + public var versionMajor: UInt32 = 0 + + /// minor version of the type + public var versionMinor: UInt32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// EncodedContent bundles the content with metadata identifying its type +/// and parameters required for correct decoding and presentation of the content. +public struct Xmtp_MessageContents_EncodedContent { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// content type identifier used to match the payload with + /// the correct decoding machinery + public var type: Xmtp_MessageContents_ContentTypeId { + get {return _type ?? Xmtp_MessageContents_ContentTypeId()} + set {_type = newValue} + } + /// Returns true if `type` has been explicitly set. + public var hasType: Bool {return self._type != nil} + /// Clears the value of `type`. Subsequent reads from it will return its default value. + public mutating func clearType() {self._type = nil} + + /// optional encoding parameters required to correctly decode the content + public var parameters: Dictionary = [:] + + /// optional fallback description of the content that can be used in case + /// the client cannot decode or render the content + public var fallback: String { + get {return _fallback ?? String()} + set {_fallback = newValue} + } + /// Returns true if `fallback` has been explicitly set. + public var hasFallback: Bool {return self._fallback != nil} + /// Clears the value of `fallback`. Subsequent reads from it will return its default value. + public mutating func clearFallback() {self._fallback = nil} + + /// optional compression; the value indicates algorithm used to + /// compress the encoded content bytes + public var compression: Xmtp_MessageContents_Compression { + get {return _compression ?? .deflate} + set {_compression = newValue} + } + /// Returns true if `compression` has been explicitly set. + public var hasCompression: Bool {return self._compression != nil} + /// Clears the value of `compression`. Subsequent reads from it will return its default value. + public mutating func clearCompression() {self._compression = nil} + + /// encoded content itself + public var content: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _type: Xmtp_MessageContents_ContentTypeId? = nil + fileprivate var _fallback: String? = nil + fileprivate var _compression: Xmtp_MessageContents_Compression? = nil +} + +/// SignedContent attaches a signature to EncodedContent. +public struct Xmtp_MessageContents_SignedContent { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// MUST contain EncodedContent + public var payload: Data = Data() + + public var sender: Xmtp_MessageContents_SignedPublicKeyBundle { + get {return _sender ?? Xmtp_MessageContents_SignedPublicKeyBundle()} + set {_sender = newValue} + } + /// Returns true if `sender` has been explicitly set. + public var hasSender: Bool {return self._sender != nil} + /// Clears the value of `sender`. Subsequent reads from it will return its default value. + public mutating func clearSender() {self._sender = nil} + + /// MUST be a signature of a concatenation of + /// the message header bytes and the payload bytes, + /// signed by the sender's pre-key. + public var signature: Xmtp_MessageContents_Signature { + get {return _signature ?? Xmtp_MessageContents_Signature()} + set {_signature = newValue} + } + /// Returns true if `signature` has been explicitly set. + public var hasSignature: Bool {return self._signature != nil} + /// Clears the value of `signature`. Subsequent reads from it will return its default value. + public mutating func clearSignature() {self._signature = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _sender: Xmtp_MessageContents_SignedPublicKeyBundle? = nil + fileprivate var _signature: Xmtp_MessageContents_Signature? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_Compression: @unchecked Sendable {} +extension Xmtp_MessageContents_ContentTypeId: @unchecked Sendable {} +extension Xmtp_MessageContents_EncodedContent: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedContent: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_Compression: SwiftProtobuf._ProtoNameProviding { + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 0: .same(proto: "COMPRESSION_DEFLATE"), + 1: .same(proto: "COMPRESSION_GZIP"), + ] +} + +extension Xmtp_MessageContents_ContentTypeId: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ContentTypeId" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "authority_id"), + 2: .standard(proto: "type_id"), + 3: .standard(proto: "version_major"), + 4: .standard(proto: "version_minor"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.authorityID) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.typeID) }() + case 3: try { try decoder.decodeSingularUInt32Field(value: &self.versionMajor) }() + case 4: try { try decoder.decodeSingularUInt32Field(value: &self.versionMinor) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.authorityID.isEmpty { + try visitor.visitSingularStringField(value: self.authorityID, fieldNumber: 1) + } + if !self.typeID.isEmpty { + try visitor.visitSingularStringField(value: self.typeID, fieldNumber: 2) + } + if self.versionMajor != 0 { + try visitor.visitSingularUInt32Field(value: self.versionMajor, fieldNumber: 3) + } + if self.versionMinor != 0 { + try visitor.visitSingularUInt32Field(value: self.versionMinor, fieldNumber: 4) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_ContentTypeId, rhs: Xmtp_MessageContents_ContentTypeId) -> Bool { + if lhs.authorityID != rhs.authorityID {return false} + if lhs.typeID != rhs.typeID {return false} + if lhs.versionMajor != rhs.versionMajor {return false} + if lhs.versionMinor != rhs.versionMinor {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_EncodedContent: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncodedContent" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "type"), + 2: .same(proto: "parameters"), + 3: .same(proto: "fallback"), + 5: .same(proto: "compression"), + 4: .same(proto: "content"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._type) }() + case 2: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: &self.parameters) }() + case 3: try { try decoder.decodeSingularStringField(value: &self._fallback) }() + case 4: try { try decoder.decodeSingularBytesField(value: &self.content) }() + case 5: try { try decoder.decodeSingularEnumField(value: &self._compression) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._type { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.parameters.isEmpty { + try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: self.parameters, fieldNumber: 2) + } + try { if let v = self._fallback { + try visitor.visitSingularStringField(value: v, fieldNumber: 3) + } }() + if !self.content.isEmpty { + try visitor.visitSingularBytesField(value: self.content, fieldNumber: 4) + } + try { if let v = self._compression { + try visitor.visitSingularEnumField(value: v, fieldNumber: 5) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_EncodedContent, rhs: Xmtp_MessageContents_EncodedContent) -> Bool { + if lhs._type != rhs._type {return false} + if lhs.parameters != rhs.parameters {return false} + if lhs._fallback != rhs._fallback {return false} + if lhs._compression != rhs._compression {return false} + if lhs.content != rhs.content {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedContent: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignedContent" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "payload"), + 2: .same(proto: "sender"), + 3: .same(proto: "signature"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.payload) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._sender) }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._signature) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.payload.isEmpty { + try visitor.visitSingularBytesField(value: self.payload, fieldNumber: 1) + } + try { if let v = self._sender { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = self._signature { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedContent, rhs: Xmtp_MessageContents_SignedContent) -> Bool { + if lhs.payload != rhs.payload {return false} + if lhs._sender != rhs._sender {return false} + if lhs._signature != rhs._signature {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift b/Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift new file mode 100644 index 00000000..d77cc233 --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift @@ -0,0 +1,113 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/conversation_reference.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Holds the ConversationReference + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// A light pointer for a conversation that contains no decryption keys +public struct Xmtp_MessageContents_ConversationReference { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var topic: String = String() + + public var peerAddress: String = String() + + public var createdNs: UInt64 = 0 + + public var context: Xmtp_MessageContents_InvitationV1.Context { + get {return _context ?? Xmtp_MessageContents_InvitationV1.Context()} + set {_context = newValue} + } + /// Returns true if `context` has been explicitly set. + public var hasContext: Bool {return self._context != nil} + /// Clears the value of `context`. Subsequent reads from it will return its default value. + public mutating func clearContext() {self._context = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _context: Xmtp_MessageContents_InvitationV1.Context? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_ConversationReference: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_ConversationReference: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".ConversationReference" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "topic"), + 2: .standard(proto: "peer_address"), + 3: .standard(proto: "created_ns"), + 4: .same(proto: "context"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.topic) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.peerAddress) }() + case 3: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + case 4: try { try decoder.decodeSingularMessageField(value: &self._context) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.topic.isEmpty { + try visitor.visitSingularStringField(value: self.topic, fieldNumber: 1) + } + if !self.peerAddress.isEmpty { + try visitor.visitSingularStringField(value: self.peerAddress, fieldNumber: 2) + } + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 3) + } + try { if let v = self._context { + try visitor.visitSingularMessageField(value: v, fieldNumber: 4) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_ConversationReference, rhs: Xmtp_MessageContents_ConversationReference) -> Bool { + if lhs.topic != rhs.topic {return false} + if lhs.peerAddress != rhs.peerAddress {return false} + if lhs.createdNs != rhs.createdNs {return false} + if lhs._context != rhs._context {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/invitation.pb.swift b/Sources/XMTP/Proto/message_contents/invitation.pb.swift new file mode 100644 index 00000000..50b29960 --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/invitation.pb.swift @@ -0,0 +1,506 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/invitation.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Invitation is used by an initiator to invite participants +/// into a new conversation. Invitation carries the chosen topic name +/// and encryption scheme and key material to be used for message encryption. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Unsealed invitation V1 +public struct Xmtp_MessageContents_InvitationV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// topic name chosen for this conversation. + /// It MUST be randomly generated bytes (length >= 32), + /// then base64 encoded without padding + public var topic: String = String() + + /// A context object defining metadata + public var context: Xmtp_MessageContents_InvitationV1.Context { + get {return _context ?? Xmtp_MessageContents_InvitationV1.Context()} + set {_context = newValue} + } + /// Returns true if `context` has been explicitly set. + public var hasContext: Bool {return self._context != nil} + /// Clears the value of `context`. Subsequent reads from it will return its default value. + public mutating func clearContext() {self._context = nil} + + /// message encryption scheme and keys for this conversation. + public var encryption: Xmtp_MessageContents_InvitationV1.OneOf_Encryption? = nil + + /// Specify the encryption method to process the key material properly. + public var aes256GcmHkdfSha256: Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256 { + get { + if case .aes256GcmHkdfSha256(let v)? = encryption {return v} + return Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256() + } + set {encryption = .aes256GcmHkdfSha256(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// message encryption scheme and keys for this conversation. + public enum OneOf_Encryption: Equatable { + /// Specify the encryption method to process the key material properly. + case aes256GcmHkdfSha256(Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_InvitationV1.OneOf_Encryption, rhs: Xmtp_MessageContents_InvitationV1.OneOf_Encryption) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.aes256GcmHkdfSha256, .aes256GcmHkdfSha256): return { + guard case .aes256GcmHkdfSha256(let l) = lhs, case .aes256GcmHkdfSha256(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// Supported encryption schemes + /// AES256-GCM-HKDF-SHA256 + public struct Aes256gcmHkdfsha256 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// randomly generated key material (32 bytes) + public var keyMaterial: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + /// The context type + public struct Context { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Expected to be a URI (ie xmtp.org/convo1) + public var conversationID: String = String() + + /// Key value map of additional metadata that would be exposed to + /// application developers and could be used for filtering + public var metadata: Dictionary = [:] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + + fileprivate var _context: Xmtp_MessageContents_InvitationV1.Context? = nil +} + +/// Sealed Invitation V1 Header +/// Header carries information that is unencrypted, thus readable by the network +/// it is however authenticated as associated data with the AEAD scheme used +/// to encrypt the invitation body, thus providing tamper evidence. +public struct Xmtp_MessageContents_SealedInvitationHeaderV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var sender: Xmtp_MessageContents_SignedPublicKeyBundle { + get {return _sender ?? Xmtp_MessageContents_SignedPublicKeyBundle()} + set {_sender = newValue} + } + /// Returns true if `sender` has been explicitly set. + public var hasSender: Bool {return self._sender != nil} + /// Clears the value of `sender`. Subsequent reads from it will return its default value. + public mutating func clearSender() {self._sender = nil} + + public var recipient: Xmtp_MessageContents_SignedPublicKeyBundle { + get {return _recipient ?? Xmtp_MessageContents_SignedPublicKeyBundle()} + set {_recipient = newValue} + } + /// Returns true if `recipient` has been explicitly set. + public var hasRecipient: Bool {return self._recipient != nil} + /// Clears the value of `recipient`. Subsequent reads from it will return its default value. + public mutating func clearRecipient() {self._recipient = nil} + + public var createdNs: UInt64 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _sender: Xmtp_MessageContents_SignedPublicKeyBundle? = nil + fileprivate var _recipient: Xmtp_MessageContents_SignedPublicKeyBundle? = nil +} + +/// Sealed Invitation V1 +/// Invitation encrypted with key material derived from the sender's and +/// recipient's public key bundles using simplified X3DH where +/// the sender's ephemeral key is replaced with sender's pre-key. +public struct Xmtp_MessageContents_SealedInvitationV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// encoded SealedInvitationHeaderV1 used as associated data for Ciphertext + public var headerBytes: Data = Data() + + /// Ciphertext.payload MUST contain encrypted InvitationV1. + public var ciphertext: Xmtp_MessageContents_Ciphertext { + get {return _ciphertext ?? Xmtp_MessageContents_Ciphertext()} + set {_ciphertext = newValue} + } + /// Returns true if `ciphertext` has been explicitly set. + public var hasCiphertext: Bool {return self._ciphertext != nil} + /// Clears the value of `ciphertext`. Subsequent reads from it will return its default value. + public mutating func clearCiphertext() {self._ciphertext = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _ciphertext: Xmtp_MessageContents_Ciphertext? = nil +} + +/// Versioned Sealed Invitation +public struct Xmtp_MessageContents_SealedInvitation { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var version: Xmtp_MessageContents_SealedInvitation.OneOf_Version? = nil + + public var v1: Xmtp_MessageContents_SealedInvitationV1 { + get { + if case .v1(let v)? = version {return v} + return Xmtp_MessageContents_SealedInvitationV1() + } + set {version = .v1(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Version: Equatable { + case v1(Xmtp_MessageContents_SealedInvitationV1) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_SealedInvitation.OneOf_Version, rhs: Xmtp_MessageContents_SealedInvitation.OneOf_Version) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.v1, .v1): return { + guard case .v1(let l) = lhs, case .v1(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_InvitationV1: @unchecked Sendable {} +extension Xmtp_MessageContents_InvitationV1.OneOf_Encryption: @unchecked Sendable {} +extension Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256: @unchecked Sendable {} +extension Xmtp_MessageContents_InvitationV1.Context: @unchecked Sendable {} +extension Xmtp_MessageContents_SealedInvitationHeaderV1: @unchecked Sendable {} +extension Xmtp_MessageContents_SealedInvitationV1: @unchecked Sendable {} +extension Xmtp_MessageContents_SealedInvitation: @unchecked Sendable {} +extension Xmtp_MessageContents_SealedInvitation.OneOf_Version: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_InvitationV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".InvitationV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "topic"), + 2: .same(proto: "context"), + 3: .standard(proto: "aes256_gcm_hkdf_sha256"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.topic) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._context) }() + case 3: try { + var v: Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256? + var hadOneofValue = false + if let current = self.encryption { + hadOneofValue = true + if case .aes256GcmHkdfSha256(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.encryption = .aes256GcmHkdfSha256(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.topic.isEmpty { + try visitor.visitSingularStringField(value: self.topic, fieldNumber: 1) + } + try { if let v = self._context { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if case .aes256GcmHkdfSha256(let v)? = self.encryption { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_InvitationV1, rhs: Xmtp_MessageContents_InvitationV1) -> Bool { + if lhs.topic != rhs.topic {return false} + if lhs._context != rhs._context {return false} + if lhs.encryption != rhs.encryption {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_InvitationV1.protoMessageName + ".Aes256gcmHkdfsha256" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "key_material"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.keyMaterial) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.keyMaterial.isEmpty { + try visitor.visitSingularBytesField(value: self.keyMaterial, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256, rhs: Xmtp_MessageContents_InvitationV1.Aes256gcmHkdfsha256) -> Bool { + if lhs.keyMaterial != rhs.keyMaterial {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_InvitationV1.Context: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_InvitationV1.protoMessageName + ".Context" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "conversation_id"), + 2: .same(proto: "metadata"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.conversationID) }() + case 2: try { try decoder.decodeMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: &self.metadata) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.conversationID.isEmpty { + try visitor.visitSingularStringField(value: self.conversationID, fieldNumber: 1) + } + if !self.metadata.isEmpty { + try visitor.visitMapField(fieldType: SwiftProtobuf._ProtobufMap.self, value: self.metadata, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_InvitationV1.Context, rhs: Xmtp_MessageContents_InvitationV1.Context) -> Bool { + if lhs.conversationID != rhs.conversationID {return false} + if lhs.metadata != rhs.metadata {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SealedInvitationHeaderV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SealedInvitationHeaderV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "sender"), + 2: .same(proto: "recipient"), + 3: .standard(proto: "created_ns"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._sender) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._recipient) }() + case 3: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._sender { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._recipient { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 3) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SealedInvitationHeaderV1, rhs: Xmtp_MessageContents_SealedInvitationHeaderV1) -> Bool { + if lhs._sender != rhs._sender {return false} + if lhs._recipient != rhs._recipient {return false} + if lhs.createdNs != rhs.createdNs {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SealedInvitationV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SealedInvitationV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "header_bytes"), + 2: .same(proto: "ciphertext"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._ciphertext) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 1) + } + try { if let v = self._ciphertext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SealedInvitationV1, rhs: Xmtp_MessageContents_SealedInvitationV1) -> Bool { + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs._ciphertext != rhs._ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SealedInvitation: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SealedInvitation" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "v1"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_SealedInvitationV1? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v1(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if case .v1(let v)? = self.version { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SealedInvitation, rhs: Xmtp_MessageContents_SealedInvitation) -> Bool { + if lhs.version != rhs.version {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/message.pb.swift b/Sources/XMTP/Proto/message_contents/message.pb.swift new file mode 100644 index 00000000..9e13e272 --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/message.pb.swift @@ -0,0 +1,600 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/message.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Messages used for transport and storage of user conversations. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Message header is encoded separately as the bytes are also used +/// as associated data for authenticated encryption +public struct Xmtp_MessageContents_MessageHeaderV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var sender: Xmtp_MessageContents_PublicKeyBundle { + get {return _storage._sender ?? Xmtp_MessageContents_PublicKeyBundle()} + set {_uniqueStorage()._sender = newValue} + } + /// Returns true if `sender` has been explicitly set. + public var hasSender: Bool {return _storage._sender != nil} + /// Clears the value of `sender`. Subsequent reads from it will return its default value. + public mutating func clearSender() {_uniqueStorage()._sender = nil} + + public var recipient: Xmtp_MessageContents_PublicKeyBundle { + get {return _storage._recipient ?? Xmtp_MessageContents_PublicKeyBundle()} + set {_uniqueStorage()._recipient = newValue} + } + /// Returns true if `recipient` has been explicitly set. + public var hasRecipient: Bool {return _storage._recipient != nil} + /// Clears the value of `recipient`. Subsequent reads from it will return its default value. + public mutating func clearRecipient() {_uniqueStorage()._recipient = nil} + + public var timestamp: UInt64 { + get {return _storage._timestamp} + set {_uniqueStorage()._timestamp = newValue} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _storage = _StorageClass.defaultInstance +} + +/// Message is the top level protocol element +public struct Xmtp_MessageContents_MessageV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// encapsulates encoded MessageHeaderV1 + public var headerBytes: Data = Data() + + /// Ciphertext.payload MUST contain encrypted EncodedContent + public var ciphertext: Xmtp_MessageContents_Ciphertext { + get {return _ciphertext ?? Xmtp_MessageContents_Ciphertext()} + set {_ciphertext = newValue} + } + /// Returns true if `ciphertext` has been explicitly set. + public var hasCiphertext: Bool {return self._ciphertext != nil} + /// Clears the value of `ciphertext`. Subsequent reads from it will return its default value. + public mutating func clearCiphertext() {self._ciphertext = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _ciphertext: Xmtp_MessageContents_Ciphertext? = nil +} + +/// Message header carries information that is not encrypted, and is therefore +/// observable by the network. It is however authenticated as associated data +/// of the AEAD encryption used to protect the message, +/// thus providing tamper evidence. +public struct Xmtp_MessageContents_MessageHeaderV2 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// sender specified message creation time + public var createdNs: UInt64 = 0 + + /// the topic the message belongs to + public var topic: String = String() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} +} + +/// Message combines the encoded header with the encrypted payload. +public struct Xmtp_MessageContents_MessageV2 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// encapsulates encoded MessageHeaderV2 + public var headerBytes: Data = Data() + + /// Ciphertext.payload MUST contain encrypted SignedContent + public var ciphertext: Xmtp_MessageContents_Ciphertext { + get {return _ciphertext ?? Xmtp_MessageContents_Ciphertext()} + set {_ciphertext = newValue} + } + /// Returns true if `ciphertext` has been explicitly set. + public var hasCiphertext: Bool {return self._ciphertext != nil} + /// Clears the value of `ciphertext`. Subsequent reads from it will return its default value. + public mutating func clearCiphertext() {self._ciphertext = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _ciphertext: Xmtp_MessageContents_Ciphertext? = nil +} + +/// Versioned Message +public struct Xmtp_MessageContents_Message { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var version: Xmtp_MessageContents_Message.OneOf_Version? = nil + + public var v1: Xmtp_MessageContents_MessageV1 { + get { + if case .v1(let v)? = version {return v} + return Xmtp_MessageContents_MessageV1() + } + set {version = .v1(newValue)} + } + + public var v2: Xmtp_MessageContents_MessageV2 { + get { + if case .v2(let v)? = version {return v} + return Xmtp_MessageContents_MessageV2() + } + set {version = .v2(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Version: Equatable { + case v1(Xmtp_MessageContents_MessageV1) + case v2(Xmtp_MessageContents_MessageV2) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_Message.OneOf_Version, rhs: Xmtp_MessageContents_Message.OneOf_Version) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.v1, .v1): return { + guard case .v1(let l) = lhs, case .v1(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.v2, .v2): return { + guard case .v2(let l) = lhs, case .v2(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} +} + +/// DecodedMessage represents the decrypted message contents. +/// DecodedMessage instances are not stored on the network, but +/// may be serialized and stored by clients +public struct Xmtp_MessageContents_DecodedMessage { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var id: String = String() + + public var messageVersion: String = String() + + public var senderAddress: String = String() + + public var recipientAddress: String { + get {return _recipientAddress ?? String()} + set {_recipientAddress = newValue} + } + /// Returns true if `recipientAddress` has been explicitly set. + public var hasRecipientAddress: Bool {return self._recipientAddress != nil} + /// Clears the value of `recipientAddress`. Subsequent reads from it will return its default value. + public mutating func clearRecipientAddress() {self._recipientAddress = nil} + + public var sentNs: UInt64 = 0 + + public var contentTopic: String = String() + + public var conversation: Xmtp_MessageContents_ConversationReference { + get {return _conversation ?? Xmtp_MessageContents_ConversationReference()} + set {_conversation = newValue} + } + /// Returns true if `conversation` has been explicitly set. + public var hasConversation: Bool {return self._conversation != nil} + /// Clears the value of `conversation`. Subsequent reads from it will return its default value. + public mutating func clearConversation() {self._conversation = nil} + + /// encapsulates EncodedContent + public var contentBytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _recipientAddress: String? = nil + fileprivate var _conversation: Xmtp_MessageContents_ConversationReference? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_MessageHeaderV1: @unchecked Sendable {} +extension Xmtp_MessageContents_MessageV1: @unchecked Sendable {} +extension Xmtp_MessageContents_MessageHeaderV2: @unchecked Sendable {} +extension Xmtp_MessageContents_MessageV2: @unchecked Sendable {} +extension Xmtp_MessageContents_Message: @unchecked Sendable {} +extension Xmtp_MessageContents_Message.OneOf_Version: @unchecked Sendable {} +extension Xmtp_MessageContents_DecodedMessage: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_MessageHeaderV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".MessageHeaderV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "sender"), + 2: .same(proto: "recipient"), + 3: .same(proto: "timestamp"), + ] + + fileprivate class _StorageClass { + var _sender: Xmtp_MessageContents_PublicKeyBundle? = nil + var _recipient: Xmtp_MessageContents_PublicKeyBundle? = nil + var _timestamp: UInt64 = 0 + + static let defaultInstance = _StorageClass() + + private init() {} + + init(copying source: _StorageClass) { + _sender = source._sender + _recipient = source._recipient + _timestamp = source._timestamp + } + } + + fileprivate mutating func _uniqueStorage() -> _StorageClass { + if !isKnownUniquelyReferenced(&_storage) { + _storage = _StorageClass(copying: _storage) + } + return _storage + } + + public mutating func decodeMessage(decoder: inout D) throws { + _ = _uniqueStorage() + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &_storage._sender) }() + case 2: try { try decoder.decodeSingularMessageField(value: &_storage._recipient) }() + case 3: try { try decoder.decodeSingularUInt64Field(value: &_storage._timestamp) }() + default: break + } + } + } + } + + public func traverse(visitor: inout V) throws { + try withExtendedLifetime(_storage) { (_storage: _StorageClass) in + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = _storage._sender { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = _storage._recipient { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + if _storage._timestamp != 0 { + try visitor.visitSingularUInt64Field(value: _storage._timestamp, fieldNumber: 3) + } + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_MessageHeaderV1, rhs: Xmtp_MessageContents_MessageHeaderV1) -> Bool { + if lhs._storage !== rhs._storage { + let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in + let _storage = _args.0 + let rhs_storage = _args.1 + if _storage._sender != rhs_storage._sender {return false} + if _storage._recipient != rhs_storage._recipient {return false} + if _storage._timestamp != rhs_storage._timestamp {return false} + return true + } + if !storagesAreEqual {return false} + } + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_MessageV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".MessageV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "header_bytes"), + 2: .same(proto: "ciphertext"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._ciphertext) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 1) + } + try { if let v = self._ciphertext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_MessageV1, rhs: Xmtp_MessageContents_MessageV1) -> Bool { + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs._ciphertext != rhs._ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_MessageHeaderV2: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".MessageHeaderV2" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "created_ns"), + 2: .same(proto: "topic"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.topic) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 1) + } + if !self.topic.isEmpty { + try visitor.visitSingularStringField(value: self.topic, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_MessageHeaderV2, rhs: Xmtp_MessageContents_MessageHeaderV2) -> Bool { + if lhs.createdNs != rhs.createdNs {return false} + if lhs.topic != rhs.topic {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_MessageV2: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".MessageV2" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "header_bytes"), + 2: .same(proto: "ciphertext"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.headerBytes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._ciphertext) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.headerBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.headerBytes, fieldNumber: 1) + } + try { if let v = self._ciphertext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_MessageV2, rhs: Xmtp_MessageContents_MessageV2) -> Bool { + if lhs.headerBytes != rhs.headerBytes {return false} + if lhs._ciphertext != rhs._ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_Message: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Message" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "v1"), + 2: .same(proto: "v2"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_MessageV1? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v1(v) + } + }() + case 2: try { + var v: Xmtp_MessageContents_MessageV2? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v2(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v2(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.version { + case .v1?: try { + guard case .v1(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .v2?: try { + guard case .v2(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Message, rhs: Xmtp_MessageContents_Message) -> Bool { + if lhs.version != rhs.version {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_DecodedMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".DecodedMessage" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "id"), + 2: .standard(proto: "message_version"), + 3: .standard(proto: "sender_address"), + 4: .standard(proto: "recipient_address"), + 5: .standard(proto: "sent_ns"), + 6: .standard(proto: "content_topic"), + 7: .same(proto: "conversation"), + 8: .standard(proto: "content_bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularStringField(value: &self.id) }() + case 2: try { try decoder.decodeSingularStringField(value: &self.messageVersion) }() + case 3: try { try decoder.decodeSingularStringField(value: &self.senderAddress) }() + case 4: try { try decoder.decodeSingularStringField(value: &self._recipientAddress) }() + case 5: try { try decoder.decodeSingularUInt64Field(value: &self.sentNs) }() + case 6: try { try decoder.decodeSingularStringField(value: &self.contentTopic) }() + case 7: try { try decoder.decodeSingularMessageField(value: &self._conversation) }() + case 8: try { try decoder.decodeSingularBytesField(value: &self.contentBytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.id.isEmpty { + try visitor.visitSingularStringField(value: self.id, fieldNumber: 1) + } + if !self.messageVersion.isEmpty { + try visitor.visitSingularStringField(value: self.messageVersion, fieldNumber: 2) + } + if !self.senderAddress.isEmpty { + try visitor.visitSingularStringField(value: self.senderAddress, fieldNumber: 3) + } + try { if let v = self._recipientAddress { + try visitor.visitSingularStringField(value: v, fieldNumber: 4) + } }() + if self.sentNs != 0 { + try visitor.visitSingularUInt64Field(value: self.sentNs, fieldNumber: 5) + } + if !self.contentTopic.isEmpty { + try visitor.visitSingularStringField(value: self.contentTopic, fieldNumber: 6) + } + try { if let v = self._conversation { + try visitor.visitSingularMessageField(value: v, fieldNumber: 7) + } }() + if !self.contentBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.contentBytes, fieldNumber: 8) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_DecodedMessage, rhs: Xmtp_MessageContents_DecodedMessage) -> Bool { + if lhs.id != rhs.id {return false} + if lhs.messageVersion != rhs.messageVersion {return false} + if lhs.senderAddress != rhs.senderAddress {return false} + if lhs._recipientAddress != rhs._recipientAddress {return false} + if lhs.sentNs != rhs.sentNs {return false} + if lhs.contentTopic != rhs.contentTopic {return false} + if lhs._conversation != rhs._conversation {return false} + if lhs.contentBytes != rhs.contentBytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/private_key.pb.swift b/Sources/XMTP/Proto/message_contents/private_key.pb.swift new file mode 100644 index 00000000..4e916b5e --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/private_key.pb.swift @@ -0,0 +1,787 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/private_key.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Private Key Storage +/// +/// Following definitions are not used in the protocol, instead +/// they provide a way for encoding private keys for storage. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// PrivateKey generalized to support different key types +public struct Xmtp_MessageContents_SignedPrivateKey { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// time the key was created + public var createdNs: UInt64 = 0 + + /// private key + public var union: Xmtp_MessageContents_SignedPrivateKey.OneOf_Union? = nil + + public var secp256K1: Xmtp_MessageContents_SignedPrivateKey.Secp256k1 { + get { + if case .secp256K1(let v)? = union {return v} + return Xmtp_MessageContents_SignedPrivateKey.Secp256k1() + } + set {union = .secp256K1(newValue)} + } + + /// public key for this private key + public var publicKey: Xmtp_MessageContents_SignedPublicKey { + get {return _publicKey ?? Xmtp_MessageContents_SignedPublicKey()} + set {_publicKey = newValue} + } + /// Returns true if `publicKey` has been explicitly set. + public var hasPublicKey: Bool {return self._publicKey != nil} + /// Clears the value of `publicKey`. Subsequent reads from it will return its default value. + public mutating func clearPublicKey() {self._publicKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// private key + public enum OneOf_Union: Equatable { + case secp256K1(Xmtp_MessageContents_SignedPrivateKey.Secp256k1) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_SignedPrivateKey.OneOf_Union, rhs: Xmtp_MessageContents_SignedPrivateKey.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.secp256K1, .secp256K1): return { + guard case .secp256K1(let l) = lhs, case .secp256K1(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// EC: SECP256k1 + public struct Secp256k1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// D big-endian, 32 bytes + public var bytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + + fileprivate var _publicKey: Xmtp_MessageContents_SignedPublicKey? = nil +} + +/// PrivateKeyBundle wraps the identityKey and the preKeys, +/// enforces usage of signed keys. +public struct Xmtp_MessageContents_PrivateKeyBundleV2 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var identityKey: Xmtp_MessageContents_SignedPrivateKey { + get {return _identityKey ?? Xmtp_MessageContents_SignedPrivateKey()} + set {_identityKey = newValue} + } + /// Returns true if `identityKey` has been explicitly set. + public var hasIdentityKey: Bool {return self._identityKey != nil} + /// Clears the value of `identityKey`. Subsequent reads from it will return its default value. + public mutating func clearIdentityKey() {self._identityKey = nil} + + /// all the known pre-keys, newer keys first, + public var preKeys: [Xmtp_MessageContents_SignedPrivateKey] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _identityKey: Xmtp_MessageContents_SignedPrivateKey? = nil +} + +/// LEGACY: PrivateKey generalized to support different key types +public struct Xmtp_MessageContents_PrivateKey { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// time the key was created + public var timestamp: UInt64 = 0 + + /// private key + public var union: Xmtp_MessageContents_PrivateKey.OneOf_Union? = nil + + public var secp256K1: Xmtp_MessageContents_PrivateKey.Secp256k1 { + get { + if case .secp256K1(let v)? = union {return v} + return Xmtp_MessageContents_PrivateKey.Secp256k1() + } + set {union = .secp256K1(newValue)} + } + + /// public key for this private key + public var publicKey: Xmtp_MessageContents_PublicKey { + get {return _publicKey ?? Xmtp_MessageContents_PublicKey()} + set {_publicKey = newValue} + } + /// Returns true if `publicKey` has been explicitly set. + public var hasPublicKey: Bool {return self._publicKey != nil} + /// Clears the value of `publicKey`. Subsequent reads from it will return its default value. + public mutating func clearPublicKey() {self._publicKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + /// private key + public enum OneOf_Union: Equatable { + case secp256K1(Xmtp_MessageContents_PrivateKey.Secp256k1) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_PrivateKey.OneOf_Union, rhs: Xmtp_MessageContents_PrivateKey.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.secp256K1, .secp256K1): return { + guard case .secp256K1(let l) = lhs, case .secp256K1(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// EC: SECP256k1 + public struct Secp256k1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// D big-endian, 32 bytes + public var bytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + + fileprivate var _publicKey: Xmtp_MessageContents_PublicKey? = nil +} + +/// LEGACY: PrivateKeyBundleV1 wraps the identityKey and the preKeys +public struct Xmtp_MessageContents_PrivateKeyBundleV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var identityKey: Xmtp_MessageContents_PrivateKey { + get {return _identityKey ?? Xmtp_MessageContents_PrivateKey()} + set {_identityKey = newValue} + } + /// Returns true if `identityKey` has been explicitly set. + public var hasIdentityKey: Bool {return self._identityKey != nil} + /// Clears the value of `identityKey`. Subsequent reads from it will return its default value. + public mutating func clearIdentityKey() {self._identityKey = nil} + + /// all the known pre-keys, newer keys first, + public var preKeys: [Xmtp_MessageContents_PrivateKey] = [] + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _identityKey: Xmtp_MessageContents_PrivateKey? = nil +} + +/// Versioned PrivateKeyBundle +public struct Xmtp_MessageContents_PrivateKeyBundle { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var version: Xmtp_MessageContents_PrivateKeyBundle.OneOf_Version? = nil + + public var v1: Xmtp_MessageContents_PrivateKeyBundleV1 { + get { + if case .v1(let v)? = version {return v} + return Xmtp_MessageContents_PrivateKeyBundleV1() + } + set {version = .v1(newValue)} + } + + public var v2: Xmtp_MessageContents_PrivateKeyBundleV2 { + get { + if case .v2(let v)? = version {return v} + return Xmtp_MessageContents_PrivateKeyBundleV2() + } + set {version = .v2(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Version: Equatable { + case v1(Xmtp_MessageContents_PrivateKeyBundleV1) + case v2(Xmtp_MessageContents_PrivateKeyBundleV2) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_PrivateKeyBundle.OneOf_Version, rhs: Xmtp_MessageContents_PrivateKeyBundle.OneOf_Version) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.v1, .v1): return { + guard case .v1(let l) = lhs, case .v1(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.v2, .v2): return { + guard case .v2(let l) = lhs, case .v2(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + public init() {} +} + +/// PrivateKeyBundle encrypted with key material generated by +/// signing a randomly generated "pre-key" with the user's wallet, +/// i.e. EIP-191 signature of a "storage signature" message with +/// the pre-key embedded in it. +/// (see xmtp-js::PrivateKeyBundle.toEncryptedBytes for details) +public struct Xmtp_MessageContents_EncryptedPrivateKeyBundleV1 { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// randomly generated pre-key + public var walletPreKey: Data = Data() + + /// MUST contain encrypted PrivateKeyBundle + public var ciphertext: Xmtp_MessageContents_Ciphertext { + get {return _ciphertext ?? Xmtp_MessageContents_Ciphertext()} + set {_ciphertext = newValue} + } + /// Returns true if `ciphertext` has been explicitly set. + public var hasCiphertext: Bool {return self._ciphertext != nil} + /// Clears the value of `ciphertext`. Subsequent reads from it will return its default value. + public mutating func clearCiphertext() {self._ciphertext = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _ciphertext: Xmtp_MessageContents_Ciphertext? = nil +} + +/// Versioned encrypted PrivateKeyBundle +public struct Xmtp_MessageContents_EncryptedPrivateKeyBundle { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var version: Xmtp_MessageContents_EncryptedPrivateKeyBundle.OneOf_Version? = nil + + public var v1: Xmtp_MessageContents_EncryptedPrivateKeyBundleV1 { + get { + if case .v1(let v)? = version {return v} + return Xmtp_MessageContents_EncryptedPrivateKeyBundleV1() + } + set {version = .v1(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Version: Equatable { + case v1(Xmtp_MessageContents_EncryptedPrivateKeyBundleV1) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_EncryptedPrivateKeyBundle.OneOf_Version, rhs: Xmtp_MessageContents_EncryptedPrivateKeyBundle.OneOf_Version) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.v1, .v1): return { + guard case .v1(let l) = lhs, case .v1(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_SignedPrivateKey: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedPrivateKey.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedPrivateKey.Secp256k1: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKeyBundleV2: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKey: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKey.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKey.Secp256k1: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKeyBundleV1: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKeyBundle: @unchecked Sendable {} +extension Xmtp_MessageContents_PrivateKeyBundle.OneOf_Version: @unchecked Sendable {} +extension Xmtp_MessageContents_EncryptedPrivateKeyBundleV1: @unchecked Sendable {} +extension Xmtp_MessageContents_EncryptedPrivateKeyBundle: @unchecked Sendable {} +extension Xmtp_MessageContents_EncryptedPrivateKeyBundle.OneOf_Version: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_SignedPrivateKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignedPrivateKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "created_ns"), + 2: .same(proto: "secp256k1"), + 3: .standard(proto: "public_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + case 2: try { + var v: Xmtp_MessageContents_SignedPrivateKey.Secp256k1? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .secp256K1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .secp256K1(v) + } + }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._publicKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 1) + } + try { if case .secp256K1(let v)? = self.union { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = self._publicKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedPrivateKey, rhs: Xmtp_MessageContents_SignedPrivateKey) -> Bool { + if lhs.createdNs != rhs.createdNs {return false} + if lhs.union != rhs.union {return false} + if lhs._publicKey != rhs._publicKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedPrivateKey.Secp256k1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_SignedPrivateKey.protoMessageName + ".Secp256k1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedPrivateKey.Secp256k1, rhs: Xmtp_MessageContents_SignedPrivateKey.Secp256k1) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PrivateKeyBundleV2: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PrivateKeyBundleV2" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "identity_key"), + 2: .standard(proto: "pre_keys"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._identityKey) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.preKeys) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._identityKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.preKeys.isEmpty { + try visitor.visitRepeatedMessageField(value: self.preKeys, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PrivateKeyBundleV2, rhs: Xmtp_MessageContents_PrivateKeyBundleV2) -> Bool { + if lhs._identityKey != rhs._identityKey {return false} + if lhs.preKeys != rhs.preKeys {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PrivateKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PrivateKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .same(proto: "secp256k1"), + 3: .standard(proto: "public_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { + var v: Xmtp_MessageContents_PrivateKey.Secp256k1? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .secp256K1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .secp256K1(v) + } + }() + case 3: try { try decoder.decodeSingularMessageField(value: &self._publicKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + try { if case .secp256K1(let v)? = self.union { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if let v = self._publicKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PrivateKey, rhs: Xmtp_MessageContents_PrivateKey) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs.union != rhs.union {return false} + if lhs._publicKey != rhs._publicKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PrivateKey.Secp256k1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_PrivateKey.protoMessageName + ".Secp256k1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PrivateKey.Secp256k1, rhs: Xmtp_MessageContents_PrivateKey.Secp256k1) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PrivateKeyBundleV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PrivateKeyBundleV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "identity_key"), + 2: .standard(proto: "pre_keys"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._identityKey) }() + case 2: try { try decoder.decodeRepeatedMessageField(value: &self.preKeys) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._identityKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + if !self.preKeys.isEmpty { + try visitor.visitRepeatedMessageField(value: self.preKeys, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PrivateKeyBundleV1, rhs: Xmtp_MessageContents_PrivateKeyBundleV1) -> Bool { + if lhs._identityKey != rhs._identityKey {return false} + if lhs.preKeys != rhs.preKeys {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PrivateKeyBundle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PrivateKeyBundle" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "v1"), + 2: .same(proto: "v2"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_PrivateKeyBundleV1? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v1(v) + } + }() + case 2: try { + var v: Xmtp_MessageContents_PrivateKeyBundleV2? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v2(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v2(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.version { + case .v1?: try { + guard case .v1(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .v2?: try { + guard case .v2(let v)? = self.version else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PrivateKeyBundle, rhs: Xmtp_MessageContents_PrivateKeyBundle) -> Bool { + if lhs.version != rhs.version {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_EncryptedPrivateKeyBundleV1: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncryptedPrivateKeyBundleV1" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "wallet_pre_key"), + 2: .same(proto: "ciphertext"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.walletPreKey) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._ciphertext) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.walletPreKey.isEmpty { + try visitor.visitSingularBytesField(value: self.walletPreKey, fieldNumber: 1) + } + try { if let v = self._ciphertext { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_EncryptedPrivateKeyBundleV1, rhs: Xmtp_MessageContents_EncryptedPrivateKeyBundleV1) -> Bool { + if lhs.walletPreKey != rhs.walletPreKey {return false} + if lhs._ciphertext != rhs._ciphertext {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_EncryptedPrivateKeyBundle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".EncryptedPrivateKeyBundle" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "v1"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_EncryptedPrivateKeyBundleV1? + var hadOneofValue = false + if let current = self.version { + hadOneofValue = true + if case .v1(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.version = .v1(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if case .v1(let v)? = self.version { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_EncryptedPrivateKeyBundle, rhs: Xmtp_MessageContents_EncryptedPrivateKeyBundle) -> Bool { + if lhs.version != rhs.version {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/public_key.pb.swift b/Sources/XMTP/Proto/message_contents/public_key.pb.swift new file mode 100644 index 00000000..a1accdaf --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/public_key.pb.swift @@ -0,0 +1,562 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/public_key.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Structure for representing public keys of different types, +/// including signatures used to authenticate the keys. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// UnsignedPublicKey represents a generalized public key, +/// defined as a union to support cryptographic algorithm agility. +public struct Xmtp_MessageContents_UnsignedPublicKey { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var createdNs: UInt64 = 0 + + public var union: Xmtp_MessageContents_UnsignedPublicKey.OneOf_Union? = nil + + public var secp256K1Uncompressed: Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed { + get { + if case .secp256K1Uncompressed(let v)? = union {return v} + return Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed() + } + set {union = .secp256K1Uncompressed(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Union: Equatable { + case secp256K1Uncompressed(Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_UnsignedPublicKey.OneOf_Union, rhs: Xmtp_MessageContents_UnsignedPublicKey.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.secp256K1Uncompressed, .secp256K1Uncompressed): return { + guard case .secp256K1Uncompressed(let l) = lhs, case .secp256K1Uncompressed(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// EC: SECP256k1 + public struct Secp256k1Uncompressed { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// uncompressed point with prefix (0x04) [ P || X || Y ], 65 bytes + public var bytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} +} + +/// SignedPublicKey +public struct Xmtp_MessageContents_SignedPublicKey { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// embeds an UnsignedPublicKey + public var keyBytes: Data = Data() + + /// signs key_bytes + public var signature: Xmtp_MessageContents_Signature { + get {return _signature ?? Xmtp_MessageContents_Signature()} + set {_signature = newValue} + } + /// Returns true if `signature` has been explicitly set. + public var hasSignature: Bool {return self._signature != nil} + /// Clears the value of `signature`. Subsequent reads from it will return its default value. + public mutating func clearSignature() {self._signature = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _signature: Xmtp_MessageContents_Signature? = nil +} + +/// PublicKeyBundle packages the cryptographic keys associated with a wallet. +public struct Xmtp_MessageContents_SignedPublicKeyBundle { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Identity key MUST be signed by the wallet. + public var identityKey: Xmtp_MessageContents_SignedPublicKey { + get {return _identityKey ?? Xmtp_MessageContents_SignedPublicKey()} + set {_identityKey = newValue} + } + /// Returns true if `identityKey` has been explicitly set. + public var hasIdentityKey: Bool {return self._identityKey != nil} + /// Clears the value of `identityKey`. Subsequent reads from it will return its default value. + public mutating func clearIdentityKey() {self._identityKey = nil} + + /// Pre-key MUST be signed by the identity key. + public var preKey: Xmtp_MessageContents_SignedPublicKey { + get {return _preKey ?? Xmtp_MessageContents_SignedPublicKey()} + set {_preKey = newValue} + } + /// Returns true if `preKey` has been explicitly set. + public var hasPreKey: Bool {return self._preKey != nil} + /// Clears the value of `preKey`. Subsequent reads from it will return its default value. + public mutating func clearPreKey() {self._preKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _identityKey: Xmtp_MessageContents_SignedPublicKey? = nil + fileprivate var _preKey: Xmtp_MessageContents_SignedPublicKey? = nil +} + +/// PublicKey represents a generalized public key, +/// defined as a union to support cryptographic algorithm agility. +public struct Xmtp_MessageContents_PublicKey { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var timestamp: UInt64 = 0 + + public var signature: Xmtp_MessageContents_Signature { + get {return _signature ?? Xmtp_MessageContents_Signature()} + set {_signature = newValue} + } + /// Returns true if `signature` has been explicitly set. + public var hasSignature: Bool {return self._signature != nil} + /// Clears the value of `signature`. Subsequent reads from it will return its default value. + public mutating func clearSignature() {self._signature = nil} + + public var union: Xmtp_MessageContents_PublicKey.OneOf_Union? = nil + + public var secp256K1Uncompressed: Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed { + get { + if case .secp256K1Uncompressed(let v)? = union {return v} + return Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed() + } + set {union = .secp256K1Uncompressed(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Union: Equatable { + case secp256K1Uncompressed(Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_PublicKey.OneOf_Union, rhs: Xmtp_MessageContents_PublicKey.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.secp256K1Uncompressed, .secp256K1Uncompressed): return { + guard case .secp256K1Uncompressed(let l) = lhs, case .secp256K1Uncompressed(let r) = rhs else { preconditionFailure() } + return l == r + }() + } + } + #endif + } + + /// The key bytes + public struct Secp256k1Uncompressed { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// uncompressed point with prefix (0x04) [ P || X || Y ], 65 bytes + public var bytes: Data = Data() + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} + + fileprivate var _signature: Xmtp_MessageContents_Signature? = nil +} + +/// PublicKeyBundle packages the cryptographic keys associated with a wallet, +/// both senders and recipients are identified by their key bundles. +public struct Xmtp_MessageContents_PublicKeyBundle { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// Identity key MUST be signed by the wallet. + public var identityKey: Xmtp_MessageContents_PublicKey { + get {return _identityKey ?? Xmtp_MessageContents_PublicKey()} + set {_identityKey = newValue} + } + /// Returns true if `identityKey` has been explicitly set. + public var hasIdentityKey: Bool {return self._identityKey != nil} + /// Clears the value of `identityKey`. Subsequent reads from it will return its default value. + public mutating func clearIdentityKey() {self._identityKey = nil} + + /// Pre-key MUST be signed by the identity key. + public var preKey: Xmtp_MessageContents_PublicKey { + get {return _preKey ?? Xmtp_MessageContents_PublicKey()} + set {_preKey = newValue} + } + /// Returns true if `preKey` has been explicitly set. + public var hasPreKey: Bool {return self._preKey != nil} + /// Clears the value of `preKey`. Subsequent reads from it will return its default value. + public mutating func clearPreKey() {self._preKey = nil} + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + + fileprivate var _identityKey: Xmtp_MessageContents_PublicKey? = nil + fileprivate var _preKey: Xmtp_MessageContents_PublicKey? = nil +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_UnsignedPublicKey: @unchecked Sendable {} +extension Xmtp_MessageContents_UnsignedPublicKey.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedPublicKey: @unchecked Sendable {} +extension Xmtp_MessageContents_SignedPublicKeyBundle: @unchecked Sendable {} +extension Xmtp_MessageContents_PublicKey: @unchecked Sendable {} +extension Xmtp_MessageContents_PublicKey.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed: @unchecked Sendable {} +extension Xmtp_MessageContents_PublicKeyBundle: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_UnsignedPublicKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".UnsignedPublicKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "created_ns"), + 3: .standard(proto: "secp256k1_uncompressed"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.createdNs) }() + case 3: try { + var v: Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .secp256K1Uncompressed(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .secp256K1Uncompressed(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.createdNs != 0 { + try visitor.visitSingularUInt64Field(value: self.createdNs, fieldNumber: 1) + } + try { if case .secp256K1Uncompressed(let v)? = self.union { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_UnsignedPublicKey, rhs: Xmtp_MessageContents_UnsignedPublicKey) -> Bool { + if lhs.createdNs != rhs.createdNs {return false} + if lhs.union != rhs.union {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_UnsignedPublicKey.protoMessageName + ".Secp256k1Uncompressed" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed, rhs: Xmtp_MessageContents_UnsignedPublicKey.Secp256k1Uncompressed) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedPublicKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignedPublicKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "key_bytes"), + 2: .same(proto: "signature"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.keyBytes) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._signature) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if !self.keyBytes.isEmpty { + try visitor.visitSingularBytesField(value: self.keyBytes, fieldNumber: 1) + } + try { if let v = self._signature { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedPublicKey, rhs: Xmtp_MessageContents_SignedPublicKey) -> Bool { + if lhs.keyBytes != rhs.keyBytes {return false} + if lhs._signature != rhs._signature {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_SignedPublicKeyBundle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".SignedPublicKeyBundle" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "identity_key"), + 2: .standard(proto: "pre_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._identityKey) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._preKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._identityKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._preKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_SignedPublicKeyBundle, rhs: Xmtp_MessageContents_SignedPublicKeyBundle) -> Bool { + if lhs._identityKey != rhs._identityKey {return false} + if lhs._preKey != rhs._preKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PublicKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PublicKey" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "timestamp"), + 2: .same(proto: "signature"), + 3: .standard(proto: "secp256k1_uncompressed"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularUInt64Field(value: &self.timestamp) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._signature) }() + case 3: try { + var v: Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .secp256K1Uncompressed(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .secp256K1Uncompressed(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + if self.timestamp != 0 { + try visitor.visitSingularUInt64Field(value: self.timestamp, fieldNumber: 1) + } + try { if let v = self._signature { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try { if case .secp256K1Uncompressed(let v)? = self.union { + try visitor.visitSingularMessageField(value: v, fieldNumber: 3) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PublicKey, rhs: Xmtp_MessageContents_PublicKey) -> Bool { + if lhs.timestamp != rhs.timestamp {return false} + if lhs._signature != rhs._signature {return false} + if lhs.union != rhs.union {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_PublicKey.protoMessageName + ".Secp256k1Uncompressed" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed, rhs: Xmtp_MessageContents_PublicKey.Secp256k1Uncompressed) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_PublicKeyBundle: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".PublicKeyBundle" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "identity_key"), + 2: .standard(proto: "pre_key"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularMessageField(value: &self._identityKey) }() + case 2: try { try decoder.decodeSingularMessageField(value: &self._preKey) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + try { if let v = self._identityKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + } }() + try { if let v = self._preKey { + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + } }() + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_PublicKeyBundle, rhs: Xmtp_MessageContents_PublicKeyBundle) -> Bool { + if lhs._identityKey != rhs._identityKey {return false} + if lhs._preKey != rhs._preKey {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/Proto/message_contents/signature.pb.swift b/Sources/XMTP/Proto/message_contents/signature.pb.swift new file mode 100644 index 00000000..9bb934db --- /dev/null +++ b/Sources/XMTP/Proto/message_contents/signature.pb.swift @@ -0,0 +1,271 @@ +// DO NOT EDIT. +// swift-format-ignore-file +// +// Generated by the Swift generator plugin for the protocol buffer compiler. +// Source: message_contents/signature.proto +// +// For information on using the generated types, please see the documentation: +// https://github.com/apple/swift-protobuf/ + +/// Signature is a generic structure for public key signatures. + +import Foundation +import SwiftProtobuf + +// If the compiler emits an error on this type, it is because this file +// was generated by a version of the `protoc` Swift plug-in that is +// incompatible with the version of SwiftProtobuf to which you are linking. +// Please ensure that you are building against the same version of the API +// that was used to generate this file. +fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck { + struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {} + typealias Version = _2 +} + +/// Signature represents a generalized public key signature, +/// defined as a union to support cryptographic algorithm agility. +public struct Xmtp_MessageContents_Signature { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + public var union: Xmtp_MessageContents_Signature.OneOf_Union? = nil + + public var ecdsaCompact: Xmtp_MessageContents_Signature.ECDSACompact { + get { + if case .ecdsaCompact(let v)? = union {return v} + return Xmtp_MessageContents_Signature.ECDSACompact() + } + set {union = .ecdsaCompact(newValue)} + } + + public var walletEcdsaCompact: Xmtp_MessageContents_Signature.WalletECDSACompact { + get { + if case .walletEcdsaCompact(let v)? = union {return v} + return Xmtp_MessageContents_Signature.WalletECDSACompact() + } + set {union = .walletEcdsaCompact(newValue)} + } + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public enum OneOf_Union: Equatable { + case ecdsaCompact(Xmtp_MessageContents_Signature.ECDSACompact) + case walletEcdsaCompact(Xmtp_MessageContents_Signature.WalletECDSACompact) + + #if !swift(>=4.1) + public static func ==(lhs: Xmtp_MessageContents_Signature.OneOf_Union, rhs: Xmtp_MessageContents_Signature.OneOf_Union) -> Bool { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch (lhs, rhs) { + case (.ecdsaCompact, .ecdsaCompact): return { + guard case .ecdsaCompact(let l) = lhs, case .ecdsaCompact(let r) = rhs else { preconditionFailure() } + return l == r + }() + case (.walletEcdsaCompact, .walletEcdsaCompact): return { + guard case .walletEcdsaCompact(let l) = lhs, case .walletEcdsaCompact(let r) = rhs else { preconditionFailure() } + return l == r + }() + default: return false + } + } + #endif + } + + /// ECDSA signature bytes and the recovery bit + public struct ECDSACompact { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// compact representation [ R || S ], 64 bytes + public var bytes: Data = Data() + + /// recovery bit + public var recovery: UInt32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + /// ECDSA signature bytes and the recovery bit + /// produced by xmtp-js::PublicKey.signWithWallet function, i.e. + /// EIP-191 signature of a "Create Identity" message with the key embedded. + /// Used to sign identity keys. + public struct WalletECDSACompact { + // SwiftProtobuf.Message conformance is added in an extension below. See the + // `Message` and `Message+*Additions` files in the SwiftProtobuf library for + // methods supported on all messages. + + /// compact representation [ R || S ], 64 bytes + public var bytes: Data = Data() + + /// recovery bit + public var recovery: UInt32 = 0 + + public var unknownFields = SwiftProtobuf.UnknownStorage() + + public init() {} + } + + public init() {} +} + +#if swift(>=5.5) && canImport(_Concurrency) +extension Xmtp_MessageContents_Signature: @unchecked Sendable {} +extension Xmtp_MessageContents_Signature.OneOf_Union: @unchecked Sendable {} +extension Xmtp_MessageContents_Signature.ECDSACompact: @unchecked Sendable {} +extension Xmtp_MessageContents_Signature.WalletECDSACompact: @unchecked Sendable {} +#endif // swift(>=5.5) && canImport(_Concurrency) + +// MARK: - Code below here is support for the SwiftProtobuf runtime. + +fileprivate let _protobuf_package = "xmtp.message_contents" + +extension Xmtp_MessageContents_Signature: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = _protobuf_package + ".Signature" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .standard(proto: "ecdsa_compact"), + 2: .standard(proto: "wallet_ecdsa_compact"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { + var v: Xmtp_MessageContents_Signature.ECDSACompact? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .ecdsaCompact(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .ecdsaCompact(v) + } + }() + case 2: try { + var v: Xmtp_MessageContents_Signature.WalletECDSACompact? + var hadOneofValue = false + if let current = self.union { + hadOneofValue = true + if case .walletEcdsaCompact(let m) = current {v = m} + } + try decoder.decodeSingularMessageField(value: &v) + if let v = v { + if hadOneofValue {try decoder.handleConflictingOneOf()} + self.union = .walletEcdsaCompact(v) + } + }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every if/case branch local when no optimizations + // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and + // https://github.com/apple/swift-protobuf/issues/1182 + switch self.union { + case .ecdsaCompact?: try { + guard case .ecdsaCompact(let v)? = self.union else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 1) + }() + case .walletEcdsaCompact?: try { + guard case .walletEcdsaCompact(let v)? = self.union else { preconditionFailure() } + try visitor.visitSingularMessageField(value: v, fieldNumber: 2) + }() + case nil: break + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Signature, rhs: Xmtp_MessageContents_Signature) -> Bool { + if lhs.union != rhs.union {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_Signature.ECDSACompact: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_Signature.protoMessageName + ".ECDSACompact" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + 2: .same(proto: "recovery"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + case 2: try { try decoder.decodeSingularUInt32Field(value: &self.recovery) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + if self.recovery != 0 { + try visitor.visitSingularUInt32Field(value: self.recovery, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Signature.ECDSACompact, rhs: Xmtp_MessageContents_Signature.ECDSACompact) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.recovery != rhs.recovery {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} + +extension Xmtp_MessageContents_Signature.WalletECDSACompact: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding { + public static let protoMessageName: String = Xmtp_MessageContents_Signature.protoMessageName + ".WalletECDSACompact" + public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [ + 1: .same(proto: "bytes"), + 2: .same(proto: "recovery"), + ] + + public mutating func decodeMessage(decoder: inout D) throws { + while let fieldNumber = try decoder.nextFieldNumber() { + // The use of inline closures is to circumvent an issue where the compiler + // allocates stack space for every case branch when no optimizations are + // enabled. https://github.com/apple/swift-protobuf/issues/1034 + switch fieldNumber { + case 1: try { try decoder.decodeSingularBytesField(value: &self.bytes) }() + case 2: try { try decoder.decodeSingularUInt32Field(value: &self.recovery) }() + default: break + } + } + } + + public func traverse(visitor: inout V) throws { + if !self.bytes.isEmpty { + try visitor.visitSingularBytesField(value: self.bytes, fieldNumber: 1) + } + if self.recovery != 0 { + try visitor.visitSingularUInt32Field(value: self.recovery, fieldNumber: 2) + } + try unknownFields.traverse(visitor: &visitor) + } + + public static func ==(lhs: Xmtp_MessageContents_Signature.WalletECDSACompact, rhs: Xmtp_MessageContents_Signature.WalletECDSACompact) -> Bool { + if lhs.bytes != rhs.bytes {return false} + if lhs.recovery != rhs.recovery {return false} + if lhs.unknownFields != rhs.unknownFields {return false} + return true + } +} diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTP/SigningKey.swift index bc1ff25f..f107b38d 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTP/SigningKey.swift @@ -37,9 +37,9 @@ extension SigningKey { let signatureText = Signature.createIdentityText(key: try slimKey.serializedData()) let signature = try await sign(message: signatureText) - let digest = try Signature.ethHash(signatureText) - let recoveredKey = try KeyUtil.recoverPublicKey(message: digest, signature: signature.rawData) - let address = KeyUtil.generateAddress(from: Data(recoveredKey.web3.bytesFromHex ?? [])).toChecksumAddress() + let message = try Signature.ethPersonalMessage(signatureText) + let recoveredKey = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) + let address = KeyUtilx.generateAddress(from: recoveredKey).toChecksumAddress() var authorized = PublicKey() authorized.secp256K1Uncompressed = slimKey.secp256K1Uncompressed diff --git a/Sources/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index 1b4e4dfe..4ea54de3 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -9,7 +9,7 @@ import Combine import XCTest @testable import XMTP -import XMTPProto + public struct FakeWallet: SigningKey { public static func generate() throws -> FakeWallet { diff --git a/Tests/XMTPTests/IntegrationTests.swift b/Tests/XMTPTests/IntegrationTests.swift index 1f2c0cb4..c8c5b105 100644 --- a/Tests/XMTPTests/IntegrationTests.swift +++ b/Tests/XMTPTests/IntegrationTests.swift @@ -9,6 +9,7 @@ import Foundation import secp256k1 import web3 import XCTest +import XMTPRust @testable import XMTP import XMTPTestHelpers @@ -375,7 +376,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: Data(keyBytes)) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -445,7 +446,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -468,7 +469,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -497,7 +498,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) let client = try await XMTP.Client.create(account: key) diff --git a/Tests/XMTPTests/MessageTests.swift b/Tests/XMTPTests/MessageTests.swift index 01948d6b..3233e789 100644 --- a/Tests/XMTPTests/MessageTests.swift +++ b/Tests/XMTPTests/MessageTests.swift @@ -7,6 +7,7 @@ import CryptoKit import XCTest +import XMTPRust @testable import XMTP import XMTPTestHelpers @@ -114,7 +115,7 @@ class MessageTests: XCTestCase { 140, 247, 221, 172, 14, 188, 52, 88, ]) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtil.xmtpGeneratePublicKey(from: key.secp256K1.bytes) + key.publicKey.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: key.secp256K1.bytes) } let keyBundleData = Data( diff --git a/Tests/XMTPTests/SignatureTests.swift b/Tests/XMTPTests/SignatureTests.swift index 21ddf607..0b2b5c4e 100644 --- a/Tests/XMTPTests/SignatureTests.swift +++ b/Tests/XMTPTests/SignatureTests.swift @@ -12,9 +12,15 @@ import XCTest class SignatureTests: XCTestCase { func testVerify() async throws { let digest = SHA256.hash(data: Data("Hello world".utf8)) + print("Message Bytes: \(Data("Hello world".utf8).toHex)") let signingKey = try PrivateKey.generate() let signature = try await signingKey.sign(Data(digest)) + print("Digest: \(digest.description)") + print("Signature: \(signature.rawData.toHex)") + print("Expected public: \(signingKey.publicKey.secp256K1Uncompressed.bytes.toHex)") + print("Recovered public: \(try KeyUtilx.recoverPublicKey(message: Data(digest), signature: signature.rawData).toHex)") + XCTAssert(try signature.verify(signedBy: signingKey.publicKey, digest: Data("Hello world".utf8))) } } diff --git a/XMTP.podspec b/XMTP.podspec index e038720d..fb4b2631 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -136,17 +136,5 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift" - - spec.subspec 'XMTPProto' do |subspec| - subspec.dependency "SwiftProtobuf" - subspec.source_files = "../proto/**/*.swift" - end - - spec.subspec 'XMTPRust' do |subspec| - subspec.source_files = "../xmtp-rust-swift/**/*.swift" - subspec.vendored_frameworks = 'XMTPRustSwift.xcframework' - end - - spec.dependency 'XMTPProto' - spec.dependency 'XMTPRust' + spec.dependency 'XMTPRust', '= 0.1.2beta-0' end diff --git a/XMTPiOSExample/Podfile b/XMTPiOSExample/Podfile index caadb8b8..e5d8fdd7 100644 --- a/XMTPiOSExample/Podfile +++ b/XMTPiOSExample/Podfile @@ -9,8 +9,8 @@ target 'NotificationService' do # Pods for XMTPiOSExample # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" pod "web3.swift" - pod "XMTPProto", path: "../../proto" - pod "XMTPRust", path: '../../xmtp-rust-swift' +# pod "XMTPProto", path: "../../proto" +# pod "XMTPRust", path: '../../xmtp-rust-swift' pod "XMTP", path: "../" end @@ -21,8 +21,8 @@ target 'XMTPiOSExample' do # Pods for XMTPiOSExample # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" pod "web3.swift" - pod "XMTPProto", path: "../../proto" - pod "XMTPRust", path: '../../xmtp-rust-swift' +# pod "XMTPProto", path: "../../proto" +# pod "XMTPRust", path: '../../xmtp-rust-swift' pod "XMTP", path: "../" end diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index 6c724d28..7a3212c2 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -16,32 +16,12 @@ PODS: - Connect-Swift - GzipSwift - web3.swift - - XMTP/XMTPProto (= 0.1.1) - - XMTP/XMTPRust (= 0.1.1) - - XMTPProto - - XMTPRust - - XMTP/XMTPProto (0.1.1): - - Connect-Swift - - GzipSwift - - SwiftProtobuf - - web3.swift - - XMTPProto - - XMTPRust - - XMTP/XMTPRust (0.1.1): - - Connect-Swift - - GzipSwift - - web3.swift - - XMTPProto - - XMTPRust - - XMTPProto (0.1.0): - - SwiftProtobuf - - XMTPRust (0.1.1) + - XMTPRust (= 0.1.2beta-0) + - XMTPRust (0.1.2-beta0) DEPENDENCIES: - web3.swift - XMTP (from `../`) - - XMTPProto (from `../../proto`) - - XMTPRust (from `../../xmtp-rust-swift`) SPEC REPOS: trunk: @@ -53,14 +33,11 @@ SPEC REPOS: - secp256k1.swift - SwiftProtobuf - web3.swift + - XMTPRust EXTERNAL SOURCES: XMTP: :path: "../" - XMTPProto: - :path: "../../proto" - XMTPRust: - :path: "../../xmtp-rust-swift" SPEC CHECKSUMS: BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 @@ -71,10 +48,9 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 5a89e947bcfbf6f8dfb1f8e2dc708fa30753f3ee - XMTPProto: 8e329d4a799e6c5dea2e8c3988ec48d54571809b - XMTPRust: d7c7f090e9993bb8cf5517f11e1622ff3a0c29af + XMTP: 728019fe8723c98479ae09f4da82ae1c061eb632 + XMTPRust: 2c356f57f034d771717933a6127a7d51667f9843 -PODFILE CHECKSUM: a5714547991f401af3096df5f89f36fa1e550806 +PODFILE CHECKSUM: 34395c840d082584c6758fd1e94cb68eaeb0c270 -COCOAPODS: 1.11.3 +COCOAPODS: 1.12.1 From c49e68ad0d8f1d1c412c571caf3f2b31498f1028 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 16:37:40 -0700 Subject: [PATCH 17/47] Make version match XMTPRust --- XMTP.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XMTP.podspec b/XMTP.podspec index fb4b2631..0de25b4d 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.1.1" + spec.version = "0.1.2" spec.summary = "XMTP pod." # This description is used to generate tags and improve search results. From d484e5ebab4abe0e5681682eb2931f26182d87fd Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 16:39:59 -0700 Subject: [PATCH 18/47] add swift version --- XMTP.podspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/XMTP.podspec b/XMTP.podspec index 0de25b4d..2c2079de 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -131,6 +131,8 @@ Pod::Spec.new do |spec| # spec.requires_arc = true + spec.swift_version = '5.3' + # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } spec.dependency "secp256k1Swift" spec.dependency "web3.swift" From a8b13ddfd6f56fa57af637485dbd573ad236a0a7 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Tue, 18 Apr 2023 17:00:38 -0700 Subject: [PATCH 19/47] wip --- XMTP.podspec | 119 ++++++++------------------------------------------- 1 file changed, 17 insertions(+), 102 deletions(-) diff --git a/XMTP.podspec b/XMTP.podspec index 2c2079de..9ab8d049 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -28,115 +28,30 @@ Pod::Spec.new do |spec| TODO DESC - spec.homepage = "https://github.com/xmtp/xmtp-ios" - # spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" + spec.homepage = "https://github.com/xmtp/xmtp-ios" + spec.license = "MIT" + spec.author = { "Pat Nakajima" => "pat@xmtp.com" } - # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # Licensing your code is important. See https://choosealicense.com for more info. - # CocoaPods will detect a license file if there is a named LICENSE* - # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. - # - - spec.license = "MIT" - # spec.license = { :type => "MIT", :file => "FILE_LICENSE" } - - - # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # Specify the authors of the library, with email addresses. Email addresses - # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also - # accepts just a name if you'd rather not provide an email address. - # - # Specify a social_media_url where others can refer to, for example a twitter - # profile URL. - # - - spec.author = { "Pat Nakajima" => "pat@xmtp.com" } - # Or just: spec.author = "Pat Nakajima" - # spec.authors = { "Pat Nakajima" => "patnakajima@gmail.com" } - # spec.social_media_url = "https://twitter.com/Pat Nakajima" - - # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # If this Pod runs only on iOS or OS X, then specify the platform and - # the deployment target. You can optionally include the target after the platform. - # - - # spec.platform = :ios - spec.platform = :ios, "16.0" - - # When using multiple platforms - # spec.ios.deployment_target = "5.0" - # spec.osx.deployment_target = "10.7" - # spec.watchos.deployment_target = "2.0" - # spec.tvos.deployment_target = "9.0" - - - # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # Specify the location from where the source should be retrieved. - # Supports git, hg, bzr, svn and HTTP. - # - - spec.source = { :git => "https://github.com/xmtp/xmtp-ios.git", :tag => "#{spec.version}" } - - - # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # CocoaPods is smart about how it includes source code. For source files - # giving a folder will include any swift, h, m, mm, c & cpp files. - # For header files it will include any header in the folder. - # Not including the public_header_files will make all headers public. - # - - spec.source_files = "Sources/**/*.swift" + spec.platform = :ios, '13.0', :macos, '11.0' - # spec.public_header_files = "Classes/**/*.h" + spec.swift_version = '5.3' + spec.source = { :git => "https://github.com/xmtp/xmtp-ios.git", :tag => "#{spec.version}" } + spec.source_files = "Sources/**/*.swift" + spec.frameworks = "CryptoKit", "UIKit" - # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # A list of resources included with the Pod. These are copied into the - # target bundle with a build phase script. Anything else will be cleaned. - # You can preserve files from being cleaned, please don't preserve - # non-essential files like tests, examples and documentation. - # - - # spec.resource = "icon.png" - # spec.resources = "Resources/*.png" - - # spec.preserve_paths = "FilesToSave", "MoreFilesToSave" - - - # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # Link your library with frameworks, or libraries. Libraries do not include - # the lib prefix of their name. - # - - # spec.framework = "SomeFramework" - spec.frameworks = "CryptoKit", "UIKit" - - # spec.library = "iconv" - # spec.libraries = "iconv", "xml2" - - - # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # If your library depends on compiler flags you can set them in the xcconfig hash - # where they will only apply to your library. If you depend on other Podspecs - # you can include multiple dependencies to ensure it works. - - # spec.requires_arc = true - - spec.swift_version = '5.3' - - # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } - spec.dependency "secp256k1Swift" spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift" spec.dependency 'XMTPRust', '= 0.1.2beta-0' + + spec.xcconfig = {'VALID_ARCHS' => 'arm64' } + spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } + + def spec.post_install(target) + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' + end + end end From bfcc8eabe61283194a2f0622f6c5db3a7b8337e1 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Mon, 8 May 2023 10:18:59 -0700 Subject: [PATCH 20/47] Integrate xmtp-rust-swift 0.2.0-beta0 (#97) * wip: does not build yet, no progress on subscribe needs AsyncIterator * fix: some tests pass, subscribe still not implemented * feat: initialize rust client outside of GRPCApiClient * feat: partial integration of newest Rust<>Swift bindings * feat: implement polling subscribe * test: add test for content in testStreamingMessagesFromV2Conversations * feat: working if you comment out NotificationService logic * Get tests building again * Cleanups * Format * Ignore pods * Updates * Update package.resolved * Fix lint * Fix more lint * update pod * Bump XMTPRust version * Get example app building again * Move everything to cocoapods * Get rid of cocoapods for the example app * Try to get XMTP buildable for testing * Fix test building * wip: tests seemed to pass * fix: reset the cocoapod * fix: tests pass with new paging info changes, removed some printlns, need to address QueryResponse ownership * fix: upgrade to XMTPRust=0.2.2-beta0 to attempt to fix Package.resolved issue in Xcode cloud * fix: delete Package.resolved from xcshareddata * fix: attempt to use Package.resolved from a passing commit * fix: open Example app and let swift re-resolve * fix: use package.resolved after running example app successfully * fix: try to undo changes to XMTP.xcscheme --------- Co-authored-by: Michael Xu --- .gitignore | 4 +- .swiftlint.yml | 3 + Package.resolved | 167 +++++++++++++++ Package.swift | 96 ++++----- Sources/XMTP/ApiClient.swift | 191 +++++++++++++----- Sources/XMTP/AuthorizedIdentity.swift | 2 - Sources/XMTP/Client.swift | 22 +- Sources/XMTP/ConversationV2.swift | 2 +- Sources/XMTP/Crypto.swift | 6 +- Sources/XMTP/Extensions/Data.swift | 5 + Sources/XMTP/Extensions/RustVec.swift | 19 ++ Sources/XMTP/KeyUtil.swift | 19 +- Sources/XMTP/Messages/MessageV2.swift | 2 +- Sources/XMTP/Messages/PrivateKey.swift | 3 +- Sources/XMTP/Messages/PrivateKeyBundle.swift | 2 +- .../XMTP/Messages/PrivateKeyBundleV1.swift | 7 - .../XMTP/Messages/PrivateKeyBundleV2.swift | 3 +- Sources/XMTP/Messages/PublicKey.swift | 4 +- Sources/XMTP/Messages/Signature.swift | 19 +- Sources/XMTP/Messages/SignedPublicKey.swift | 4 +- Sources/XMTP/Push/XMTPPush.swift | 170 ++++++++-------- Sources/XMTP/SigningKey.swift | 2 +- Sources/XMTPTestHelpers/TestHelpers.swift | 29 +-- Tests/XMTPTests/ClientTests.swift | 120 ++++++----- Tests/XMTPTests/ConversationTests.swift | 6 +- Tests/XMTPTests/IntegrationTests.swift | 90 ++++----- Tests/XMTPTests/MessageTests.swift | 2 +- XMTP.podspec | 6 +- .../NotificationService.swift | 23 ++- XMTPiOSExample/Podfile | 3 + XMTPiOSExample/Podfile.lock | 24 ++- .../XMTPiOSExample.xcodeproj/project.pbxproj | 173 +++++----------- .../xcshareddata/swiftpm/Package.resolved | 78 ++++--- .../xcshareddata/xcschemes/XMTP.xcscheme | 66 ++++++ .../contents.xcworkspacedata | 10 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../Account/WalletConnection.swift | 1 + .../XMTPiOSExample/ContentView.swift | 2 +- script/lint | 2 +- 39 files changed, 852 insertions(+), 543 deletions(-) create mode 100644 Package.resolved create mode 100644 Sources/XMTP/Extensions/RustVec.swift create mode 100644 XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme delete mode 100644 XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata delete mode 100644 XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/.gitignore b/.gitignore index bbb46d66..aa13e2fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +XMTPiOSExample/Pods/ +XMTPiOSExample/build + .DS_Store /.build /Packages @@ -8,6 +11,5 @@ DerivedData/ .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc -Package.resolved .vscode XMTPiOSExample/Pods diff --git a/.swiftlint.yml b/.swiftlint.yml index f102816c..26470bdb 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,3 +1,6 @@ +excluded: + - Sources/XMTP/Proto + disabled_rules: # rule identifiers turned on by default to exclude from running - type_name - identifier_name diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 00000000..91c2ab5e --- /dev/null +++ b/Package.resolved @@ -0,0 +1,167 @@ +{ + "pins" : [ + { + "identity" : "bigint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/attaswift/BigInt", + "state" : { + "revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6", + "version" : "5.3.0" + } + }, + { + "identity" : "connect-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/bufbuild/connect-swift", + "state" : { + "revision" : "6f5afc57f44a3ed15b9a01381ce73f84d15e43db", + "version" : "0.3.0" + } + }, + { + "identity" : "generic-json-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/zoul/generic-json-swift", + "state" : { + "revision" : "0a06575f4038b504e78ac330913d920f1630f510", + "version" : "2.0.2" + } + }, + { + "identity" : "gzipswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/1024jp/GzipSwift", + "state" : { + "revision" : "7a7f17761c76a932662ab77028a4329f67d645a4", + "version" : "5.2.0" + } + }, + { + "identity" : "proto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/proto", + "state" : { + "branch" : "ios_minus_grpc_keeping_messageapi", + "revision" : "c74e3237e4de2aa481b91f91b1d23f6f9d87734e" + } + }, + { + "identity" : "secp256k1.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", + "state" : { + "branch" : "main", + "revision" : "1542d3a9968ddac9c33d04f7b22a6ad54a415e29" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", + "version" : "1.0.3" + } + }, + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin.git", + "state" : { + "revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-docc-symbolkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-symbolkit", + "state" : { + "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", + "version" : "1.4.4" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "edfceecba13d68c1c993382806e72f7e96feaa86", + "version" : "2.44.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", + "version" : "2.23.0" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", + "version" : "1.15.0" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8", + "version" : "1.20.3" + } + }, + { + "identity" : "web3.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/argentlabs/web3.swift", + "state" : { + "revision" : "9da09d639d4e5d06eb59518e636b3ae957e8e9cd", + "version" : "1.3.0" + } + }, + { + "identity" : "websocket-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/websocket-kit.git", + "state" : { + "revision" : "2d9d2188a08eef4a869d368daab21b3c08510991", + "version" : "2.6.1" + } + }, + { + "identity" : "xmtp-rust-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/xmtp-rust-swift", + "state" : { + "revision" : "eccfc16bb8f866857ecbb1604c1dab855b1960f7", + "version" : "0.2.2-beta0" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift index 8224ecac..e2714518 100644 --- a/Package.swift +++ b/Package.swift @@ -4,52 +4,52 @@ import PackageDescription let package = Package( - name: "XMTP", - platforms: [.iOS(.v14), .macOS(.v11)], - products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "XMTP", - targets: ["XMTP"] - ), - .library( - name: "XMTPTestHelpers", - targets: ["XMTPTestHelpers"] - ), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), - - .package(url: "https://github.com/xmtp/proto", branch: "ios_minus_grpc_keeping_messageapi"), - .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", branch: "main"), - .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", from: "0.3.0"), - .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "../xmtp-rust-swift/", branch: "michaelx_secp256k1_wip") - ], - 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: "XMTP", - dependencies: [ - .product(name: "XMTPProto", package: "proto"), - .product(name: "secp256k1", package: "secp256k1.swift"), - "web3.swift", - .product(name: "Gzip", package: "GzipSwift"), - .product(name: "Connect", package: "connect-swift"), - .product(name: "XMTPRust", package: "xmtp-rust-swift") - ] - ), - .target( - name: "XMTPTestHelpers", - dependencies: ["XMTP"] - ), - .testTarget( - name: "XMTPTests", - dependencies: ["XMTP", "XMTPTestHelpers"] - ), - ] + name: "XMTP", + platforms: [.iOS(.v14), .macOS(.v11)], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "XMTP", + targets: ["XMTP"] + ), + .library( + name: "XMTPTestHelpers", + targets: ["XMTPTestHelpers"] + ), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + + .package(url: "https://github.com/xmtp/proto", branch: "ios_minus_grpc_keeping_messageapi"), + .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", branch: "main"), + .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", from: "0.3.0"), + .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), + .package(url: "https://github.com/xmtp/xmtp-rust-swift", from: "0.2.2-beta0"), + ], + 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: "XMTP", + dependencies: [ + .product(name: "XMTPProto", package: "proto"), + .product(name: "secp256k1", package: "secp256k1.swift"), + "web3.swift", + .product(name: "Gzip", package: "GzipSwift"), + .product(name: "Connect", package: "connect-swift"), + .product(name: "XMTPRust", package: "xmtp-rust-swift"), + ] + ), + .target( + name: "XMTPTestHelpers", + dependencies: ["XMTP"] + ), + .testTarget( + name: "XMTPTests", + dependencies: ["XMTP", "XMTPTestHelpers"] + ), + ] ) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 5fc0217a..154fc53e 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -5,15 +5,16 @@ // Created by Pat Nakajima on 11/17/22. // +import Foundation import XMTPRust -public typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse -public typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse -public typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest +typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse +typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse +typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest protocol ApiClient { var environment: XMTPEnvironment { get } - init(environment: XMTPEnvironment, secure: Bool) throws + init(environment: XMTPEnvironment, secure: Bool, rustClient: XMTPRust.RustClient) throws func setAuthToken(_ token: String) func query(topic: String, pagination: Pagination?, cursor: Xmtp_MessageApi_V1_Cursor?) async throws -> QueryResponse func query(topic: Topic, pagination: Pagination?) async throws -> QueryResponse @@ -22,6 +23,24 @@ protocol ApiClient { func subscribe(topics: [String]) -> AsyncThrowingStream } +extension Data { + func dataToRustVec() -> RustVec { + let rustVec = RustVec() + for byte in self { + rustVec.push(value: byte) + } + return rustVec + } + + func dataFromRustVec(rustVec: RustVec) -> Data { + var listBytes: [UInt8] = [] + for byte in rustVec { + listBytes.append(byte) + } + return Data(listBytes) + } +} + class GRPCApiClient: ApiClient { let ClientVersionHeaderKey = "X-Client-Version" let AppVersionHeaderKey = "X-App-Version" @@ -29,25 +48,87 @@ class GRPCApiClient: ApiClient { var environment: XMTPEnvironment var authToken = "" - private var rustClient: XMTPRust.ApiService! + var rustClient: XMTPRust.RustClient - required init(environment: XMTPEnvironment, secure: Bool = true) throws { + required init(environment: XMTPEnvironment, secure _: Bool = true, rustClient: XMTPRust.RustClient) throws { self.environment = environment - // Secure flag is useless for now, XMTPRust checks the URL scheme to see if it's https - rustClient = XMTPRust.ApiService(environment:envToUrl(env: environment), secure:true) + // TODO: this is a hack to do an async thing in a synchronous way + self.rustClient = rustClient + } + + func dataToRustVec(data: Data) -> RustVec { + let rustVec = RustVec() + for byte in data { + rustVec.push(value: byte) + } + return rustVec + } + + func dataFromRustVec(rustVec: RustVec) -> Data { + var listBytes: [UInt8] = [] + for byte in rustVec { + listBytes.append(byte) + } + return Data(listBytes) + } + + static func envToUrl(env: XMTPEnvironment) -> String { + switch env { + case XMTPEnvironment.local: return "http://localhost:5556" + case XMTPEnvironment.dev: return "https://dev.xmtp.network:5556" + case XMTPEnvironment.production: return "https://xmtp.network:5556" + } } - - func envToUrl(env: XMTPEnvironment) -> String { - switch (env) { - case XMTPEnvironment.local: return "http://localhost:5556"; - case XMTPEnvironment.dev: return "https://dev.xmtp.network:5556"; - case XMTPEnvironment.production: return "https://xmtp.network:5556"; - } - } func setAuthToken(_ token: String) { authToken = token } + + func rustPagingInfoFromRequest(request: Xmtp_MessageApi_V1_QueryRequest) -> XMTPRust.PagingInfo { + var rustPaging = XMTPRust.PagingInfo(limit: 0, cursor: nil, direction: XMTPRust.SortDirection.Ascending) + rustPaging.limit = request.pagingInfo.limit + if request.hasPagingInfo && request.pagingInfo.hasCursor { + let cursor = request.pagingInfo.cursor; + let digest = cursor.index.digest.dataToRustVec() + let senderTimeNs = cursor.index.senderTimeNs + rustPaging.cursor = XMTPRust.IndexCursor(digest: digest, sender_time_ns: senderTimeNs) + } + + // Set rustPaging.direction based off a switch-case conversion + switch request.pagingInfo.direction { + case .ascending: + rustPaging.direction = XMTPRust.SortDirection.Ascending + case .descending: + rustPaging.direction = XMTPRust.SortDirection.Descending + case .unspecified: + rustPaging.direction = XMTPRust.SortDirection.Unspecified + case .UNRECOGNIZED(_): + rustPaging.direction = XMTPRust.SortDirection.Unspecified + } + + return rustPaging; + } + + func parseRustPagingInfoFromResponse(response: XMTPRust.QueryResponse) -> PagingInfo { + var pagingInfo = PagingInfo() + if let rustPaging = response.paging_info() { + pagingInfo.limit = rustPaging.limit + if let rustCursor = rustPaging.cursor { + var cursor = PagingInfoCursor() + cursor.index.digest = Data(rustCursor.digest) + cursor.index.senderTimeNs = rustCursor.sender_time_ns + } + switch rustPaging.direction { + case XMTPRust.SortDirection.Ascending: + pagingInfo.direction = .ascending + case XMTPRust.SortDirection.Descending: + pagingInfo.direction = .descending + case XMTPRust.SortDirection.Unspecified: + pagingInfo.direction = .unspecified + } + } + return pagingInfo + } func query(topic: String, pagination: Pagination? = nil, cursor: Xmtp_MessageApi_V1_Cursor? = nil) async throws -> QueryResponse { var request = Xmtp_MessageApi_V1_QueryRequest() @@ -71,14 +152,26 @@ class GRPCApiClient: ApiClient { request.pagingInfo.cursor = cursor } - var encodedPaging = "" - if request.hasPagingInfo { - encodedPaging = try request.pagingInfo.jsonString() - } - let responseJson = try await rustClient.query(topic: topic, json_paging_info: encodedPaging) - // Decode the response as a QueryResponse - let decodedQueryResponse = try QueryResponse(jsonString: responseJson) - return decodedQueryResponse + + let startTimeParam: UInt64? = pagination == nil ? nil : request.startTimeNs + let endTimeParam: UInt64? = pagination == nil ? nil : request.endTimeNs + let rustPagingInfo = rustPagingInfoFromRequest(request: request) + let response = try await rustClient.query(topic.intoRustString(), startTimeParam, endTimeParam, rustPagingInfo) + // response has .envelopes() and .paging_info() but the envelopes need to be mapped into Envelope objects that Swift understands + var queryResponse = QueryResponse() + // Build the query response from response fields + queryResponse.envelopes = response.envelopes().map { rustEnvelope in + var envelope = Envelope() + envelope.contentTopic = rustEnvelope.get_topic().toString() + envelope.timestampNs = rustEnvelope.get_sender_time_ns() + envelope.message = dataFromRustVec(rustVec: rustEnvelope.get_payload()) + return envelope + } + // TODO: uncomment this once we clear up ownership issues on QueryResponse for the Rust side +// if let responsePagingInfo = response.paging_info() { +// queryResponse.pagingInfo = parseRustPagingInfoFromResponse(response: response) +// } + return queryResponse } func envelopes(topic: String, pagination: Pagination? = nil) async throws -> [Envelope] { @@ -105,9 +198,22 @@ class GRPCApiClient: ApiClient { func subscribe(topics: [String]) -> AsyncThrowingStream { return AsyncThrowingStream { continuation in Task { - for try await envelopeJson in self.rustClient.subscribe(topics: topics) { - let envelope = try Envelope(jsonString: envelopeJson) - continuation.yield(envelope) + let topicsVec = RustVec() + for topic in topics { + topicsVec.push(value: topic.intoRustString()) + } + let subscription = try await self.rustClient.subscribe(topicsVec) + // Run a continuous for loop polling subscription.get_messages() and then waiting for 2 seconds + while true { + let rustEnvelopes = try subscription.get_messages() + for rustEnvelope in rustEnvelopes { + var swiftEnvelope = Envelope() + swiftEnvelope.contentTopic = rustEnvelope.get_topic().toString() + swiftEnvelope.timestampNs = rustEnvelope.get_sender_time_ns() + swiftEnvelope.message = Data().dataFromRustVec(rustVec: rustEnvelope.get_payload()) + continuation.yield(swiftEnvelope) + } + try await Task.sleep(nanoseconds: 50_000_000) // 50ms } } } @@ -117,23 +223,18 @@ class GRPCApiClient: ApiClient { var request = Xmtp_MessageApi_V1_PublishRequest() request.envelopes = envelopes - // return try await client.publish(request, callOptions: options) - // Use the JSON encoding api for rustClient to publish - let encodedEnvelopes = try envelopes.map { try $0.jsonString() } - let responseJson = try await rustClient.publish(token: authToken, envelopes: encodedEnvelopes) - // Decode the response as a PublishResponse - let decodedPublishResponse = try PublishResponse(jsonString: responseJson) - return decodedPublishResponse + let envelopesVec = RustVec() + + envelopes.forEach { envelope in + let rustEnvelope = XMTPRust.create_envelope(envelope.contentTopic.intoRustString(), envelope.timestampNs, dataToRustVec(data: envelope.message)) + envelopesVec.push(value: rustEnvelope) + } + let response = try await rustClient.publish(authToken.intoRustString(), envelopesVec) + let publishResponse = PublishResponse() + return publishResponse + } + + public static func runGrpcTest() async throws -> Int { + return 0 } - - public static func runGrpcTest() async throws -> Int { - - let json = "{\"contentTopic\":\"/xmtp/0/privatestore-0x144a87F6dB31445B916BF4d896A425C91DbA7f84/key_bundle/proto\",\"timestampNs\":\"1681678277321011968\",\"message\":\"CvYDCiBPVY2cN8BNkvA2Ypoh0GvaMKNKmAtUsaPMNMwsRDRsmhLRAwrOAwogJ2zn2csOlNN6h2Llb9H4sAvp2Qs6x2L8Dra4ZTG9OvoSDIXSSqfFBhJgYMPSuxqbA68nOkGUPsV1WKjzs2LBuktCdGAEt3tWAbW1jNSF3KaA8XBkbhmM5zwSIbv69vszBzBp9/cYXxW4/rAJtkOuyNlsX04x/i+hswL4T6EkpTl/SGgzRfAHZs+SKbfhwsdcVC577r0u5mm7a9C/DOrsdo42zXDL1cKv8DGSmLzIMGQTrryo6bOH+6JhHUu0bVdXC8KF13zhQxnbdnjg5NMN7PRfUZWP5iz/bfv2H3FZC7fFfmkxIM+yn4y0XQCPjhrygAZyzMhiUC2cPWBj+iTX/lDRed3qy5RmvHhBiOVwumtzkSCy2kreZ2Kd6xMBk+mfKnjLU9cDd2QDmlyJDjZ8FZlk83AeJr7rPCdRDPVPCxUhFNET605QBrx90HoTr6o+EK8N9KUgCHGuijqLen1aARBpqsWkit2zn371Poi3zQvGL/gEQuR7yGd+0Gi+sx/A/08jxcqKNtNOSO0XbtWzASYnEc8gDup+1CsEkMpvKJ/F5CbmQN2yAV0ZIHhsCpdIQ9uUe3C8lwVkns5oWlfZNX/FWKrqRMk6Nlvobg==\"}" - let envelope = try Envelope(jsonString: json) - let service = XMTPRust.ApiService(environment: "http://localhost:5556", secure: false) - let response = try await service.query(topic: "test", json_paging_info: "") - // Try to parse the response JSON into a QueryResponse - let queryResponse = try QueryResponse(jsonString: response) - return queryResponse.envelopes.count - } } diff --git a/Sources/XMTP/AuthorizedIdentity.swift b/Sources/XMTP/AuthorizedIdentity.swift index 4cdc97c3..a4ff3e31 100644 --- a/Sources/XMTP/AuthorizedIdentity.swift +++ b/Sources/XMTP/AuthorizedIdentity.swift @@ -17,8 +17,6 @@ struct AuthorizedIdentity { let authDataBytes = try authData.serializedData() let signature = try await identity.sign(Util.keccak256(authDataBytes)) - print("SIG: \(signature.rawData.toHex)") - var token = Token() token.identityKey = authorized diff --git a/Sources/XMTP/Client.swift b/Sources/XMTP/Client.swift index 968a2f3a..69211fe4 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTP/Client.swift @@ -7,6 +7,7 @@ import Foundation import web3 +import XMTPRust /// Specify configuration options for creating a ``Client``. public struct ClientOptions { @@ -72,15 +73,16 @@ public class Client { public static func create(account: SigningKey, options: ClientOptions? = nil) async throws -> Client { let options = options ?? ClientOptions() + let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) let apiClient = try GRPCApiClient( environment: options.api.env, - secure: options.api.isSecure + secure: options.api.isSecure, + rustClient: client ) - + return try await create(account: account, apiClient: apiClient) } - static func create(account: SigningKey, apiClient: ApiClient) async throws -> Client { let privateKeyBundleV1 = try await loadOrCreateKeys(for: account, apiClient: apiClient) @@ -94,7 +96,7 @@ public class Client { // swiftlint:disable no_optional_try if let keys = try await loadPrivateKeys(for: account, apiClient: apiClient) { // swiftlint:enable no_optional_try - + print("loading existing private keys.") #if DEBUG print("Loaded existing private keys.") #endif @@ -111,10 +113,8 @@ public class Client { var authorizedIdentity = AuthorizedIdentity(privateKeyBundleV1: keys) authorizedIdentity.address = account.address let authToken = try await authorizedIdentity.createAuthToken() - let apiClient = apiClient apiClient.setAuthToken(authToken) - _ = try await apiClient.publish(envelopes: [ Envelope(topic: .userPrivateStoreKeyBundle(account.address), timestamp: Date(), message: try encryptedKeys.serializedData()), ]) @@ -138,19 +138,21 @@ public class Client { return nil } - public static func from(bundle: PrivateKeyBundle, options: ClientOptions? = nil) throws -> Client { - return try from(v1Bundle: bundle.v1, options: options) + public static func from(bundle: PrivateKeyBundle, options: ClientOptions? = nil) async throws -> Client { + return try await from(v1Bundle: bundle.v1, options: options) } /// Create a Client from saved v1 key bundle. - public static func from(v1Bundle: PrivateKeyBundleV1, options: ClientOptions? = nil) throws -> Client { + public static func from(v1Bundle: PrivateKeyBundleV1, options: ClientOptions? = nil) async throws -> Client { let address = try v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress let options = options ?? ClientOptions() + let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) let apiClient = try GRPCApiClient( environment: options.api.env, - secure: options.api.isSecure + secure: options.api.isSecure, + rustClient: client ) return try Client(address: address, privateKeyBundleV1: v1Bundle, apiClient: apiClient) diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTP/ConversationV2.swift index 255c3277..41c5a10c 100644 --- a/Sources/XMTP/ConversationV2.swift +++ b/Sources/XMTP/ConversationV2.swift @@ -38,7 +38,7 @@ public struct ConversationV2 { let peer = try myKeys.walletAddress == (try header.sender.walletAddress) ? header.recipient : header.sender let peerAddress = try peer.walletAddress - let keyMaterial = Data(invitation.aes256GcmHkdfSha256.keyMaterial.bytes) + let keyMaterial = Data(invitation.aes256GcmHkdfSha256.keyMaterial.bytes) return ConversationV2( topic: invitation.topic, diff --git a/Sources/XMTP/Crypto.swift b/Sources/XMTP/Crypto.swift index 5fa41ff6..c9fccd34 100644 --- a/Sources/XMTP/Crypto.swift +++ b/Sources/XMTP/Crypto.swift @@ -47,11 +47,11 @@ enum Crypto { let salt = ciphertext.aes256GcmHkdfSha256.hkdfSalt let nonceData = ciphertext.aes256GcmHkdfSha256.gcmNonce let nonce = try AES.GCM.Nonce(data: nonceData) - let payload = ciphertext.aes256GcmHkdfSha256.payload.bytes + let payload = ciphertext.aes256GcmHkdfSha256.payload.bytes - let ciphertext = payload[0 ..< payload.count - 16] + let ciphertextBytes = payload[0 ..< payload.count - 16] let tag = payload[payload.count - 16 ..< payload.count] - let box = try AES.GCM.SealedBox(nonce: nonce, ciphertext: ciphertext, tag: tag) + let box = try AES.GCM.SealedBox(nonce: nonce, ciphertext: ciphertextBytes, tag: tag) let resultKey = HKDF.deriveKey( inputKeyMaterial: SymmetricKey(data: secret), diff --git a/Sources/XMTP/Extensions/Data.swift b/Sources/XMTP/Extensions/Data.swift index e2bbdba3..5d2ba4fc 100644 --- a/Sources/XMTP/Extensions/Data.swift +++ b/Sources/XMTP/Extensions/Data.swift @@ -6,12 +6,17 @@ // import Foundation +import XMTPRust extension Data { init?(base64String: String) { self.init(base64Encoded: Data(base64String.utf8)) } + init(_ rustVec: RustVec) { + self.init(rustVec.map { $0 }) + } + var toHex: String { return reduce("") { $0 + String(format: "%02x", $1) } } diff --git a/Sources/XMTP/Extensions/RustVec.swift b/Sources/XMTP/Extensions/RustVec.swift new file mode 100644 index 00000000..f63d1f7d --- /dev/null +++ b/Sources/XMTP/Extensions/RustVec.swift @@ -0,0 +1,19 @@ +// +// File.swift +// +// +// Created by Pat Nakajima on 4/24/23. +// + +import Foundation +import XMTPRust + +extension RustVec where T == UInt8 { + convenience init(_ data: Data) { + self.init() + + for byte in data { + push(value: byte) + } + } +} diff --git a/Sources/XMTP/KeyUtil.swift b/Sources/XMTP/KeyUtil.swift index cdca6bcd..dff570ba 100644 --- a/Sources/XMTP/KeyUtil.swift +++ b/Sources/XMTP/KeyUtil.swift @@ -20,17 +20,23 @@ enum KeyUtilError: Error { // Copied from web3.swift since its version is `internal` enum KeyUtilx { - private static var logger: Logger { - Logger(label: "web3.swift.key-util") + static func generatePublicKey(from data: Data) throws -> Data { + let vec = try XMTPRust.public_key_from_private_key_k256(RustVec(data)) + return Data(vec) } - static func generatePublicKey(from data: Data) throws -> Data { - try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: data) + static func recoverPublicKeySHA256(from data: Data, message: Data) throws -> Data { + let vec = try XMTPRust.recover_public_key_k256_sha256(RustVec(message), RustVec(data)) + return Data(vec) + } + + static func recoverPublicKeyKeccak256(from data: Data, message: Data) throws -> Data { + let vec = try XMTPRust.recover_public_key_k256_keccak256(RustVec(message), RustVec(data)) + return Data(vec) } static func sign(message: Data, with privateKey: Data, hashing: Bool) throws -> Data { guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)) else { - logger.warning("Failed to sign message: invalid context.") throw KeyUtilError.invalidContext } @@ -46,7 +52,6 @@ enum KeyUtilx { signaturePtr.deallocate() } guard secp256k1_ecdsa_sign_recoverable(ctx, signaturePtr, msg, privateKeyPtr, nil, nil) == 1 else { - logger.warning("Failed to sign message: recoverable ECDSA signature creation failed.") throw KeyUtilError.signatureFailure } @@ -79,7 +84,6 @@ enum KeyUtilx { static func recoverPublicKey(message: Data, signature: Data) throws -> Data { guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY)) else { - logger.warning("Failed to sign message: invalid context.") throw KeyUtilError.invalidContext } defer { secp256k1_context_destroy(ctx) } @@ -101,7 +105,6 @@ enum KeyUtilx { // swiftlint:disable force_unwrapping try serializedSignature.withUnsafeBytes { guard secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, signaturePtr, $0.bindMemory(to: UInt8.self).baseAddress!, v) == 1 else { - logger.warning("Failed to parse signature: recoverable ECDSA signature parse failed.") throw KeyUtilError.signatureParseFailure } } diff --git a/Sources/XMTP/Messages/MessageV2.swift b/Sources/XMTP/Messages/MessageV2.swift index 369b5baf..e5bc5d3a 100644 --- a/Sources/XMTP/Messages/MessageV2.swift +++ b/Sources/XMTP/Messages/MessageV2.swift @@ -43,7 +43,7 @@ extension MessageV2 { // Verify content signature let key = try PublicKey.with { key in - key.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(message.headerBytes + signed.payload), signature: signed.signature.rawData) + key.secp256K1Uncompressed.bytes = try KeyUtilx.recoverPublicKeySHA256(from: signed.signature.rawData, message: Data(message.headerBytes + signed.payload)) } if key.walletAddress != (try PublicKey(signed.sender.preKey).walletAddress) { diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTP/Messages/PrivateKey.swift index 4bb38b3e..35e7a3a3 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTP/Messages/PrivateKey.swift @@ -8,7 +8,6 @@ import Foundation import XMTPRust import CryptoKit -import web3 /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it /// to create a ``Client``. @@ -55,7 +54,7 @@ public extension PrivateKey { timestamp = UInt64(Date().millisecondsSinceEpoch) secp256K1.bytes = privateKeyData - let publicData = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: privateKeyData) + let publicData = try KeyUtilx.generatePublicKey(from: privateKeyData) publicKey.secp256K1Uncompressed.bytes = publicData publicKey.timestamp = timestamp } diff --git a/Sources/XMTP/Messages/PrivateKeyBundle.swift b/Sources/XMTP/Messages/PrivateKeyBundle.swift index 96331dd9..c202c778 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundle.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundle.swift @@ -29,7 +29,7 @@ extension PrivateKeyBundle { var encryptedBundle = EncryptedPrivateKeyBundle() encryptedBundle.v1.walletPreKey = walletPreKey - encryptedBundle.v1.ciphertext = cipherText + encryptedBundle.v1.ciphertext = cipherText return encryptedBundle } diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift index 3b35f599..7f36257b 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift @@ -24,13 +24,6 @@ extension PrivateKeyBundleV1 { let bytesToSign = try UnsignedPublicKey(preKey.publicKey).serializedData() let signature = try await privateKey.sign(Data(SHA256.hash(data: bytesToSign))) - - print("Signature: \(signature.rawData)") - - print("KeyUtilx recovered: \(try KeyUtilx.recoverPublicKey(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData).toHex)") - print("XMTPRust recovered: \(try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(SHA256.hash(data: bytesToSign)), signature: signature.rawData).toHex)") - - bundle.v1.identityKey = authorizedIdentity.identity bundle.v1.identityKey.publicKey = authorizedIdentity.authorized preKey.publicKey.signature = signature diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift index fb6b8fa2..910ad437 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift @@ -8,7 +8,6 @@ import Foundation import XMTPRust - public typealias PrivateKeyBundleV2 = Xmtp_MessageContents_PrivateKeyBundleV2 extension PrivateKeyBundleV2 { @@ -35,7 +34,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - return try XMTPRust.CoreCrypto.diffie_hellman_k256(privateKeyBytes: privateData, publicKeyBytes: publicData) + return Data(try XMTPRust.diffie_hellman_k256(privateData.dataToRustVec(), publicData.dataToRustVec())) } func findPreKey(_ myPreKey: SignedPublicKey) throws -> SignedPrivateKey { diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTP/Messages/PublicKey.swift index 6113bd1a..6a3f7d79 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTP/Messages/PublicKey.swift @@ -70,7 +70,7 @@ extension PublicKey { let sigText = Signature.createIdentityText(key: try slimKey.serializedData()) let message = try Signature.ethPersonalMessage(sigText) - let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) + let pubKeyData = try KeyUtilx.recoverPublicKeyKeccak256(from: signature.rawData, message: message) return try PublicKey(pubKeyData) } @@ -85,7 +85,7 @@ extension PublicKey { slimKey.timestamp = timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: bytesToSign, signature: signature.rawData) + let pubKeyData = try KeyUtilx.recoverPublicKeySHA256(from: signature.rawData, message: bytesToSign) return try PublicKey(pubKeyData) } diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 01cd1879..2c34a218 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -8,7 +8,6 @@ import Foundation import XMTPRust - /// Represents a secp256k1 compact recoverable signature. public typealias Signature = Xmtp_MessageContents_Signature @@ -102,16 +101,14 @@ extension Signature { } } - func verify(signedBy: PublicKey, digest: Data) throws -> Bool { - // let recoverySignature = try secp256k1.Recovery.ECDSASignature(compactRepresentation: ecdsaCompact.bytes, recoveryId: Int32(ecdsaCompact.recovery)) - // let ecdsaSignature = try recoverySignature.normalize - // let signingKey = try secp256k1.Signing.PublicKey(rawRepresentation: signedBy.secp256K1Uncompressed.bytes, format: .uncompressed) - // - // return signingKey.ecdsa.isValidSignature(ecdsaSignature, for: digest) - // NOTE: it says "digest" in this function header but really it's the message. The verify_k256_sha256 function does - // the additional sha256 operation to convert the message into 32 bytes. - return try XMTPRust.CoreCrypto.verify_k256_sha256(publicKeyBytes: signedBy.secp256K1Uncompressed.bytes, message: digest, signature: ecdsaCompact.bytes, recoveryId: UInt8(ecdsaCompact.recovery)) - } + func verify(signedBy: PublicKey, digest: Data) throws -> Bool { + do { + try XMTPRust.verify_k256_sha256(signedBy.secp256K1Uncompressed.bytes.dataToRustVec(), digest.dataToRustVec(), ecdsaCompact.bytes.dataToRustVec(), UInt8(ecdsaCompact.recovery)) + } catch { + return false + } + return true + } } extension Signature: Codable { diff --git a/Sources/XMTP/Messages/SignedPublicKey.swift b/Sources/XMTP/Messages/SignedPublicKey.swift index 574e4e24..bf0aabbd 100644 --- a/Sources/XMTP/Messages/SignedPublicKey.swift +++ b/Sources/XMTP/Messages/SignedPublicKey.swift @@ -64,7 +64,7 @@ extension SignedPublicKey { slimKey.timestamp = publicKey.timestamp let bytesToSign = try slimKey.serializedData() - let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_sha256(message: Data(SHA256.hash(data: bytesToSign)), signature: publicKey.signature.rawData) + let pubKeyData = try KeyUtilx.recoverPublicKeySHA256(from: publicKey.signature.rawData, message: bytesToSign) return try PublicKey(pubKeyData) } @@ -72,7 +72,7 @@ extension SignedPublicKey { let sigText = Signature.createIdentityText(key: keyBytes) let message = try Signature.ethPersonalMessage(sigText) - let pubKeyData = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) + let pubKeyData = try KeyUtilx.recoverPublicKeyKeccak256(from: signature.rawData, message: message) return try PublicKey(pubKeyData) } diff --git a/Sources/XMTP/Push/XMTPPush.swift b/Sources/XMTP/Push/XMTPPush.swift index 005b1bfc..9b3fb916 100644 --- a/Sources/XMTP/Push/XMTPPush.swift +++ b/Sources/XMTP/Push/XMTPPush.swift @@ -5,116 +5,116 @@ // Created by Pat Nakajima on 1/20/23. // #if canImport(UIKit) -import Connect -import UIKit -import UserNotifications + import Connect + import UIKit + import UserNotifications -enum XMTPPushError: Error { - case noPushServer -} + enum XMTPPushError: Error { + case noPushServer + } -public struct XMTPPush { - public static var shared = XMTPPush() + public struct XMTPPush { + public static var shared = XMTPPush() - var installationID: String - var installationIDKey: String = "installationID" + var installationID: String + var installationIDKey: String = "installationID" - var pushServer: String = "" + var pushServer: String = "" - private init() { - if let id = UserDefaults.standard.string(forKey: installationIDKey) { - installationID = id - } else { - installationID = UUID().uuidString - UserDefaults.standard.set(installationID, forKey: installationIDKey) + private init() { + if let id = UserDefaults.standard.string(forKey: installationIDKey) { + installationID = id + } else { + installationID = UUID().uuidString + UserDefaults.standard.set(installationID, forKey: installationIDKey) + } } - } - - public mutating func setPushServer(_ server: String) { - pushServer = server - } - public func request() async throws -> Bool { - if pushServer == "" { - throw XMTPPushError.noPushServer + public mutating func setPushServer(_ server: String) { + pushServer = server } - if try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge]) { -// await UIApplication.shared.registerForRemoteNotifications() + public func request() async throws -> Bool { + if pushServer == "" { + throw XMTPPushError.noPushServer + } + + if try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge]) { +// await UIApplication.shared.registerForRemoteNotifications() + + return true + } - return true + return false } - return false - } + public func register(token: String) async throws { + if pushServer == "" { + throw XMTPPushError.noPushServer + } + + let request = Notifications_V1_RegisterInstallationRequest.with { request in + request.installationID = installationID + request.deliveryMechanism = Notifications_V1_DeliveryMechanism.with { delivery in + delivery.apnsDeviceToken = token + delivery.deliveryMechanismType = .apnsDeviceToken(token) + } + } - public func register(token: String) async throws { - if pushServer == "" { - throw XMTPPushError.noPushServer + _ = await client.registerInstallation(request: request) } - let request = Notifications_V1_RegisterInstallationRequest.with { request in - request.installationID = installationID - request.deliveryMechanism = Notifications_V1_DeliveryMechanism.with { delivery in - delivery.apnsDeviceToken = token - delivery.deliveryMechanismType = .apnsDeviceToken(token) + public func subscribe(topics: [String]) async throws { + if pushServer == "" { + throw XMTPPushError.noPushServer } + + let request = Notifications_V1_SubscribeRequest.with { request in + request.installationID = installationID + request.topics = topics + } + + _ = await client.subscribe(request: request) } - _ = await client.registerInstallation(request: request) + var client: Notifications_V1_NotificationsClient { + let protocolClient = ProtocolClient( + httpClient: URLSessionHTTPClient(), + config: ProtocolClientConfig( + host: pushServer, + networkProtocol: .connect, + codec: ProtoCodec() + ) + ) + + return Notifications_V1_NotificationsClient(client: protocolClient) + } } +#else + public struct XMTPPush { + public static var shared = XMTPPush() + private init() { + fatalError("XMTPPush not available") + } - public func subscribe(topics: [String]) async throws { - if pushServer == "" { - throw XMTPPushError.noPushServer + public mutating func setPushServer(_: String) { + fatalError("XMTPPush not available") } - let request = Notifications_V1_SubscribeRequest.with { request in - request.installationID = installationID - request.topics = topics + public func request() async throws -> Bool { + fatalError("XMTPPush not available") } - _ = await client.subscribe(request: request) - } + public func register(token _: String) async throws { + fatalError("XMTPPush not available") + } - var client: Notifications_V1_NotificationsClient { - let protocolClient = ProtocolClient( - httpClient: URLSessionHTTPClient(), - config: ProtocolClientConfig( - host: pushServer, - networkProtocol: .connect, - codec: ProtoCodec() - ) - ) + public func subscribe(topics _: [String]) async throws { + fatalError("XMTPPush not available") + } - return Notifications_V1_NotificationsClient(client: protocolClient) - } -} -#else -public struct XMTPPush { - public static var shared = XMTPPush() - private init() { - fatalError("XMTPPush not available") - } - - public mutating func setPushServer(_ server: String) { - fatalError("XMTPPush not available") - } - - public func request() async throws -> Bool { - fatalError("XMTPPush not available") - } - - public func register(token: String) async throws { - fatalError("XMTPPush not available") - } - - public func subscribe(topics: [String]) async throws { - fatalError("XMTPPush not available") - } - - var client: Notifications_V1_NotificationsClient { - fatalError("XMTPPush not available") + var client: Notifications_V1_NotificationsClient { + fatalError("XMTPPush not available") + } } -} #endif diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTP/SigningKey.swift index f107b38d..7b9131a8 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTP/SigningKey.swift @@ -38,7 +38,7 @@ extension SigningKey { let signature = try await sign(message: signatureText) let message = try Signature.ethPersonalMessage(signatureText) - let recoveredKey = try XMTPRust.CoreCrypto.recover_public_key_keccak256(message: message, signature: signature.rawData) + let recoveredKey = try KeyUtilx.recoverPublicKeyKeccak256(from: signature.rawData, message: message) let address = KeyUtilx.generateAddress(from: recoveredKey).toChecksumAddress() var authorized = PublicKey() diff --git a/Sources/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index 4ea54de3..7f27a977 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -9,7 +9,7 @@ import Combine import XCTest @testable import XMTP - +import XMTPRust public struct FakeWallet: SigningKey { public static func generate() throws -> FakeWallet { @@ -43,9 +43,9 @@ enum FakeApiClientError: String, Error { } class FakeStreamHolder: ObservableObject { - @Published var envelope: Envelope? + @Published var envelope: XMTP.Envelope? - func send(envelope: Envelope) { + func send(envelope: XMTP.Envelope) { self.envelope = envelope } } @@ -58,9 +58,9 @@ public class FakeApiClient: ApiClient { public var environment: XMTPEnvironment public var authToken: String = "" - private var responses: [String: [Envelope]] = [:] + private var responses: [String: [XMTP.Envelope]] = [:] private var stream = FakeStreamHolder() - public var published: [Envelope] = [] + public var published: [XMTP.Envelope] = [] var cancellable: AnyCancellable? var forbiddingQueries = false @@ -82,7 +82,7 @@ public class FakeApiClient: ApiClient { forbiddingQueries = false } - public func register(message: [Envelope], for topic: Topic) { + public func register(message: [XMTP.Envelope], for topic: Topic) { var responsesForTopic = responses[topic.description] ?? [] responsesForTopic.append(contentsOf: message) responses[topic.description] = responsesForTopic @@ -92,15 +92,15 @@ public class FakeApiClient: ApiClient { environment = .local } - public func send(envelope: Envelope) { + public func send(envelope: XMTP.Envelope) { stream.send(envelope: envelope) } - public func findPublishedEnvelope(_ topic: Topic) -> Envelope? { + public func findPublishedEnvelope(_ topic: Topic) -> XMTP.Envelope? { return findPublishedEnvelope(topic.description) } - public func findPublishedEnvelope(_ topic: String) -> Envelope? { + public func findPublishedEnvelope(_ topic: String) -> XMTP.Envelope? { for envelope in published.reversed() { if envelope.contentTopic == topic.description { return envelope @@ -112,11 +112,11 @@ public class FakeApiClient: ApiClient { // MARK: ApiClient conformance - public required init(environment: XMTP.XMTPEnvironment, secure _: Bool) throws { + public required init(environment: XMTP.XMTPEnvironment, secure _: Bool, rustClient _: XMTPRust.RustClient) throws { self.environment = environment } - public func subscribe(topics: [String]) -> AsyncThrowingStream { + public func subscribe(topics: [String]) -> AsyncThrowingStream { AsyncThrowingStream { continuation in self.cancellable = stream.$envelope.sink(receiveValue: { env in if let env, topics.contains(env.contentTopic) { @@ -136,7 +136,7 @@ public class FakeApiClient: ApiClient { throw FakeApiClientError.queryAssertionFailure } - var result: [Envelope] = [] + var result: [XMTP.Envelope] = [] if let response = responses.removeValue(forKey: topic) { result.append(contentsOf: response) @@ -231,6 +231,11 @@ public struct Fixtures { public extension XCTestCase { @available(iOS 15, *) func fixtures() async -> Fixtures { + do { + try await Fixtures() + } catch { + print("ERROR: \(error.localizedDescription)") + } // swiftlint:disable force_try return try! await Fixtures() } diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 63f4bef1..562ab056 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -9,62 +9,74 @@ import Foundation import XCTest @testable import XMTP +import XMTPRust import XMTPTestHelpers @available(iOS 15, *) class ClientTests: XCTestCase { - func testTakesAWallet() async throws { - let fakeWallet = try PrivateKey.generate() - _ = try await Client.create(account: fakeWallet) - } - - func testXMTPgRPC() async throws { - let numEnvelopes = try await GRPCApiClient.runGrpcTest() - XCTAssertEqual(numEnvelopes, 0) - } - - func testCanMessage() async throws { - let fixtures = await fixtures() - let notOnNetwork = try PrivateKey.generate() - - let canMessage = try await fixtures.aliceClient.canMessage(fixtures.bobClient.address) - let cannotMessage = try await fixtures.aliceClient.canMessage(notOnNetwork.address) - XCTAssertTrue(canMessage) - XCTAssertFalse(cannotMessage) - } - - func testHasPrivateKeyBundleV1() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - XCTAssertEqual(1, client.privateKeyBundleV1.preKeys.count) - - let preKey = client.privateKeyBundleV1.preKeys[0] - - XCTAssert(preKey.publicKey.hasSignature, "prekey not signed") - } - - func testCanBeCreatedWithBundle() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - let bundle = client.privateKeyBundle - let clientFromV1Bundle = try Client.from(bundle: bundle) - - XCTAssertEqual(client.address, clientFromV1Bundle.address) - XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) - XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) - } - - func testCanBeCreatedWithV1Bundle() async throws { - let fakeWallet = try PrivateKey.generate() - let client = try await Client.create(account: fakeWallet) - - let bundleV1 = client.v1keys - let clientFromV1Bundle = try Client.from(v1Bundle: bundleV1) - - XCTAssertEqual(client.address, clientFromV1Bundle.address) - XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) - XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) - } + func testTakesAWallet() async { + do { + let fakeWallet = try PrivateKey.generate() + _ = try await Client.create(account: fakeWallet) + } catch let error where error is RustString { + print("Hello \(error.localizedDescription) type: \(type(of: error))") + } catch { + print("\(error) \(type(of: error))") + } + } + + func testTakesAKeyAsWallet() async throws { + let fakeWallet = try PrivateKey.generate() + _ = try await Client.create(account: fakeWallet) + } + + func testXMTPgRPC() async throws { + let numEnvelopes = try await GRPCApiClient.runGrpcTest() + XCTAssertEqual(numEnvelopes, 0) + } + + func testCanMessage() async throws { + let fixtures = await fixtures() + let notOnNetwork = try PrivateKey.generate() + + let canMessage = try await fixtures.aliceClient.canMessage(fixtures.bobClient.address) + let cannotMessage = try await fixtures.aliceClient.canMessage(notOnNetwork.address) + XCTAssertTrue(canMessage) + XCTAssertFalse(cannotMessage) + } + + func testHasPrivateKeyBundleV1() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet, apiClient: FakeApiClient()) + + XCTAssertEqual(1, client.privateKeyBundleV1.preKeys.count) + + let preKey = client.privateKeyBundleV1.preKeys[0] + + XCTAssert(preKey.publicKey.hasSignature, "prekey not signed") + } + + func testCanBeCreatedWithBundle() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet) + + let bundle = client.privateKeyBundle + let clientFromV1Bundle = try await Client.from(bundle: bundle) + + XCTAssertEqual(client.address, clientFromV1Bundle.address) + XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) + XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) + } + + func testCanBeCreatedWithV1Bundle() async throws { + let fakeWallet = try PrivateKey.generate() + let client = try await Client.create(account: fakeWallet) + + let bundleV1 = client.v1keys + let clientFromV1Bundle = try await Client.from(v1Bundle: bundleV1) + + XCTAssertEqual(client.address, clientFromV1Bundle.address) + XCTAssertEqual(client.privateKeyBundleV1.identityKey, clientFromV1Bundle.privateKeyBundleV1.identityKey) + XCTAssertEqual(client.privateKeyBundleV1.preKeys, clientFromV1Bundle.privateKeyBundleV1.preKeys) + } } diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index e81bb5ee..e370894b 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -355,8 +355,10 @@ class ConversationTests: XCTestCase { let expectation = expectation(description: "got a message") Task(priority: .userInitiated) { - for try await _ in conversation.streamMessages() { - expectation.fulfill() + for try await message in conversation.streamMessages() { + if message.body == "hi alice" { + expectation.fulfill() + } } } diff --git a/Tests/XMTPTests/IntegrationTests.swift b/Tests/XMTPTests/IntegrationTests.swift index c8c5b105..583a2990 100644 --- a/Tests/XMTPTests/IntegrationTests.swift +++ b/Tests/XMTPTests/IntegrationTests.swift @@ -11,43 +11,39 @@ import web3 import XCTest import XMTPRust @testable import XMTP +import XMTPRust import XMTPTestHelpers @available(iOS 16, *) final class IntegrationTests: XCTestCase { - func testSaveKey() async throws { - for i in 1...1 { - let alice = try PrivateKey.generate() - let identity = try PrivateKey.generate() - - let authorized = try await alice.createIdentity(identity) - - let authToken = try await authorized.createAuthToken() - - let api = try GRPCApiClient(environment: .local, secure: false) - api.setAuthToken(authToken) - - let encryptedBundle = try await authorized.toBundle.encrypted(with: alice) - - var envelope = Envelope() - envelope.contentTopic = Topic.userPrivateStoreKeyBundle(authorized.address).description - envelope.timestampNs = UInt64(Date().millisecondsSinceEpoch) * 1_000_000 - envelope.message = try encryptedBundle.serializedData() - - try await api.publish(envelopes: [envelope]) - - try await Task.sleep(nanoseconds: 20_000_000) - var result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) - let starttime = Date().millisecondsSinceEpoch - - for u in 1...10000 { - result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) - } - XCTAssert(result.envelopes.count == 1) - let endtime = Date().millisecondsSinceEpoch - XCTAssertEqual(0.0, (endtime - starttime) / (10000000.0)) - } - } + func testSaveKey() async throws { + throw XCTSkip("integration only (requires local node)") + + let alice = try PrivateKey.generate() + let identity = try PrivateKey.generate() + + let authorized = try await alice.createIdentity(identity) + + let authToken = try await authorized.createAuthToken() + + let rustClient = try await XMTPRust.create_client(XMTP.GRPCApiClient.envToUrl(env: .local), false) + let api = try GRPCApiClient(environment: .local, secure: false, rustClient: rustClient) + api.setAuthToken(authToken) + + let encryptedBundle = try await authorized.toBundle.encrypted(with: alice) + + var envelope = Envelope() + envelope.contentTopic = Topic.userPrivateStoreKeyBundle(authorized.address).description + envelope.timestampNs = UInt64(Date().millisecondsSinceEpoch) * 1_000_000 + envelope.message = try encryptedBundle.serializedData() + + try await api.publish(envelopes: [envelope]) + + try await Task.sleep(nanoseconds: 2_000_000_000) + + let result = try await api.query(topic: .userPrivateStoreKeyBundle(authorized.address)) + XCTAssert(result.envelopes.count == 1) + } func testPublishingAndFetchingContactBundlesWithWhileGeneratingKeys() async throws { throw XCTSkip("integration only (requires local node)") @@ -79,7 +75,8 @@ final class IntegrationTests: XCTestCase { let identity = try PrivateKey.generate() let authorized = try await aliceWallet.createIdentity(identity) let authToken = try await authorized.createAuthToken() - var api = try GRPCApiClient(environment: .local, secure: false) + let rustClient = try await XMTPRust.create_client(XMTP.GRPCApiClient.envToUrl(env: .local), false) + let api = try GRPCApiClient(environment: .local, secure: false, rustClient: rustClient) api.setAuthToken(authToken) let encryptedBundle = try await PrivateKeyBundle(v1: alice).encrypted(with: aliceWallet) var envelope = Envelope() @@ -367,16 +364,16 @@ final class IntegrationTests: XCTestCase { throw XCTSkip("integration only (requires dev network)") // Generated from JS script - let keyBytes: [UInt8] = [ + let keyBytes = Data([ 31, 116, 198, 193, 189, 122, 19, 254, 191, 189, 211, 215, 255, 131, 171, 239, 243, 33, 4, 62, 143, 86, 18, 195, 251, 61, 128, 90, 34, 126, 219, 236, - ] + ]) var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -437,16 +434,16 @@ final class IntegrationTests: XCTestCase { func testCanReadGzipCompressedMessages() async throws { throw XCTSkip("integration only (requires dev network)") - let keyBytes: [UInt8] = [ + let keyBytes = Data([ 225, 2, 36, 98, 37, 243, 68, 234, 42, 126, 248, 246, 126, 83, 186, 197, 204, 186, 19, 173, 51, 0, 64, 0, 155, 8, 249, 247, 163, 185, 124, 159, - ] + ]) var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -460,16 +457,16 @@ final class IntegrationTests: XCTestCase { func testCanReadZipCompressedMessages() async throws { throw XCTSkip("integration only (requires dev network)") - let keyBytes: [UInt8] = [ + let keyBytes = Data([ 60, 45, 240, 192, 223, 2, 14, 166, 122, 65, 231, 31, 122, 178, 158, 137, 192, 97, 139, 83, 133, 245, 149, 250, 25, 125, 25, 11, 203, 97, 12, 200, - ] + ]) var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) let client = try await XMTP.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -489,16 +486,17 @@ final class IntegrationTests: XCTestCase { func testCanLoadAllConversations() async throws { throw XCTSkip("integration only (requires dev network)") - let keyBytes: [UInt8] = [ + let keyBytes = Data([ 105, 207, 193, 11, 240, 115, 115, 204, 117, 134, 201, 10, 56, 59, 52, 90, 229, 103, 15, 66, 20, 113, 118, 137, 44, 62, 130, 90, 30, 158, 182, 178, - ] + ]) var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: Data(keyBytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) + let client = try await XMTP.Client.create(account: key) diff --git a/Tests/XMTPTests/MessageTests.swift b/Tests/XMTPTests/MessageTests.swift index 3233e789..72b3768b 100644 --- a/Tests/XMTPTests/MessageTests.swift +++ b/Tests/XMTPTests/MessageTests.swift @@ -115,7 +115,7 @@ class MessageTests: XCTestCase { 140, 247, 221, 172, 14, 188, 52, 88, ]) - key.publicKey.secp256K1Uncompressed.bytes = try XMTPRust.CoreCrypto.get_public_key_from_private(privateKeyBytes: key.secp256K1.bytes) + key.publicKey.secp256K1Uncompressed.bytes = try KeyUtilx.generatePublicKey(from: key.secp256K1.bytes) } let keyBundleData = Data( diff --git a/XMTP.podspec b/XMTP.podspec index 9ab8d049..1c6bc1b9 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.1.2" + spec.version = "0.2.0" spec.summary = "XMTP pod." # This description is used to generate tags and improve search results. @@ -44,10 +44,10 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift" - spec.dependency 'XMTPRust', '= 0.1.2beta-0' + spec.dependency 'XMTPRust', '= 0.2.0-beta0' spec.xcconfig = {'VALID_ARCHS' => 'arm64' } - spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } +# spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } def spec.post_install(target) target.build_configurations.each do |config| diff --git a/XMTPiOSExample/NotificationService/NotificationService.swift b/XMTPiOSExample/NotificationService/NotificationService.swift index 61973008..15c2893c 100644 --- a/XMTPiOSExample/NotificationService/NotificationService.swift +++ b/XMTPiOSExample/NotificationService/NotificationService.swift @@ -36,22 +36,23 @@ class NotificationService: UNNotificationServiceExtension { return } - let client = try Client.from(bundle: keys) - let conversation = conversationContainer.decode(with: client) + Task { + let client = try await Client.from(bundle: keys) + let conversation = conversationContainer.decode(with: client) - let envelope = XMTP.Envelope.with { envelope in - envelope.message = encryptedMessageData - envelope.contentTopic = topic - } + let envelope = XMTP.Envelope.with { envelope in + envelope.message = encryptedMessageData + envelope.contentTopic = topic + } - if let bestAttemptContent = bestAttemptContent { - let decodedMessage = try conversation.decode(envelope) + if let bestAttemptContent = bestAttemptContent { + let decodedMessage = try conversation.decode(envelope) - bestAttemptContent.body = (try? decodedMessage.content()) ?? "no content" + bestAttemptContent.body = (try? decodedMessage.content()) ?? "no content" - contentHandler(bestAttemptContent) + contentHandler(bestAttemptContent) + } } - // swiftlint:enable no_optional_try } catch { print("Error receiving notification: \(error)") diff --git a/XMTPiOSExample/Podfile b/XMTPiOSExample/Podfile index e5d8fdd7..0658c8c1 100644 --- a/XMTPiOSExample/Podfile +++ b/XMTPiOSExample/Podfile @@ -9,6 +9,7 @@ target 'NotificationService' do # Pods for XMTPiOSExample # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" pod "web3.swift" + pod 'KeychainAccess' # pod "XMTPProto", path: "../../proto" # pod "XMTPRust", path: '../../xmtp-rust-swift' pod "XMTP", path: "../" @@ -20,7 +21,9 @@ target 'XMTPiOSExample' do # Pods for XMTPiOSExample # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" + pod 'WalletConnectSwift' pod "web3.swift" + pod 'KeychainAccess' # pod "XMTPProto", path: "../../proto" # pod "XMTPRust", path: '../../xmtp-rust-swift' pod "XMTP", path: "../" diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index 7a3212c2..4ee11942 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -2,24 +2,30 @@ PODS: - BigInt (5.0.0) - Connect-Swift (0.5.0): - SwiftProtobuf (~> 1.21.0) + - CryptoSwift (1.6.0) - GenericJSON (2.0.2) - GzipSwift (5.1.1) + - KeychainAccess (4.2.2) - Logging (1.0.0) - secp256k1.swift (0.1.4) - SwiftProtobuf (1.21.0) + - WalletConnectSwift (1.7.0): + - CryptoSwift (~> 1.5) - web3.swift (1.6.0): - BigInt (~> 5.0.0) - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.1.1): + - XMTP (0.2.0): - Connect-Swift - GzipSwift - web3.swift - - XMTPRust (= 0.1.2beta-0) - - XMTPRust (0.1.2-beta0) + - XMTPRust (= 0.2.0-beta0) + - XMTPRust (0.2.0-beta0) DEPENDENCIES: + - KeychainAccess + - WalletConnectSwift - web3.swift - XMTP (from `../`) @@ -27,11 +33,14 @@ SPEC REPOS: trunk: - BigInt - Connect-Swift + - CryptoSwift - GenericJSON - GzipSwift + - KeychainAccess - Logging - secp256k1.swift - SwiftProtobuf + - WalletConnectSwift - web3.swift - XMTPRust @@ -42,15 +51,18 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 Connect-Swift: a75380c30c1341e483012444044105ff49b6093a + CryptoSwift: 562f8eceb40e80796fffc668b0cad9313284cfa6 GenericJSON: 79a840eeb77030962e8cf02a62d36bd413b67626 GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa + KeychainAccess: c0c4f7f38f6fc7bbe58f5702e25f7bd2f65abf51 Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 + WalletConnectSwift: 6309bf3011b0b30e3e9d1e7449535302a9240f71 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 728019fe8723c98479ae09f4da82ae1c061eb632 - XMTPRust: 2c356f57f034d771717933a6127a7d51667f9843 + XMTP: 0a8f3478a8739d526404b61dfaa9538a187577c6 + XMTPRust: 7eb2da98f2bdb6d5d1a1d648dc0e9a91365ed211 -PODFILE CHECKSUM: 34395c840d082584c6758fd1e94cb68eaeb0c270 +PODFILE CHECKSUM: b08ce1433b369fe0cf978eda8c1642c21fe389d6 COCOAPODS: 1.12.1 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index 6bf92874..2d350258 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -7,8 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 6AEE396D29F330CD0027B657 /* secp256k1 */; }; - 32C62D213641651EBC32117E /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */; }; A60FC8BF293AD054001697E3 /* MessageComposerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8BE293AD054001697E3 /* MessageComposerView.swift */; }; A60FC8C1293AD171001697E3 /* ConversationDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */; }; A60FC8C3293AD18A001697E3 /* PreviewClientProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */; }; @@ -19,8 +17,11 @@ A6557A312941166E00CC4C7B /* MessageCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6557A302941166E00CC4C7B /* MessageCellView.swift */; }; A6557A3329411F4F00CC4C7B /* NewConversationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6557A3229411F4F00CC4C7B /* NewConversationView.swift */; }; A65F0704297B5D4E00C3C76E /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; - A65F0707297B5E7600C3C76E /* WalletConnectSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A65F0706297B5E7600C3C76E /* WalletConnectSwift */; }; - A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A65F0709297B5E8600C3C76E /* KeychainAccess */; }; + A678243129F8660F00D30FF7 /* WalletConnectSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A678243029F8660F00D30FF7 /* WalletConnectSwift */; }; + A678243429F8661F00D30FF7 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A678243329F8661F00D30FF7 /* KeychainAccess */; }; + A678243729F8666F00D30FF7 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A678243629F8666F00D30FF7 /* XMTP */; }; + A678243929F8667A00D30FF7 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A678243829F8667A00D30FF7 /* KeychainAccess */; }; + A678243B29F8669600D30FF7 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A678243A29F8669600D30FF7 /* XMTP */; }; A67CCEC129355B4B00131F5C /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A67CCEC029355B4B00131F5C /* AccountManager.swift */; }; A683860C293EA862006336FF /* MessageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A683860B293EA862006336FF /* MessageListView.swift */; }; A687810729679BC700042FAB /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810629679BC700042FAB /* Account.swift */; }; @@ -31,9 +32,7 @@ A6AE5187297B61AE006FDD0F /* NotificationService.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A6AE5180297B61AE006FDD0F /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; A6AE518E297B6210006FDD0F /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AE518C297B6210006FDD0F /* NotificationService.swift */; }; A6AE5192297B6270006FDD0F /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; - A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A6AE5193297B62C8006FDD0F /* KeychainAccess */; }; A6D192D0293A7B97006B49F2 /* ConversationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D192CF293A7B97006B49F2 /* ConversationListView.swift */; }; - B815305000C45E0BDC765F4E /* Pods_XMTPiOSExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -61,9 +60,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMTPiOSExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.release.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.release.xcconfig"; sourceTree = ""; }; - 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = ""; }; A60FC8BE293AD054001697E3 /* MessageComposerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView.swift; sourceTree = ""; }; A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationDetailView.swift; sourceTree = ""; }; A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewClientProvider.swift; sourceTree = ""; }; @@ -76,6 +72,7 @@ A6557A302941166E00CC4C7B /* MessageCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCellView.swift; sourceTree = ""; }; A6557A3229411F4F00CC4C7B /* NewConversationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationView.swift; sourceTree = ""; }; A65F0703297B5D4E00C3C76E /* Persistence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; + A678243529F8662800D30FF7 /* xmtp-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "xmtp-ios"; path = ..; sourceTree = ""; }; A67CCEC029355B4B00131F5C /* AccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManager.swift; sourceTree = ""; }; A683860B293EA862006336FF /* MessageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListView.swift; sourceTree = ""; }; A687810629679BC700042FAB /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; @@ -86,10 +83,8 @@ A6AE5180297B61AE006FDD0F /* NotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A6AE518B297B61C8006FDD0F /* NotificationService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationService.entitlements; sourceTree = ""; }; A6AE518C297B6210006FDD0F /* NotificationService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; + A6CB98CB29F85D9200F2DC58 /* XMTP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = XMTP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A6D192CF293A7B97006B49F2 /* ConversationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationListView.swift; sourceTree = ""; }; - AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = ""; }; - B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.debug.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -97,11 +92,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A65F0707297B5E7600C3C76E /* WalletConnectSwift in Frameworks */, - 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */, - A69F33C6292DC992005A5556 /* XMTP in Frameworks */, - A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */, - B815305000C45E0BDC765F4E /* Pods_XMTPiOSExample.framework in Frameworks */, + A678243B29F8669600D30FF7 /* XMTP in Frameworks */, + A678243429F8661F00D30FF7 /* KeychainAccess in Frameworks */, + A678243129F8660F00D30FF7 /* WalletConnectSwift in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -109,8 +102,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */, - 32C62D213641651EBC32117E /* Pods_NotificationService.framework in Frameworks */, + A678243929F8667A00D30FF7 /* KeychainAccess in Frameworks */, + A678243729F8666F00D30FF7 /* XMTP in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -120,10 +113,6 @@ 3F738A9EAAA632479874E954 /* Pods */ = { isa = PBXGroup; children = ( - 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */, - AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */, - B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */, - 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -131,6 +120,7 @@ A6281986292DC825004B9117 = { isa = PBXGroup; children = ( + A6CB98C829F85CE600F2DC58 /* Packages */, A6281991292DC825004B9117 /* XMTPiOSExample */, A6AE5181297B61AE006FDD0F /* NotificationService */, A6281990292DC825004B9117 /* Products */, @@ -185,8 +175,7 @@ A69F33C4292DC992005A5556 /* Frameworks */ = { isa = PBXGroup; children = ( - B1A60F43A14DA4C930D19139 /* Pods_NotificationService.framework */, - 01A605D7B630CB965056BE4D /* Pods_XMTPiOSExample.framework */, + A6CB98CB29F85D9200F2DC58 /* XMTP.framework */, ); name = Frameworks; sourceTree = ""; @@ -216,6 +205,14 @@ path = NotificationService; sourceTree = ""; }; + A6CB98C829F85CE600F2DC58 /* Packages */ = { + isa = PBXGroup; + children = ( + A678243529F8662800D30FF7 /* xmtp-ios */, + ); + name = Packages; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -223,12 +220,10 @@ isa = PBXNativeTarget; buildConfigurationList = A628199E292DC826004B9117 /* Build configuration list for PBXNativeTarget "XMTPiOSExample" */; buildPhases = ( - C50343F196FCC7C930B85889 /* [CP] Check Pods Manifest.lock */, A628198B292DC825004B9117 /* Sources */, A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, A65F0701297B5BCC00C3C76E /* Embed Foundation Extensions */, - 00BCA10454D1CCB2B86AC7A0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -237,9 +232,9 @@ ); name = XMTPiOSExample; packageProductDependencies = ( - A65F0706297B5E7600C3C76E /* WalletConnectSwift */, - A65F0709297B5E8600C3C76E /* KeychainAccess */, - 6AEE396D29F330CD0027B657 /* secp256k1 */, + A678243029F8660F00D30FF7 /* WalletConnectSwift */, + A678243329F8661F00D30FF7 /* KeychainAccess */, + A678243A29F8669600D30FF7 /* XMTP */, ); productName = XMTPiOSExample; productReference = A628198F292DC825004B9117 /* XMTPiOSExample.app */; @@ -249,7 +244,6 @@ isa = PBXNativeTarget; buildConfigurationList = A6AE5188297B61AE006FDD0F /* Build configuration list for PBXNativeTarget "NotificationService" */; buildPhases = ( - F3EFD13DA11B8942E54F4C0B /* [CP] Check Pods Manifest.lock */, A6AE517C297B61AE006FDD0F /* Sources */, A6AE517D297B61AE006FDD0F /* Frameworks */, A6AE517E297B61AE006FDD0F /* Resources */, @@ -260,7 +254,8 @@ ); name = NotificationService; packageProductDependencies = ( - A6AE5193297B62C8006FDD0F /* KeychainAccess */, + A678243629F8666F00D30FF7 /* XMTP */, + A678243829F8667A00D30FF7 /* KeychainAccess */, ); productName = NotificationService; productReference = A6AE5180297B61AE006FDD0F /* NotificationService.appex */; @@ -294,9 +289,8 @@ ); mainGroup = A6281986292DC825004B9117; packageReferences = ( - A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */, - A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */, - 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */, + A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */, + A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */, ); productRefGroup = A6281990292DC825004B9117 /* Products */; projectDirPath = ""; @@ -327,70 +321,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 00BCA10454D1CCB2B86AC7A0 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - C50343F196FCC7C930B85889 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-XMTPiOSExample-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - F3EFD13DA11B8942E54F4C0B /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ A628198B292DC825004B9117 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -546,7 +476,6 @@ }; A628199F292DC826004B9117 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = B27A4C8939C130ECFD718BA7 /* Pods-XMTPiOSExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -587,7 +516,6 @@ }; A62819A0292DC826004B9117 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 5B8C4A0CD993FC7198522C13 /* Pods-XMTPiOSExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -627,7 +555,6 @@ }; A6AE5189297B61AE006FDD0F /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9395B708EC7F5A8D3E9BC297 /* Pods-NotificationService.debug.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -656,7 +583,6 @@ }; A6AE518A297B61AE006FDD0F /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = AC94A32B5A9066C82DCAD2EB /* Pods-NotificationService.release.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -717,23 +643,15 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/GigaBitcoin/secp256k1.swift.git"; - requirement = { - kind = exactVersion; - version = 0.10.0; - }; - }; - A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */ = { + A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/WalletConnect/WalletConnectSwift"; requirement = { - branch = master; - kind = branch; + kind = upToNextMajorVersion; + minimumVersion = 1.0.0; }; }; - A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { + A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess"; requirement = { @@ -744,26 +662,29 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 6AEE396D29F330CD0027B657 /* secp256k1 */ = { - isa = XCSwiftPackageProductDependency; - package = 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */; - productName = secp256k1; - }; - A65F0706297B5E7600C3C76E /* WalletConnectSwift */ = { + A678243029F8660F00D30FF7 /* WalletConnectSwift */ = { isa = XCSwiftPackageProductDependency; - package = A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */; + package = A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */; productName = WalletConnectSwift; }; - A65F0709297B5E8600C3C76E /* KeychainAccess */ = { + A678243329F8661F00D30FF7 /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; - package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; + package = A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; - A6AE5193297B62C8006FDD0F /* KeychainAccess */ = { + A678243629F8666F00D30FF7 /* XMTP */ = { + isa = XCSwiftPackageProductDependency; + productName = XMTP; + }; + A678243829F8667A00D30FF7 /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; - package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; + package = A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; + A678243A29F8669600D30FF7 /* XMTP */ = { + isa = XCSwiftPackageProductDependency; + productName = XMTP; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = A6281987292DC825004B9117 /* Project object */; diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e77431a2..96750746 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,14 +14,14 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/bufbuild/connect-swift", "state" : { - "revision" : "6f5afc57f44a3ed15b9a01381ce73f84d15e43db", - "version" : "0.3.0" + "revision" : "b3ed034307b850d5dc4c6d14dd92070041acbdad", + "version" : "0.5.0" } }, { "identity" : "cryptoswift", "kind" : "remoteSourceControl", - "location" : "https://github.com/krzyzanowskim/CryptoSwift", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", "state" : { "revision" : "039f56c5d7960f277087a0be51f5eb04ed0ec073", "version" : "1.5.1" @@ -30,7 +30,7 @@ { "identity" : "generic-json-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/zoul/generic-json-swift", + "location" : "https://github.com/iwill/generic-json-swift", "state" : { "revision" : "0a06575f4038b504e78ac330913d920f1630f510", "version" : "2.0.2" @@ -51,7 +51,7 @@ "location" : "https://github.com/kishikawakatsumi/KeychainAccess", "state" : { "branch" : "master", - "revision" : "6299daec1d74be12164fec090faf9ed14d0da9d6" + "revision" : "ecb18d8ce4d88277cc4fb103973352d91e18c535" } }, { @@ -68,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", "state" : { - "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", - "version" : "0.10.0" + "branch" : "main", + "revision" : "06792cfc951df870045f5fdb8095ae2e8bc83b69" } }, { @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-atomics.git", "state" : { - "revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", - "version" : "1.0.2" + "revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10", + "version" : "1.1.0" } }, { @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", - "version" : "1.0.3" + "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", + "version" : "1.0.4" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", - "version" : "1.4.4" + "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", + "version" : "1.5.2" } }, { @@ -122,8 +122,26 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "e855380cb5234e96b760d93e0bfdc403e381e928", - "version" : "2.45.0" + "revision" : "546eaa261ec5028b9cc5c7fa883fba9dd5881a3b", + "version" : "2.52.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997", + "version" : "1.19.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "6d021a48483dbb273a9be43f65234bdc9185b364", + "version" : "1.26.0" } }, { @@ -131,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", - "version" : "2.23.0" + "revision" : "e866a626e105042a6a72a870c88b4c531ba05f83", + "version" : "2.24.0" } }, { @@ -140,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-transport-services.git", "state" : { - "revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", - "version" : "1.15.0" + "revision" : "41f4098903878418537020075a4d8a6e20a0b182", + "version" : "1.17.0" } }, { @@ -149,8 +167,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8", - "version" : "1.20.3" + "revision" : "0af9125c4eae12a4973fb66574c53a54962a9e1e", + "version" : "1.21.0" } }, { @@ -158,8 +176,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwift", "state" : { - "branch" : "master", - "revision" : "9e4dfba34fb35336fd5da551285d7986ff536cb8" + "revision" : "e0bbfd16d5c54a7aa7e316956d765399c6332fa2", + "version" : "1.7.0" } }, { @@ -167,8 +185,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/argentlabs/web3.swift", "state" : { - "revision" : "9da09d639d4e5d06eb59518e636b3ae957e8e9cd", - "version" : "1.3.0" + "revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db", + "version" : "1.6.0" } }, { @@ -176,17 +194,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/websocket-kit.git", "state" : { - "revision" : "2d9d2188a08eef4a869d368daab21b3c08510991", - "version" : "2.6.1" + "revision" : "2166cbe932b29b6419f9cd751e8b27c647e1238e", + "version" : "2.8.0" } }, { "identity" : "xmtp-rust-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/xmtp-rust-swift/", + "location" : "https://github.com/xmtp/xmtp-rust-swift", "state" : { - "branch" : "local_only_test_008", - "revision" : "da21b494941cd867df5fc8071450c1b1f22712e8" + "revision" : "eccfc16bb8f866857ecbb1604c1dab855b1960f7", + "version" : "0.2.2-beta0" } } ], diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme new file mode 100644 index 00000000..e97a6a6f --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata b/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 157b58d4..00000000 --- a/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d98100..00000000 --- a/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift b/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift index e1426a37..c2ab1318 100644 --- a/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift +++ b/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift @@ -6,6 +6,7 @@ // import Foundation +import UIKit import WalletConnectSwift import web3 import XMTP diff --git a/XMTPiOSExample/XMTPiOSExample/ContentView.swift b/XMTPiOSExample/XMTPiOSExample/ContentView.swift index ffda7b1a..00e6fea8 100644 --- a/XMTPiOSExample/XMTPiOSExample/ContentView.swift +++ b/XMTPiOSExample/XMTPiOSExample/ContentView.swift @@ -105,7 +105,7 @@ struct ContentView: View { Task { do { let wallet = try PrivateKey.generate() - let client = try! await Client.create(account: wallet, options: .init(api: .init(env: .local, isSecure: false))) + let client = try await Client.create(account: wallet, options: .init(api: .init(env: .dev, isSecure: true))) let keysData = try client.privateKeyBundle.serializedData() Persistence().saveKeys(keysData) diff --git a/script/lint b/script/lint index 659a9f34..367da22b 100755 --- a/script/lint +++ b/script/lint @@ -1,3 +1,3 @@ #!/usr/bin/env sh -swiftlint Sources/ XMTPiOSExample/ +swiftlint Sources/ XMTPiOSExample/XMTPiOSExample From 25353efc94c258189d24031a72be181c6e116bb3 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Tue, 9 May 2023 07:05:22 -0700 Subject: [PATCH 21/47] Use Buf to generate proto code (#93) --- .../message_api/v1/message_api.grpc.swift | 744 ------------------ buf.gen.yaml | 8 + script/gen-proto | 3 + 3 files changed, 11 insertions(+), 744 deletions(-) delete mode 100644 Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift create mode 100644 buf.gen.yaml create mode 100755 script/gen-proto diff --git a/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift b/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift deleted file mode 100644 index ac098abb..00000000 --- a/Sources/XMTP/Proto/message_api/v1/message_api.grpc.swift +++ /dev/null @@ -1,744 +0,0 @@ -// -// DO NOT EDIT. -// -// Generated by the protocol buffer compiler. -// Source: message_api/v1/message_api.proto -// - -// -// Copyright 2018, gRPC Authors All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#if canImport(GRPC) -import GRPC -import NIO -import NIOConcurrencyHelpers -import SwiftProtobuf - - -/// RPC -/// -/// Usage: instantiate `Xmtp_MessageApi_V1_MessageApiClient`, then call methods of this protocol to make API calls. -public protocol Xmtp_MessageApi_V1_MessageApiClientProtocol: GRPCClient { - var serviceName: String { get } - var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { get } - - func publish( - _ request: Xmtp_MessageApi_V1_PublishRequest, - callOptions: CallOptions? - ) -> UnaryCall - - func subscribe( - _ request: Xmtp_MessageApi_V1_SubscribeRequest, - callOptions: CallOptions?, - handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void - ) -> ServerStreamingCall - - func subscribeAll( - _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, - callOptions: CallOptions?, - handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void - ) -> ServerStreamingCall - - func query( - _ request: Xmtp_MessageApi_V1_QueryRequest, - callOptions: CallOptions? - ) -> UnaryCall - - func batchQuery( - _ request: Xmtp_MessageApi_V1_BatchQueryRequest, - callOptions: CallOptions? - ) -> UnaryCall -} - -extension Xmtp_MessageApi_V1_MessageApiClientProtocol { - public var serviceName: String { - return "xmtp.message_api.v1.MessageApi" - } - - /// Publish messages to the network - /// - /// - Parameters: - /// - request: Request to send to Publish. - /// - callOptions: Call options. - /// - Returns: A `UnaryCall` with futures for the metadata, status and response. - public func publish( - _ request: Xmtp_MessageApi_V1_PublishRequest, - callOptions: CallOptions? = nil - ) -> UnaryCall { - return self.makeUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makePublishInterceptors() ?? [] - ) - } - - /// Subscribe to a stream of new envelopes matching a predicate - /// - /// - Parameters: - /// - request: Request to send to Subscribe. - /// - callOptions: Call options. - /// - handler: A closure called when each response is received from the server. - /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. - public func subscribe( - _ request: Xmtp_MessageApi_V1_SubscribeRequest, - callOptions: CallOptions? = nil, - handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void - ) -> ServerStreamingCall { - return self.makeServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], - handler: handler - ) - } - - /// Subscribe to a stream of all messages - /// - /// - Parameters: - /// - request: Request to send to SubscribeAll. - /// - callOptions: Call options. - /// - handler: A closure called when each response is received from the server. - /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. - public func subscribeAll( - _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, - callOptions: CallOptions? = nil, - handler: @escaping (Xmtp_MessageApi_V1_Envelope) -> Void - ) -> ServerStreamingCall { - return self.makeServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], - handler: handler - ) - } - - /// Query the store for messages - /// - /// - Parameters: - /// - request: Request to send to Query. - /// - callOptions: Call options. - /// - Returns: A `UnaryCall` with futures for the metadata, status and response. - public func query( - _ request: Xmtp_MessageApi_V1_QueryRequest, - callOptions: CallOptions? = nil - ) -> UnaryCall { - return self.makeUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeQueryInterceptors() ?? [] - ) - } - - /// BatchQuery containing a set of queries to be processed - /// - /// - Parameters: - /// - request: Request to send to BatchQuery. - /// - callOptions: Call options. - /// - Returns: A `UnaryCall` with futures for the metadata, status and response. - public func batchQuery( - _ request: Xmtp_MessageApi_V1_BatchQueryRequest, - callOptions: CallOptions? = nil - ) -> UnaryCall { - return self.makeUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] - ) - } -} - -#if compiler(>=5.6) -@available(*, deprecated) -extension Xmtp_MessageApi_V1_MessageApiClient: @unchecked Sendable {} -#endif // compiler(>=5.6) - -@available(*, deprecated, renamed: "Xmtp_MessageApi_V1_MessageApiNIOClient") -public final class Xmtp_MessageApi_V1_MessageApiClient: Xmtp_MessageApi_V1_MessageApiClientProtocol { - private let lock = Lock() - private var _defaultCallOptions: CallOptions - private var _interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? - public let channel: GRPCChannel - public var defaultCallOptions: CallOptions { - get { self.lock.withLock { return self._defaultCallOptions } } - set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } - } - public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { - get { self.lock.withLock { return self._interceptors } } - set { self.lock.withLockVoid { self._interceptors = newValue } } - } - - /// Creates a client for the xmtp.message_api.v1.MessageApi service. - /// - /// - Parameters: - /// - channel: `GRPCChannel` to the service host. - /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. - /// - interceptors: A factory providing interceptors for each RPC. - public init( - channel: GRPCChannel, - defaultCallOptions: CallOptions = CallOptions(), - interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil - ) { - self.channel = channel - self._defaultCallOptions = defaultCallOptions - self._interceptors = interceptors - } -} - -public struct Xmtp_MessageApi_V1_MessageApiNIOClient: Xmtp_MessageApi_V1_MessageApiClientProtocol { - public var channel: GRPCChannel - public var defaultCallOptions: CallOptions - public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? - - /// Creates a client for the xmtp.message_api.v1.MessageApi service. - /// - /// - Parameters: - /// - channel: `GRPCChannel` to the service host. - /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. - /// - interceptors: A factory providing interceptors for each RPC. - public init( - channel: GRPCChannel, - defaultCallOptions: CallOptions = CallOptions(), - interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil - ) { - self.channel = channel - self.defaultCallOptions = defaultCallOptions - self.interceptors = interceptors - } -} - -#if compiler(>=5.6) -/// RPC -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public protocol Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol: GRPCClient { - static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { get } - - func makePublishCall( - _ request: Xmtp_MessageApi_V1_PublishRequest, - callOptions: CallOptions? - ) -> GRPCAsyncUnaryCall - - func makeSubscribeCall( - _ request: Xmtp_MessageApi_V1_SubscribeRequest, - callOptions: CallOptions? - ) -> GRPCAsyncServerStreamingCall - - func makeSubscribeAllCall( - _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, - callOptions: CallOptions? - ) -> GRPCAsyncServerStreamingCall - - func makeQueryCall( - _ request: Xmtp_MessageApi_V1_QueryRequest, - callOptions: CallOptions? - ) -> GRPCAsyncUnaryCall - - func makeBatchQueryCall( - _ request: Xmtp_MessageApi_V1_BatchQueryRequest, - callOptions: CallOptions? - ) -> GRPCAsyncUnaryCall -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { - public static var serviceDescriptor: GRPCServiceDescriptor { - return Xmtp_MessageApi_V1_MessageApiClientMetadata.serviceDescriptor - } - - public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? { - return nil - } - - public func makePublishCall( - _ request: Xmtp_MessageApi_V1_PublishRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncUnaryCall { - return self.makeAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makePublishInterceptors() ?? [] - ) - } - - public func makeSubscribeCall( - _ request: Xmtp_MessageApi_V1_SubscribeRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncServerStreamingCall { - return self.makeAsyncServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [] - ) - } - - public func makeSubscribeAllCall( - _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncServerStreamingCall { - return self.makeAsyncServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [] - ) - } - - public func makeQueryCall( - _ request: Xmtp_MessageApi_V1_QueryRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncUnaryCall { - return self.makeAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeQueryInterceptors() ?? [] - ) - } - - public func makeBatchQueryCall( - _ request: Xmtp_MessageApi_V1_BatchQueryRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncUnaryCall { - return self.makeAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] - ) - } -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { - public func publish( - _ request: Xmtp_MessageApi_V1_PublishRequest, - callOptions: CallOptions? = nil - ) async throws -> Xmtp_MessageApi_V1_PublishResponse { - return try await self.performAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makePublishInterceptors() ?? [] - ) - } - - public func subscribe( - _ request: Xmtp_MessageApi_V1_SubscribeRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncResponseStream { - return self.performAsyncServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [] - ) - } - - public func subscribeAll( - _ request: Xmtp_MessageApi_V1_SubscribeAllRequest, - callOptions: CallOptions? = nil - ) -> GRPCAsyncResponseStream { - return self.performAsyncServerStreamingCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [] - ) - } - - public func query( - _ request: Xmtp_MessageApi_V1_QueryRequest, - callOptions: CallOptions? = nil - ) async throws -> Xmtp_MessageApi_V1_QueryResponse { - return try await self.performAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeQueryInterceptors() ?? [] - ) - } - - public func batchQuery( - _ request: Xmtp_MessageApi_V1_BatchQueryRequest, - callOptions: CallOptions? = nil - ) async throws -> Xmtp_MessageApi_V1_BatchQueryResponse { - return try await self.performAsyncUnaryCall( - path: Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery.path, - request: request, - callOptions: callOptions ?? self.defaultCallOptions, - interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [] - ) - } -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public struct Xmtp_MessageApi_V1_MessageApiAsyncClient: Xmtp_MessageApi_V1_MessageApiAsyncClientProtocol { - public var channel: GRPCChannel - public var defaultCallOptions: CallOptions - public var interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? - - public init( - channel: GRPCChannel, - defaultCallOptions: CallOptions = CallOptions(), - interceptors: Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol? = nil - ) { - self.channel = channel - self.defaultCallOptions = defaultCallOptions - self.interceptors = interceptors - } -} - -#endif // compiler(>=5.6) - -public protocol Xmtp_MessageApi_V1_MessageApiClientInterceptorFactoryProtocol: GRPCSendable { - - /// - Returns: Interceptors to use when invoking 'publish'. - func makePublishInterceptors() -> [ClientInterceptor] - - /// - Returns: Interceptors to use when invoking 'subscribe'. - func makeSubscribeInterceptors() -> [ClientInterceptor] - - /// - Returns: Interceptors to use when invoking 'subscribeAll'. - func makeSubscribeAllInterceptors() -> [ClientInterceptor] - - /// - Returns: Interceptors to use when invoking 'query'. - func makeQueryInterceptors() -> [ClientInterceptor] - - /// - Returns: Interceptors to use when invoking 'batchQuery'. - func makeBatchQueryInterceptors() -> [ClientInterceptor] -} - -public enum Xmtp_MessageApi_V1_MessageApiClientMetadata { - public static let serviceDescriptor = GRPCServiceDescriptor( - name: "MessageApi", - fullName: "xmtp.message_api.v1.MessageApi", - methods: [ - Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.publish, - Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribe, - Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.subscribeAll, - Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.query, - Xmtp_MessageApi_V1_MessageApiClientMetadata.Methods.batchQuery, - ] - ) - - public enum Methods { - public static let publish = GRPCMethodDescriptor( - name: "Publish", - path: "/xmtp.message_api.v1.MessageApi/Publish", - type: GRPCCallType.unary - ) - - public static let subscribe = GRPCMethodDescriptor( - name: "Subscribe", - path: "/xmtp.message_api.v1.MessageApi/Subscribe", - type: GRPCCallType.serverStreaming - ) - - public static let subscribeAll = GRPCMethodDescriptor( - name: "SubscribeAll", - path: "/xmtp.message_api.v1.MessageApi/SubscribeAll", - type: GRPCCallType.serverStreaming - ) - - public static let query = GRPCMethodDescriptor( - name: "Query", - path: "/xmtp.message_api.v1.MessageApi/Query", - type: GRPCCallType.unary - ) - - public static let batchQuery = GRPCMethodDescriptor( - name: "BatchQuery", - path: "/xmtp.message_api.v1.MessageApi/BatchQuery", - type: GRPCCallType.unary - ) - } -} - -/// RPC -/// -/// To build a server, implement a class that conforms to this protocol. -public protocol Xmtp_MessageApi_V1_MessageApiProvider: CallHandlerProvider { - var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { get } - - /// Publish messages to the network - func publish(request: Xmtp_MessageApi_V1_PublishRequest, context: StatusOnlyCallContext) -> EventLoopFuture - - /// Subscribe to a stream of new envelopes matching a predicate - func subscribe(request: Xmtp_MessageApi_V1_SubscribeRequest, context: StreamingResponseCallContext) -> EventLoopFuture - - /// Subscribe to a stream of all messages - func subscribeAll(request: Xmtp_MessageApi_V1_SubscribeAllRequest, context: StreamingResponseCallContext) -> EventLoopFuture - - /// Query the store for messages - func query(request: Xmtp_MessageApi_V1_QueryRequest, context: StatusOnlyCallContext) -> EventLoopFuture - - /// BatchQuery containing a set of queries to be processed - func batchQuery(request: Xmtp_MessageApi_V1_BatchQueryRequest, context: StatusOnlyCallContext) -> EventLoopFuture -} - -extension Xmtp_MessageApi_V1_MessageApiProvider { - public var serviceName: Substring { - return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor.fullName[...] - } - - /// Determines, calls and returns the appropriate request handler, depending on the request's method. - /// Returns nil for methods not handled by this service. - public func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "Publish": - return UnaryServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makePublishInterceptors() ?? [], - userFunction: self.publish(request:context:) - ) - - case "Subscribe": - return ServerStreamingServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], - userFunction: self.subscribe(request:context:) - ) - - case "SubscribeAll": - return ServerStreamingServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], - userFunction: self.subscribeAll(request:context:) - ) - - case "Query": - return UnaryServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeQueryInterceptors() ?? [], - userFunction: self.query(request:context:) - ) - - case "BatchQuery": - return UnaryServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [], - userFunction: self.batchQuery(request:context:) - ) - - default: - return nil - } - } -} - -#if compiler(>=5.6) - -/// RPC -/// -/// To implement a server, implement an object which conforms to this protocol. -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -public protocol Xmtp_MessageApi_V1_MessageApiAsyncProvider: CallHandlerProvider { - static var serviceDescriptor: GRPCServiceDescriptor { get } - var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { get } - - /// Publish messages to the network - @Sendable func publish( - request: Xmtp_MessageApi_V1_PublishRequest, - context: GRPCAsyncServerCallContext - ) async throws -> Xmtp_MessageApi_V1_PublishResponse - - /// Subscribe to a stream of new envelopes matching a predicate - @Sendable func subscribe( - request: Xmtp_MessageApi_V1_SubscribeRequest, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws - - /// Subscribe to a stream of all messages - @Sendable func subscribeAll( - request: Xmtp_MessageApi_V1_SubscribeAllRequest, - responseStream: GRPCAsyncResponseStreamWriter, - context: GRPCAsyncServerCallContext - ) async throws - - /// Query the store for messages - @Sendable func query( - request: Xmtp_MessageApi_V1_QueryRequest, - context: GRPCAsyncServerCallContext - ) async throws -> Xmtp_MessageApi_V1_QueryResponse - - /// BatchQuery containing a set of queries to be processed - @Sendable func batchQuery( - request: Xmtp_MessageApi_V1_BatchQueryRequest, - context: GRPCAsyncServerCallContext - ) async throws -> Xmtp_MessageApi_V1_BatchQueryResponse -} - -@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) -extension Xmtp_MessageApi_V1_MessageApiAsyncProvider { - public static var serviceDescriptor: GRPCServiceDescriptor { - return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor - } - - public var serviceName: Substring { - return Xmtp_MessageApi_V1_MessageApiServerMetadata.serviceDescriptor.fullName[...] - } - - public var interceptors: Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol? { - return nil - } - - public func handle( - method name: Substring, - context: CallHandlerContext - ) -> GRPCServerHandlerProtocol? { - switch name { - case "Publish": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makePublishInterceptors() ?? [], - wrapping: self.publish(request:context:) - ) - - case "Subscribe": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeSubscribeInterceptors() ?? [], - wrapping: self.subscribe(request:responseStream:context:) - ) - - case "SubscribeAll": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeSubscribeAllInterceptors() ?? [], - wrapping: self.subscribeAll(request:responseStream:context:) - ) - - case "Query": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeQueryInterceptors() ?? [], - wrapping: self.query(request:context:) - ) - - case "BatchQuery": - return GRPCAsyncServerHandler( - context: context, - requestDeserializer: ProtobufDeserializer(), - responseSerializer: ProtobufSerializer(), - interceptors: self.interceptors?.makeBatchQueryInterceptors() ?? [], - wrapping: self.batchQuery(request:context:) - ) - - default: - return nil - } - } -} - -#endif // compiler(>=5.6) - -public protocol Xmtp_MessageApi_V1_MessageApiServerInterceptorFactoryProtocol { - - /// - Returns: Interceptors to use when handling 'publish'. - /// Defaults to calling `self.makeInterceptors()`. - func makePublishInterceptors() -> [ServerInterceptor] - - /// - Returns: Interceptors to use when handling 'subscribe'. - /// Defaults to calling `self.makeInterceptors()`. - func makeSubscribeInterceptors() -> [ServerInterceptor] - - /// - Returns: Interceptors to use when handling 'subscribeAll'. - /// Defaults to calling `self.makeInterceptors()`. - func makeSubscribeAllInterceptors() -> [ServerInterceptor] - - /// - Returns: Interceptors to use when handling 'query'. - /// Defaults to calling `self.makeInterceptors()`. - func makeQueryInterceptors() -> [ServerInterceptor] - - /// - Returns: Interceptors to use when handling 'batchQuery'. - /// Defaults to calling `self.makeInterceptors()`. - func makeBatchQueryInterceptors() -> [ServerInterceptor] -} - -public enum Xmtp_MessageApi_V1_MessageApiServerMetadata { - public static let serviceDescriptor = GRPCServiceDescriptor( - name: "MessageApi", - fullName: "xmtp.message_api.v1.MessageApi", - methods: [ - Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.publish, - Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.subscribe, - Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.subscribeAll, - Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.query, - Xmtp_MessageApi_V1_MessageApiServerMetadata.Methods.batchQuery, - ] - ) - - public enum Methods { - public static let publish = GRPCMethodDescriptor( - name: "Publish", - path: "/xmtp.message_api.v1.MessageApi/Publish", - type: GRPCCallType.unary - ) - - public static let subscribe = GRPCMethodDescriptor( - name: "Subscribe", - path: "/xmtp.message_api.v1.MessageApi/Subscribe", - type: GRPCCallType.serverStreaming - ) - - public static let subscribeAll = GRPCMethodDescriptor( - name: "SubscribeAll", - path: "/xmtp.message_api.v1.MessageApi/SubscribeAll", - type: GRPCCallType.serverStreaming - ) - - public static let query = GRPCMethodDescriptor( - name: "Query", - path: "/xmtp.message_api.v1.MessageApi/Query", - type: GRPCCallType.unary - ) - - public static let batchQuery = GRPCMethodDescriptor( - name: "BatchQuery", - path: "/xmtp.message_api.v1.MessageApi/BatchQuery", - type: GRPCCallType.unary - ) - } -} -#endif diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 00000000..9da67da7 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,8 @@ +version: v1 +managed: + enabled: true +plugins: + - plugin: buf.build/apple/swift + out: Sources/XMTP/Proto + opt: + - Visibility=Public diff --git a/script/gen-proto b/script/gen-proto new file mode 100755 index 00000000..eefa9f76 --- /dev/null +++ b/script/gen-proto @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +buf generate buf.build/xmtp/proto \ No newline at end of file From 2b32f5c71a931642dfe08a48dcb0e0c3d7a57b00 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Thu, 11 May 2023 11:14:15 -0700 Subject: [PATCH 22/47] fix: remove proto dependency from Package.swift (#101) * feat: remove proto Package.swift dependency * fix: try a pod install --- Package.resolved | 9 -- Package.swift | 2 - Sources/XMTP/Messages/Signature.swift | 2 +- XMTP.podspec | 12 +-- XMTPiOSExample/Podfile.lock | 4 +- .../XMTPiOSExample.xcodeproj/project.pbxproj | 87 +++++++++++++++++++ 6 files changed, 96 insertions(+), 20 deletions(-) diff --git a/Package.resolved b/Package.resolved index 91c2ab5e..89da0e53 100644 --- a/Package.resolved +++ b/Package.resolved @@ -36,15 +36,6 @@ "version" : "5.2.0" } }, - { - "identity" : "proto", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/proto", - "state" : { - "branch" : "ios_minus_grpc_keeping_messageapi", - "revision" : "c74e3237e4de2aa481b91f91b1d23f6f9d87734e" - } - }, { "identity" : "secp256k1.swift", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index e2714518..276813a5 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,6 @@ let package = Package( // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(url: "https://github.com/xmtp/proto", branch: "ios_minus_grpc_keeping_messageapi"), .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", branch: "main"), .package(url: "https://github.com/argentlabs/web3.swift", from: "1.1.0"), .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), @@ -35,7 +34,6 @@ let package = Package( .target( name: "XMTP", dependencies: [ - .product(name: "XMTPProto", package: "proto"), .product(name: "secp256k1", package: "secp256k1.swift"), "web3.swift", .product(name: "Gzip", package: "GzipSwift"), diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 2c34a218..9859cd26 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -103,7 +103,7 @@ extension Signature { func verify(signedBy: PublicKey, digest: Data) throws -> Bool { do { - try XMTPRust.verify_k256_sha256(signedBy.secp256K1Uncompressed.bytes.dataToRustVec(), digest.dataToRustVec(), ecdsaCompact.bytes.dataToRustVec(), UInt8(ecdsaCompact.recovery)) + let _ = try XMTPRust.verify_k256_sha256(signedBy.secp256K1Uncompressed.bytes.dataToRustVec(), digest.dataToRustVec(), ecdsaCompact.bytes.dataToRustVec(), UInt8(ecdsaCompact.recovery)) } catch { return false } diff --git a/XMTP.podspec b/XMTP.podspec index 1c6bc1b9..92e34195 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -33,7 +33,7 @@ Pod::Spec.new do |spec| spec.license = "MIT" spec.author = { "Pat Nakajima" => "pat@xmtp.com" } - spec.platform = :ios, '13.0', :macos, '11.0' + spec.platform = :ios, '14.0', :macos, '11.0' spec.swift_version = '5.3' @@ -49,9 +49,9 @@ Pod::Spec.new do |spec| spec.xcconfig = {'VALID_ARCHS' => 'arm64' } # spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } - def spec.post_install(target) - target.build_configurations.each do |config| - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' - end - end +# def spec.post_install(target) +# target.build_configurations.each do |config| +# config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' +# end +# end end diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index 4ee11942..7965c969 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -60,9 +60,9 @@ SPEC CHECKSUMS: SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 WalletConnectSwift: 6309bf3011b0b30e3e9d1e7449535302a9240f71 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 0a8f3478a8739d526404b61dfaa9538a187577c6 + XMTP: d54871c3b0037c652dc8e61d3ed4d1f7ae1f9f55 XMTPRust: 7eb2da98f2bdb6d5d1a1d648dc0e9a91365ed211 PODFILE CHECKSUM: b08ce1433b369fe0cf978eda8c1642c21fe389d6 -COCOAPODS: 1.12.1 +COCOAPODS: 1.12.0 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index 2d350258..714ca912 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -33,6 +33,8 @@ A6AE518E297B6210006FDD0F /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AE518C297B6210006FDD0F /* NotificationService.swift */; }; A6AE5192297B6270006FDD0F /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; A6D192D0293A7B97006B49F2 /* ConversationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D192CF293A7B97006B49F2 /* ConversationListView.swift */; }; + BE941824EC1DA5A7E1ED4B38 /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */; }; + F72E430B9719F31B6C1C4E10 /* Pods_XMTPiOSExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -60,6 +62,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.debug.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.debug.xcconfig"; sourceTree = ""; }; + 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = ""; }; + 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = ""; }; + 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMTPiOSExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.release.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.release.xcconfig"; sourceTree = ""; }; A60FC8BE293AD054001697E3 /* MessageComposerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView.swift; sourceTree = ""; }; A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationDetailView.swift; sourceTree = ""; }; A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewClientProvider.swift; sourceTree = ""; }; @@ -95,6 +103,7 @@ A678243B29F8669600D30FF7 /* XMTP in Frameworks */, A678243429F8661F00D30FF7 /* KeychainAccess in Frameworks */, A678243129F8660F00D30FF7 /* WalletConnectSwift in Frameworks */, + F72E430B9719F31B6C1C4E10 /* Pods_XMTPiOSExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -104,6 +113,7 @@ files = ( A678243929F8667A00D30FF7 /* KeychainAccess in Frameworks */, A678243729F8666F00D30FF7 /* XMTP in Frameworks */, + BE941824EC1DA5A7E1ED4B38 /* Pods_NotificationService.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -113,6 +123,10 @@ 3F738A9EAAA632479874E954 /* Pods */ = { isa = PBXGroup; children = ( + 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */, + 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */, + 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */, + 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -176,6 +190,8 @@ isa = PBXGroup; children = ( A6CB98CB29F85D9200F2DC58 /* XMTP.framework */, + 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */, + 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */, ); name = Frameworks; sourceTree = ""; @@ -220,10 +236,12 @@ isa = PBXNativeTarget; buildConfigurationList = A628199E292DC826004B9117 /* Build configuration list for PBXNativeTarget "XMTPiOSExample" */; buildPhases = ( + 8F079FC76F159362232F01B5 /* [CP] Check Pods Manifest.lock */, A628198B292DC825004B9117 /* Sources */, A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, A65F0701297B5BCC00C3C76E /* Embed Foundation Extensions */, + 0B299A73F511D2C1FC8A9615 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -244,6 +262,7 @@ isa = PBXNativeTarget; buildConfigurationList = A6AE5188297B61AE006FDD0F /* Build configuration list for PBXNativeTarget "NotificationService" */; buildPhases = ( + 312007D7F759D2B7DA4EB709 /* [CP] Check Pods Manifest.lock */, A6AE517C297B61AE006FDD0F /* Sources */, A6AE517D297B61AE006FDD0F /* Frameworks */, A6AE517E297B61AE006FDD0F /* Resources */, @@ -321,6 +340,70 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 0B299A73F511D2C1FC8A9615 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 312007D7F759D2B7DA4EB709 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 8F079FC76F159362232F01B5 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-XMTPiOSExample-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ A628198B292DC825004B9117 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -476,6 +559,7 @@ }; A628199F292DC826004B9117 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -516,6 +600,7 @@ }; A62819A0292DC826004B9117 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -555,6 +640,7 @@ }; A6AE5189297B61AE006FDD0F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -583,6 +669,7 @@ }; A6AE518A297B61AE006FDD0F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; From 9201979291db3c5703ab049f1be629db6971a88e Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 15 May 2023 10:03:32 -0700 Subject: [PATCH 23/47] fix: local tests failing due to improper mem copying, .bytes extension not available in pods (#102) * fix: re-introduce 16.0 restriction * fix: passes pod lint now --- Sources/XMTP/ConversationV2.swift | 2 +- Sources/XMTP/Crypto.swift | 12 +++++++++--- XMTP.podspec | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTP/ConversationV2.swift index 41c5a10c..fe571825 100644 --- a/Sources/XMTP/ConversationV2.swift +++ b/Sources/XMTP/ConversationV2.swift @@ -38,7 +38,7 @@ public struct ConversationV2 { let peer = try myKeys.walletAddress == (try header.sender.walletAddress) ? header.recipient : header.sender let peerAddress = try peer.walletAddress - let keyMaterial = Data(invitation.aes256GcmHkdfSha256.keyMaterial.bytes) + let keyMaterial = Data(invitation.aes256GcmHkdfSha256.keyMaterial) return ConversationV2( topic: invitation.topic, diff --git a/Sources/XMTP/Crypto.swift b/Sources/XMTP/Crypto.swift index c9fccd34..4adebbd3 100644 --- a/Sources/XMTP/Crypto.swift +++ b/Sources/XMTP/Crypto.swift @@ -35,8 +35,14 @@ enum Crypto { } var ciphertext = CipherText() - - ciphertext.aes256GcmHkdfSha256.payload = payload.ciphertext + payload.tag + // Copy the ciphertext data out, otherwise it's a region sliced from a combined Data (nonce, ciphertext, tag) + // with offsets like lowerBound=12, upperBound=224. Without copying, trying to index like payload[0] crashes + // up until payload[12]. This is mostly a problem for unit tests where we decrypt what we encrypt in memory, as + // serialization/deserialization acts as copying and avoids this issue. + var payloadData = Data(payload.ciphertext.subdata(in: 12 ..< payload.ciphertext.count+12)) + let startTag = 12 + payload.ciphertext.count + payloadData.append(payload.tag.subdata(in: startTag ..< startTag + payload.tag.count)) + ciphertext.aes256GcmHkdfSha256.payload = payloadData ciphertext.aes256GcmHkdfSha256.hkdfSalt = salt ciphertext.aes256GcmHkdfSha256.gcmNonce = nonceData @@ -47,7 +53,7 @@ enum Crypto { let salt = ciphertext.aes256GcmHkdfSha256.hkdfSalt let nonceData = ciphertext.aes256GcmHkdfSha256.gcmNonce let nonce = try AES.GCM.Nonce(data: nonceData) - let payload = ciphertext.aes256GcmHkdfSha256.payload.bytes + let payload = ciphertext.aes256GcmHkdfSha256.payload let ciphertextBytes = payload[0 ..< payload.count - 16] let tag = payload[payload.count - 16 ..< payload.count] diff --git a/XMTP.podspec b/XMTP.podspec index 92e34195..bc63809e 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -48,7 +48,7 @@ Pod::Spec.new do |spec| spec.xcconfig = {'VALID_ARCHS' => 'arm64' } # spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } - +# # def spec.post_install(target) # target.build_configurations.each do |config| # config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' From 1427b3ded73433be71042de6aa91fb2a4191327a Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 15 May 2023 11:11:48 -0700 Subject: [PATCH 24/47] fix: use exact secp256k1 version --- Package.resolved | 4 ++-- Package.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index 89da0e53..4a5ace9e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", "state" : { - "branch" : "main", - "revision" : "1542d3a9968ddac9c33d04f7b22a6ad54a415e29" + "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", + "version" : "0.10.0" } }, { diff --git a/Package.swift b/Package.swift index 276813a5..171ab1af 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( // 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", branch: "main"), + .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", from: "0.3.0"), From 22f878329fc14bfa45c4a955d609c8a081c6a276 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 15 May 2023 11:42:02 -0700 Subject: [PATCH 25/47] fix: utilize QueryResponse paging info --- Sources/XMTP/ApiClient.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 154fc53e..6531a5fe 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -167,10 +167,9 @@ class GRPCApiClient: ApiClient { envelope.message = dataFromRustVec(rustVec: rustEnvelope.get_payload()) return envelope } - // TODO: uncomment this once we clear up ownership issues on QueryResponse for the Rust side -// if let responsePagingInfo = response.paging_info() { -// queryResponse.pagingInfo = parseRustPagingInfoFromResponse(response: response) -// } + if let _ = response.paging_info() { + queryResponse.pagingInfo = parseRustPagingInfoFromResponse(response: response) + } return queryResponse } From 5e97876302e46d32a2298020f16bc406b8580f49 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 15 May 2023 13:09:46 -0700 Subject: [PATCH 26/47] fix: use 0.2.2-beta0 XMTPRust --- XMTP.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XMTP.podspec b/XMTP.podspec index bc63809e..fb065305 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -44,7 +44,7 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift" - spec.dependency 'XMTPRust', '= 0.2.0-beta0' + spec.dependency 'XMTPRust', '= 0.2.2-beta0' spec.xcconfig = {'VALID_ARCHS' => 'arm64' } # spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } From 76eb4438324bea90c7cf344082d42f87ca97db57 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 15 May 2023 13:27:05 -0700 Subject: [PATCH 27/47] feat: prep for 0.2.0-alpha0 test release --- XMTP.podspec | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/XMTP.podspec b/XMTP.podspec index fb065305..39a444fe 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.2.0" + spec.version = "0.2.0-alpha0" spec.summary = "XMTP pod." # This description is used to generate tags and improve search results. @@ -47,11 +47,4 @@ Pod::Spec.new do |spec| spec.dependency 'XMTPRust', '= 0.2.2-beta0' spec.xcconfig = {'VALID_ARCHS' => 'arm64' } -# spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } -# -# def spec.post_install(target) -# target.build_configurations.each do |config| -# config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' -# end -# end end From a0b8296bbfba64ebd32890a63ca3f68e08050ee6 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 14:34:39 -0700 Subject: [PATCH 28/47] fix: commit updated dependency manifests --- XMTPiOSExample/Podfile.lock | 14 +++++++------- .../xcshareddata/swiftpm/Package.resolved | 13 ++----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index 7965c969..6c4da14c 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -2,7 +2,7 @@ PODS: - BigInt (5.0.0) - Connect-Swift (0.5.0): - SwiftProtobuf (~> 1.21.0) - - CryptoSwift (1.6.0) + - CryptoSwift (1.7.1) - GenericJSON (2.0.2) - GzipSwift (5.1.1) - KeychainAccess (4.2.2) @@ -16,12 +16,12 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.2.0): + - XMTP (0.2.0-alpha0): - Connect-Swift - GzipSwift - web3.swift - - XMTPRust (= 0.2.0-beta0) - - XMTPRust (0.2.0-beta0) + - XMTPRust (= 0.2.2-beta0) + - XMTPRust (0.2.2-beta0) DEPENDENCIES: - KeychainAccess @@ -51,7 +51,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 Connect-Swift: a75380c30c1341e483012444044105ff49b6093a - CryptoSwift: 562f8eceb40e80796fffc668b0cad9313284cfa6 + CryptoSwift: d3d18dc357932f7e6d580689e065cf1f176007c1 GenericJSON: 79a840eeb77030962e8cf02a62d36bd413b67626 GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa KeychainAccess: c0c4f7f38f6fc7bbe58f5702e25f7bd2f65abf51 @@ -60,8 +60,8 @@ SPEC CHECKSUMS: SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 WalletConnectSwift: 6309bf3011b0b30e3e9d1e7449535302a9240f71 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: d54871c3b0037c652dc8e61d3ed4d1f7ae1f9f55 - XMTPRust: 7eb2da98f2bdb6d5d1a1d648dc0e9a91365ed211 + XMTP: 21d0ab77de34cd2ec2310d52f568f9752f2cd22c + XMTPRust: 10f79ec17747b15d3c626984f433b4f5ce948fff PODFILE CHECKSUM: b08ce1433b369fe0cf978eda8c1642c21fe389d6 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 96750746..628d4391 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -54,22 +54,13 @@ "revision" : "ecb18d8ce4d88277cc4fb103973352d91e18c535" } }, - { - "identity" : "proto", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/proto", - "state" : { - "branch" : "ios_minus_grpc_keeping_messageapi", - "revision" : "c74e3237e4de2aa481b91f91b1d23f6f9d87734e" - } - }, { "identity" : "secp256k1.swift", "kind" : "remoteSourceControl", "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", "state" : { - "branch" : "main", - "revision" : "06792cfc951df870045f5fdb8095ae2e8bc83b69" + "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", + "version" : "0.10.0" } }, { From f47d7e2fd37969f42e28a735f1476c20c9b9390c Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 14:37:50 -0700 Subject: [PATCH 29/47] fix: make sure to return cursor information from response --- Sources/XMTP/ApiClient.swift | 1 + XMTP.podspec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 6531a5fe..9bfce0a6 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -117,6 +117,7 @@ class GRPCApiClient: ApiClient { var cursor = PagingInfoCursor() cursor.index.digest = Data(rustCursor.digest) cursor.index.senderTimeNs = rustCursor.sender_time_ns + pagingInfo.cursor = cursor } switch rustPaging.direction { case XMTPRust.SortDirection.Ascending: diff --git a/XMTP.podspec b/XMTP.podspec index 39a444fe..15939b83 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.2.0-alpha0" + spec.version = "0.2.1-alpha0" spec.summary = "XMTP pod." # This description is used to generate tags and improve search results. From b1e88e13e43f84f9a2742de8da2310bddb6986dc Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 15:59:24 -0700 Subject: [PATCH 30/47] style: fix indent in the ApiClient.swift file --- Sources/XMTP/ApiClient.swift | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 9bfce0a6..8b91cd6b 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -97,38 +97,38 @@ class GRPCApiClient: ApiClient { // Set rustPaging.direction based off a switch-case conversion switch request.pagingInfo.direction { case .ascending: - rustPaging.direction = XMTPRust.SortDirection.Ascending + rustPaging.direction = XMTPRust.SortDirection.Ascending case .descending: rustPaging.direction = XMTPRust.SortDirection.Descending case .unspecified: rustPaging.direction = XMTPRust.SortDirection.Unspecified case .UNRECOGNIZED(_): - rustPaging.direction = XMTPRust.SortDirection.Unspecified + rustPaging.direction = XMTPRust.SortDirection.Unspecified } return rustPaging; } func parseRustPagingInfoFromResponse(response: XMTPRust.QueryResponse) -> PagingInfo { - var pagingInfo = PagingInfo() - if let rustPaging = response.paging_info() { - pagingInfo.limit = rustPaging.limit - if let rustCursor = rustPaging.cursor { - var cursor = PagingInfoCursor() - cursor.index.digest = Data(rustCursor.digest) - cursor.index.senderTimeNs = rustCursor.sender_time_ns - pagingInfo.cursor = cursor - } - switch rustPaging.direction { - case XMTPRust.SortDirection.Ascending: - pagingInfo.direction = .ascending - case XMTPRust.SortDirection.Descending: - pagingInfo.direction = .descending - case XMTPRust.SortDirection.Unspecified: - pagingInfo.direction = .unspecified - } - } - return pagingInfo + var pagingInfo = PagingInfo() + if let rustPaging = response.paging_info() { + pagingInfo.limit = rustPaging.limit + if let rustCursor = rustPaging.cursor { + var cursor = PagingInfoCursor() + cursor.index.digest = Data(rustCursor.digest) + cursor.index.senderTimeNs = rustCursor.sender_time_ns + pagingInfo.cursor = cursor + } + switch rustPaging.direction { + case XMTPRust.SortDirection.Ascending: + pagingInfo.direction = .ascending + case XMTPRust.SortDirection.Descending: + pagingInfo.direction = .descending + case XMTPRust.SortDirection.Unspecified: + pagingInfo.direction = .unspecified + } + } + return pagingInfo } func query(topic: String, pagination: Pagination? = nil, cursor: Xmtp_MessageApi_V1_Cursor? = nil) async throws -> QueryResponse { From ff3f48f559bd0c81499552f38ee426e86be09722 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 16:01:51 -0700 Subject: [PATCH 31/47] test: remove empty no-op gRPC test --- Sources/XMTP/ApiClient.swift | 4 ---- Tests/XMTPTests/ClientTests.swift | 5 ----- 2 files changed, 9 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 8b91cd6b..a1f62c0b 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -233,8 +233,4 @@ class GRPCApiClient: ApiClient { let publishResponse = PublishResponse() return publishResponse } - - public static func runGrpcTest() async throws -> Int { - return 0 - } } diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 562ab056..c533de49 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -30,11 +30,6 @@ class ClientTests: XCTestCase { _ = try await Client.create(account: fakeWallet) } - func testXMTPgRPC() async throws { - let numEnvelopes = try await GRPCApiClient.runGrpcTest() - XCTAssertEqual(numEnvelopes, 0) - } - func testCanMessage() async throws { let fixtures = await fixtures() let notOnNetwork = try PrivateKey.generate() From d531da95b09196ab2e056563e6fd912cc6d04403 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 16:10:02 -0700 Subject: [PATCH 32/47] style: fix indents and remove imports --- Sources/XMTP/Messages/MessageV2.swift | 1 - Sources/XMTP/Messages/PrivateKeyBundle.swift | 2 +- Sources/XMTP/Messages/PrivateKeyBundleV1.swift | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/XMTP/Messages/MessageV2.swift b/Sources/XMTP/Messages/MessageV2.swift index e5bc5d3a..9fb0a772 100644 --- a/Sources/XMTP/Messages/MessageV2.swift +++ b/Sources/XMTP/Messages/MessageV2.swift @@ -8,7 +8,6 @@ import CryptoKit import Foundation import XMTPRust -import web3 typealias MessageV2 = Xmtp_MessageContents_MessageV2 diff --git a/Sources/XMTP/Messages/PrivateKeyBundle.swift b/Sources/XMTP/Messages/PrivateKeyBundle.swift index c202c778..96331dd9 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundle.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundle.swift @@ -29,7 +29,7 @@ extension PrivateKeyBundle { var encryptedBundle = EncryptedPrivateKeyBundle() encryptedBundle.v1.walletPreKey = walletPreKey - encryptedBundle.v1.ciphertext = cipherText + encryptedBundle.v1.ciphertext = cipherText return encryptedBundle } diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift index 7f36257b..5161f1d3 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV1.swift @@ -7,7 +7,6 @@ import CryptoKit import Foundation -import web3 import XMTPRust From 8dc40f029e9041d804e0b827e153c9190c6f20b6 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 16:22:51 -0700 Subject: [PATCH 33/47] fix: remove unnecessary Data extension and replace with existing for RustVecs --- Sources/XMTP/ApiClient.swift | 22 ++----------------- .../XMTP/Messages/PrivateKeyBundleV2.swift | 2 +- Sources/XMTP/Messages/Signature.swift | 2 +- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index a1f62c0b..5c26615f 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -23,24 +23,6 @@ protocol ApiClient { func subscribe(topics: [String]) -> AsyncThrowingStream } -extension Data { - func dataToRustVec() -> RustVec { - let rustVec = RustVec() - for byte in self { - rustVec.push(value: byte) - } - return rustVec - } - - func dataFromRustVec(rustVec: RustVec) -> Data { - var listBytes: [UInt8] = [] - for byte in rustVec { - listBytes.append(byte) - } - return Data(listBytes) - } -} - class GRPCApiClient: ApiClient { let ClientVersionHeaderKey = "X-Client-Version" let AppVersionHeaderKey = "X-App-Version" @@ -89,7 +71,7 @@ class GRPCApiClient: ApiClient { rustPaging.limit = request.pagingInfo.limit if request.hasPagingInfo && request.pagingInfo.hasCursor { let cursor = request.pagingInfo.cursor; - let digest = cursor.index.digest.dataToRustVec() + let digest = RustVec(cursor.index.digest) let senderTimeNs = cursor.index.senderTimeNs rustPaging.cursor = XMTPRust.IndexCursor(digest: digest, sender_time_ns: senderTimeNs) } @@ -210,7 +192,7 @@ class GRPCApiClient: ApiClient { var swiftEnvelope = Envelope() swiftEnvelope.contentTopic = rustEnvelope.get_topic().toString() swiftEnvelope.timestampNs = rustEnvelope.get_sender_time_ns() - swiftEnvelope.message = Data().dataFromRustVec(rustVec: rustEnvelope.get_payload()) + swiftEnvelope.message = Data(rustEnvelope.get_payload()) continuation.yield(swiftEnvelope) } try await Task.sleep(nanoseconds: 50_000_000) // 50ms diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift index 910ad437..031642b9 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTP/Messages/PrivateKeyBundleV2.swift @@ -34,7 +34,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - return Data(try XMTPRust.diffie_hellman_k256(privateData.dataToRustVec(), publicData.dataToRustVec())) + return Data(try XMTPRust.diffie_hellman_k256(RustVec(privateData), RustVec(publicData))) } func findPreKey(_ myPreKey: SignedPublicKey) throws -> SignedPrivateKey { diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTP/Messages/Signature.swift index 9859cd26..df390e87 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTP/Messages/Signature.swift @@ -103,7 +103,7 @@ extension Signature { func verify(signedBy: PublicKey, digest: Data) throws -> Bool { do { - let _ = try XMTPRust.verify_k256_sha256(signedBy.secp256K1Uncompressed.bytes.dataToRustVec(), digest.dataToRustVec(), ecdsaCompact.bytes.dataToRustVec(), UInt8(ecdsaCompact.recovery)) + let _ = try XMTPRust.verify_k256_sha256(RustVec(signedBy.secp256K1Uncompressed.bytes), RustVec(digest), RustVec(ecdsaCompact.bytes), UInt8(ecdsaCompact.recovery)) } catch { return false } From 827e985c5077a36d4e9a74a062dd95843ff064de Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 16:28:46 -0700 Subject: [PATCH 34/47] test: add a PaginationTest class --- Tests/XMTPTests/PaginationTests.swift | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Tests/XMTPTests/PaginationTests.swift diff --git a/Tests/XMTPTests/PaginationTests.swift b/Tests/XMTPTests/PaginationTests.swift new file mode 100644 index 00000000..ef71ff6a --- /dev/null +++ b/Tests/XMTPTests/PaginationTests.swift @@ -0,0 +1,132 @@ +// +// PaginationTests.swift +// +// +// Created by Michael Xu on 05/16/23. +// + +import Foundation + +import XCTest +@testable import XMTP +import XMTPRust + +@available(iOS 15, *) +class PaginationTests: XCTestCase { + + func newClientHelper(account: PrivateKey) async throws -> Client { + let client = try await Client.create(account: account, options: ClientOptions(api: .init(env: .local, isSecure: false))) + return client + } + + func testLongConvo() async throws { + let alice = try PrivateKey.generate() + let bob = try PrivateKey.generate() + + let aliceClient = try await newClientHelper(account: alice) + let bobClient = try await newClientHelper(account: bob) + + let canAliceMessageBob = try await aliceClient.canMessage(bobClient.address) + XCTAssert(canAliceMessageBob) + + // Start a conversation with alice + + guard case let .v2(bobConversation) = try await bobClient.conversations.newConversation(with: alice.address, context: InvitationV1.Context(conversationID: "hi")) else { + XCTFail("did not get a v2 conversation for alice") + return + } + + guard case let .v2(aliceConversation) = try await aliceClient.conversations.newConversation(with: bob.address, context: InvitationV1.Context(conversationID: "hi")) else { + XCTFail("did not get a v2 conversation for alice") + return + } + + try await bobConversation.send(content: "hey alice 1", sentAt: Date().addingTimeInterval(-1000)) + try await bobConversation.send(content: "hey alice 2", sentAt: Date().addingTimeInterval(-500)) + try await bobConversation.send(content: "hey alice 3", sentAt: Date()) + + let messages = try await aliceConversation.messages(limit: 1) + XCTAssertEqual(1, messages.count) + XCTAssertEqual("hey alice 3", messages[0].body) + + let messages2 = try await aliceConversation.messages(limit: 1, before: messages[0].sent) + XCTAssertEqual(1, messages2.count) + XCTAssertEqual("hey alice 2", messages2[0].body) + + // Send many many more messages, such that it forces cursor saving and pagination + for i in 4..<101 { + try await bobConversation.send(content: "hey alice \(i)", sentAt: Date()) + } + // Grab the messages 50 at a time + let messages3 = try await aliceConversation.messages(limit: 50) + XCTAssertEqual(50, messages3.count) + XCTAssertEqual("hey alice 100", messages3[0].body) + XCTAssertEqual("hey alice 51", messages3[49].body) + + let messages4 = try await aliceConversation.messages(limit: 100, before: messages3[49].sent) + XCTAssertEqual(50, messages4.count) + XCTAssertEqual("hey alice 50", messages4[0].body) + XCTAssertEqual("hey alice 1", messages4[49].body) + } + + func testCanStreamConversationsV2() async throws { + let alice = try PrivateKey.generate() + let bob = try PrivateKey.generate() + + let bobClient = try await newClientHelper(account: bob) + let expectation1 = expectation(description: "got a conversation") + expectation1.expectedFulfillmentCount = 2 + + Task(priority: .userInitiated) { + for try await _ in bobClient.conversations.stream() { + expectation1.fulfill() + } + } + + guard case let .v2(conversation) = try await bobClient.conversations.newConversation(with: alice.walletAddress) else { + XCTFail("Did not create a v2 convo") + return + } + + try await conversation.send(content: "hi") + + guard case let .v2(conversation) = try await bobClient.conversations.newConversation(with: alice.walletAddress) else { + XCTFail("Did not create a v2 convo") + return + } + + try await conversation.send(content: "hi again") + + let newWallet = try PrivateKey.generate() + + guard case let .v2(conversation2) = try await bobClient.conversations.newConversation(with: newWallet.walletAddress) else { + XCTFail("Did not create a v2 convo") + return + } + + try await conversation2.send(content: "hi from new wallet") + + await waitForExpectations(timeout: 3) + + // Test that we can stream a few more messages + let expectation2 = expectation(description: "got follow-up messages") + expectation2.expectedFulfillmentCount = 5 + Task(priority: .userInitiated) { + for try await message in conversation.streamMessages() { + print("Got message: \(message)") + expectation2.fulfill() + } + } + + // Slowly send out messages + Task(priority: .userInitiated) { + try! await conversation.send(content: "hi") + try! await conversation.send(content: "hi again") + try! await conversation.send(content: "hi again again") + try! await conversation.send(content: "hi again again again") + try! await conversation.send(content: "hi again again again again") + } + + await waitForExpectations(timeout: 5) + } +} From 7c91dfd3ff285a058812c734bd2ebed299c48938 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:20:08 -0700 Subject: [PATCH 35/47] test: need to do unused client initializations to upload contact bundles --- Tests/XMTPTests/PaginationTests.swift | 6 +++++- Tests/XMTPTests/SignatureTests.swift | 7 ------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Tests/XMTPTests/PaginationTests.swift b/Tests/XMTPTests/PaginationTests.swift index ef71ff6a..1c38b927 100644 --- a/Tests/XMTPTests/PaginationTests.swift +++ b/Tests/XMTPTests/PaginationTests.swift @@ -73,12 +73,15 @@ class PaginationTests: XCTestCase { let alice = try PrivateKey.generate() let bob = try PrivateKey.generate() + // Need to upload Alice's contact bundle + let _ = try await newClientHelper(account: alice) let bobClient = try await newClientHelper(account: bob) let expectation1 = expectation(description: "got a conversation") expectation1.expectedFulfillmentCount = 2 Task(priority: .userInitiated) { for try await _ in bobClient.conversations.stream() { + print("Got one conversation") expectation1.fulfill() } } @@ -98,7 +101,8 @@ class PaginationTests: XCTestCase { try await conversation.send(content: "hi again") let newWallet = try PrivateKey.generate() - + // Need to upload contact bundle + let _ = try await newClientHelper(account: newWallet) guard case let .v2(conversation2) = try await bobClient.conversations.newConversation(with: newWallet.walletAddress) else { XCTFail("Did not create a v2 convo") return diff --git a/Tests/XMTPTests/SignatureTests.swift b/Tests/XMTPTests/SignatureTests.swift index 0b2b5c4e..edf72a75 100644 --- a/Tests/XMTPTests/SignatureTests.swift +++ b/Tests/XMTPTests/SignatureTests.swift @@ -12,15 +12,8 @@ import XCTest class SignatureTests: XCTestCase { func testVerify() async throws { let digest = SHA256.hash(data: Data("Hello world".utf8)) - print("Message Bytes: \(Data("Hello world".utf8).toHex)") let signingKey = try PrivateKey.generate() let signature = try await signingKey.sign(Data(digest)) - - print("Digest: \(digest.description)") - print("Signature: \(signature.rawData.toHex)") - print("Expected public: \(signingKey.publicKey.secp256K1Uncompressed.bytes.toHex)") - print("Recovered public: \(try KeyUtilx.recoverPublicKey(message: Data(digest), signature: signature.rawData).toHex)") - XCTAssert(try signature.verify(signedBy: signingKey.publicKey, digest: Data("Hello world".utf8))) } } From e924c02647eb0ec7852961aab4accf077b42efb1 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:22:12 -0700 Subject: [PATCH 36/47] fix: remove unnecessary comment and remaining unneeded Data<>RustVec extensions --- Sources/XMTP/ApiClient.swift | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 5c26615f..61d9fc08 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -34,26 +34,9 @@ class GRPCApiClient: ApiClient { required init(environment: XMTPEnvironment, secure _: Bool = true, rustClient: XMTPRust.RustClient) throws { self.environment = environment - // TODO: this is a hack to do an async thing in a synchronous way self.rustClient = rustClient } - func dataToRustVec(data: Data) -> RustVec { - let rustVec = RustVec() - for byte in data { - rustVec.push(value: byte) - } - return rustVec - } - - func dataFromRustVec(rustVec: RustVec) -> Data { - var listBytes: [UInt8] = [] - for byte in rustVec { - listBytes.append(byte) - } - return Data(listBytes) - } - static func envToUrl(env: XMTPEnvironment) -> String { switch env { case XMTPEnvironment.local: return "http://localhost:5556" @@ -147,7 +130,7 @@ class GRPCApiClient: ApiClient { var envelope = Envelope() envelope.contentTopic = rustEnvelope.get_topic().toString() envelope.timestampNs = rustEnvelope.get_sender_time_ns() - envelope.message = dataFromRustVec(rustVec: rustEnvelope.get_payload()) + envelope.message = Data(rustEnvelope.get_payload()) return envelope } if let _ = response.paging_info() { @@ -208,7 +191,7 @@ class GRPCApiClient: ApiClient { let envelopesVec = RustVec() envelopes.forEach { envelope in - let rustEnvelope = XMTPRust.create_envelope(envelope.contentTopic.intoRustString(), envelope.timestampNs, dataToRustVec(data: envelope.message)) + let rustEnvelope = XMTPRust.create_envelope(envelope.contentTopic.intoRustString(), envelope.timestampNs, RustVec(envelope.message)) envelopesVec.push(value: rustEnvelope) } let response = try await rustClient.publish(authToken.intoRustString(), envelopesVec) From 3f521e2b6b504f4ddcfc036f5f5cbdf9b5f2ab65 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:26:26 -0700 Subject: [PATCH 37/47] docs: add comment and flush out podspec description --- Sources/XMTP/ApiClient.swift | 1 + XMTP.podspec | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 61d9fc08..5a00b807 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -196,6 +196,7 @@ class GRPCApiClient: ApiClient { } let response = try await rustClient.publish(authToken.intoRustString(), envelopesVec) let publishResponse = PublishResponse() + // TODO: do we need to populate anything from response into PublishResponse? return publishResponse } } diff --git a/XMTP.podspec b/XMTP.podspec index 15939b83..51e25c4d 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,8 +16,8 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.2.1-alpha0" - spec.summary = "XMTP pod." + spec.version = "0.2.2-alpha0" + spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. # * Think: What does it do? Why did you write it? What is the focus? @@ -25,7 +25,7 @@ Pod::Spec.new do |spec| # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! spec.description = <<-DESC - TODO + The XMTP cocoapod implements the XMTP protocol for iOS. It handles cryptographic operations and network communication with the XMTP network. DESC spec.homepage = "https://github.com/xmtp/xmtp-ios" From 8e90581471abe39264aa5d836c4e018a6120b22e Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:27:26 -0700 Subject: [PATCH 38/47] style: add spaces to example podfile --- XMTPiOSExample/Podfile | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/XMTPiOSExample/Podfile b/XMTPiOSExample/Podfile index 0658c8c1..3b86ae4e 100644 --- a/XMTPiOSExample/Podfile +++ b/XMTPiOSExample/Podfile @@ -6,13 +6,9 @@ target 'NotificationService' do use_frameworks! # Pods for NotificationService - # Pods for XMTPiOSExample - # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" pod "web3.swift" - pod 'KeychainAccess' -# pod "XMTPProto", path: "../../proto" -# pod "XMTPRust", path: '../../xmtp-rust-swift' - pod "XMTP", path: "../" + pod 'KeychainAccess' + pod "XMTP", path: '../' end target 'XMTPiOSExample' do @@ -20,21 +16,18 @@ target 'XMTPiOSExample' do use_frameworks! # Pods for XMTPiOSExample - # pod "secp256k1Swift", git: "https://github.com/portto/secp256k1.swift" - pod 'WalletConnectSwift' + pod 'WalletConnectSwift' pod "web3.swift" - pod 'KeychainAccess' -# pod "XMTPProto", path: "../../proto" -# pod "XMTPRust", path: '../../xmtp-rust-swift' - pod "XMTP", path: "../" + pod 'KeychainAccess' + pod "XMTP", path: '../' end post_install do |installer| - installer.generated_projects.each do |project| - project.targets.each do |target| - target.build_configurations.each do |config| - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' - end - end - end + installer.generated_projects.each do |project| + project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' + end + end + end end From 4e74ede407377e3e60f331101a6ed963ab275897 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:28:49 -0700 Subject: [PATCH 39/47] test: remove extraneous takesAWallet test --- Tests/XMTPTests/ClientTests.swift | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index c533de49..59227c29 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -14,18 +14,7 @@ import XMTPTestHelpers @available(iOS 15, *) class ClientTests: XCTestCase { - func testTakesAWallet() async { - do { - let fakeWallet = try PrivateKey.generate() - _ = try await Client.create(account: fakeWallet) - } catch let error where error is RustString { - print("Hello \(error.localizedDescription) type: \(type(of: error))") - } catch { - print("\(error) \(type(of: error))") - } - } - - func testTakesAKeyAsWallet() async throws { + func testTakesAWallet() async throws { let fakeWallet = try PrivateKey.generate() _ = try await Client.create(account: fakeWallet) } From 6221b69d029ae71117478ddca5956955499962cb Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 16 May 2023 18:29:49 -0700 Subject: [PATCH 40/47] test: remove unnecessary test lines in TestHelper --- Sources/XMTPTestHelpers/TestHelpers.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sources/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index 7f27a977..c99d0028 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -231,11 +231,6 @@ public struct Fixtures { public extension XCTestCase { @available(iOS 15, *) func fixtures() async -> Fixtures { - do { - try await Fixtures() - } catch { - print("ERROR: \(error.localizedDescription)") - } // swiftlint:disable force_try return try! await Fixtures() } From e5dff28c8d5c5a893a27899edafbc063858811ca Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 10:19:37 -0700 Subject: [PATCH 41/47] docs: fix comment about empty PublishResponse --- Sources/XMTP/ApiClient.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift index 5a00b807..954d23ff 100644 --- a/Sources/XMTP/ApiClient.swift +++ b/Sources/XMTP/ApiClient.swift @@ -194,9 +194,9 @@ class GRPCApiClient: ApiClient { let rustEnvelope = XMTPRust.create_envelope(envelope.contentTopic.intoRustString(), envelope.timestampNs, RustVec(envelope.message)) envelopesVec.push(value: rustEnvelope) } - let response = try await rustClient.publish(authToken.intoRustString(), envelopesVec) + let _ = try await rustClient.publish(authToken.intoRustString(), envelopesVec) + // NOTE: PublishResponse proto has no fields let publishResponse = PublishResponse() - // TODO: do we need to populate anything from response into PublishResponse? return publishResponse } } From bca5e5ac6ad0c1a6f7e047cebee4a3f1abb0264a Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 10:19:52 -0700 Subject: [PATCH 42/47] test: fix pagination test race condition with duplicate convos --- Tests/XMTPTests/PaginationTests.swift | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Tests/XMTPTests/PaginationTests.swift b/Tests/XMTPTests/PaginationTests.swift index 1c38b927..dd8de35e 100644 --- a/Tests/XMTPTests/PaginationTests.swift +++ b/Tests/XMTPTests/PaginationTests.swift @@ -93,13 +93,6 @@ class PaginationTests: XCTestCase { try await conversation.send(content: "hi") - guard case let .v2(conversation) = try await bobClient.conversations.newConversation(with: alice.walletAddress) else { - XCTFail("Did not create a v2 convo") - return - } - - try await conversation.send(content: "hi again") - let newWallet = try PrivateKey.generate() // Need to upload contact bundle let _ = try await newClientHelper(account: newWallet) @@ -110,7 +103,7 @@ class PaginationTests: XCTestCase { try await conversation2.send(content: "hi from new wallet") - await waitForExpectations(timeout: 3) + await waitForExpectations(timeout: 5) // Test that we can stream a few more messages let expectation2 = expectation(description: "got follow-up messages") From 999808108cc33f437ad9f34187618c3226a17f2d Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 16:41:56 -0700 Subject: [PATCH 43/47] fix: attempt to see if xcode cloud works without cocoapods --- XMTPiOSExample/Podfile | 13 ++-- XMTPiOSExample/Podfile.lock | 67 +------------------ .../XMTPiOSExample.xcodeproj/project.pbxproj | 18 ----- 3 files changed, 7 insertions(+), 91 deletions(-) diff --git a/XMTPiOSExample/Podfile b/XMTPiOSExample/Podfile index 3b86ae4e..05489aa4 100644 --- a/XMTPiOSExample/Podfile +++ b/XMTPiOSExample/Podfile @@ -6,9 +6,8 @@ target 'NotificationService' do use_frameworks! # Pods for NotificationService - pod "web3.swift" - pod 'KeychainAccess' - pod "XMTP", path: '../' +# pod "web3.swift" +# pod 'KeychainAccess' end target 'XMTPiOSExample' do @@ -16,10 +15,10 @@ target 'XMTPiOSExample' do use_frameworks! # Pods for XMTPiOSExample - pod 'WalletConnectSwift' - pod "web3.swift" - pod 'KeychainAccess' - pod "XMTP", path: '../' +# pod 'WalletConnectSwift' +# pod "web3.swift" +# pod 'KeychainAccess' +# pod "XMTP", path: '../' end post_install do |installer| diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index 6c4da14c..76b699fe 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -1,68 +1,3 @@ -PODS: - - BigInt (5.0.0) - - Connect-Swift (0.5.0): - - SwiftProtobuf (~> 1.21.0) - - CryptoSwift (1.7.1) - - GenericJSON (2.0.2) - - GzipSwift (5.1.1) - - KeychainAccess (4.2.2) - - Logging (1.0.0) - - secp256k1.swift (0.1.4) - - SwiftProtobuf (1.21.0) - - WalletConnectSwift (1.7.0): - - CryptoSwift (~> 1.5) - - web3.swift (1.6.0): - - BigInt (~> 5.0.0) - - GenericJSON (~> 2.0) - - Logging (~> 1.0.0) - - secp256k1.swift (~> 0.1) - - XMTP (0.2.0-alpha0): - - Connect-Swift - - GzipSwift - - web3.swift - - XMTPRust (= 0.2.2-beta0) - - XMTPRust (0.2.2-beta0) - -DEPENDENCIES: - - KeychainAccess - - WalletConnectSwift - - web3.swift - - XMTP (from `../`) - -SPEC REPOS: - trunk: - - BigInt - - Connect-Swift - - CryptoSwift - - GenericJSON - - GzipSwift - - KeychainAccess - - Logging - - secp256k1.swift - - SwiftProtobuf - - WalletConnectSwift - - web3.swift - - XMTPRust - -EXTERNAL SOURCES: - XMTP: - :path: "../" - -SPEC CHECKSUMS: - BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 - Connect-Swift: a75380c30c1341e483012444044105ff49b6093a - CryptoSwift: d3d18dc357932f7e6d580689e065cf1f176007c1 - GenericJSON: 79a840eeb77030962e8cf02a62d36bd413b67626 - GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa - KeychainAccess: c0c4f7f38f6fc7bbe58f5702e25f7bd2f65abf51 - Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 - secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 - SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7 - WalletConnectSwift: 6309bf3011b0b30e3e9d1e7449535302a9240f71 - web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 21d0ab77de34cd2ec2310d52f568f9752f2cd22c - XMTPRust: 10f79ec17747b15d3c626984f433b4f5ce948fff - -PODFILE CHECKSUM: b08ce1433b369fe0cf978eda8c1642c21fe389d6 +PODFILE CHECKSUM: e82385142d41677b470dd3362d25b239b9c3621c COCOAPODS: 1.12.0 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index 714ca912..6d18a82a 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -241,7 +241,6 @@ A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, A65F0701297B5BCC00C3C76E /* Embed Foundation Extensions */, - 0B299A73F511D2C1FC8A9615 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -341,23 +340,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0B299A73F511D2C1FC8A9615 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 312007D7F759D2B7DA4EB709 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; From 58e7c3f3f829e2b361e45391bb267cdb66f3e705 Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 16:55:38 -0700 Subject: [PATCH 44/47] fix: attempt to revert example app to main --- .../XMTPiOSExample.xcodeproj/project.pbxproj | 170 ++++++------------ .../xcshareddata/swiftpm/Package.resolved | 85 +++++---- 2 files changed, 97 insertions(+), 158 deletions(-) diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index 6d18a82a..b6e0eadf 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */ = {isa = PBXBuildFile; productRef = 6AEE396D29F330CD0027B657 /* secp256k1 */; }; A60FC8BF293AD054001697E3 /* MessageComposerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8BE293AD054001697E3 /* MessageComposerView.swift */; }; A60FC8C1293AD171001697E3 /* ConversationDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */; }; A60FC8C3293AD18A001697E3 /* PreviewClientProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */; }; @@ -17,24 +18,22 @@ A6557A312941166E00CC4C7B /* MessageCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6557A302941166E00CC4C7B /* MessageCellView.swift */; }; A6557A3329411F4F00CC4C7B /* NewConversationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6557A3229411F4F00CC4C7B /* NewConversationView.swift */; }; A65F0704297B5D4E00C3C76E /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; - A678243129F8660F00D30FF7 /* WalletConnectSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A678243029F8660F00D30FF7 /* WalletConnectSwift */; }; - A678243429F8661F00D30FF7 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A678243329F8661F00D30FF7 /* KeychainAccess */; }; - A678243729F8666F00D30FF7 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A678243629F8666F00D30FF7 /* XMTP */; }; - A678243929F8667A00D30FF7 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A678243829F8667A00D30FF7 /* KeychainAccess */; }; - A678243B29F8669600D30FF7 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A678243A29F8669600D30FF7 /* XMTP */; }; + A65F0707297B5E7600C3C76E /* WalletConnectSwift in Frameworks */ = {isa = PBXBuildFile; productRef = A65F0706297B5E7600C3C76E /* WalletConnectSwift */; }; + A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A65F0709297B5E8600C3C76E /* KeychainAccess */; }; A67CCEC129355B4B00131F5C /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A67CCEC029355B4B00131F5C /* AccountManager.swift */; }; A683860C293EA862006336FF /* MessageListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A683860B293EA862006336FF /* MessageListView.swift */; }; A687810729679BC700042FAB /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810629679BC700042FAB /* Account.swift */; }; A687810C29679BFC00042FAB /* WalletConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810B29679BFC00042FAB /* WalletConnection.swift */; }; A687810E29679C0D00042FAB /* WalletConnectionMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = A687810D29679C0D00042FAB /* WalletConnectionMethod.swift */; }; + A69F33C6292DC992005A5556 /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A69F33C5292DC992005A5556 /* XMTP */; }; A69F33CA292DD557005A5556 /* LoggedInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A69F33C9292DD557005A5556 /* LoggedInView.swift */; }; A69F33CC292DD568005A5556 /* QRCodeSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A69F33CB292DD568005A5556 /* QRCodeSheetView.swift */; }; A6AE5187297B61AE006FDD0F /* NotificationService.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = A6AE5180297B61AE006FDD0F /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; A6AE518E297B6210006FDD0F /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AE518C297B6210006FDD0F /* NotificationService.swift */; }; + A6AE5191297B625F006FDD0F /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A6AE5190297B625F006FDD0F /* XMTP */; }; A6AE5192297B6270006FDD0F /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F0703297B5D4E00C3C76E /* Persistence.swift */; }; + A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A6AE5193297B62C8006FDD0F /* KeychainAccess */; }; A6D192D0293A7B97006B49F2 /* ConversationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D192CF293A7B97006B49F2 /* ConversationListView.swift */; }; - BE941824EC1DA5A7E1ED4B38 /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */; }; - F72E430B9719F31B6C1C4E10 /* Pods_XMTPiOSExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -62,12 +61,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.debug.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.debug.xcconfig"; sourceTree = ""; }; - 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = ""; }; - 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = ""; }; - 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMTPiOSExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.release.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.release.xcconfig"; sourceTree = ""; }; A60FC8BE293AD054001697E3 /* MessageComposerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView.swift; sourceTree = ""; }; A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationDetailView.swift; sourceTree = ""; }; A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewClientProvider.swift; sourceTree = ""; }; @@ -80,18 +73,17 @@ A6557A302941166E00CC4C7B /* MessageCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCellView.swift; sourceTree = ""; }; A6557A3229411F4F00CC4C7B /* NewConversationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationView.swift; sourceTree = ""; }; A65F0703297B5D4E00C3C76E /* Persistence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; - A678243529F8662800D30FF7 /* xmtp-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "xmtp-ios"; path = ..; sourceTree = ""; }; A67CCEC029355B4B00131F5C /* AccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManager.swift; sourceTree = ""; }; A683860B293EA862006336FF /* MessageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListView.swift; sourceTree = ""; }; A687810629679BC700042FAB /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; A687810B29679BFC00042FAB /* WalletConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletConnection.swift; sourceTree = ""; }; A687810D29679C0D00042FAB /* WalletConnectionMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletConnectionMethod.swift; sourceTree = ""; }; + A69F33C7292DD3A9005A5556 /* xmtp-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "xmtp-ios"; path = ..; sourceTree = ""; }; A69F33C9292DD557005A5556 /* LoggedInView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggedInView.swift; sourceTree = ""; }; A69F33CB292DD568005A5556 /* QRCodeSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeSheetView.swift; sourceTree = ""; }; A6AE5180297B61AE006FDD0F /* NotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A6AE518B297B61C8006FDD0F /* NotificationService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationService.entitlements; sourceTree = ""; }; A6AE518C297B6210006FDD0F /* NotificationService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; - A6CB98CB29F85D9200F2DC58 /* XMTP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = XMTP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A6D192CF293A7B97006B49F2 /* ConversationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationListView.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -100,10 +92,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A678243B29F8669600D30FF7 /* XMTP in Frameworks */, - A678243429F8661F00D30FF7 /* KeychainAccess in Frameworks */, - A678243129F8660F00D30FF7 /* WalletConnectSwift in Frameworks */, - F72E430B9719F31B6C1C4E10 /* Pods_XMTPiOSExample.framework in Frameworks */, + A65F0707297B5E7600C3C76E /* WalletConnectSwift in Frameworks */, + 6AEE396E29F330CD0027B657 /* secp256k1 in Frameworks */, + A69F33C6292DC992005A5556 /* XMTP in Frameworks */, + A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -111,35 +103,22 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A678243929F8667A00D30FF7 /* KeychainAccess in Frameworks */, - A678243729F8666F00D30FF7 /* XMTP in Frameworks */, - BE941824EC1DA5A7E1ED4B38 /* Pods_NotificationService.framework in Frameworks */, + A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */, + A6AE5191297B625F006FDD0F /* XMTP in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 3F738A9EAAA632479874E954 /* Pods */ = { - isa = PBXGroup; - children = ( - 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */, - 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */, - 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */, - 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */, - ); - path = Pods; - sourceTree = ""; - }; A6281986292DC825004B9117 = { isa = PBXGroup; children = ( - A6CB98C829F85CE600F2DC58 /* Packages */, + A69F33C7292DD3A9005A5556 /* xmtp-ios */, A6281991292DC825004B9117 /* XMTPiOSExample */, A6AE5181297B61AE006FDD0F /* NotificationService */, A6281990292DC825004B9117 /* Products */, A69F33C4292DC992005A5556 /* Frameworks */, - 3F738A9EAAA632479874E954 /* Pods */, ); sourceTree = ""; }; @@ -189,9 +168,6 @@ A69F33C4292DC992005A5556 /* Frameworks */ = { isa = PBXGroup; children = ( - A6CB98CB29F85D9200F2DC58 /* XMTP.framework */, - 3B6B2CD0D9BFE5805FD75F1B /* Pods_NotificationService.framework */, - 714523F2DE15A728DCD1342D /* Pods_XMTPiOSExample.framework */, ); name = Frameworks; sourceTree = ""; @@ -221,14 +197,6 @@ path = NotificationService; sourceTree = ""; }; - A6CB98C829F85CE600F2DC58 /* Packages */ = { - isa = PBXGroup; - children = ( - A678243529F8662800D30FF7 /* xmtp-ios */, - ); - name = Packages; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -236,7 +204,6 @@ isa = PBXNativeTarget; buildConfigurationList = A628199E292DC826004B9117 /* Build configuration list for PBXNativeTarget "XMTPiOSExample" */; buildPhases = ( - 8F079FC76F159362232F01B5 /* [CP] Check Pods Manifest.lock */, A628198B292DC825004B9117 /* Sources */, A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, @@ -249,9 +216,10 @@ ); name = XMTPiOSExample; packageProductDependencies = ( - A678243029F8660F00D30FF7 /* WalletConnectSwift */, - A678243329F8661F00D30FF7 /* KeychainAccess */, - A678243A29F8669600D30FF7 /* XMTP */, + A69F33C5292DC992005A5556 /* XMTP */, + A65F0706297B5E7600C3C76E /* WalletConnectSwift */, + A65F0709297B5E8600C3C76E /* KeychainAccess */, + 6AEE396D29F330CD0027B657 /* secp256k1 */, ); productName = XMTPiOSExample; productReference = A628198F292DC825004B9117 /* XMTPiOSExample.app */; @@ -261,7 +229,6 @@ isa = PBXNativeTarget; buildConfigurationList = A6AE5188297B61AE006FDD0F /* Build configuration list for PBXNativeTarget "NotificationService" */; buildPhases = ( - 312007D7F759D2B7DA4EB709 /* [CP] Check Pods Manifest.lock */, A6AE517C297B61AE006FDD0F /* Sources */, A6AE517D297B61AE006FDD0F /* Frameworks */, A6AE517E297B61AE006FDD0F /* Resources */, @@ -272,8 +239,8 @@ ); name = NotificationService; packageProductDependencies = ( - A678243629F8666F00D30FF7 /* XMTP */, - A678243829F8667A00D30FF7 /* KeychainAccess */, + A6AE5190297B625F006FDD0F /* XMTP */, + A6AE5193297B62C8006FDD0F /* KeychainAccess */, ); productName = NotificationService; productReference = A6AE5180297B61AE006FDD0F /* NotificationService.appex */; @@ -307,8 +274,9 @@ ); mainGroup = A6281986292DC825004B9117; packageReferences = ( - A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */, - A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */, + A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */, + A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */, + 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */, ); productRefGroup = A6281990292DC825004B9117 /* Products */; projectDirPath = ""; @@ -339,53 +307,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 312007D7F759D2B7DA4EB709 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - 8F079FC76F159362232F01B5 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-XMTPiOSExample-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ A628198B292DC825004B9117 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -541,7 +462,6 @@ }; A628199F292DC826004B9117 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 26935F0C8B18F5FBC9FAF3A9 /* Pods-XMTPiOSExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -582,7 +502,6 @@ }; A62819A0292DC826004B9117 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 84D6E12168D73497F2E0F6E3 /* Pods-XMTPiOSExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -622,7 +541,6 @@ }; A6AE5189297B61AE006FDD0F /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3AE2571C02A5EC2D3BE73E10 /* Pods-NotificationService.debug.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -651,7 +569,6 @@ }; A6AE518A297B61AE006FDD0F /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 67E3F3B7A7EDC1AF97AC0439 /* Pods-NotificationService.release.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -712,15 +629,23 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */ = { + 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/GigaBitcoin/secp256k1.swift.git"; + requirement = { + kind = exactVersion; + version = 0.10.0; + }; + }; + A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/WalletConnect/WalletConnectSwift"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.0.0; + branch = master; + kind = branch; }; }; - A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { + A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess"; requirement = { @@ -731,28 +656,33 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - A678243029F8660F00D30FF7 /* WalletConnectSwift */ = { + 6AEE396D29F330CD0027B657 /* secp256k1 */ = { + isa = XCSwiftPackageProductDependency; + package = 6AEE396C29F330CD0027B657 /* XCRemoteSwiftPackageReference "secp256k1.swift" */; + productName = secp256k1; + }; + A65F0706297B5E7600C3C76E /* WalletConnectSwift */ = { isa = XCSwiftPackageProductDependency; - package = A678242F29F8660F00D30FF7 /* XCRemoteSwiftPackageReference "WalletConnectSwift" */; + package = A65F0705297B5E7500C3C76E /* XCRemoteSwiftPackageReference "WalletConnectSwift" */; productName = WalletConnectSwift; }; - A678243329F8661F00D30FF7 /* KeychainAccess */ = { + A65F0709297B5E8600C3C76E /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; - package = A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */; + package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; - A678243629F8666F00D30FF7 /* XMTP */ = { + A69F33C5292DC992005A5556 /* XMTP */ = { isa = XCSwiftPackageProductDependency; productName = XMTP; }; - A678243829F8667A00D30FF7 /* KeychainAccess */ = { + A6AE5190297B625F006FDD0F /* XMTP */ = { isa = XCSwiftPackageProductDependency; - package = A678243229F8661F00D30FF7 /* XCRemoteSwiftPackageReference "KeychainAccess" */; - productName = KeychainAccess; + productName = XMTP; }; - A678243A29F8669600D30FF7 /* XMTP */ = { + A6AE5193297B62C8006FDD0F /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; - productName = XMTP; + package = A65F0708297B5E8600C3C76E /* XCRemoteSwiftPackageReference "KeychainAccess" */; + productName = KeychainAccess; }; /* End XCSwiftPackageProductDependency section */ }; diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 628d4391..7ebf09d3 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,14 +14,14 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/bufbuild/connect-swift", "state" : { - "revision" : "b3ed034307b850d5dc4c6d14dd92070041acbdad", - "version" : "0.5.0" + "revision" : "6f5afc57f44a3ed15b9a01381ce73f84d15e43db", + "version" : "0.3.0" } }, { "identity" : "cryptoswift", "kind" : "remoteSourceControl", - "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "location" : "https://github.com/krzyzanowskim/CryptoSwift", "state" : { "revision" : "039f56c5d7960f277087a0be51f5eb04ed0ec073", "version" : "1.5.1" @@ -30,12 +30,21 @@ { "identity" : "generic-json-swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/iwill/generic-json-swift", + "location" : "https://github.com/zoul/generic-json-swift", "state" : { "revision" : "0a06575f4038b504e78ac330913d920f1630f510", "version" : "2.0.2" } }, + { + "identity" : "grpc-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/grpc/grpc-swift", + "state" : { + "revision" : "3e17f2b847da39b50329b7a11c5ad23453190e8b", + "version" : "1.13.0" + } + }, { "identity" : "gzipswift", "kind" : "remoteSourceControl", @@ -51,7 +60,16 @@ "location" : "https://github.com/kishikawakatsumi/KeychainAccess", "state" : { "branch" : "master", - "revision" : "ecb18d8ce4d88277cc4fb103973352d91e18c535" + "revision" : "6299daec1d74be12164fec090faf9ed14d0da9d6" + } + }, + { + "identity" : "proto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/proto", + "state" : { + "branch" : "main", + "revision" : "6a8905a8b260406698433d210c25c4397a93cef1" } }, { @@ -68,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-atomics.git", "state" : { - "revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10", - "version" : "1.1.0" + "revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", + "version" : "1.0.2" } }, { @@ -77,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version" : "1.0.4" + "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", + "version" : "1.0.3" } }, { @@ -104,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", - "version" : "1.5.2" + "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", + "version" : "1.4.4" } }, { @@ -113,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "546eaa261ec5028b9cc5c7fa883fba9dd5881a3b", - "version" : "2.52.0" + "revision" : "e855380cb5234e96b760d93e0bfdc403e381e928", + "version" : "2.45.0" } }, { @@ -122,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-extras.git", "state" : { - "revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997", - "version" : "1.19.0" + "revision" : "91dd2d61fb772e1311bb5f13b59266b579d77e42", + "version" : "1.15.0" } }, { @@ -131,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-http2.git", "state" : { - "revision" : "6d021a48483dbb273a9be43f65234bdc9185b364", - "version" : "1.26.0" + "revision" : "d6656967f33ed8b368b38e4b198631fc7c484a40", + "version" : "1.23.1" } }, { @@ -140,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "e866a626e105042a6a72a870c88b4c531ba05f83", - "version" : "2.24.0" + "revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", + "version" : "2.23.0" } }, { @@ -149,8 +167,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-transport-services.git", "state" : { - "revision" : "41f4098903878418537020075a4d8a6e20a0b182", - "version" : "1.17.0" + "revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", + "version" : "1.15.0" } }, { @@ -158,8 +176,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "0af9125c4eae12a4973fb66574c53a54962a9e1e", - "version" : "1.21.0" + "revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8", + "version" : "1.20.3" } }, { @@ -167,8 +185,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwift", "state" : { - "revision" : "e0bbfd16d5c54a7aa7e316956d765399c6332fa2", - "version" : "1.7.0" + "branch" : "master", + "revision" : "9e4dfba34fb35336fd5da551285d7986ff536cb8" } }, { @@ -176,8 +194,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/argentlabs/web3.swift", "state" : { - "revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db", - "version" : "1.6.0" + "revision" : "9da09d639d4e5d06eb59518e636b3ae957e8e9cd", + "version" : "1.3.0" } }, { @@ -185,17 +203,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/websocket-kit.git", "state" : { - "revision" : "2166cbe932b29b6419f9cd751e8b27c647e1238e", - "version" : "2.8.0" - } - }, - { - "identity" : "xmtp-rust-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/xmtp-rust-swift", - "state" : { - "revision" : "eccfc16bb8f866857ecbb1604c1dab855b1960f7", - "version" : "0.2.2-beta0" + "revision" : "2d9d2188a08eef4a869d368daab21b3c08510991", + "version" : "2.6.1" } } ], From 4bbe200d717a6c17ac2874fa823652bdd706da0f Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 17:42:14 -0700 Subject: [PATCH 45/47] fix: updated Package.resolved --- .../xcshareddata/swiftpm/Package.resolved | 47 ++++--------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 7ebf09d3..77aa8e91 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -21,7 +21,7 @@ { "identity" : "cryptoswift", "kind" : "remoteSourceControl", - "location" : "https://github.com/krzyzanowskim/CryptoSwift", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", "state" : { "revision" : "039f56c5d7960f277087a0be51f5eb04ed0ec073", "version" : "1.5.1" @@ -36,15 +36,6 @@ "version" : "2.0.2" } }, - { - "identity" : "grpc-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/grpc/grpc-swift", - "state" : { - "revision" : "3e17f2b847da39b50329b7a11c5ad23453190e8b", - "version" : "1.13.0" - } - }, { "identity" : "gzipswift", "kind" : "remoteSourceControl", @@ -63,15 +54,6 @@ "revision" : "6299daec1d74be12164fec090faf9ed14d0da9d6" } }, - { - "identity" : "proto", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/proto", - "state" : { - "branch" : "main", - "revision" : "6a8905a8b260406698433d210c25c4397a93cef1" - } - }, { "identity" : "secp256k1.swift", "kind" : "remoteSourceControl", @@ -135,24 +117,6 @@ "version" : "2.45.0" } }, - { - "identity" : "swift-nio-extras", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-extras.git", - "state" : { - "revision" : "91dd2d61fb772e1311bb5f13b59266b579d77e42", - "version" : "1.15.0" - } - }, - { - "identity" : "swift-nio-http2", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-http2.git", - "state" : { - "revision" : "d6656967f33ed8b368b38e4b198631fc7c484a40", - "version" : "1.23.1" - } - }, { "identity" : "swift-nio-ssl", "kind" : "remoteSourceControl", @@ -206,6 +170,15 @@ "revision" : "2d9d2188a08eef4a869d368daab21b3c08510991", "version" : "2.6.1" } + }, + { + "identity" : "xmtp-rust-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/xmtp-rust-swift", + "state" : { + "revision" : "eccfc16bb8f866857ecbb1604c1dab855b1960f7", + "version" : "0.2.2-beta0" + } } ], "version" : 2 From 1871cde20e2312df9a3381f4c29e0d88a139948e Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 22:45:55 -0700 Subject: [PATCH 46/47] fix: delete unnecessary new schemes that are missing from main --- .../xcshareddata/xcschemes/Example.xcscheme | 77 ------------------- .../xcshareddata/xcschemes/XMTP.xcscheme | 66 ---------------- 2 files changed, 143 deletions(-) delete mode 100644 XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/Example.xcscheme delete mode 100644 XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/Example.xcscheme b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/Example.xcscheme deleted file mode 100644 index 1d7f092b..00000000 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme b/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme deleted file mode 100644 index e97a6a6f..00000000 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/xcshareddata/xcschemes/XMTP.xcscheme +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - From 322fc06ecc022820cefc3c812a23eb91c181d95a Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Wed, 17 May 2023 22:55:10 -0700 Subject: [PATCH 47/47] test: pagination tests should be local node only --- Tests/XMTPTests/PaginationTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/XMTPTests/PaginationTests.swift b/Tests/XMTPTests/PaginationTests.swift index dd8de35e..f36b440c 100644 --- a/Tests/XMTPTests/PaginationTests.swift +++ b/Tests/XMTPTests/PaginationTests.swift @@ -20,6 +20,8 @@ class PaginationTests: XCTestCase { } func testLongConvo() async throws { + throw XCTSkip("integration only (requires local node)") + let alice = try PrivateKey.generate() let bob = try PrivateKey.generate() @@ -70,6 +72,8 @@ class PaginationTests: XCTestCase { } func testCanStreamConversationsV2() async throws { + throw XCTSkip("integration only (requires local node)") + let alice = try PrivateKey.generate() let bob = try PrivateKey.generate()