From 2ad3394d3ba25697e5ad6b048ac44b946560e2ec Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Mon, 22 Jan 2024 09:41:31 -0800 Subject: [PATCH] Replace xmtp-rust-swift with libxmtp-swift (#217) * rename module from XMTP to XMTPiOS * more renaming * remove xmtp-rust-swift references * Use new V2 client from libxmtp * building clean * remove PublishResponse * Use actual dep instead of local * Update XMTP.podspec Co-authored-by: Naomi Plasterer * implement streaming and pagination * Update XMTP.podspec Co-authored-by: Cameron Voell * disable file_length linter --------- Co-authored-by: Naomi Plasterer Co-authored-by: Cameron Voell --- .swiftlint.yml | 1 + Package.resolved | 87 +++----- Package.swift | 17 +- README.md | 6 +- Sources/XMTP/ApiClient.swift | 180 ---------------- Sources/XMTP/Extensions/RustVec.swift | 19 -- Sources/XMTPTestHelpers/TestHelpers.swift | 48 +++-- Sources/XMTPiOS/ApiClient.swift | 173 ++++++++++++++++ .../AuthorizedIdentity.swift | 0 Sources/{XMTP => XMTPiOS}/Client.swift | 96 ++++----- Sources/{XMTP => XMTPiOS}/CodecRegistry.swift | 0 .../Codecs/AttachmentCodec.swift | 0 .../{XMTP => XMTPiOS}/Codecs/Composite.swift | 0 .../Codecs/ContentCodec.swift | 0 .../Codecs/ContentTypeID.swift | 0 .../Codecs/DecodedComposite.swift | 0 .../Codecs/EncryptedEncodedContent.swift | 0 .../Codecs/ReactionCodec.swift | 0 .../Codecs/ReadReceiptCodec.swift | 0 .../Codecs/RemoteAttachmentCodec.swift | 0 .../{XMTP => XMTPiOS}/Codecs/ReplyCodec.swift | 0 .../{XMTP => XMTPiOS}/Codecs/TextCodec.swift | 0 Sources/{XMTP => XMTPiOS}/Constants.swift | 0 Sources/{XMTP => XMTPiOS}/Contacts.swift | 135 ++++++------ Sources/{XMTP => XMTPiOS}/Conversation.swift | 0 .../ConversationExport.swift | 0 .../{XMTP => XMTPiOS}/ConversationV1.swift | 0 .../{XMTP => XMTPiOS}/ConversationV2.swift | 0 Sources/{XMTP => XMTPiOS}/Conversations.swift | 0 Sources/{XMTP => XMTPiOS}/Crypto.swift | 0 .../{XMTP => XMTPiOS}/DecodedMessage.swift | 0 .../EncodedContentCompression.swift | 0 .../{XMTP => XMTPiOS}/Extensions/Data.swift | 6 +- .../{XMTP => XMTPiOS}/Extensions/Date.swift | 0 Sources/XMTPiOS/Extensions/Ffi.swift | 194 ++++++++++++++++++ Sources/{XMTP => XMTPiOS}/KeyUtil.swift | 10 +- .../{XMTP => XMTPiOS}/Messages/AuthData.swift | 0 .../Messages/ContactBundle.swift | 2 +- .../Messages/DecryptedMessage.swift | 0 .../Messages/EncryptedPrivateKeyBundle.swift | 0 .../{XMTP => XMTPiOS}/Messages/Envelope.swift | 0 .../Messages/Invitation.swift | 0 .../{XMTP => XMTPiOS}/Messages/Message.swift | 0 .../Messages/MessageHeaderV1.swift | 0 .../Messages/MessageHeaderV2.swift | 0 .../Messages/MessageV1.swift | 0 .../Messages/MessageV2.swift | 2 +- .../Messages/PagingInfo.swift | 0 .../Messages/PrivateKey.swift | 2 +- .../Messages/PrivateKeyBundle.swift | 0 .../Messages/PrivateKeyBundleV1.swift | 2 +- .../Messages/PrivateKeyBundleV2.swift | 4 +- .../Messages/PublicKey.swift | 2 +- .../Messages/PublicKeyBundle.swift | 0 .../Messages/SealedInvitation.swift | 0 .../Messages/SealedInvitationHeaderV1.swift | 0 .../Messages/SealedInvitationV1.swift | 0 .../Messages/Signature.swift | 9 +- .../Messages/SignedContent.swift | 0 .../Messages/SignedPrivateKey.swift | 0 .../Messages/SignedPublicKey.swift | 2 +- .../Messages/SignedPublicKeyBundle.swift | 0 .../{XMTP => XMTPiOS}/Messages/Token.swift | 0 .../{XMTP => XMTPiOS}/Messages/Topic.swift | 0 .../Messages/UnsignedPublicKey.swift | 0 .../{XMTP => XMTPiOS}/PreparedMessage.swift | 0 .../Proto/keystore_api/v1/keystore.pb.swift | 0 .../Proto/message_api/v1/authn.pb.swift | 0 .../Proto/message_api/v1/message_api.pb.swift | 0 .../message_contents/ciphertext.pb.swift | 0 .../Proto/message_contents/composite.pb.swift | 0 .../Proto/message_contents/contact.pb.swift | 0 .../Proto/message_contents/content.pb.swift | 0 .../conversation_reference.pb.swift | 0 .../Proto/message_contents/ecies.pb.swift | 0 .../message_contents/invitation.pb.swift | 0 .../Proto/message_contents/message.pb.swift | 0 .../message_contents/private_key.pb.swift | 0 .../private_preferences.pb.swift | 0 .../message_contents/public_key.pb.swift | 0 .../Proto/message_contents/signature.pb.swift | 0 .../message_contents/signed_payload.pb.swift | 0 Sources/{XMTP => XMTPiOS}/Push/XMTPPush.swift | 0 .../Push/service.connect.swift | 0 .../{XMTP => XMTPiOS}/Push/service.pb.swift | 0 Sources/{XMTP => XMTPiOS}/SendOptions.swift | 0 Sources/{XMTP => XMTPiOS}/SigningKey.swift | 2 +- Sources/{XMTP => XMTPiOS}/Util.swift | 0 .../{XMTP => XMTPiOS}/XMTPEnvironment.swift | 2 +- Tests/XMTPTests/AttachmentTests.swift | 2 +- Tests/XMTPTests/AuthenticationTests.swift | 2 +- Tests/XMTPTests/ClientTests.swift | 4 +- Tests/XMTPTests/CodecTests.swift | 8 +- Tests/XMTPTests/ContactTests.swift | 2 +- Tests/XMTPTests/ContactsTests.swift | 2 +- Tests/XMTPTests/ConversationTests.swift | 2 +- Tests/XMTPTests/ConversationsTest.swift | 2 +- Tests/XMTPTests/CryptoTests.swift | 2 +- Tests/XMTPTests/IntegrationTests.swift | 24 +-- Tests/XMTPTests/InvitationTests.swift | 2 +- Tests/XMTPTests/MessageTests.swift | 4 +- Tests/XMTPTests/PaginationTests.swift | 4 +- Tests/XMTPTests/PrivateKeyBundleTests.swift | 2 +- Tests/XMTPTests/ReactionTests.swift | 2 +- Tests/XMTPTests/ReadReceiptTests.swift | 2 +- Tests/XMTPTests/RemoteAttachmentTest.swift | 2 +- Tests/XMTPTests/ReplyTests.swift | 2 +- Tests/XMTPTests/SignatureTests.swift | 2 +- XMTP.podspec | 2 +- .../NotificationService.swift | 2 +- .../XMTPiOSExample/Account/Account.swift | 2 +- .../Account/AccountManager.swift | 2 +- .../Account/WalletConnection.swift | 2 +- .../XMTPiOSExample/ContentView.swift | 2 +- .../XMTPiOSExample/Persistence.swift | 2 +- .../Views/ConversationDetailView.swift | 2 +- .../Views/ConversationListView.swift | 2 +- .../XMTPiOSExample/Views/LoggedInView.swift | 2 +- .../XMTPiOSExample/Views/LoginView.swift | 2 +- .../Views/MessageCellView.swift | 2 +- .../Views/MessageComposerView.swift | 2 +- .../Views/MessageListView.swift | 2 +- .../Views/NewConversationView.swift | 2 +- .../Views/PreviewClientProvider.swift | 2 +- .../XMTPiOSExample/XMTPiOSExampleApp.swift | 2 +- 125 files changed, 621 insertions(+), 486 deletions(-) delete mode 100644 Sources/XMTP/ApiClient.swift delete mode 100644 Sources/XMTP/Extensions/RustVec.swift create mode 100644 Sources/XMTPiOS/ApiClient.swift rename Sources/{XMTP => XMTPiOS}/AuthorizedIdentity.swift (100%) rename Sources/{XMTP => XMTPiOS}/Client.swift (82%) rename Sources/{XMTP => XMTPiOS}/CodecRegistry.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/AttachmentCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/Composite.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/ContentCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/ContentTypeID.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/DecodedComposite.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/EncryptedEncodedContent.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/ReactionCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/ReadReceiptCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/RemoteAttachmentCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/ReplyCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Codecs/TextCodec.swift (100%) rename Sources/{XMTP => XMTPiOS}/Constants.swift (100%) rename Sources/{XMTP => XMTPiOS}/Contacts.swift (56%) rename Sources/{XMTP => XMTPiOS}/Conversation.swift (100%) rename Sources/{XMTP => XMTPiOS}/ConversationExport.swift (100%) rename Sources/{XMTP => XMTPiOS}/ConversationV1.swift (100%) rename Sources/{XMTP => XMTPiOS}/ConversationV2.swift (100%) rename Sources/{XMTP => XMTPiOS}/Conversations.swift (100%) rename Sources/{XMTP => XMTPiOS}/Crypto.swift (100%) rename Sources/{XMTP => XMTPiOS}/DecodedMessage.swift (100%) rename Sources/{XMTP => XMTPiOS}/EncodedContentCompression.swift (100%) rename Sources/{XMTP => XMTPiOS}/Extensions/Data.swift (75%) rename Sources/{XMTP => XMTPiOS}/Extensions/Date.swift (100%) create mode 100644 Sources/XMTPiOS/Extensions/Ffi.swift rename Sources/{XMTP => XMTPiOS}/KeyUtil.swift (91%) rename Sources/{XMTP => XMTPiOS}/Messages/AuthData.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/ContactBundle.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/DecryptedMessage.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/EncryptedPrivateKeyBundle.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Envelope.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Invitation.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Message.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/MessageHeaderV1.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/MessageHeaderV2.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/MessageV1.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/MessageV2.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/PagingInfo.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/PrivateKey.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/PrivateKeyBundle.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/PrivateKeyBundleV1.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/PrivateKeyBundleV2.swift (93%) rename Sources/{XMTP => XMTPiOS}/Messages/PublicKey.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/PublicKeyBundle.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/SealedInvitation.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/SealedInvitationHeaderV1.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/SealedInvitationV1.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Signature.swift (92%) rename Sources/{XMTP => XMTPiOS}/Messages/SignedContent.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/SignedPrivateKey.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/SignedPublicKey.swift (99%) rename Sources/{XMTP => XMTPiOS}/Messages/SignedPublicKeyBundle.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Token.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/Topic.swift (100%) rename Sources/{XMTP => XMTPiOS}/Messages/UnsignedPublicKey.swift (100%) rename Sources/{XMTP => XMTPiOS}/PreparedMessage.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/keystore_api/v1/keystore.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_api/v1/authn.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_api/v1/message_api.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/ciphertext.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/composite.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/contact.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/content.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/conversation_reference.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/ecies.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/invitation.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/message.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/private_key.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/private_preferences.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/public_key.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/signature.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Proto/message_contents/signed_payload.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/Push/XMTPPush.swift (100%) rename Sources/{XMTP => XMTPiOS}/Push/service.connect.swift (100%) rename Sources/{XMTP => XMTPiOS}/Push/service.pb.swift (100%) rename Sources/{XMTP => XMTPiOS}/SendOptions.swift (100%) rename Sources/{XMTP => XMTPiOS}/SigningKey.swift (99%) rename Sources/{XMTP => XMTPiOS}/Util.swift (100%) rename Sources/{XMTP => XMTPiOS}/XMTPEnvironment.swift (83%) diff --git a/.swiftlint.yml b/.swiftlint.yml index 26470bdb..e9f40901 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -10,6 +10,7 @@ disabled_rules: # rule identifiers turned on by default to exclude from running - opening_brace - nesting - type_body_length + - file_length opt_in_rules: - force_unwrapping diff --git a/Package.resolved b/Package.resolved index 125cbf2d..f24dcde4 100644 --- a/Package.resolved +++ b/Package.resolved @@ -21,7 +21,7 @@ { "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" @@ -36,6 +36,15 @@ "version" : "5.2.0" } }, + { + "identity" : "libxmtp-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/libxmtp-swift", + "state" : { + "branch" : "60b99d0", + "revision" : "60b99d04f642a7e2b15156d818dabc4aab65b1c0" + } + }, { "identity" : "secp256k1.swift", "kind" : "remoteSourceControl", @@ -50,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-atomics.git", "state" : { - "revision" : "cd142fd2f64be2100422d658e7411e39489da985", - "version" : "1.2.0" + "revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe", + "version" : "1.0.2" } }, { @@ -59,8 +68,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307", - "version" : "1.0.5" + "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", + "version" : "1.0.3" } }, { @@ -68,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-docc-plugin.git", "state" : { - "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", - "version" : "1.3.0" + "revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda", + "version" : "1.2.0" } }, { @@ -81,22 +90,13 @@ "version" : "1.0.0" } }, - { - "identity" : "swift-http-types", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-http-types", - "state" : { - "revision" : "1827dc94bdab2eb5f2fc804e9b0cb43574282566", - "version" : "1.0.2" - } - }, { "identity" : "swift-log", "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", - "version" : "1.5.3" + "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", + "version" : "1.4.4" } }, { @@ -104,26 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c", - "version" : "2.62.0" - } - }, - { - "identity" : "swift-nio-extras", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-extras.git", - "state" : { - "revision" : "798c962495593a23fdea0c0c63fd55571d8dff51", - "version" : "1.20.0" - } - }, - { - "identity" : "swift-nio-http2", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-http2.git", - "state" : { - "revision" : "3bd9004b9d685ed6b629760fc84903e48efec806", - "version" : "1.29.0" + "revision" : "edfceecba13d68c1c993382806e72f7e96feaa86", + "version" : "2.44.0" } }, { @@ -131,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9", - "version" : "2.25.0" + "revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", + "version" : "2.23.0" } }, { @@ -140,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-transport-services.git", "state" : { - "revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e", - "version" : "1.20.0" + "revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", + "version" : "1.15.0" } }, { @@ -149,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", "state" : { - "revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8", - "version" : "1.25.2" + "revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8", + "version" : "1.20.3" } }, { @@ -158,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/argentlabs/web3.swift", "state" : { - "revision" : "1e75f98a5738c470b23bbfffa9314e9f788df76b", - "version" : "1.6.1" + "revision" : "9da09d639d4e5d06eb59518e636b3ae957e8e9cd", + "version" : "1.3.0" } }, { @@ -167,17 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/websocket-kit.git", "state" : { - "revision" : "53fe0639a98903858d0196b699720decb42aee7b", - "version" : "2.14.0" - } - }, - { - "identity" : "xmtp-rust-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/xmtp/xmtp-rust-swift", - "state" : { - "branch" : "main", - "revision" : "e08af6942841054ae02a6fe01d90d18e76d5f248" + "revision" : "2d9d2188a08eef4a869d368daab21b3c08510991", + "version" : "2.6.1" } } ], diff --git a/Package.swift b/Package.swift index 52f0e5d2..be7444d8 100644 --- a/Package.swift +++ b/Package.swift @@ -4,13 +4,13 @@ import PackageDescription let package = Package( - name: "XMTP", + name: "XMTPiOS", platforms: [.iOS(.v14), .macOS(.v11)], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( - name: "XMTP", - targets: ["XMTP"] + name: "XMTPiOS", + targets: ["XMTPiOS"] ), .library( name: "XMTPTestHelpers", @@ -26,28 +26,29 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "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: "main"), + .package(url: "https://github.com/xmtp/libxmtp-swift", revision: "60b99d0"), +// .package(path: "../libxmtp-swift") ], 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", + name: "XMTPiOS", dependencies: [ .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"), + .product(name: "LibXMTP", package: "libxmtp-swift"), ] ), .target( name: "XMTPTestHelpers", - dependencies: ["XMTP"] + dependencies: ["XMTPiOS"] ), .testTarget( name: "XMTPTests", - dependencies: ["XMTP", "XMTPTestHelpers"] + dependencies: ["XMTPiOS", "XMTPTestHelpers"] ), ] ) diff --git a/README.md b/README.md index 0900249b..96a4391f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Use Xcode to add to the project (**File** > **Add Packages…**) or add this to The XMTP message API revolves around a message API client (client) that allows retrieving and sending messages to other XMTP network participants. A client must connect to a wallet app on startup. If this is the very first time the client is created, the client will generate a key bundle that is used to encrypt and authenticate messages. The key bundle persists encrypted in the network using an account signature. The public side of the key bundle is also regularly advertised on the network to allow parties to establish shared encryption keys. All of this happens transparently, without requiring any additional code. ```swift -import XMTP +import XMTPiOS // You'll want to replace this with a wallet from your application. let account = try PrivateKey.generate() @@ -69,7 +69,7 @@ A client is created with `Client.create(account: SigningKey) async throws -> Cli > The client connects to the XMTP `dev` environment by default. [Use `ClientOptions`](#configure-the-client) to change this and other parameters of the network connection. ```swift -import XMTP +import XMTPiOS // Create the client with a `SigningKey` from your app let client = try await Client.create(account: account, options: .init(api: .init(env: .production))) @@ -129,7 +129,7 @@ To learn more about using `AttachmentCodec` and `RemoteAttachmentCodec`, see [Ha Most of the time, when interacting with the network, you'll want to do it through `conversations`. Conversations are between two accounts. ```swift -import XMTP +import XMTPiOS // Create the client with a wallet from your app let client = try await Client.create(account: account) let conversations = try await client.conversations.list() diff --git a/Sources/XMTP/ApiClient.swift b/Sources/XMTP/ApiClient.swift deleted file mode 100644 index 3d2d335a..00000000 --- a/Sources/XMTP/ApiClient.swift +++ /dev/null @@ -1,180 +0,0 @@ -// -// ApiClient.swift -// -// -// Created by Pat Nakajima on 11/17/22. -// - -import Foundation -import XMTPRust -import XMTPRustSwift - -public typealias PublishRequest = Xmtp_MessageApi_V1_PublishRequest -public typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse -public typealias BatchQueryRequest = Xmtp_MessageApi_V1_BatchQueryRequest -public typealias BatchQueryResponse = Xmtp_MessageApi_V1_BatchQueryResponse -public typealias Cursor = Xmtp_MessageApi_V1_Cursor -public typealias QueryRequest = Xmtp_MessageApi_V1_QueryRequest -public typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse -public typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest - -public enum ApiClientError: Error { - case batchQueryError(String) - case queryError(String) - case publishError(String) - case subscribeError(String) -} - -protocol ApiClient: Sendable { - var environment: XMTPEnvironment { get } - init(environment: XMTPEnvironment, secure: Bool, rustClient: XMTPRust.RustClient, appVersion: String?) throws - func setAuthToken(_ token: String) - func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse - func query(topic: String, pagination: Pagination?, cursor: Xmtp_MessageApi_V1_Cursor?) async throws -> QueryResponse - func query(topic: Topic, pagination: Pagination?) async throws -> QueryResponse - func query(request: QueryRequest) async throws -> QueryResponse - func envelopes(topic: String, pagination: Pagination?) async throws -> [Envelope] - func publish(envelopes: [Envelope]) async throws -> PublishResponse - func publish(request: PublishRequest) async throws -> PublishResponse - func subscribe(topics: [String]) -> AsyncThrowingStream -} - -func makeQueryRequest(topic: String, pagination: Pagination? = nil, cursor: Cursor? = nil) -> QueryRequest { - return QueryRequest.with { - $0.contentTopics = [topic] - if let pagination { - $0.pagingInfo = pagination.pagingInfo - } - if let endAt = pagination?.before { - $0.endTimeNs = UInt64(endAt.millisecondsSinceEpoch) * 1_000_000 - $0.pagingInfo.direction = pagination?.direction ?? .descending - } - if let startAt = pagination?.after { - $0.startTimeNs = UInt64(startAt.millisecondsSinceEpoch) * 1_000_000 - $0.pagingInfo.direction = pagination?.direction ?? .descending - } - if let cursor { - $0.pagingInfo.cursor = cursor - } - } -} - -class GRPCApiClient: ApiClient { - let ClientVersionHeaderKey = "X-Client-Version" - let AppVersionHeaderKey = "X-App-Version" - - var environment: XMTPEnvironment - var authToken = "" - - var rustClient: XMTPRust.RustClient - - required init(environment: XMTPEnvironment, secure _: Bool = true, rustClient: XMTPRust.RustClient, appVersion: String? = nil) throws { - self.environment = environment - self.rustClient = rustClient - if let appVersion = appVersion { - rustClient.set_app_version(appVersion.intoRustString()) - } - } - - 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://production.xmtp.network:5556" - } - } - - func setAuthToken(_ token: String) { - authToken = token - } - - func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse { - do { - let req = RustVec(try request.serializedData()) - let res: RustVec = try await rustClient.batch_query(req) - return try BatchQueryResponse(serializedData: Data(res)) - } catch let error as RustString { - throw ApiClientError.batchQueryError(error.toString()) - } - } - - func query(request: QueryRequest) async throws -> QueryResponse { - do { - let req = RustVec(try request.serializedData()) - let res: RustVec = try await rustClient.query(req) - return try QueryResponse(serializedData: Data(res)) - } catch let error as RustString { - throw ApiClientError.queryError(error.toString()) - } - } - - func query(topic: String, pagination: Pagination? = nil, cursor: Cursor? = nil) async throws -> QueryResponse { - return try await query(request: makeQueryRequest(topic: topic, pagination: pagination, cursor: cursor)) - } - - func query(topic: Topic, pagination: Pagination? = nil) async throws -> QueryResponse { - return try await query(request: makeQueryRequest(topic: topic.description, pagination: pagination)) - } - - func envelopes(topic: String, pagination: Pagination? = nil) async throws -> [Envelope] { - var envelopes: [Envelope] = [] - var hasNextPage = true - var cursor: Xmtp_MessageApi_V1_Cursor? - - while hasNextPage { - let response = try await query(topic: topic, pagination: pagination, cursor: cursor) - - envelopes.append(contentsOf: response.envelopes) - - cursor = response.pagingInfo.cursor - hasNextPage = !response.envelopes.isEmpty && response.pagingInfo.hasCursor - - if let limit = pagination?.limit, envelopes.count >= limit { - envelopes = Array(envelopes.prefix(limit)) - break - } - } - - return envelopes - } - - func subscribe(topics: [String]) -> AsyncThrowingStream { - return AsyncThrowingStream { continuation in - Task { - let request = SubscribeRequest.with { $0.contentTopics = topics } - let req = RustVec(try request.serializedData()) - do { - let subscription = try await self.rustClient.subscribe(req) - // Run a continuous for loop polling and sleeping for a bit each loop. - while true { - let buf = try subscription.get_envelopes_as_query_response() - // Note: it uses QueryResponse as a convenient envelopes wrapper. - let res = try QueryResponse(serializedData: Data(buf)) - for envelope in res.envelopes { - continuation.yield(envelope) - } - try await Task.sleep(nanoseconds: 50_000_000) // 50ms - } - } catch let error as RustString { - throw ApiClientError.subscribeError(error.toString()) - } - } - } - } - - func publish(request: PublishRequest) async throws -> PublishResponse { - do { - let req = RustVec(try request.serializedData()) - let res: RustVec = try await rustClient.publish(authToken.intoRustString(), req) - return try PublishResponse(serializedData: Data(res)) - } catch let error as RustString { - throw ApiClientError.publishError(error.toString()) - } - } - - @discardableResult func publish(envelopes: [Envelope]) async throws -> PublishResponse { - return try await publish(request: PublishRequest.with { - $0.envelopes = envelopes - }) - } -} diff --git a/Sources/XMTP/Extensions/RustVec.swift b/Sources/XMTP/Extensions/RustVec.swift deleted file mode 100644 index f63d1f7d..00000000 --- a/Sources/XMTP/Extensions/RustVec.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// 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/XMTPTestHelpers/TestHelpers.swift b/Sources/XMTPTestHelpers/TestHelpers.swift index eb67dac6..9ef4a82e 100644 --- a/Sources/XMTPTestHelpers/TestHelpers.swift +++ b/Sources/XMTPTestHelpers/TestHelpers.swift @@ -8,8 +8,8 @@ #if canImport(XCTest) import Combine import XCTest -@testable import XMTP -import XMTPRust +@testable import XMTPiOS +import LibXMTP public struct TestConfig { static let TEST_SERVER_ENABLED = _env("TEST_SERVER_ENABLED") == "true" @@ -50,12 +50,12 @@ public struct FakeWallet: SigningKey { key.walletAddress } - public func sign(_ data: Data) async throws -> XMTP.Signature { + public func sign(_ data: Data) async throws -> XMTPiOS.Signature { let signature = try await key.sign(data) return signature } - public func sign(message: String) async throws -> XMTP.Signature { + public func sign(message: String) async throws -> XMTPiOS.Signature { let signature = try await key.sign(message: message) return signature } @@ -72,25 +72,25 @@ enum FakeApiClientError: String, Error { } class FakeStreamHolder: ObservableObject { - @Published var envelope: XMTP.Envelope? + @Published var envelope: XMTPiOS.Envelope? - func send(envelope: XMTP.Envelope) { + func send(envelope: XMTPiOS.Envelope) { self.envelope = envelope } } @available(iOS 15, *) public class FakeApiClient: ApiClient { - public func envelopes(topic: String, pagination: XMTP.Pagination?) async throws -> [XMTP.Envelope] { + public func envelopes(topic: String, pagination: XMTPiOS.Pagination?) async throws -> [XMTPiOS.Envelope] { try await query(topic: topic, pagination: pagination).envelopes } public var environment: XMTPEnvironment public var authToken: String = "" public var appVersion: String - private var responses: [String: [XMTP.Envelope]] = [:] + private var responses: [String: [XMTPiOS.Envelope]] = [:] private var stream = FakeStreamHolder() - public var published: [XMTP.Envelope] = [] + public var published: [XMTPiOS.Envelope] = [] var cancellable: AnyCancellable? var forbiddingQueries = false @@ -112,7 +112,7 @@ public class FakeApiClient: ApiClient { forbiddingQueries = false } - public func register(message: [XMTP.Envelope], for topic: Topic) { + public func register(message: [XMTPiOS.Envelope], for topic: Topic) { var responsesForTopic = responses[topic.description] ?? [] responsesForTopic.append(contentsOf: message) responses[topic.description] = responsesForTopic @@ -123,26 +123,26 @@ public class FakeApiClient: ApiClient { appVersion = "test/0.0.0" } - public func send(envelope: XMTP.Envelope) { + public func send(envelope: XMTPiOS.Envelope) { stream.send(envelope: envelope) } - public func findPublishedEnvelope(_ topic: Topic) -> XMTP.Envelope? { + public func findPublishedEnvelope(_ topic: Topic) -> XMTPiOS.Envelope? { return findPublishedEnvelope(topic.description) } - public func findPublishedEnvelope(_ topic: String) -> XMTP.Envelope? { + public func findPublishedEnvelope(_ topic: String) -> XMTPiOS.Envelope? { return published.reversed().first { $0.contentTopic == topic.description } } // MARK: ApiClient conformance - public required init(environment: XMTP.XMTPEnvironment, secure _: Bool, rustClient _: XMTPRust.RustClient, appVersion: String?) throws { + public required init(environment: XMTPiOS.XMTPEnvironment, secure _: Bool, rustClient _: LibXMTP.FfiV2ApiClient, appVersion: String?) throws { self.environment = environment self.appVersion = appVersion ?? "0.0.0" } - 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) { @@ -156,13 +156,13 @@ public class FakeApiClient: ApiClient { authToken = token } - public func query(topic: String, pagination: Pagination? = nil, cursor _: Xmtp_MessageApi_V1_Cursor? = nil) async throws -> XMTP.QueryResponse { + public func query(topic: String, pagination: Pagination? = nil, cursor _: Xmtp_MessageApi_V1_Cursor? = nil) async throws -> XMTPiOS.QueryResponse { if forbiddingQueries { XCTFail("Attempted to query \(topic)") throw FakeApiClientError.queryAssertionFailure } - var result: [XMTP.Envelope] = [] + var result: [XMTPiOS.Envelope] = [] if let response = responses.removeValue(forKey: topic) { result.append(contentsOf: response) @@ -213,21 +213,19 @@ public class FakeApiClient: ApiClient { return queryResponse } - public func query(topic: XMTP.Topic, pagination: Pagination? = nil) async throws -> XMTP.QueryResponse { + public func query(topic: XMTPiOS.Topic, pagination: Pagination? = nil) async throws -> XMTPiOS.QueryResponse { return try await query(topic: topic.description, pagination: pagination, cursor: nil) } - public func publish(envelopes: [XMTP.Envelope]) async throws -> XMTP.PublishResponse { + public func publish(envelopes: [XMTPiOS.Envelope]) async throws { for envelope in envelopes { send(envelope: envelope) } published.append(contentsOf: envelopes) - - return PublishResponse() } - public func batchQuery(request: XMTP.BatchQueryRequest) async throws -> XMTP.BatchQueryResponse { + public func batchQuery(request: XMTPiOS.BatchQueryRequest) async throws -> XMTPiOS.BatchQueryResponse { let responses = try await withThrowingTaskGroup(of: QueryResponse.self) { group in for r in request.requests { group.addTask { @@ -243,17 +241,17 @@ public class FakeApiClient: ApiClient { return results } - var queryResponse = XMTP.BatchQueryResponse() + var queryResponse = XMTPiOS.BatchQueryResponse() queryResponse.responses = responses return queryResponse } - public func query(request: XMTP.QueryRequest) async throws -> XMTP.QueryResponse { + public func query(request: XMTPiOS.QueryRequest) async throws -> XMTPiOS.QueryResponse { abort() // Not supported on Fake } - public func publish(request: XMTP.PublishRequest) async throws -> XMTP.PublishResponse { + public func publish(request: XMTPiOS.PublishRequest) async throws { abort() // Not supported on Fake } diff --git a/Sources/XMTPiOS/ApiClient.swift b/Sources/XMTPiOS/ApiClient.swift new file mode 100644 index 00000000..9309d5da --- /dev/null +++ b/Sources/XMTPiOS/ApiClient.swift @@ -0,0 +1,173 @@ +// +// ApiClient.swift +// +// +// Created by Pat Nakajima on 11/17/22. +// + +import Foundation +import LibXMTP + +public typealias PublishRequest = Xmtp_MessageApi_V1_PublishRequest +public typealias PublishResponse = Xmtp_MessageApi_V1_PublishResponse +public typealias BatchQueryRequest = Xmtp_MessageApi_V1_BatchQueryRequest +public typealias BatchQueryResponse = Xmtp_MessageApi_V1_BatchQueryResponse +public typealias Cursor = Xmtp_MessageApi_V1_Cursor +public typealias QueryRequest = Xmtp_MessageApi_V1_QueryRequest +public typealias QueryResponse = Xmtp_MessageApi_V1_QueryResponse +public typealias SubscribeRequest = Xmtp_MessageApi_V1_SubscribeRequest + +public enum ApiClientError: Error { + case batchQueryError(String) + case queryError(String) + case publishError(String) + case subscribeError(String) +} + +protocol ApiClient: Sendable { + var environment: XMTPEnvironment { get } + init(environment: XMTPEnvironment, secure: Bool, rustClient: LibXMTP.FfiV2ApiClient, appVersion: String?) throws + func setAuthToken(_ token: String) + func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse + func query(topic: String, pagination: Pagination?, cursor: Xmtp_MessageApi_V1_Cursor?) async throws -> QueryResponse + func query(topic: Topic, pagination: Pagination?) async throws -> QueryResponse + func query(request: QueryRequest) async throws -> QueryResponse + func envelopes(topic: String, pagination: Pagination?) async throws -> [Envelope] + func publish(envelopes: [Envelope]) async throws + func publish(request: PublishRequest) async throws + func subscribe(topics: [String]) -> AsyncThrowingStream +} + +func makeQueryRequest(topic: String, pagination: Pagination? = nil, cursor: Cursor? = nil) -> QueryRequest { + return QueryRequest.with { + $0.contentTopics = [topic] + if let pagination { + $0.pagingInfo = pagination.pagingInfo + } + if let endAt = pagination?.before { + $0.endTimeNs = UInt64(endAt.millisecondsSinceEpoch) * 1_000_000 + $0.pagingInfo.direction = pagination?.direction ?? .descending + } + if let startAt = pagination?.after { + $0.startTimeNs = UInt64(startAt.millisecondsSinceEpoch) * 1_000_000 + $0.pagingInfo.direction = pagination?.direction ?? .descending + } + if let cursor { + $0.pagingInfo.cursor = cursor + } + } +} + +final class GRPCApiClient: ApiClient { + let ClientVersionHeaderKey = "X-Client-Version" + let AppVersionHeaderKey = "X-App-Version" + + let environment: XMTPEnvironment + var authToken = "" + + var rustClient: LibXMTP.FfiV2ApiClient + + required init(environment: XMTPEnvironment, secure _: Bool = true, rustClient: LibXMTP.FfiV2ApiClient, appVersion: String? = nil) throws { + self.environment = environment + self.rustClient = rustClient + if let appVersion = appVersion { + rustClient.setAppVersion(version: appVersion) + } + } + + 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://production.xmtp.network:5556" + } + } + + func setAuthToken(_ token: String) { + authToken = token + } + + func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse { + do { + return try await rustClient.batchQuery(req: request.toFFI).fromFFI + } catch { + throw ApiClientError.batchQueryError(error.localizedDescription) + } + } + + func query(request: QueryRequest) async throws -> QueryResponse { + do { + return try await rustClient.query(request: request.toFFI).fromFFI + } catch { + throw ApiClientError.queryError(error.localizedDescription) + } + } + + func query(topic: String, pagination: Pagination? = nil, cursor: Cursor? = nil) async throws -> QueryResponse { + return try await query(request: makeQueryRequest(topic: topic, pagination: pagination, cursor: cursor)) + } + + func query(topic: Topic, pagination: Pagination? = nil) async throws -> QueryResponse { + return try await query(request: makeQueryRequest(topic: topic.description, pagination: pagination)) + } + + func envelopes(topic: String, pagination: Pagination? = nil) async throws -> [Envelope] { + var envelopes: [Envelope] = [] + var hasNextPage = true + var cursor: Xmtp_MessageApi_V1_Cursor? + + while hasNextPage { + let response = try await query(topic: topic, pagination: pagination, cursor: cursor) + + envelopes.append(contentsOf: response.envelopes) + + cursor = response.pagingInfo.cursor + hasNextPage = !response.envelopes.isEmpty && response.pagingInfo.hasCursor + + if let limit = pagination?.limit, envelopes.count >= limit { + envelopes = Array(envelopes.prefix(limit)) + break + } + } + + return envelopes + } + + func subscribe(topics: [String]) -> AsyncThrowingStream { + return AsyncThrowingStream { continuation in + Task { + let request = SubscribeRequest.with { $0.contentTopics = topics } + do { + let subscription = try await rustClient.subscribe(request: request.toFFI) + + defer { + Task { + await subscription.end() + } + } + + while true { + let nextEnvelope = try await subscription.next() + continuation.yield(nextEnvelope.fromFFI) + } + } catch { + throw ApiClientError.subscribeError(error.localizedDescription) + } + } + } + } + + func publish(request: PublishRequest) async throws { + do { + try await rustClient.publish(request: request.toFFI, authToken: authToken) + } catch { + throw ApiClientError.publishError(error.localizedDescription) + } + } + + func publish(envelopes: [Envelope]) async throws { + return try await publish(request: PublishRequest.with { + $0.envelopes = envelopes + }) + } +} diff --git a/Sources/XMTP/AuthorizedIdentity.swift b/Sources/XMTPiOS/AuthorizedIdentity.swift similarity index 100% rename from Sources/XMTP/AuthorizedIdentity.swift rename to Sources/XMTPiOS/AuthorizedIdentity.swift diff --git a/Sources/XMTP/Client.swift b/Sources/XMTPiOS/Client.swift similarity index 82% rename from Sources/XMTP/Client.swift rename to Sources/XMTPiOS/Client.swift index 14fc7f37..b50bfd46 100644 --- a/Sources/XMTP/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -6,13 +6,13 @@ // import Foundation +import LibXMTP import web3 -import XMTPRust public typealias PreEventCallback = () async throws -> Void public enum ClientError: Error { - case creationError(String) + case creationError(String) } /// Specify configuration options for creating a ``Client``. @@ -24,26 +24,26 @@ public struct ClientOptions { /// Optional: Specify self-reported version e.g. XMTPInbox/v1.0.0. public var isSecure: Bool = true - - /// Specify whether the API client should use TLS security. In general this should only be false when using the `.local` environment. - public var appVersion: String? = nil - public init(env: XMTPEnvironment = .dev, isSecure: Bool = true, appVersion: String? = nil) { + /// Specify whether the API client should use TLS security. In general this should only be false when using the `.local` environment. + public var appVersion: String? + + public init(env: XMTPEnvironment = .dev, isSecure: Bool = true, appVersion: String? = nil) { self.env = env self.isSecure = isSecure - self.appVersion = appVersion + self.appVersion = appVersion } } public var api = Api() public var codecs: [any ContentCodec] = [] - + /// `preEnableIdentityCallback` will be called immediately before an Enable Identity wallet signature is requested from the user. - public var preEnableIdentityCallback: PreEventCallback? = nil - + public var preEnableIdentityCallback: PreEventCallback? + /// `preCreateIdentityCallback` will be called immediately before a Create Identity wallet signature is requested from the user. - public var preCreateIdentityCallback: PreEventCallback? = nil - + public var preCreateIdentityCallback: PreEventCallback? + public init(api: Api = Api(), codecs: [any ContentCodec] = [], preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil) { self.api = api self.codecs = codecs @@ -86,17 +86,17 @@ public final class Client: Sendable { /// Creates a client. public static func create(account: SigningKey, options: ClientOptions? = nil) async throws -> Client { let options = options ?? ClientOptions() - do { - 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, - rustClient: client - ) - return try await create(account: account, apiClient: apiClient, options: options) - } catch let error as RustString { - throw ClientError.creationError(error.toString()) - } + do { + let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local) + let apiClient = try GRPCApiClient( + environment: options.api.env, + secure: options.api.isSecure, + rustClient: client + ) + return try await create(account: account, apiClient: apiClient, options: options) + } catch { + throw ClientError.creationError(error.localizedDescription) + } } static func create(account: SigningKey, apiClient: ApiClient, options: ClientOptions? = nil) async throws -> Client { @@ -112,7 +112,7 @@ public final class Client: Sendable { // swiftlint:disable no_optional_try if let keys = try await loadPrivateKeys(for: account, apiClient: apiClient, options: options) { // swiftlint:enable no_optional_try - print("loading existing private keys.") + print("loading existing private keys.") #if DEBUG print("Loaded existing private keys.") #endif @@ -130,7 +130,7 @@ public final class Client: Sendable { let apiClient = apiClient apiClient.setAuthToken(authToken) _ = try await apiClient.publish(envelopes: [ - Envelope(topic: .userPrivateStoreKeyBundle(account.address), timestamp: Date(), message: try encryptedKeys.serializedData()), + Envelope(topic: .userPrivateStoreKeyBundle(account.address), timestamp: Date(), message: encryptedKeys.serializedData()), ]) return keys @@ -145,11 +145,11 @@ public final class Client: Sendable { for envelope in res.envelopes { let encryptedBundle = try EncryptedPrivateKeyBundle(serializedData: envelope.message) - let bundle = try await encryptedBundle.decrypted(with: account, preEnableIdentityCallback: options?.preEnableIdentityCallback ) - if case .v1 = bundle.version { - return bundle.v1 - } - print("discarding unsupported stored key bundle") + let bundle = try await encryptedBundle.decrypted(with: account, preEnableIdentityCallback: options?.preEnableIdentityCallback) + if case .v1 = bundle.version { + return bundle.v1 + } + print("discarding unsupported stored key bundle") } return nil @@ -165,7 +165,7 @@ public final class Client: Sendable { let options = options ?? ClientOptions() - let client = try await XMTPRust.create_client(GRPCApiClient.envToUrl(env: options.api.env), options.api.env != .local) + let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local) let apiClient = try GRPCApiClient( environment: options.api.env, secure: options.api.isSecure, @@ -200,18 +200,18 @@ public final class Client: Sendable { public func canMessage(_ peerAddress: String) async throws -> Bool { return try await query(topic: .contact(peerAddress)).envelopes.count > 0 } - - public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool { - 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, - rustClient: client - ) - return try await apiClient.query(topic: .contact(peerAddress)).envelopes.count > 0 - } + + public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool { + let options = options ?? ClientOptions() + + let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local) + let apiClient = try GRPCApiClient( + environment: options.api.env, + secure: options.api.isSecure, + rustClient: client + ) + return try await apiClient.query(topic: Topic.contact(peerAddress)).envelopes.count > 0 + } public func importConversation(from conversationData: Data) throws -> Conversation? { let jsonDecoder = JSONDecoder() @@ -308,17 +308,17 @@ public final class Client: Sendable { ) } - public func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse { - return try await apiClient.batchQuery(request: request) - } + public func batchQuery(request: BatchQueryRequest) async throws -> BatchQueryResponse { + return try await apiClient.batchQuery(request: request) + } - @discardableResult public func publish(envelopes: [Envelope]) async throws -> PublishResponse { + public func publish(envelopes: [Envelope]) async throws { let authorized = AuthorizedIdentity(address: address, authorized: privateKeyBundleV1.identityKey.publicKey, identity: privateKeyBundleV1.identityKey) let authToken = try await authorized.createAuthToken() apiClient.setAuthToken(authToken) - return try await apiClient.publish(envelopes: envelopes) + try await apiClient.publish(envelopes: envelopes) } public func subscribe(topics: [String]) -> AsyncThrowingStream { diff --git a/Sources/XMTP/CodecRegistry.swift b/Sources/XMTPiOS/CodecRegistry.swift similarity index 100% rename from Sources/XMTP/CodecRegistry.swift rename to Sources/XMTPiOS/CodecRegistry.swift diff --git a/Sources/XMTP/Codecs/AttachmentCodec.swift b/Sources/XMTPiOS/Codecs/AttachmentCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/AttachmentCodec.swift rename to Sources/XMTPiOS/Codecs/AttachmentCodec.swift diff --git a/Sources/XMTP/Codecs/Composite.swift b/Sources/XMTPiOS/Codecs/Composite.swift similarity index 100% rename from Sources/XMTP/Codecs/Composite.swift rename to Sources/XMTPiOS/Codecs/Composite.swift diff --git a/Sources/XMTP/Codecs/ContentCodec.swift b/Sources/XMTPiOS/Codecs/ContentCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/ContentCodec.swift rename to Sources/XMTPiOS/Codecs/ContentCodec.swift diff --git a/Sources/XMTP/Codecs/ContentTypeID.swift b/Sources/XMTPiOS/Codecs/ContentTypeID.swift similarity index 100% rename from Sources/XMTP/Codecs/ContentTypeID.swift rename to Sources/XMTPiOS/Codecs/ContentTypeID.swift diff --git a/Sources/XMTP/Codecs/DecodedComposite.swift b/Sources/XMTPiOS/Codecs/DecodedComposite.swift similarity index 100% rename from Sources/XMTP/Codecs/DecodedComposite.swift rename to Sources/XMTPiOS/Codecs/DecodedComposite.swift diff --git a/Sources/XMTP/Codecs/EncryptedEncodedContent.swift b/Sources/XMTPiOS/Codecs/EncryptedEncodedContent.swift similarity index 100% rename from Sources/XMTP/Codecs/EncryptedEncodedContent.swift rename to Sources/XMTPiOS/Codecs/EncryptedEncodedContent.swift diff --git a/Sources/XMTP/Codecs/ReactionCodec.swift b/Sources/XMTPiOS/Codecs/ReactionCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/ReactionCodec.swift rename to Sources/XMTPiOS/Codecs/ReactionCodec.swift diff --git a/Sources/XMTP/Codecs/ReadReceiptCodec.swift b/Sources/XMTPiOS/Codecs/ReadReceiptCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/ReadReceiptCodec.swift rename to Sources/XMTPiOS/Codecs/ReadReceiptCodec.swift diff --git a/Sources/XMTP/Codecs/RemoteAttachmentCodec.swift b/Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/RemoteAttachmentCodec.swift rename to Sources/XMTPiOS/Codecs/RemoteAttachmentCodec.swift diff --git a/Sources/XMTP/Codecs/ReplyCodec.swift b/Sources/XMTPiOS/Codecs/ReplyCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/ReplyCodec.swift rename to Sources/XMTPiOS/Codecs/ReplyCodec.swift diff --git a/Sources/XMTP/Codecs/TextCodec.swift b/Sources/XMTPiOS/Codecs/TextCodec.swift similarity index 100% rename from Sources/XMTP/Codecs/TextCodec.swift rename to Sources/XMTPiOS/Codecs/TextCodec.swift diff --git a/Sources/XMTP/Constants.swift b/Sources/XMTPiOS/Constants.swift similarity index 100% rename from Sources/XMTP/Constants.swift rename to Sources/XMTPiOS/Constants.swift diff --git a/Sources/XMTP/Contacts.swift b/Sources/XMTPiOS/Contacts.swift similarity index 56% rename from Sources/XMTP/Contacts.swift rename to Sources/XMTPiOS/Contacts.swift index 9c1889e4..662333ba 100644 --- a/Sources/XMTP/Contacts.swift +++ b/Sources/XMTPiOS/Contacts.swift @@ -6,8 +6,7 @@ // import Foundation -import XMTPRust - +import LibXMTP public typealias PrivatePreferencesAction = Xmtp_MessageContents_PrivatePreferencesAction @@ -34,79 +33,75 @@ public struct ConsentListEntry: Codable, Hashable { } public enum ContactError: Error { - case invalidIdentifier + case invalidIdentifier } public class ConsentList { public var entries: [String: ConsentListEntry] = [:] - var publicKey: Data - var privateKey: Data - var identifier: String? - - var client: Client - - init(client: Client) { - self.client = client - self.privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes - self.publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes - // swiftlint:disable no_optional_try - self.identifier = try? XMTPRust.generate_private_preferences_topic_identifier(RustVec(privateKey)).toString() - // swiftlint:enable no_optional_try - } - - func load() async throws -> ConsentList { - guard let identifier = identifier else { - throw ContactError.invalidIdentifier - } - - let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: Pagination(direction: .ascending)) + var publicKey: Data + var privateKey: Data + var identifier: String? + + var client: Client + + init(client: Client) { + self.client = client + privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes + publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes + // swiftlint:disable no_optional_try + identifier = try? LibXMTP.generatePrivatePreferencesTopicIdentifier(privateKey: privateKey.bytes) + // swiftlint:enable no_optional_try + } + func load() async throws -> ConsentList { + guard let identifier = identifier else { + throw ContactError.invalidIdentifier + } + + + let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: Pagination(direction: .ascending)) let consentList = ConsentList(client: client) - - var preferences: [PrivatePreferencesAction] = [] + + var preferences: [PrivatePreferencesAction] = [] for envelope in envelopes { + let payload = try LibXMTP.userPreferencesDecrypt(publicKey: publicKey.bytes, privateKey: privateKey.bytes, message: envelope.message.bytes) - let payload = try XMTPRust.user_preferences_decrypt( - RustVec(publicKey), - RustVec(privateKey), - RustVec(envelope.message) - ) + try preferences.append(PrivatePreferencesAction(serializedData: Data(payload))) + } - preferences.append(try PrivatePreferencesAction(serializedData: Data(payload))) + for preference in preferences { + for address in preference.allow.walletAddresses { + _ = consentList.allow(address: address) + } + + for address in preference.block.walletAddresses { + _ = consentList.deny(address: address) + } } - - preferences.forEach { preference in - preference.allow.walletAddresses.forEach { address in - consentList.allow(address: address) - } - preference.block.walletAddresses.forEach { address in - consentList.deny(address: address) - } - } return consentList } func publish(entry: ConsentListEntry) async throws { - guard let identifier = identifier else { - throw ContactError.invalidIdentifier - } - - var payload = PrivatePreferencesAction() - switch entry.consentType { - case .allowed: - payload.allow.walletAddresses = [entry.value] - case .denied: - payload.block.walletAddresses = [entry.value] - case .unknown: - payload.messageType = nil - } - - let message = try XMTPRust.user_preferences_encrypt( - RustVec(publicKey), - RustVec(privateKey), - RustVec(payload.serializedData()) + guard let identifier = identifier else { + throw ContactError.invalidIdentifier + } + + var payload = PrivatePreferencesAction() + switch entry.consentType { + case .allowed: + payload.allow.walletAddresses = [entry.value] + case .denied: + payload.block.walletAddresses = [entry.value] + case .unknown: + payload.messageType = nil + } + + let message = try LibXMTP.userPreferencesEncrypt( + publicKey: publicKey.bytes, + privateKey: privateKey.bytes, + message: payload.serializedData().bytes ) let envelope = Envelope( @@ -119,14 +114,14 @@ public class ConsentList { } func allow(address: String) -> ConsentListEntry { - let entry = ConsentListEntry.address(address, type: ConsentState.allowed) + let entry = ConsentListEntry.address(address, type: ConsentState.allowed) entries[ConsentListEntry.address(address).key] = entry return entry } func deny(address: String) -> ConsentListEntry { - let entry = ConsentListEntry.address(address, type: ConsentState.denied) + let entry = ConsentListEntry.address(address, type: ConsentState.denied) entries[ConsentListEntry.address(address).key] = entry return entry @@ -134,10 +129,10 @@ public class ConsentList { func state(address: String) -> ConsentState { let entry = entries[ConsentListEntry.address(address).key] - - // swiftlint:disable no_optional_try - return entry?.consentType ?? .unknown - // swiftlint:enable no_optional_try + + // swiftlint:disable no_optional_try + return entry?.consentType ?? .unknown + // swiftlint:enable no_optional_try } } @@ -151,16 +146,16 @@ public actor Contacts { // Whether or not we have sent invite/intro to this contact var hasIntroduced: [String: Bool] = [:] - public var consentList: ConsentList - - init(client: Client) { + public var consentList: ConsentList + + init(client: Client) { self.client = client - self.consentList = ConsentList(client: client) + consentList = ConsentList(client: client) } public func refreshConsentList() async throws -> ConsentList { consentList = try await ConsentList(client: client).load() - return consentList + return consentList } public func isAllowed(_ address: String) -> Bool { diff --git a/Sources/XMTP/Conversation.swift b/Sources/XMTPiOS/Conversation.swift similarity index 100% rename from Sources/XMTP/Conversation.swift rename to Sources/XMTPiOS/Conversation.swift diff --git a/Sources/XMTP/ConversationExport.swift b/Sources/XMTPiOS/ConversationExport.swift similarity index 100% rename from Sources/XMTP/ConversationExport.swift rename to Sources/XMTPiOS/ConversationExport.swift diff --git a/Sources/XMTP/ConversationV1.swift b/Sources/XMTPiOS/ConversationV1.swift similarity index 100% rename from Sources/XMTP/ConversationV1.swift rename to Sources/XMTPiOS/ConversationV1.swift diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTPiOS/ConversationV2.swift similarity index 100% rename from Sources/XMTP/ConversationV2.swift rename to Sources/XMTPiOS/ConversationV2.swift diff --git a/Sources/XMTP/Conversations.swift b/Sources/XMTPiOS/Conversations.swift similarity index 100% rename from Sources/XMTP/Conversations.swift rename to Sources/XMTPiOS/Conversations.swift diff --git a/Sources/XMTP/Crypto.swift b/Sources/XMTPiOS/Crypto.swift similarity index 100% rename from Sources/XMTP/Crypto.swift rename to Sources/XMTPiOS/Crypto.swift diff --git a/Sources/XMTP/DecodedMessage.swift b/Sources/XMTPiOS/DecodedMessage.swift similarity index 100% rename from Sources/XMTP/DecodedMessage.swift rename to Sources/XMTPiOS/DecodedMessage.swift diff --git a/Sources/XMTP/EncodedContentCompression.swift b/Sources/XMTPiOS/EncodedContentCompression.swift similarity index 100% rename from Sources/XMTP/EncodedContentCompression.swift rename to Sources/XMTPiOS/EncodedContentCompression.swift diff --git a/Sources/XMTP/Extensions/Data.swift b/Sources/XMTPiOS/Extensions/Data.swift similarity index 75% rename from Sources/XMTP/Extensions/Data.swift rename to Sources/XMTPiOS/Extensions/Data.swift index 5d2ba4fc..031eac7e 100644 --- a/Sources/XMTP/Extensions/Data.swift +++ b/Sources/XMTPiOS/Extensions/Data.swift @@ -6,17 +6,13 @@ // import Foundation -import XMTPRust +import LibXMTP 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/Date.swift b/Sources/XMTPiOS/Extensions/Date.swift similarity index 100% rename from Sources/XMTP/Extensions/Date.swift rename to Sources/XMTPiOS/Extensions/Date.swift diff --git a/Sources/XMTPiOS/Extensions/Ffi.swift b/Sources/XMTPiOS/Extensions/Ffi.swift new file mode 100644 index 00000000..ba7b7b52 --- /dev/null +++ b/Sources/XMTPiOS/Extensions/Ffi.swift @@ -0,0 +1,194 @@ +// +// File.swift +// +// +// Created by Pat Nakajima on 1/16/24. +// + +import Foundation +import LibXMTP + +// MARK: PagingInfo + +extension PagingInfo { + var toFFI: FfiPagingInfo { + FfiPagingInfo(limit: limit, cursor: cursor.toFFI, direction: direction.toFFI) + } +} + +extension FfiPagingInfo { + var fromFFI: PagingInfo { + PagingInfo.with { + $0.limit = limit + + if let cursor { + $0.cursor = cursor.fromFFI + } + + $0.direction = direction.fromFFI + } + } +} + +extension Cursor { + var toFFI: FfiCursor { + FfiCursor(digest: [UInt8](self.index.digest), senderTimeNs: self.index.senderTimeNs) + } +} + +extension FfiCursor { + var fromFFI: Cursor { + Cursor.with { + $0.index.digest = Data(digest) + $0.index.senderTimeNs = senderTimeNs + } + } +} + +extension PagingInfoSortDirection { + var toFFI: FfiSortDirection { + switch self { + case .ascending: + return .ascending + case .descending: + return .descending + default: + return .unspecified + } + } +} + +extension FfiSortDirection { + var fromFFI: PagingInfoSortDirection { + switch self { + case .ascending: + return .ascending + case .descending: + return .descending + default: + return .unspecified + } + } +} + +// MARK: QueryRequest + +extension QueryRequest { + var toFFI: FfiV2QueryRequest { + FfiV2QueryRequest( + contentTopics: contentTopics, + startTimeNs: startTimeNs, + endTimeNs: endTimeNs, + pagingInfo: pagingInfo.toFFI + ) + } +} + +extension FfiV2QueryRequest { + var fromFFI: QueryRequest { + QueryRequest.with { + $0.contentTopics = contentTopics + $0.startTimeNs = startTimeNs + $0.endTimeNs = endTimeNs + $0.pagingInfo = pagingInfo?.fromFFI ?? PagingInfo() + } + } +} + +// MARK: BatchQueryRequest + +extension BatchQueryRequest { + var toFFI: FfiV2BatchQueryRequest { + FfiV2BatchQueryRequest(requests: requests.map(\.toFFI)) + } +} + +extension FfiV2BatchQueryRequest { + var fromFFI: BatchQueryRequest { + BatchQueryRequest.with { + $0.requests = requests.map(\.fromFFI) + } + } +} + +// MARK: QueryResponse + +extension QueryResponse { + var toFFI: FfiV2QueryResponse { + FfiV2QueryResponse(envelopes: envelopes.map(\.toFFI), pagingInfo: nil) + } +} + +extension FfiV2QueryResponse { + var fromFFI: QueryResponse { + QueryResponse.with { + $0.envelopes = envelopes.map(\.fromFFI) + $0.pagingInfo = pagingInfo?.fromFFI ?? PagingInfo() + } + } +} + +// MARK: BatchQueryResponse + +extension BatchQueryResponse { + var toFFI: FfiV2BatchQueryResponse { + FfiV2BatchQueryResponse(responses: responses.map(\.toFFI)) + } +} + +extension FfiV2BatchQueryResponse { + var fromFFI: BatchQueryResponse { + BatchQueryResponse.with { + $0.responses = responses.map(\.fromFFI) + } + } +} + +// MARK: Envelope + +extension Envelope { + var toFFI: FfiEnvelope { + FfiEnvelope(contentTopic: contentTopic, timestampNs: timestampNs, message: [UInt8](message)) + } +} + +extension FfiEnvelope { + var fromFFI: Envelope { + Envelope.with { + $0.contentTopic = contentTopic + $0.timestampNs = timestampNs + $0.message = Data(message) + } + } +} + +// MARK: PublishRequest + +extension PublishRequest { + var toFFI: FfiPublishRequest { + FfiPublishRequest(envelopes: envelopes.map(\.toFFI)) + } +} + +extension FfiPublishRequest { + var fromFFI: PublishRequest { + PublishRequest.with { + $0.envelopes = envelopes.map(\.fromFFI) + } + } +} + +// MARK: SubscribeRequest +extension SubscribeRequest { + var toFFI: FfiV2SubscribeRequest { + FfiV2SubscribeRequest(contentTopics: contentTopics) + } +} + +extension FfiV2SubscribeRequest { + var fromFFI: SubscribeRequest { + SubscribeRequest.with { + $0.contentTopics = contentTopics + } + } +} diff --git a/Sources/XMTP/KeyUtil.swift b/Sources/XMTPiOS/KeyUtil.swift similarity index 91% rename from Sources/XMTP/KeyUtil.swift rename to Sources/XMTPiOS/KeyUtil.swift index dff570ba..83ae7219 100644 --- a/Sources/XMTP/KeyUtil.swift +++ b/Sources/XMTPiOS/KeyUtil.swift @@ -6,7 +6,7 @@ import Foundation import Logging import secp256k1 import web3 -import XMTPRust +import LibXMTP enum KeyUtilError: Error { case invalidContext @@ -21,18 +21,16 @@ enum KeyUtilError: Error { // Copied from web3.swift since its version is `internal` enum KeyUtilx { static func generatePublicKey(from data: Data) throws -> Data { - let vec = try XMTPRust.public_key_from_private_key_k256(RustVec(data)) + let vec = try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: data.bytes) return Data(vec) } 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) + return try Data(LibXMTP.recoverPublicKeyK256Sha256(message: message.bytes, signature: data.bytes)) } 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) + return Data(try LibXMTP.recoverPublicKeyK256Keccak256(message: message.bytes, signature: data.bytes)) } static func sign(message: Data, with privateKey: Data, hashing: Bool) throws -> Data { diff --git a/Sources/XMTP/Messages/AuthData.swift b/Sources/XMTPiOS/Messages/AuthData.swift similarity index 100% rename from Sources/XMTP/Messages/AuthData.swift rename to Sources/XMTPiOS/Messages/AuthData.swift diff --git a/Sources/XMTP/Messages/ContactBundle.swift b/Sources/XMTPiOS/Messages/ContactBundle.swift similarity index 99% rename from Sources/XMTP/Messages/ContactBundle.swift rename to Sources/XMTPiOS/Messages/ContactBundle.swift index 267ac63d..ea93486e 100644 --- a/Sources/XMTP/Messages/ContactBundle.swift +++ b/Sources/XMTPiOS/Messages/ContactBundle.swift @@ -6,7 +6,7 @@ // import web3 -import XMTPRust +import LibXMTP typealias ContactBundle = Xmtp_MessageContents_ContactBundle typealias ContactBundleV1 = Xmtp_MessageContents_ContactBundleV1 diff --git a/Sources/XMTP/Messages/DecryptedMessage.swift b/Sources/XMTPiOS/Messages/DecryptedMessage.swift similarity index 100% rename from Sources/XMTP/Messages/DecryptedMessage.swift rename to Sources/XMTPiOS/Messages/DecryptedMessage.swift diff --git a/Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift b/Sources/XMTPiOS/Messages/EncryptedPrivateKeyBundle.swift similarity index 100% rename from Sources/XMTP/Messages/EncryptedPrivateKeyBundle.swift rename to Sources/XMTPiOS/Messages/EncryptedPrivateKeyBundle.swift diff --git a/Sources/XMTP/Messages/Envelope.swift b/Sources/XMTPiOS/Messages/Envelope.swift similarity index 100% rename from Sources/XMTP/Messages/Envelope.swift rename to Sources/XMTPiOS/Messages/Envelope.swift diff --git a/Sources/XMTP/Messages/Invitation.swift b/Sources/XMTPiOS/Messages/Invitation.swift similarity index 100% rename from Sources/XMTP/Messages/Invitation.swift rename to Sources/XMTPiOS/Messages/Invitation.swift diff --git a/Sources/XMTP/Messages/Message.swift b/Sources/XMTPiOS/Messages/Message.swift similarity index 100% rename from Sources/XMTP/Messages/Message.swift rename to Sources/XMTPiOS/Messages/Message.swift diff --git a/Sources/XMTP/Messages/MessageHeaderV1.swift b/Sources/XMTPiOS/Messages/MessageHeaderV1.swift similarity index 100% rename from Sources/XMTP/Messages/MessageHeaderV1.swift rename to Sources/XMTPiOS/Messages/MessageHeaderV1.swift diff --git a/Sources/XMTP/Messages/MessageHeaderV2.swift b/Sources/XMTPiOS/Messages/MessageHeaderV2.swift similarity index 100% rename from Sources/XMTP/Messages/MessageHeaderV2.swift rename to Sources/XMTPiOS/Messages/MessageHeaderV2.swift diff --git a/Sources/XMTP/Messages/MessageV1.swift b/Sources/XMTPiOS/Messages/MessageV1.swift similarity index 100% rename from Sources/XMTP/Messages/MessageV1.swift rename to Sources/XMTPiOS/Messages/MessageV1.swift diff --git a/Sources/XMTP/Messages/MessageV2.swift b/Sources/XMTPiOS/Messages/MessageV2.swift similarity index 99% rename from Sources/XMTP/Messages/MessageV2.swift rename to Sources/XMTPiOS/Messages/MessageV2.swift index 07ef2061..71de2c9a 100644 --- a/Sources/XMTP/Messages/MessageV2.swift +++ b/Sources/XMTPiOS/Messages/MessageV2.swift @@ -7,7 +7,7 @@ import CryptoKit import Foundation -import XMTPRust +import LibXMTP typealias MessageV2 = Xmtp_MessageContents_MessageV2 diff --git a/Sources/XMTP/Messages/PagingInfo.swift b/Sources/XMTPiOS/Messages/PagingInfo.swift similarity index 100% rename from Sources/XMTP/Messages/PagingInfo.swift rename to Sources/XMTPiOS/Messages/PagingInfo.swift diff --git a/Sources/XMTP/Messages/PrivateKey.swift b/Sources/XMTPiOS/Messages/PrivateKey.swift similarity index 99% rename from Sources/XMTP/Messages/PrivateKey.swift rename to Sources/XMTPiOS/Messages/PrivateKey.swift index 35e7a3a3..4e2f4186 100644 --- a/Sources/XMTP/Messages/PrivateKey.swift +++ b/Sources/XMTPiOS/Messages/PrivateKey.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPRust +import LibXMTP import CryptoKit /// Represents a secp256k1 private key. ``PrivateKey`` conforms to ``SigningKey`` so you can use it diff --git a/Sources/XMTP/Messages/PrivateKeyBundle.swift b/Sources/XMTPiOS/Messages/PrivateKeyBundle.swift similarity index 100% rename from Sources/XMTP/Messages/PrivateKeyBundle.swift rename to Sources/XMTPiOS/Messages/PrivateKeyBundle.swift diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift b/Sources/XMTPiOS/Messages/PrivateKeyBundleV1.swift similarity index 99% rename from Sources/XMTP/Messages/PrivateKeyBundleV1.swift rename to Sources/XMTPiOS/Messages/PrivateKeyBundleV1.swift index 504c1ed0..cc4627d3 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV1.swift +++ b/Sources/XMTPiOS/Messages/PrivateKeyBundleV1.swift @@ -7,7 +7,7 @@ import CryptoKit import Foundation -import XMTPRust +import LibXMTP public typealias PrivateKeyBundleV1 = Xmtp_MessageContents_PrivateKeyBundleV1 diff --git a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift b/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift similarity index 93% rename from Sources/XMTP/Messages/PrivateKeyBundleV2.swift rename to Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift index 031642b9..8eae75bc 100644 --- a/Sources/XMTP/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPRust +import LibXMTP public typealias PrivateKeyBundleV2 = Xmtp_MessageContents_PrivateKeyBundleV2 @@ -34,7 +34,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - return Data(try XMTPRust.diffie_hellman_k256(RustVec(privateData), RustVec(publicData))) + return Data(try LibXMTP.diffieHellmanK256(privateKeyBytes: [UInt8](privateData), publicKeyBytes: [UInt8](publicData))) } func findPreKey(_ myPreKey: SignedPublicKey) throws -> SignedPrivateKey { diff --git a/Sources/XMTP/Messages/PublicKey.swift b/Sources/XMTPiOS/Messages/PublicKey.swift similarity index 99% rename from Sources/XMTP/Messages/PublicKey.swift rename to Sources/XMTPiOS/Messages/PublicKey.swift index 6a3f7d79..a465668b 100644 --- a/Sources/XMTP/Messages/PublicKey.swift +++ b/Sources/XMTPiOS/Messages/PublicKey.swift @@ -7,7 +7,7 @@ import Foundation -import XMTPRust +import LibXMTP import web3 import CryptoKit diff --git a/Sources/XMTP/Messages/PublicKeyBundle.swift b/Sources/XMTPiOS/Messages/PublicKeyBundle.swift similarity index 100% rename from Sources/XMTP/Messages/PublicKeyBundle.swift rename to Sources/XMTPiOS/Messages/PublicKeyBundle.swift diff --git a/Sources/XMTP/Messages/SealedInvitation.swift b/Sources/XMTPiOS/Messages/SealedInvitation.swift similarity index 100% rename from Sources/XMTP/Messages/SealedInvitation.swift rename to Sources/XMTPiOS/Messages/SealedInvitation.swift diff --git a/Sources/XMTP/Messages/SealedInvitationHeaderV1.swift b/Sources/XMTPiOS/Messages/SealedInvitationHeaderV1.swift similarity index 100% rename from Sources/XMTP/Messages/SealedInvitationHeaderV1.swift rename to Sources/XMTPiOS/Messages/SealedInvitationHeaderV1.swift diff --git a/Sources/XMTP/Messages/SealedInvitationV1.swift b/Sources/XMTPiOS/Messages/SealedInvitationV1.swift similarity index 100% rename from Sources/XMTP/Messages/SealedInvitationV1.swift rename to Sources/XMTPiOS/Messages/SealedInvitationV1.swift diff --git a/Sources/XMTP/Messages/Signature.swift b/Sources/XMTPiOS/Messages/Signature.swift similarity index 92% rename from Sources/XMTP/Messages/Signature.swift rename to Sources/XMTPiOS/Messages/Signature.swift index df390e87..791c753f 100644 --- a/Sources/XMTP/Messages/Signature.swift +++ b/Sources/XMTPiOS/Messages/Signature.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTPRust +import LibXMTP /// Represents a secp256k1 compact recoverable signature. public typealias Signature = Xmtp_MessageContents_Signature @@ -103,7 +103,12 @@ extension Signature { func verify(signedBy: PublicKey, digest: Data) throws -> Bool { do { - let _ = try XMTPRust.verify_k256_sha256(RustVec(signedBy.secp256K1Uncompressed.bytes), RustVec(digest), RustVec(ecdsaCompact.bytes), UInt8(ecdsaCompact.recovery)) + _ = try LibXMTP.verifyK256Sha256( + signedBy: signedBy.secp256K1Uncompressed.bytes.bytes, + message: digest.bytes, + signature: ecdsaCompact.bytes.bytes, + recoveryId: UInt8(ecdsaCompact.recovery) + ) } catch { return false } diff --git a/Sources/XMTP/Messages/SignedContent.swift b/Sources/XMTPiOS/Messages/SignedContent.swift similarity index 100% rename from Sources/XMTP/Messages/SignedContent.swift rename to Sources/XMTPiOS/Messages/SignedContent.swift diff --git a/Sources/XMTP/Messages/SignedPrivateKey.swift b/Sources/XMTPiOS/Messages/SignedPrivateKey.swift similarity index 100% rename from Sources/XMTP/Messages/SignedPrivateKey.swift rename to Sources/XMTPiOS/Messages/SignedPrivateKey.swift diff --git a/Sources/XMTP/Messages/SignedPublicKey.swift b/Sources/XMTPiOS/Messages/SignedPublicKey.swift similarity index 99% rename from Sources/XMTP/Messages/SignedPublicKey.swift rename to Sources/XMTPiOS/Messages/SignedPublicKey.swift index bf0aabbd..bd0581f9 100644 --- a/Sources/XMTP/Messages/SignedPublicKey.swift +++ b/Sources/XMTPiOS/Messages/SignedPublicKey.swift @@ -8,7 +8,7 @@ import CryptoKit import Foundation -import XMTPRust +import LibXMTP import web3 typealias SignedPublicKey = Xmtp_MessageContents_SignedPublicKey diff --git a/Sources/XMTP/Messages/SignedPublicKeyBundle.swift b/Sources/XMTPiOS/Messages/SignedPublicKeyBundle.swift similarity index 100% rename from Sources/XMTP/Messages/SignedPublicKeyBundle.swift rename to Sources/XMTPiOS/Messages/SignedPublicKeyBundle.swift diff --git a/Sources/XMTP/Messages/Token.swift b/Sources/XMTPiOS/Messages/Token.swift similarity index 100% rename from Sources/XMTP/Messages/Token.swift rename to Sources/XMTPiOS/Messages/Token.swift diff --git a/Sources/XMTP/Messages/Topic.swift b/Sources/XMTPiOS/Messages/Topic.swift similarity index 100% rename from Sources/XMTP/Messages/Topic.swift rename to Sources/XMTPiOS/Messages/Topic.swift diff --git a/Sources/XMTP/Messages/UnsignedPublicKey.swift b/Sources/XMTPiOS/Messages/UnsignedPublicKey.swift similarity index 100% rename from Sources/XMTP/Messages/UnsignedPublicKey.swift rename to Sources/XMTPiOS/Messages/UnsignedPublicKey.swift diff --git a/Sources/XMTP/PreparedMessage.swift b/Sources/XMTPiOS/PreparedMessage.swift similarity index 100% rename from Sources/XMTP/PreparedMessage.swift rename to Sources/XMTPiOS/PreparedMessage.swift diff --git a/Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift b/Sources/XMTPiOS/Proto/keystore_api/v1/keystore.pb.swift similarity index 100% rename from Sources/XMTP/Proto/keystore_api/v1/keystore.pb.swift rename to Sources/XMTPiOS/Proto/keystore_api/v1/keystore.pb.swift diff --git a/Sources/XMTP/Proto/message_api/v1/authn.pb.swift b/Sources/XMTPiOS/Proto/message_api/v1/authn.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_api/v1/authn.pb.swift rename to Sources/XMTPiOS/Proto/message_api/v1/authn.pb.swift diff --git a/Sources/XMTP/Proto/message_api/v1/message_api.pb.swift b/Sources/XMTPiOS/Proto/message_api/v1/message_api.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_api/v1/message_api.pb.swift rename to Sources/XMTPiOS/Proto/message_api/v1/message_api.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/ciphertext.pb.swift b/Sources/XMTPiOS/Proto/message_contents/ciphertext.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/ciphertext.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/ciphertext.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/composite.pb.swift b/Sources/XMTPiOS/Proto/message_contents/composite.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/composite.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/composite.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/contact.pb.swift b/Sources/XMTPiOS/Proto/message_contents/contact.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/contact.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/contact.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/content.pb.swift b/Sources/XMTPiOS/Proto/message_contents/content.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/content.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/content.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift b/Sources/XMTPiOS/Proto/message_contents/conversation_reference.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/conversation_reference.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/conversation_reference.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/ecies.pb.swift b/Sources/XMTPiOS/Proto/message_contents/ecies.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/ecies.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/ecies.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/invitation.pb.swift b/Sources/XMTPiOS/Proto/message_contents/invitation.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/invitation.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/invitation.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/message.pb.swift b/Sources/XMTPiOS/Proto/message_contents/message.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/message.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/message.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/private_key.pb.swift b/Sources/XMTPiOS/Proto/message_contents/private_key.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/private_key.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/private_key.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/private_preferences.pb.swift b/Sources/XMTPiOS/Proto/message_contents/private_preferences.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/private_preferences.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/private_preferences.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/public_key.pb.swift b/Sources/XMTPiOS/Proto/message_contents/public_key.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/public_key.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/public_key.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/signature.pb.swift b/Sources/XMTPiOS/Proto/message_contents/signature.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/signature.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/signature.pb.swift diff --git a/Sources/XMTP/Proto/message_contents/signed_payload.pb.swift b/Sources/XMTPiOS/Proto/message_contents/signed_payload.pb.swift similarity index 100% rename from Sources/XMTP/Proto/message_contents/signed_payload.pb.swift rename to Sources/XMTPiOS/Proto/message_contents/signed_payload.pb.swift diff --git a/Sources/XMTP/Push/XMTPPush.swift b/Sources/XMTPiOS/Push/XMTPPush.swift similarity index 100% rename from Sources/XMTP/Push/XMTPPush.swift rename to Sources/XMTPiOS/Push/XMTPPush.swift diff --git a/Sources/XMTP/Push/service.connect.swift b/Sources/XMTPiOS/Push/service.connect.swift similarity index 100% rename from Sources/XMTP/Push/service.connect.swift rename to Sources/XMTPiOS/Push/service.connect.swift diff --git a/Sources/XMTP/Push/service.pb.swift b/Sources/XMTPiOS/Push/service.pb.swift similarity index 100% rename from Sources/XMTP/Push/service.pb.swift rename to Sources/XMTPiOS/Push/service.pb.swift diff --git a/Sources/XMTP/SendOptions.swift b/Sources/XMTPiOS/SendOptions.swift similarity index 100% rename from Sources/XMTP/SendOptions.swift rename to Sources/XMTPiOS/SendOptions.swift diff --git a/Sources/XMTP/SigningKey.swift b/Sources/XMTPiOS/SigningKey.swift similarity index 99% rename from Sources/XMTP/SigningKey.swift rename to Sources/XMTPiOS/SigningKey.swift index 4f2b608d..3f5673e1 100644 --- a/Sources/XMTP/SigningKey.swift +++ b/Sources/XMTPiOS/SigningKey.swift @@ -7,7 +7,7 @@ import Foundation import web3 -import XMTPRust +import LibXMTP /// Defines a type that is used by a ``Client`` to sign keys and messages. /// diff --git a/Sources/XMTP/Util.swift b/Sources/XMTPiOS/Util.swift similarity index 100% rename from Sources/XMTP/Util.swift rename to Sources/XMTPiOS/Util.swift diff --git a/Sources/XMTP/XMTPEnvironment.swift b/Sources/XMTPiOS/XMTPEnvironment.swift similarity index 83% rename from Sources/XMTP/XMTPEnvironment.swift rename to Sources/XMTPiOS/XMTPEnvironment.swift index 0ed23bf0..e24fe343 100644 --- a/Sources/XMTP/XMTPEnvironment.swift +++ b/Sources/XMTPiOS/XMTPEnvironment.swift @@ -8,7 +8,7 @@ import Foundation /// Contains hosts an `ApiClient` can connect to -public enum XMTPEnvironment: String { +public enum XMTPEnvironment: String, Sendable { case dev = "dev.xmtp.network", production = "production.xmtp.network", local = "localhost" diff --git a/Tests/XMTPTests/AttachmentTests.swift b/Tests/XMTPTests/AttachmentTests.swift index 6a0d6d48..f551afe9 100644 --- a/Tests/XMTPTests/AttachmentTests.swift +++ b/Tests/XMTPTests/AttachmentTests.swift @@ -7,7 +7,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS @available(iOS 15, *) class AttachmentsTests: XCTestCase { diff --git a/Tests/XMTPTests/AuthenticationTests.swift b/Tests/XMTPTests/AuthenticationTests.swift index 2cc76568..ad1568ba 100644 --- a/Tests/XMTPTests/AuthenticationTests.swift +++ b/Tests/XMTPTests/AuthenticationTests.swift @@ -8,7 +8,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS final class AuthenticationTests: XCTestCase { func testCreateToken() async throws { diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 7a2e7e7d..4850094f 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -8,8 +8,8 @@ import Foundation import XCTest -@testable import XMTP -import XMTPRust +@testable import XMTPiOS +import LibXMTP import XMTPTestHelpers @available(iOS 15, *) diff --git a/Tests/XMTPTests/CodecTests.swift b/Tests/XMTPTests/CodecTests.swift index 258a896a..f4850990 100644 --- a/Tests/XMTPTests/CodecTests.swift +++ b/Tests/XMTPTests/CodecTests.swift @@ -6,7 +6,7 @@ // import XCTest -@testable import XMTP +@testable import XMTPiOS struct NumberCodec: ContentCodec { func fallback(content: Double) throws -> String? { @@ -15,11 +15,11 @@ struct NumberCodec: ContentCodec { typealias T = Double - var contentType: XMTP.ContentTypeID { + var contentType: XMTPiOS.ContentTypeID { ContentTypeID(authorityID: "example.com", typeID: "number", versionMajor: 1, versionMinor: 1) } - func encode(content: Double, client _: Client) throws -> XMTP.EncodedContent { + func encode(content: Double, client _: Client) throws -> XMTPiOS.EncodedContent { var encodedContent = EncodedContent() encodedContent.type = ContentTypeID(authorityID: "example.com", typeID: "number", versionMajor: 1, versionMinor: 1) @@ -28,7 +28,7 @@ struct NumberCodec: ContentCodec { return encodedContent } - func decode(content: XMTP.EncodedContent, client _: Client) throws -> Double { + func decode(content: XMTPiOS.EncodedContent, client _: Client) throws -> Double { return try JSONDecoder().decode(Double.self, from: content.content) } } diff --git a/Tests/XMTPTests/ContactTests.swift b/Tests/XMTPTests/ContactTests.swift index a1d14f66..838942e0 100644 --- a/Tests/XMTPTests/ContactTests.swift +++ b/Tests/XMTPTests/ContactTests.swift @@ -6,7 +6,7 @@ // import XCTest -@testable import XMTP +@testable import XMTPiOS class ContactTests: XCTestCase { func testParsingV2Bundle() throws { diff --git a/Tests/XMTPTests/ContactsTests.swift b/Tests/XMTPTests/ContactsTests.swift index 8168af94..da5087cf 100644 --- a/Tests/XMTPTests/ContactsTests.swift +++ b/Tests/XMTPTests/ContactsTests.swift @@ -6,7 +6,7 @@ // import XCTest -@testable import XMTP +@testable import XMTPiOS import XMTPTestHelpers @available(iOS 15, *) diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index 969e6e7d..8a6d6412 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -7,7 +7,7 @@ import CryptoKit import XCTest -@testable import XMTP +@testable import XMTPiOS import XMTPTestHelpers @available(iOS 16, *) diff --git a/Tests/XMTPTests/ConversationsTest.swift b/Tests/XMTPTests/ConversationsTest.swift index f87e7d8a..84a6f21f 100644 --- a/Tests/XMTPTests/ConversationsTest.swift +++ b/Tests/XMTPTests/ConversationsTest.swift @@ -7,7 +7,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS @available(macOS 13.0, *) @available(iOS 15, *) diff --git a/Tests/XMTPTests/CryptoTests.swift b/Tests/XMTPTests/CryptoTests.swift index 1417f3d3..9d9ee074 100644 --- a/Tests/XMTPTests/CryptoTests.swift +++ b/Tests/XMTPTests/CryptoTests.swift @@ -7,7 +7,7 @@ import secp256k1 import XCTest -@testable import XMTP +@testable import XMTPiOS final class CryptoTests: XCTestCase { func testCodec() throws { diff --git a/Tests/XMTPTests/IntegrationTests.swift b/Tests/XMTPTests/IntegrationTests.swift index abaae304..4e33ad45 100644 --- a/Tests/XMTPTests/IntegrationTests.swift +++ b/Tests/XMTPTests/IntegrationTests.swift @@ -9,9 +9,9 @@ import Foundation import secp256k1 import web3 import XCTest -import XMTPRust -@testable import XMTP -import XMTPRust +import LibXMTP +@testable import XMTPiOS +import LibXMTP import XMTPTestHelpers @available(macOS 13.0, *) @@ -27,7 +27,7 @@ final class IntegrationTests: XCTestCase { let authToken = try await authorized.createAuthToken() - let rustClient = try await XMTPRust.create_client(XMTP.GRPCApiClient.envToUrl(env: .local), false) + let rustClient = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: .local), isSecure: false) let api = try GRPCApiClient(environment: .local, secure: false, rustClient: rustClient) api.setAuthToken(authToken) @@ -494,9 +494,9 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) - let client = try await XMTP.Client.create(account: key) + let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) let conversations = try await client.conversations.list() @@ -564,9 +564,9 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) - let client = try await XMTP.Client.create(account: key) + let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) let convo = try await client.conversations.list()[0] @@ -587,9 +587,9 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) - let client = try await XMTP.Client.create(account: key) + let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) let convo = try await client.conversations.list()[0] @@ -616,10 +616,10 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try XMTPRust.public_key_from_private_key_k256(RustVec(keyBytes))) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) - let client = try await XMTP.Client.create(account: key) + let client = try await XMTPiOS.Client.create(account: key) let conversations = try await client.conversations.list() diff --git a/Tests/XMTPTests/InvitationTests.swift b/Tests/XMTPTests/InvitationTests.swift index 2650d403..aa025d76 100644 --- a/Tests/XMTPTests/InvitationTests.swift +++ b/Tests/XMTPTests/InvitationTests.swift @@ -7,7 +7,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS import XMTPTestHelpers @available(iOS 16.0, *) diff --git a/Tests/XMTPTests/MessageTests.swift b/Tests/XMTPTests/MessageTests.swift index 0f801327..e1a9ffc9 100644 --- a/Tests/XMTPTests/MessageTests.swift +++ b/Tests/XMTPTests/MessageTests.swift @@ -7,8 +7,8 @@ import CryptoKit import XCTest -import XMTPRust -@testable import XMTP +import LibXMTP +@testable import XMTPiOS import XMTPTestHelpers @available(iOS 16.0, *) diff --git a/Tests/XMTPTests/PaginationTests.swift b/Tests/XMTPTests/PaginationTests.swift index 8b792ab9..92939c7d 100644 --- a/Tests/XMTPTests/PaginationTests.swift +++ b/Tests/XMTPTests/PaginationTests.swift @@ -8,8 +8,8 @@ import Foundation import XCTest -@testable import XMTP -import XMTPRust +@testable import XMTPiOS +import LibXMTP import XMTPTestHelpers @available(iOS 15, *) diff --git a/Tests/XMTPTests/PrivateKeyBundleTests.swift b/Tests/XMTPTests/PrivateKeyBundleTests.swift index cd72e54d..08108469 100644 --- a/Tests/XMTPTests/PrivateKeyBundleTests.swift +++ b/Tests/XMTPTests/PrivateKeyBundleTests.swift @@ -7,7 +7,7 @@ import secp256k1 import XCTest -@testable import XMTP +@testable import XMTPiOS class PrivateKeyBundleTests: XCTestCase { func testConversion() async throws { diff --git a/Tests/XMTPTests/ReactionTests.swift b/Tests/XMTPTests/ReactionTests.swift index 797a1dcc..f1d6e26d 100644 --- a/Tests/XMTPTests/ReactionTests.swift +++ b/Tests/XMTPTests/ReactionTests.swift @@ -8,7 +8,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS @available(iOS 15, *) class ReactionTests: XCTestCase { diff --git a/Tests/XMTPTests/ReadReceiptTests.swift b/Tests/XMTPTests/ReadReceiptTests.swift index 8a91e38b..9675cc36 100644 --- a/Tests/XMTPTests/ReadReceiptTests.swift +++ b/Tests/XMTPTests/ReadReceiptTests.swift @@ -8,7 +8,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS @available(iOS 15, *) class ReadReceiptTests: XCTestCase { diff --git a/Tests/XMTPTests/RemoteAttachmentTest.swift b/Tests/XMTPTests/RemoteAttachmentTest.swift index 712f55d4..a49882d3 100644 --- a/Tests/XMTPTests/RemoteAttachmentTest.swift +++ b/Tests/XMTPTests/RemoteAttachmentTest.swift @@ -7,7 +7,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS // Fakes HTTPS urls struct TestFetcher: RemoteContentFetcher { diff --git a/Tests/XMTPTests/ReplyTests.swift b/Tests/XMTPTests/ReplyTests.swift index 72a7dbae..3e4433c5 100644 --- a/Tests/XMTPTests/ReplyTests.swift +++ b/Tests/XMTPTests/ReplyTests.swift @@ -7,7 +7,7 @@ import Foundation import XCTest -@testable import XMTP +@testable import XMTPiOS @available(iOS 15, *) class ReplyTests: XCTestCase { diff --git a/Tests/XMTPTests/SignatureTests.swift b/Tests/XMTPTests/SignatureTests.swift index edf72a75..235dbd2c 100644 --- a/Tests/XMTPTests/SignatureTests.swift +++ b/Tests/XMTPTests/SignatureTests.swift @@ -7,7 +7,7 @@ import CryptoKit import XCTest -@testable import XMTP +@testable import XMTPiOS class SignatureTests: XCTestCase { func testVerify() async throws { diff --git a/XMTP.podspec b/XMTP.podspec index 547b4645..3bbf1898 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -44,5 +44,5 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift", "= 0.3.0" - spec.dependency 'XMTPRust', '= 0.3.7-beta0' + spec.dependency 'LibXMTP', '= 0.0.1-timeout0' end diff --git a/XMTPiOSExample/NotificationService/NotificationService.swift b/XMTPiOSExample/NotificationService/NotificationService.swift index 15c2893c..27f07d1c 100644 --- a/XMTPiOSExample/NotificationService/NotificationService.swift +++ b/XMTPiOSExample/NotificationService/NotificationService.swift @@ -6,7 +6,7 @@ // import UserNotifications -import XMTP +import XMTPiOS class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? diff --git a/XMTPiOSExample/XMTPiOSExample/Account/Account.swift b/XMTPiOSExample/XMTPiOSExample/Account/Account.swift index 08dee608..a0acfb79 100644 --- a/XMTPiOSExample/XMTPiOSExample/Account/Account.swift +++ b/XMTPiOSExample/XMTPiOSExample/Account/Account.swift @@ -5,7 +5,7 @@ // Created by Pat Nakajima on 11/22/22. // import Foundation -import XMTP +import XMTPiOS /// Wrapper around a WalletConnect V1 wallet connection. Account conforms to ``SigningKey`` so /// you can use it to create a ``Client``. diff --git a/XMTPiOSExample/XMTPiOSExample/Account/AccountManager.swift b/XMTPiOSExample/XMTPiOSExample/Account/AccountManager.swift index 68a95939..9dd31539 100644 --- a/XMTPiOSExample/XMTPiOSExample/Account/AccountManager.swift +++ b/XMTPiOSExample/XMTPiOSExample/Account/AccountManager.swift @@ -6,7 +6,7 @@ // import Foundation -import XMTP +import XMTPiOS class AccountManager: ObservableObject { var account: Account diff --git a/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift b/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift index 830ec56d..2c6461c7 100644 --- a/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift +++ b/XMTPiOSExample/XMTPiOSExample/Account/WalletConnection.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import WalletConnectSwift import web3 -import XMTP +import XMTPiOS import UIKit extension WCURL { diff --git a/XMTPiOSExample/XMTPiOSExample/ContentView.swift b/XMTPiOSExample/XMTPiOSExample/ContentView.swift index 1b80321a..1ff2877b 100644 --- a/XMTPiOSExample/XMTPiOSExample/ContentView.swift +++ b/XMTPiOSExample/XMTPiOSExample/ContentView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct ContentView: View { enum Status { diff --git a/XMTPiOSExample/XMTPiOSExample/Persistence.swift b/XMTPiOSExample/XMTPiOSExample/Persistence.swift index 9ed963db..ec5cea5d 100644 --- a/XMTPiOSExample/XMTPiOSExample/Persistence.swift +++ b/XMTPiOSExample/XMTPiOSExample/Persistence.swift @@ -7,7 +7,7 @@ import Foundation import KeychainAccess -import XMTP +import XMTPiOS struct Persistence { var keychain: Keychain diff --git a/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift b/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift index 123fd2bc..8fb8ab06 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct ConversationDetailView: View { var client: XMTP.Client diff --git a/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift b/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift index f92c2465..b9de7d2c 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct ConversationListView: View { var client: XMTP.Client diff --git a/XMTPiOSExample/XMTPiOSExample/Views/LoggedInView.swift b/XMTPiOSExample/XMTPiOSExample/Views/LoggedInView.swift index 9af2774c..bbd917cb 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/LoggedInView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/LoggedInView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS class EnvironmentCoordinator: ObservableObject { @Published var path = NavigationPath() diff --git a/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift b/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift index 3cf8523c..508e4e8c 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift @@ -7,7 +7,7 @@ import SwiftUI import WebKit -import XMTP +import XMTPiOS import WalletConnectRelay import Combine import SwiftUI diff --git a/XMTPiOSExample/XMTPiOSExample/Views/MessageCellView.swift b/XMTPiOSExample/XMTPiOSExample/Views/MessageCellView.swift index 624c015e..4af9468b 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/MessageCellView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/MessageCellView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct MessageCellView: View { var myAddress: String diff --git a/XMTPiOSExample/XMTPiOSExample/Views/MessageComposerView.swift b/XMTPiOSExample/XMTPiOSExample/Views/MessageComposerView.swift index 22203cca..3e7f8fa9 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/MessageComposerView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/MessageComposerView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct MessageComposerView: View { @State private var text: String = "" diff --git a/XMTPiOSExample/XMTPiOSExample/Views/MessageListView.swift b/XMTPiOSExample/XMTPiOSExample/Views/MessageListView.swift index 9b3da2b2..11e63e0e 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/MessageListView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/MessageListView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct MessageListView: View { var myAddress: String diff --git a/XMTPiOSExample/XMTPiOSExample/Views/NewConversationView.swift b/XMTPiOSExample/XMTPiOSExample/Views/NewConversationView.swift index b5f3b623..c40170a5 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/NewConversationView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/NewConversationView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS struct NewConversationView: View { var client: XMTP.Client diff --git a/XMTPiOSExample/XMTPiOSExample/Views/PreviewClientProvider.swift b/XMTPiOSExample/XMTPiOSExample/Views/PreviewClientProvider.swift index a709a64c..b3ff40f7 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/PreviewClientProvider.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/PreviewClientProvider.swift @@ -7,7 +7,7 @@ import Foundation import SwiftUI -import XMTP +import XMTPiOS struct PreviewClientProvider: View { @State private var client: Client? diff --git a/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift b/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift index 75dda939..58ebb7b0 100644 --- a/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift +++ b/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift @@ -6,7 +6,7 @@ // import SwiftUI -import XMTP +import XMTPiOS class AppDelegate: NSObject, UIApplicationDelegate { func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {