From 2cd20cefa9b87f3c6be87fd69e273431326534df Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 17 Oct 2024 21:46:17 -0700 Subject: [PATCH] update to the latest libxmtp functions --- Sources/XMTPiOS/Client.swift | 4 ++-- Sources/XMTPiOS/Contacts.swift | 2 +- Sources/XMTPiOS/Conversations.swift | 14 +++++++------- Sources/XMTPiOS/Extensions/Ffi.swift | 6 +++--- Sources/XMTPiOS/Group.swift | 8 ++++---- Sources/XMTPiOS/Mls/Member.swift | 4 ++-- Sources/XMTPiOS/SigningKey.swift | 12 ++++++++++++ Tests/XMTPTests/ClientTests.swift | 22 ++++++++-------------- Tests/XMTPTests/V3ClientTests.swift | 12 +----------- 9 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index a53a06af..e9039bde 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -210,7 +210,7 @@ public final class Client { ) } - public static func buildV3(address: String, scwChainId: Int64?, options: ClientOptions) async throws -> Client { + public static func buildV3(address: String, scwChainId: Int64? = nil, options: ClientOptions) async throws -> Client { let accountAddress = if(scwChainId != nil) { "eip155:\(String(describing: scwChainId)):\(address.lowercased())" } else { address } let inboxId = try await getOrCreateInboxId(options: options, address: accountAddress) @@ -688,7 +688,7 @@ public final class Client { throw ClientError.noV3Client("Error no V3 client initialized") } do { - return Group(ffiGroup: try client.group(groupId: groupId.hexToData), client: self) + return Group(ffiGroup: try client.conversation(conversationId: groupId.hexToData), client: self) } catch { return nil } diff --git a/Sources/XMTPiOS/Contacts.swift b/Sources/XMTPiOS/Contacts.swift index c6c7e6ec..d7963054 100644 --- a/Sources/XMTPiOS/Contacts.swift +++ b/Sources/XMTPiOS/Contacts.swift @@ -248,7 +248,7 @@ public class ConsentList { func groupState(groupId: String) async throws -> ConsentState { if let client = client.v3Client { return try await client.getConsentState( - entityType: .groupId, + entityType: .conversationId, entity: groupId ).fromFFI } diff --git a/Sources/XMTPiOS/Conversations.swift b/Sources/XMTPiOS/Conversations.swift index 91c47095..98dc482b 100644 --- a/Sources/XMTPiOS/Conversations.swift +++ b/Sources/XMTPiOS/Conversations.swift @@ -54,7 +54,7 @@ final class GroupStreamCallback: FfiConversationCallback { self.callback = callback } - func onConversation(conversation: FfiGroup) { + func onConversation(conversation: FfiConversation) { self.callback(conversation.fromFFI(client: client)) } } @@ -119,7 +119,7 @@ public actor Conversations { guard let v3Client = client.v3Client else { return 0 } - return try await v3Client.conversations().syncAllGroups() + return try await v3Client.conversations().syncAllConversations() } public func groups(createdAfter: Date? = nil, createdBefore: Date? = nil, limit: Int? = nil) async throws -> [Group] { @@ -136,7 +136,7 @@ public actor Conversations { if let limit { options.limit = Int64(limit) } - return try await v3Client.conversations().list(opts: options).map { $0.fromFFI(client: client) } + return try await v3Client.conversations().listGroups(opts: options).map { $0.fromFFI(client: client) } } public func streamGroups() async throws -> AsyncThrowingStream { @@ -150,7 +150,7 @@ public actor Conversations { } continuation.yield(group) } - guard let stream = await self.client.v3Client?.conversations().stream(callback: groupCallback) else { + guard let stream = await self.client.v3Client?.conversations().streamGroups(callback: groupCallback) else { continuation.finish(throwing: GroupError.streamingFailure) return } @@ -175,7 +175,7 @@ public actor Conversations { AsyncThrowingStream { continuation in let ffiStreamActor = FfiStreamActor() let task = Task { - let stream = await self.client.v3Client?.conversations().stream( + let stream = await self.client.v3Client?.conversations().streamGroups( callback: GroupStreamCallback(client: self.client) { group in guard !Task.isCancelled else { continuation.finish() @@ -435,7 +435,7 @@ public actor Conversations { AsyncThrowingStream { continuation in let ffiStreamActor = FfiStreamActor() let task = Task { - let stream = await self.client.v3Client?.conversations().streamAllMessages( + let stream = await self.client.v3Client?.conversations().streamAllGroupMessages( messageCallback: MessageCallback(client: self.client) { message in guard !Task.isCancelled else { continuation.finish() @@ -500,7 +500,7 @@ public actor Conversations { AsyncThrowingStream { continuation in let ffiStreamActor = FfiStreamActor() let task = Task { - let stream = await self.client.v3Client?.conversations().streamAllMessages( + let stream = await self.client.v3Client?.conversations().streamAllGroupMessages( messageCallback: MessageCallback(client: self.client) { message in guard !Task.isCancelled else { continuation.finish() diff --git a/Sources/XMTPiOS/Extensions/Ffi.swift b/Sources/XMTPiOS/Extensions/Ffi.swift index 23c58f8f..60e6787b 100644 --- a/Sources/XMTPiOS/Extensions/Ffi.swift +++ b/Sources/XMTPiOS/Extensions/Ffi.swift @@ -195,13 +195,13 @@ extension FfiV2SubscribeRequest { // MARK: Group -extension FfiGroup { +extension FfiConversation { func fromFFI(client: Client) -> Group { Group(ffiGroup: self, client: client) } } -extension FfiGroupMember { +extension FfiConversationMember { var fromFFI: Member { Member(ffiGroupMember: self) } @@ -230,7 +230,7 @@ extension FfiConsentState { extension EntryType { var toFFI: FfiConsentEntityType{ switch (self) { - case .group_id: return FfiConsentEntityType.groupId + case .group_id: return FfiConsentEntityType.conversationId case .inbox_id: return FfiConsentEntityType.inboxId case .address: return FfiConsentEntityType.address } diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index b9ee9d24..dfc4a2e1 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -27,7 +27,7 @@ final class StreamHolder { } public struct Group: Identifiable, Equatable, Hashable { - var ffiGroup: FfiGroup + var ffiGroup: FfiConversation var client: Client let streamHolder = StreamHolder() @@ -39,7 +39,7 @@ public struct Group: Identifiable, Equatable, Hashable { Topic.groupMessage(id).description } - func metadata() throws -> FfiGroupMetadata { + func metadata() throws -> FfiConversationMetadata { return try ffiGroup.groupMetadata() } @@ -230,12 +230,12 @@ public struct Group: Identifiable, Equatable, Hashable { } public func processMessage(envelopeBytes: Data) async throws -> DecodedMessage { - let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes) + let message = try await ffiGroup.processStreamedConversationMessage(envelopeBytes: envelopeBytes) return try MessageV3(client: client, ffiMessage: message).decode() } public func processMessageDecrypted(envelopeBytes: Data) async throws -> DecryptedMessage { - let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes) + let message = try await ffiGroup.processStreamedConversationMessage(envelopeBytes: envelopeBytes) return try MessageV3(client: client, ffiMessage: message).decrypt() } diff --git a/Sources/XMTPiOS/Mls/Member.swift b/Sources/XMTPiOS/Mls/Member.swift index 1e0885e3..fcc4a1e4 100644 --- a/Sources/XMTPiOS/Mls/Member.swift +++ b/Sources/XMTPiOS/Mls/Member.swift @@ -13,9 +13,9 @@ public enum PermissionLevel { } public struct Member { - var ffiGroupMember: FfiGroupMember + var ffiGroupMember: FfiConversationMember - init(ffiGroupMember: FfiGroupMember) { + init(ffiGroupMember: FfiConversationMember) { self.ffiGroupMember = ffiGroupMember } diff --git a/Sources/XMTPiOS/SigningKey.swift b/Sources/XMTPiOS/SigningKey.swift index 4208cba6..20523242 100644 --- a/Sources/XMTPiOS/SigningKey.swift +++ b/Sources/XMTPiOS/SigningKey.swift @@ -74,4 +74,16 @@ extension SigningKey { return AuthorizedIdentity(address: address, authorized: authorized, identity: identity) } + + public func sign(_ data: Data) async throws -> Signature { + throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "sign(Data) not implemented."]) + } + + public func sign(message: String) async throws -> Signature { + throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "sign(String) not implemented."]) + } + + public func signSCW(message: String) async throws -> Data { + throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "signSCW(String) not implemented."]) + } } diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index eb687e23..00843749 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -469,12 +469,19 @@ class ClientTests: XCTestCase { let inboxId = try await Client.getOrCreateInboxId(options: options, address: alix.address) - let alixClient = try await Client.createOrBuild( + let alixClient = try await Client.createV3( account: alix, options: options ) XCTAssertEqual(inboxId, alixClient.inboxID) + + let alixClient2 = try await Client.buildV3( + address: alix.address, + options: options + ) + + XCTAssertEqual(alixClient2.inboxID, alixClient.inboxID) } func testRevokesAllOtherInstallations() async throws { @@ -514,17 +521,4 @@ class ClientTests: XCTestCase { let newState = try await alixClient3.inboxState(refreshFromNetwork: true) XCTAssertEqual(newState.installations.count, 1) } - - func testCanCreateASCW() async throws { - let key = try Crypto.secureRandomBytes(count: 32) - let davonSCW = try FakeSCWWallet.generate() - let davonSCWClient = try await Client.createOrBuild( - account: davonSCW, - options: .init( - api: .init(env: .local, isSecure: false), - enableV3: true, - encryptionKey: key - ) - ) - } } diff --git a/Tests/XMTPTests/V3ClientTests.swift b/Tests/XMTPTests/V3ClientTests.swift index 9a19b5e0..91a70fd8 100644 --- a/Tests/XMTPTests/V3ClientTests.swift +++ b/Tests/XMTPTests/V3ClientTests.swift @@ -34,7 +34,7 @@ class V3ClientTests: XCTestCase { ) ) let boV3 = try PrivateKey.generate() - let boV3Client = try await Client.createOrBuild( + let boV3Client = try await Client.createV3( account: boV3, options: .init( api: .init(env: .local, isSecure: false), @@ -52,16 +52,6 @@ class V3ClientTests: XCTestCase { ) ) - let davonSCW = try FakeSCWWallet.generate() - let davonSCWClient = try await Client.createOrBuild( - account: davonSCW, - options: .init( - api: .init(env: .local, isSecure: false), - enableV3: true, - encryptionKey: key - ) - ) - return .init( alixV2: alixV2,