diff --git a/Package.swift b/Package.swift index f69541a6..4f2a16d0 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "0.12.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.7-beta4"), + .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.8-beta0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index 7e3273a3..62071acf 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -603,4 +603,26 @@ public final class Client { } try await client.requestHistorySync() } + + public func revokeAllOtherInstallations(signingKey: SigningKey) async throws { + guard let client = v3Client else { + throw ClientError.noV3Client("Error: No V3 client initialized") + } + + let signatureRequest = try await client.revokeAllOtherInstallations() + do { + let signedData = try await signingKey.sign(message: signatureRequest.signatureText()) + try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData) + try await client.applySignatureRequest(signatureRequest: signatureRequest) + } catch { + throw ClientError.creationError("Failed to sign the message: \(error.localizedDescription)") + } + } + + public func inboxState(refreshFromNetwork: Bool) async throws -> InboxState { + guard let client = v3Client else { + throw ClientError.noV3Client("Error: No V3 client initialized") + } + return InboxState(ffiInboxState: try await client.inboxState(refreshFromNetwork: refreshFromNetwork)) + } } diff --git a/Sources/XMTPiOS/Mls/InboxState.swift b/Sources/XMTPiOS/Mls/InboxState.swift new file mode 100644 index 00000000..f604f15c --- /dev/null +++ b/Sources/XMTPiOS/Mls/InboxState.swift @@ -0,0 +1,34 @@ +// +// InboxState.swift +// +// +// Created by Naomi Plasterer on 8/21/24. +// + +import Foundation +import LibXMTP + +public struct InboxState { + var ffiInboxState: FfiInboxState + + init(ffiInboxState: FfiInboxState) { + self.ffiInboxState = ffiInboxState + } + + public var inboxId: String { + ffiInboxState.inboxId + } + + public var addresses: [String] { + ffiInboxState.accountAddresses + } + + public var installationIds: [String] { + ffiInboxState.installationIds.map { $0.toHex } + } + + public var recoveryAddress: String { + ffiInboxState.recoveryAddress + } + +} diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 6ecdf6bd..27c0381a 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -455,4 +455,41 @@ class ClientTests: XCTestCase { XCTAssertEqual(inboxId, alixClient.inboxID) } + + func testRevokesAllOtherInstallations() async throws { + let key = try Crypto.secureRandomBytes(count: 32) + let alix = try PrivateKey.generate() + let options = ClientOptions.init( + api: .init(env: .local, isSecure: false), + enableV3: true, + encryptionKey: key + ) + + let alixClient = try await Client.create( + account: alix, + options: options + ) + try alixClient.dropLocalDatabaseConnection() + try alixClient.deleteLocalDatabase() + + let alixClient2 = try await Client.create( + account: alix, + options: options + ) + try alixClient2.dropLocalDatabaseConnection() + try alixClient2.deleteLocalDatabase() + + let alixClient3 = try await Client.create( + account: alix, + options: options + ) + + let state = try await alixClient3.inboxState(refreshFromNetwork: true) + XCTAssertEqual(state.installationIds.count, 3) + + try await alixClient3.revokeAllOtherInstallations(signingKey: alix) + + let newState = try await alixClient3.inboxState(refreshFromNetwork: true) + XCTAssertEqual(newState.installationIds.count, 1) + } } diff --git a/XMTP.podspec b/XMTP.podspec index dd81f389..04c6fc6d 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "XMTP" - spec.version = "0.14.7" + spec.version = "0.14.8" spec.summary = "XMTP SDK Cocoapod" # This description is used to generate tags and improve search results. @@ -44,5 +44,5 @@ Pod::Spec.new do |spec| spec.dependency "web3.swift" spec.dependency "GzipSwift" spec.dependency "Connect-Swift", "= 0.12.0" - spec.dependency 'LibXMTP', '= 0.5.7-beta4' + spec.dependency 'LibXMTP', '= 0.5.8-beta0' end diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5f1e124e..44ba5919 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift.git", "state" : { - "revision" : "39a3bfd39adc93cf3207946ab302a3579014f369", - "version" : "0.5.7-beta4" + "revision" : "5ff057ed6ab42ba8cdc9cb9c107dddfc5fb4746b", + "version" : "0.5.8-beta0" } }, {