diff --git a/LibXMTP.podspec b/LibXMTP.podspec index 810a15a..edc7bf5 100644 --- a/LibXMTP.podspec +++ b/LibXMTP.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LibXMTP' - s.version = '0.4.4-beta6' + s.version = '0.5.0-beta0' s.summary = 'XMTP shared Rust code that powers cross-platform SDKs' s.homepage = 'https://github.com/xmtp/libxmtp-swift' @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.platform = :ios, '13.0', :macos, '11.0' s.swift_version = '5.3' - s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-5b7cb6b/LibXMTPSwiftFFI.zip", :type => :zip } + s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-ca024cb/LibXMTPSwiftFFI.zip", :type => :zip } s.vendored_frameworks = 'LibXMTPSwiftFFI.xcframework' s.source_files = 'Sources/LibXMTP/**/*' end diff --git a/Package.swift b/Package.swift index b745012..5866c32 100644 --- a/Package.swift +++ b/Package.swift @@ -27,8 +27,8 @@ let package = Package( ), .binaryTarget( name: "LibXMTPSwiftFFI", - url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-5b7cb6b/LibXMTPSwiftFFI.zip", - checksum: "983c29d166fb5433b9a2c3025e624e420a05854a20946e897c76468ad92d5928" + url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-ca024cb/LibXMTPSwiftFFI.zip", + checksum: "2e06d57a14c849e89803c2294d46c4f09ae6d7797153ebbd510194adc6c42852" ), .testTarget(name: "LibXMTPTests", dependencies: ["LibXMTP"]), ] diff --git a/Sources/LibXMTP/libxmtp-version.txt b/Sources/LibXMTP/libxmtp-version.txt index d916fa7..9311802 100644 --- a/Sources/LibXMTP/libxmtp-version.txt +++ b/Sources/LibXMTP/libxmtp-version.txt @@ -1,3 +1,3 @@ -Version: 5b7cb6bc +Version: ca024cbb Branch: main -Date: 2024-05-23 17:10:07 +0000 +Date: 2024-05-24 20:35:12 +0000 diff --git a/Sources/LibXMTP/xmtpv3.swift b/Sources/LibXMTP/xmtpv3.swift index 18a1659..5296dd9 100644 --- a/Sources/LibXMTP/xmtpv3.swift +++ b/Sources/LibXMTP/xmtpv3.swift @@ -1,5 +1,7 @@ // This file was autogenerated by some hot garbage in the `uniffi` crate. // Trust me, you don't want to mess with it! + +// swiftlint:disable all import Foundation // Depending on the consumer's build setup, the low-level FFI code @@ -18,6 +20,10 @@ private extension RustBuffer { self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) } + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len: 0, data: nil) + } + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { try! rustCall { ffi_xmtpv3_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } @@ -221,9 +227,17 @@ private enum UniffiInternalError: LocalizedError { } } +private extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + lock() + defer { self.unlock() } + return try f() + } +} + private let CALL_SUCCESS: Int8 = 0 private let CALL_ERROR: Int8 = 1 -private let CALL_PANIC: Int8 = 2 +private let CALL_UNEXPECTED_ERROR: Int8 = 2 private let CALL_CANCELLED: Int8 = 3 private extension RustCallStatus { @@ -277,7 +291,7 @@ private func uniffiCheckCallStatus( throw UniffiInternalError.unexpectedRustCallError } - case CALL_PANIC: + case CALL_UNEXPECTED_ERROR: // When the rust code sees a panic, it tries to construct a RustBuffer // with the message. But if that code panics, then it just sends back // an empty buffer. @@ -289,13 +303,81 @@ private func uniffiCheckCallStatus( } case CALL_CANCELLED: - throw CancellationError() + fatalError("Cancellation not supported yet") default: throw UniffiInternalError.unexpectedRustCallStatusCode } } +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void +) { + do { + try writeReturn(makeCall()) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> Void, + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private class UniffiHandleMap { + private var map: [UInt64: T] = [:] + private let lock = NSLock() + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + map.count + } +} + // Public interface members begin here. private struct FfiConverterUInt8: FfiConverterPrimitive { @@ -424,116 +506,149 @@ private struct FfiConverterData: FfiConverterRustBuffer { } } -public protocol FfiConversationsProtocol { +public protocol FfiConversationsProtocol: AnyObject { func createGroup(accountAddresses: [String], permissions: GroupPermissions?) async throws -> FfiGroup + func list(opts: FfiListConversationsOptions) async throws -> [FfiGroup] + func processStreamedWelcomeMessage(envelopeBytes: Data) throws -> FfiGroup + func stream(callback: FfiConversationCallback) async throws -> FfiStreamCloser + func streamAllMessages(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser + func sync() async throws } -public class FfiConversations: FfiConversationsProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiConversations: + FfiConversationsProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_fficonversations(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_fficonversations(pointer, $0) } } - public func createGroup(accountAddresses: [String], permissions: GroupPermissions?) async throws -> FfiGroup { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_fficonversations_create_group( - self.pointer, - FfiConverterSequenceString.lower(accountAddresses), - FfiConverterOptionTypeGroupPermissions.lower(permissions) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiGroup.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func createGroup(accountAddresses: [String], permissions: GroupPermissions?) async throws -> FfiGroup { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_fficonversations_create_group( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(accountAddresses), FfiConverterOptionTypeGroupPermissions.lower(permissions) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiGroup.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func list(opts: FfiListConversationsOptions) async throws -> [FfiGroup] { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_fficonversations_list( - self.pointer, - FfiConverterTypeFfiListConversationsOptions.lower(opts) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterSequenceTypeFfiGroup.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func list(opts: FfiListConversationsOptions) async throws -> [FfiGroup] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_fficonversations_list( + self.uniffiClonePointer(), + FfiConverterTypeFfiListConversationsOptions.lower(opts) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceTypeFfiGroup.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func processStreamedWelcomeMessage(envelopeBytes: Data) throws -> FfiGroup { - return try FfiConverterTypeFfiGroup.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_fficonversations_process_streamed_welcome_message(self.pointer, - FfiConverterData.lower(envelopeBytes), $0) - } - ) + open func processStreamedWelcomeMessage(envelopeBytes: Data) throws -> FfiGroup { + return try FfiConverterTypeFfiGroup.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_fficonversations_process_streamed_welcome_message(self.uniffiClonePointer(), + FfiConverterData.lower(envelopeBytes), $0) + }) } - public func stream(callback: FfiConversationCallback) async throws -> FfiStreamCloser { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_fficonversations_stream( - self.pointer, - FfiConverterCallbackInterfaceFfiConversationCallback.lower(callback) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiStreamCloser.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func stream(callback: FfiConversationCallback) async throws -> FfiStreamCloser { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_fficonversations_stream( + self.uniffiClonePointer(), + FfiConverterCallbackInterfaceFfiConversationCallback.lower(callback) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiStreamCloser.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func streamAllMessages(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_fficonversations_stream_all_messages( - self.pointer, - FfiConverterCallbackInterfaceFfiMessageCallback.lower(messageCallback) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiStreamCloser.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func streamAllMessages(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_fficonversations_stream_all_messages( + self.uniffiClonePointer(), + FfiConverterCallbackInterfaceFfiMessageCallback.lower(messageCallback) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiStreamCloser.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func sync() async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_fficonversations_sync( - self.pointer - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func sync() async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_fficonversations_sync( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } } @@ -541,6 +656,14 @@ public struct FfiConverterTypeFfiConversations: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiConversations + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiConversations { + return FfiConversations(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiConversations) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiConversations { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -557,14 +680,6 @@ public struct FfiConverterTypeFfiConversations: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiConversations { - return FfiConversations(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiConversations) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiConversations_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiConversations { @@ -575,214 +690,281 @@ public func FfiConverterTypeFfiConversations_lower(_ value: FfiConversations) -> return FfiConverterTypeFfiConversations.lower(value) } -public protocol FfiGroupProtocol { +public protocol FfiGroupProtocol: AnyObject { func addMembers(accountAddresses: [String]) async throws - func addedByAddress() throws -> String + + func addMembersByInboxId(inboxIds: [String]) async throws + + func addedByInboxId() throws -> String + func createdAtNs() -> Int64 + func findMessages(opts: FfiListMessagesOptions) throws -> [FfiMessage] + func groupMetadata() throws -> FfiGroupMetadata + func groupName() throws -> String + func id() -> Data + func isActive() throws -> Bool + func listMembers() throws -> [FfiGroupMember] + func processStreamedGroupMessage(envelopeBytes: Data) async throws -> FfiMessage + func removeMembers(accountAddresses: [String]) async throws + + func removeMembersByInboxId(inboxIds: [String]) async throws + func send(contentBytes: Data) async throws -> Data + func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser + func sync() async throws + func updateGroupName(groupName: String) async throws } -public class FfiGroup: FfiGroupProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiGroup: + FfiGroupProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffigroup(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffigroup(pointer, $0) } } - public func addMembers(accountAddresses: [String]) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_add_members( - self.pointer, - FfiConverterSequenceString.lower(accountAddresses) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func addMembers(accountAddresses: [String]) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_add_members( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(accountAddresses) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func addedByAddress() throws -> String { - return try FfiConverterString.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_added_by_address(self.pointer, $0) - } - ) + open func addMembersByInboxId(inboxIds: [String]) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_add_members_by_inbox_id( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(inboxIds) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func createdAtNs() -> Int64 { - return try! FfiConverterInt64.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffigroup_created_at_ns(self.pointer, $0) - } - ) + open func addedByInboxId() throws -> String { + return try FfiConverterString.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_added_by_inbox_id(self.uniffiClonePointer(), $0) + }) } - public func findMessages(opts: FfiListMessagesOptions) throws -> [FfiMessage] { - return try FfiConverterSequenceTypeFfiMessage.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_find_messages(self.pointer, - FfiConverterTypeFfiListMessagesOptions.lower(opts), $0) - } - ) + open func createdAtNs() -> Int64 { + return try! FfiConverterInt64.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffigroup_created_at_ns(self.uniffiClonePointer(), $0) + }) } - public func groupMetadata() throws -> FfiGroupMetadata { - return try FfiConverterTypeFfiGroupMetadata.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_group_metadata(self.pointer, $0) - } - ) + open func findMessages(opts: FfiListMessagesOptions) throws -> [FfiMessage] { + return try FfiConverterSequenceTypeFfiMessage.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_find_messages(self.uniffiClonePointer(), + FfiConverterTypeFfiListMessagesOptions.lower(opts), $0) + }) } - public func groupName() throws -> String { - return try FfiConverterString.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_group_name(self.pointer, $0) - } - ) + open func groupMetadata() throws -> FfiGroupMetadata { + return try FfiConverterTypeFfiGroupMetadata.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_group_metadata(self.uniffiClonePointer(), $0) + }) } - public func id() -> Data { - return try! FfiConverterData.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffigroup_id(self.pointer, $0) - } - ) + open func groupName() throws -> String { + return try FfiConverterString.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_group_name(self.uniffiClonePointer(), $0) + }) } - public func isActive() throws -> Bool { - return try FfiConverterBool.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_is_active(self.pointer, $0) - } - ) + open func id() -> Data { + return try! FfiConverterData.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffigroup_id(self.uniffiClonePointer(), $0) + }) } - public func listMembers() throws -> [FfiGroupMember] { - return try FfiConverterSequenceTypeFfiGroupMember.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigroup_list_members(self.pointer, $0) - } - ) + open func isActive() throws -> Bool { + return try FfiConverterBool.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_is_active(self.uniffiClonePointer(), $0) + }) } - public func processStreamedGroupMessage(envelopeBytes: Data) async throws -> FfiMessage { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_process_streamed_group_message( - self.pointer, - FfiConverterData.lower(envelopeBytes) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeFfiMessage.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func listMembers() throws -> [FfiGroupMember] { + return try FfiConverterSequenceTypeFfiGroupMember.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_list_members(self.uniffiClonePointer(), $0) + }) } - public func removeMembers(accountAddresses: [String]) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_remove_members( - self.pointer, - FfiConverterSequenceString.lower(accountAddresses) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func processStreamedGroupMessage(envelopeBytes: Data) async throws -> FfiMessage { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_process_streamed_group_message( + self.uniffiClonePointer(), + FfiConverterData.lower(envelopeBytes) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeFfiMessage.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func send(contentBytes: Data) async throws -> Data { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_send( - self.pointer, - FfiConverterData.lower(contentBytes) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterData.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func removeMembers(accountAddresses: [String]) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_remove_members( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(accountAddresses) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_stream( - self.pointer, - FfiConverterCallbackInterfaceFfiMessageCallback.lower(messageCallback) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiStreamCloser.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func removeMembersByInboxId(inboxIds: [String]) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_remove_members_by_inbox_id( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(inboxIds) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func sync() async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_sync( - self.pointer - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func send(contentBytes: Data) async throws -> Data { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_send( + self.uniffiClonePointer(), + FfiConverterData.lower(contentBytes) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterData.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func updateGroupName(groupName: String) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffigroup_update_group_name( - self.pointer, - FfiConverterString.lower(groupName) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func stream(messageCallback: FfiMessageCallback) async throws -> FfiStreamCloser { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_stream( + self.uniffiClonePointer(), + FfiConverterCallbackInterfaceFfiMessageCallback.lower(messageCallback) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiStreamCloser.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + + open func sync() async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_sync( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + + open func updateGroupName(groupName: String) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffigroup_update_group_name( + self.uniffiClonePointer(), + FfiConverterString.lower(groupName) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } } @@ -790,6 +972,14 @@ public struct FfiConverterTypeFfiGroup: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiGroup + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroup { + return FfiGroup(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiGroup) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGroup { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -806,14 +996,6 @@ public struct FfiConverterTypeFfiGroup: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroup { - return FfiGroup(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiGroup) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiGroup_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroup { @@ -824,41 +1006,62 @@ public func FfiConverterTypeFfiGroup_lower(_ value: FfiGroup) -> UnsafeMutableRa return FfiConverterTypeFfiGroup.lower(value) } -public protocol FfiGroupMetadataProtocol { +public protocol FfiGroupMetadataProtocol: AnyObject { func conversationType() -> String - func creatorAccountAddress() -> String + + func creatorInboxId() -> String } -public class FfiGroupMetadata: FfiGroupMetadataProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiGroupMetadata: + FfiGroupMetadataProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffigroupmetadata(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffigroupmetadata(pointer, $0) } } - public func conversationType() -> String { - return try! FfiConverterString.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffigroupmetadata_conversation_type(self.pointer, $0) - } - ) + open func conversationType() -> String { + return try! FfiConverterString.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffigroupmetadata_conversation_type(self.uniffiClonePointer(), $0) + }) } - public func creatorAccountAddress() -> String { - return try! FfiConverterString.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffigroupmetadata_creator_account_address(self.pointer, $0) - } - ) + open func creatorInboxId() -> String { + return try! FfiConverterString.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffigroupmetadata_creator_inbox_id(self.uniffiClonePointer(), $0) + }) } } @@ -866,6 +1069,14 @@ public struct FfiConverterTypeFfiGroupMetadata: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiGroupMetadata + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupMetadata { + return FfiGroupMetadata(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiGroupMetadata) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGroupMetadata { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -882,14 +1093,6 @@ public struct FfiConverterTypeFfiGroupMetadata: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupMetadata { - return FfiGroupMetadata(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiGroupMetadata) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiGroupMetadata_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupMetadata { @@ -900,30 +1103,54 @@ public func FfiConverterTypeFfiGroupMetadata_lower(_ value: FfiGroupMetadata) -> return FfiConverterTypeFfiGroupMetadata.lower(value) } -public protocol FfiGroupPermissionsProtocol { +public protocol FfiGroupPermissionsProtocol: AnyObject { func policyType() throws -> GroupPermissions } -public class FfiGroupPermissions: FfiGroupPermissionsProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiGroupPermissions: + FfiGroupPermissionsProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffigrouppermissions(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffigrouppermissions(pointer, $0) } } - public func policyType() throws -> GroupPermissions { - return try FfiConverterTypeGroupPermissions.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffigrouppermissions_policy_type(self.pointer, $0) - } - ) + open func policyType() throws -> GroupPermissions { + return try FfiConverterTypeGroupPermissions.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigrouppermissions_policy_type(self.uniffiClonePointer(), $0) + }) } } @@ -931,6 +1158,14 @@ public struct FfiConverterTypeFfiGroupPermissions: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiGroupPermissions + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupPermissions { + return FfiGroupPermissions(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiGroupPermissions) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGroupPermissions { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -947,14 +1182,6 @@ public struct FfiConverterTypeFfiGroupPermissions: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupPermissions { - return FfiGroupPermissions(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiGroupPermissions) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiGroupPermissions_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiGroupPermissions { @@ -965,39 +1192,222 @@ public func FfiConverterTypeFfiGroupPermissions_lower(_ value: FfiGroupPermissio return FfiConverterTypeFfiGroupPermissions.lower(value) } -public protocol FfiStreamCloserProtocol { +public protocol FfiSignatureRequestProtocol: AnyObject { + func addEcdsaSignature(signatureBytes: Data) async throws + + func addErc1271Signature(signatureBytes: Data, address: String, chainRpcUrl: String) async throws + + /** + * missing signatures that are from [MemberKind::Address] + */ + func missingAddressSignatures() async throws -> [String] + + func signatureText() async throws -> String +} + +open class FfiSignatureRequest: + FfiSignatureRequestProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffisignaturerequest(self.pointer, $0) } + } + + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_xmtpv3_fn_free_ffisignaturerequest(pointer, $0) } + } + + open func addEcdsaSignature(signatureBytes: Data) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffisignaturerequest_add_ecdsa_signature( + self.uniffiClonePointer(), + FfiConverterData.lower(signatureBytes) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + + open func addErc1271Signature(signatureBytes: Data, address: String, chainRpcUrl: String) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffisignaturerequest_add_erc1271_signature( + self.uniffiClonePointer(), + FfiConverterData.lower(signatureBytes), FfiConverterString.lower(address), FfiConverterString.lower(chainRpcUrl) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + + /** + * missing signatures that are from [MemberKind::Address] + */ + open func missingAddressSignatures() async throws -> [String] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffisignaturerequest_missing_address_signatures( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceString.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + + open func signatureText() async throws -> String { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffisignaturerequest_signature_text( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterString.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) + } +} + +public struct FfiConverterTypeFfiSignatureRequest: FfiConverter { + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = FfiSignatureRequest + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiSignatureRequest { + return FfiSignatureRequest(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiSignatureRequest) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiSignatureRequest { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if ptr == nil { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: FfiSignatureRequest, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + +public func FfiConverterTypeFfiSignatureRequest_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiSignatureRequest { + return try FfiConverterTypeFfiSignatureRequest.lift(pointer) +} + +public func FfiConverterTypeFfiSignatureRequest_lower(_ value: FfiSignatureRequest) -> UnsafeMutableRawPointer { + return FfiConverterTypeFfiSignatureRequest.lower(value) +} + +public protocol FfiStreamCloserProtocol: AnyObject { func end() + func isClosed() -> Bool } -public class FfiStreamCloser: FfiStreamCloserProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiStreamCloser: + FfiStreamCloserProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffistreamcloser(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffistreamcloser(pointer, $0) } } - public func end() { - try! - rustCall { - uniffi_xmtpv3_fn_method_ffistreamcloser_end(self.pointer, $0) - } + open func end() { try! rustCall { + uniffi_xmtpv3_fn_method_ffistreamcloser_end(self.uniffiClonePointer(), $0) + } } - public func isClosed() -> Bool { - return try! FfiConverterBool.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(self.pointer, $0) - } - ) + open func isClosed() -> Bool { + return try! FfiConverterBool.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffistreamcloser_is_closed(self.uniffiClonePointer(), $0) + }) } } @@ -1005,6 +1415,14 @@ public struct FfiConverterTypeFfiStreamCloser: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiStreamCloser + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiStreamCloser { + return FfiStreamCloser(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiStreamCloser) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiStreamCloser { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -1021,14 +1439,6 @@ public struct FfiConverterTypeFfiStreamCloser: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiStreamCloser { - return FfiStreamCloser(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiStreamCloser) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiStreamCloser_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiStreamCloser { @@ -1039,99 +1449,130 @@ public func FfiConverterTypeFfiStreamCloser_lower(_ value: FfiStreamCloser) -> U return FfiConverterTypeFfiStreamCloser.lower(value) } -public protocol FfiV2ApiClientProtocol { +public protocol FfiV2ApiClientProtocol: AnyObject { func batchQuery(req: FfiV2BatchQueryRequest) async throws -> FfiV2BatchQueryResponse + func publish(request: FfiPublishRequest, authToken: String) async throws + func query(request: FfiV2QueryRequest) async throws -> FfiV2QueryResponse + func setAppVersion(version: String) + func subscribe(request: FfiV2SubscribeRequest) async throws -> FfiV2Subscription } -public class FfiV2ApiClient: FfiV2ApiClientProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiV2ApiClient: + FfiV2ApiClientProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffiv2apiclient(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffiv2apiclient(pointer, $0) } } - public func batchQuery(req: FfiV2BatchQueryRequest) async throws -> FfiV2BatchQueryResponse { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2apiclient_batch_query( - self.pointer, - FfiConverterTypeFfiV2BatchQueryRequest.lower(req) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeFfiV2BatchQueryResponse.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func batchQuery(req: FfiV2BatchQueryRequest) async throws -> FfiV2BatchQueryResponse { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2apiclient_batch_query( + self.uniffiClonePointer(), + FfiConverterTypeFfiV2BatchQueryRequest.lower(req) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeFfiV2BatchQueryResponse.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func publish(request: FfiPublishRequest, authToken: String) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2apiclient_publish( - self.pointer, - FfiConverterTypeFfiPublishRequest.lower(request), - FfiConverterString.lower(authToken) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func publish(request: FfiPublishRequest, authToken: String) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2apiclient_publish( + self.uniffiClonePointer(), + FfiConverterTypeFfiPublishRequest.lower(request), FfiConverterString.lower(authToken) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func query(request: FfiV2QueryRequest) async throws -> FfiV2QueryResponse { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2apiclient_query( - self.pointer, - FfiConverterTypeFfiV2QueryRequest.lower(request) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeFfiV2QueryResponse.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func query(request: FfiV2QueryRequest) async throws -> FfiV2QueryResponse { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2apiclient_query( + self.uniffiClonePointer(), + FfiConverterTypeFfiV2QueryRequest.lower(request) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeFfiV2QueryResponse.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func setAppVersion(version: String) { - try! - rustCall { - uniffi_xmtpv3_fn_method_ffiv2apiclient_set_app_version(self.pointer, - FfiConverterString.lower(version), $0) - } + open func setAppVersion(version: String) { try! rustCall { + uniffi_xmtpv3_fn_method_ffiv2apiclient_set_app_version(self.uniffiClonePointer(), + FfiConverterString.lower(version), $0) + } } - public func subscribe(request: FfiV2SubscribeRequest) async throws -> FfiV2Subscription { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2apiclient_subscribe( - self.pointer, - FfiConverterTypeFfiV2SubscribeRequest.lower(request) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiV2Subscription.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func subscribe(request: FfiV2SubscribeRequest) async throws -> FfiV2Subscription { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2apiclient_subscribe( + self.uniffiClonePointer(), + FfiConverterTypeFfiV2SubscribeRequest.lower(request) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiV2Subscription.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } } @@ -1139,6 +1580,14 @@ public struct FfiConverterTypeFfiV2ApiClient: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiV2ApiClient + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2ApiClient { + return FfiV2ApiClient(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiV2ApiClient) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2ApiClient { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -1155,14 +1604,6 @@ public struct FfiConverterTypeFfiV2ApiClient: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2ApiClient { - return FfiV2ApiClient(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiV2ApiClient) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiV2ApiClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2ApiClient { @@ -1173,70 +1614,101 @@ public func FfiConverterTypeFfiV2ApiClient_lower(_ value: FfiV2ApiClient) -> Uns return FfiConverterTypeFfiV2ApiClient.lower(value) } -public protocol FfiV2SubscriptionProtocol { +public protocol FfiV2SubscriptionProtocol: AnyObject { func end() async + func next() async throws -> FfiEnvelope + func update(req: FfiV2SubscribeRequest) async throws } -public class FfiV2Subscription: FfiV2SubscriptionProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiV2Subscription: + FfiV2SubscriptionProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffiv2subscription(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffiv2subscription(pointer, $0) } } - public func end() async { - return try! await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2subscription_end( - self.pointer - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: nil - ) + open func end() async { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2subscription_end( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: nil + ) } - public func next() async throws -> FfiEnvelope { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2subscription_next( - self.pointer - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterTypeFfiEnvelope.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func next() async throws -> FfiEnvelope { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2subscription_next( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeFfiEnvelope.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func update(req: FfiV2SubscribeRequest) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffiv2subscription_update( - self.pointer, - FfiConverterTypeFfiV2SubscribeRequest.lower(req) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func update(req: FfiV2SubscribeRequest) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffiv2subscription_update( + self.uniffiClonePointer(), + FfiConverterTypeFfiV2SubscribeRequest.lower(req) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } } @@ -1244,6 +1716,14 @@ public struct FfiConverterTypeFfiV2Subscription: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiV2Subscription + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2Subscription { + return FfiV2Subscription(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiV2Subscription) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2Subscription { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -1260,14 +1740,6 @@ public struct FfiConverterTypeFfiV2Subscription: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2Subscription { - return FfiV2Subscription(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiV2Subscription) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiV2Subscription_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiV2Subscription { @@ -1278,119 +1750,141 @@ public func FfiConverterTypeFfiV2Subscription_lower(_ value: FfiV2Subscription) return FfiConverterTypeFfiV2Subscription.lower(value) } -public protocol FfiXmtpClientProtocol { - func accountAddress() -> String +public protocol FfiXmtpClientProtocol: AnyObject { func canMessage(accountAddresses: [String]) async throws -> [String: Bool] + func conversations() -> FfiConversations + func dbReconnect() async throws + + func inboxId() -> String + func installationId() -> Data - func registerIdentity(recoverableWalletSignature: Data?) async throws + + func registerIdentity(signatureRequest: FfiSignatureRequest) async throws + func releaseDbConnection() throws - func textToSign() -> String? + + func signatureRequest() -> FfiSignatureRequest? } -public class FfiXmtpClient: FfiXmtpClientProtocol { - fileprivate let pointer: UnsafeMutableRawPointer +open class FfiXmtpClient: + FfiXmtpClientProtocol +{ + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + public struct NoPointer { + public init() {} + } // TODO: We'd like this to be `private` but for Swifty reasons, // we can't implement `FfiConverter` without making this `required` and we can't // make it `required` without making it `public`. - required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } + /// This constructor can be used to instantiate a fake object. + /// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + /// + /// - Warning: + /// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. + public init(noPointer _: NoPointer) { + pointer = nil + } + + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_xmtpv3_fn_clone_ffixmtpclient(self.pointer, $0) } + } + + // No primary constructor declared for this class. + deinit { + guard let pointer = pointer else { + return + } + try! rustCall { uniffi_xmtpv3_fn_free_ffixmtpclient(pointer, $0) } } - public func accountAddress() -> String { - return try! FfiConverterString.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffixmtpclient_account_address(self.pointer, $0) - } - ) + open func canMessage(accountAddresses: [String]) async throws -> [String: Bool] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffixmtpclient_can_message( + self.uniffiClonePointer(), + FfiConverterSequenceString.lower(accountAddresses) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterDictionaryStringBool.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func canMessage(accountAddresses: [String]) async throws -> [String: Bool] { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffixmtpclient_can_message( - self.pointer, - FfiConverterSequenceString.lower(accountAddresses) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, - completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, - freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, - liftFunc: FfiConverterDictionaryStringBool.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func conversations() -> FfiConversations { + return try! FfiConverterTypeFfiConversations.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffixmtpclient_conversations(self.uniffiClonePointer(), $0) + }) } - public func conversations() -> FfiConversations { - return try! FfiConverterTypeFfiConversations.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffixmtpclient_conversations(self.pointer, $0) - } - ) + open func dbReconnect() async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffixmtpclient_db_reconnect( + self.uniffiClonePointer() + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func dbReconnect() async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffixmtpclient_db_reconnect( - self.pointer - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func inboxId() -> String { + return try! FfiConverterString.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffixmtpclient_inbox_id(self.uniffiClonePointer(), $0) + }) } - public func installationId() -> Data { - return try! FfiConverterData.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffixmtpclient_installation_id(self.pointer, $0) - } - ) + open func installationId() -> Data { + return try! FfiConverterData.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffixmtpclient_installation_id(self.uniffiClonePointer(), $0) + }) } - public func registerIdentity(recoverableWalletSignature: Data?) async throws { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_method_ffixmtpclient_register_identity( - self.pointer, - FfiConverterOptionData.lower(recoverableWalletSignature) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_void, - completeFunc: ffi_xmtpv3_rust_future_complete_void, - freeFunc: ffi_xmtpv3_rust_future_free_void, - liftFunc: { $0 }, - errorHandler: FfiConverterTypeGenericError.lift - ) + open func registerIdentity(signatureRequest: FfiSignatureRequest) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffixmtpclient_register_identity( + self.uniffiClonePointer(), + FfiConverterTypeFfiSignatureRequest.lower(signatureRequest) + ) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_void, + completeFunc: ffi_xmtpv3_rust_future_complete_void, + freeFunc: ffi_xmtpv3_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeGenericError.lift + ) } - public func releaseDbConnection() throws { - try - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_method_ffixmtpclient_release_db_connection(self.pointer, $0) - } + open func releaseDbConnection() throws { try rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffixmtpclient_release_db_connection(self.uniffiClonePointer(), $0) + } } - public func textToSign() -> String? { - return try! FfiConverterOptionString.lift( - try! - rustCall { - uniffi_xmtpv3_fn_method_ffixmtpclient_text_to_sign(self.pointer, $0) - } - ) + open func signatureRequest() -> FfiSignatureRequest? { + return try! FfiConverterOptionTypeFfiSignatureRequest.lift(try! rustCall { + uniffi_xmtpv3_fn_method_ffixmtpclient_signature_request(self.uniffiClonePointer(), $0) + }) } } @@ -1398,6 +1892,14 @@ public struct FfiConverterTypeFfiXmtpClient: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = FfiXmtpClient + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiXmtpClient { + return FfiXmtpClient(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: FfiXmtpClient) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiXmtpClient { let v: UInt64 = try readInt(&buf) // The Rust code won't compile if a pointer won't fit in a UInt64. @@ -1414,14 +1916,6 @@ public struct FfiConverterTypeFfiXmtpClient: FfiConverter { // The Rust code won't compile if a pointer won't fit in a `UInt64`. writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiXmtpClient { - return FfiXmtpClient(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: FfiXmtpClient) -> UnsafeMutableRawPointer { - return value.pointer - } } public func FfiConverterTypeFfiXmtpClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiXmtpClient { @@ -1463,10 +1957,11 @@ extension FfiCursor: Equatable, Hashable { public struct FfiConverterTypeFfiCursor: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiCursor { - return try FfiCursor( - digest: FfiConverterData.read(from: &buf), - senderTimeNs: FfiConverterUInt64.read(from: &buf) - ) + return + try FfiCursor( + digest: FfiConverterData.read(from: &buf), + senderTimeNs: FfiConverterUInt64.read(from: &buf) + ) } public static func write(_ value: FfiCursor, into buf: inout [UInt8]) { @@ -1520,11 +2015,12 @@ extension FfiEnvelope: Equatable, Hashable { public struct FfiConverterTypeFfiEnvelope: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiEnvelope { - return try FfiEnvelope( - contentTopic: FfiConverterString.read(from: &buf), - timestampNs: FfiConverterUInt64.read(from: &buf), - message: FfiConverterData.read(from: &buf) - ) + return + try FfiEnvelope( + contentTopic: FfiConverterString.read(from: &buf), + timestampNs: FfiConverterUInt64.read(from: &buf), + message: FfiConverterData.read(from: &buf) + ) } public static func write(_ value: FfiEnvelope, into buf: inout [UInt8]) { @@ -1543,20 +2039,25 @@ public func FfiConverterTypeFfiEnvelope_lower(_ value: FfiEnvelope) -> RustBuffe } public struct FfiGroupMember { - public var accountAddress: String + public var inboxId: String + public var accountAddresses: [String] public var installationIds: [Data] // Default memberwise initializers are never public by default, so we // declare one manually. - public init(accountAddress: String, installationIds: [Data]) { - self.accountAddress = accountAddress + public init(inboxId: String, accountAddresses: [String], installationIds: [Data]) { + self.inboxId = inboxId + self.accountAddresses = accountAddresses self.installationIds = installationIds } } extension FfiGroupMember: Equatable, Hashable { public static func == (lhs: FfiGroupMember, rhs: FfiGroupMember) -> Bool { - if lhs.accountAddress != rhs.accountAddress { + if lhs.inboxId != rhs.inboxId { + return false + } + if lhs.accountAddresses != rhs.accountAddresses { return false } if lhs.installationIds != rhs.installationIds { @@ -1566,21 +2067,25 @@ extension FfiGroupMember: Equatable, Hashable { } public func hash(into hasher: inout Hasher) { - hasher.combine(accountAddress) + hasher.combine(inboxId) + hasher.combine(accountAddresses) hasher.combine(installationIds) } } public struct FfiConverterTypeFfiGroupMember: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiGroupMember { - return try FfiGroupMember( - accountAddress: FfiConverterString.read(from: &buf), - installationIds: FfiConverterSequenceData.read(from: &buf) - ) + return + try FfiGroupMember( + inboxId: FfiConverterString.read(from: &buf), + accountAddresses: FfiConverterSequenceString.read(from: &buf), + installationIds: FfiConverterSequenceData.read(from: &buf) + ) } public static func write(_ value: FfiGroupMember, into buf: inout [UInt8]) { - FfiConverterString.write(value.accountAddress, into: &buf) + FfiConverterString.write(value.inboxId, into: &buf) + FfiConverterSequenceString.write(value.accountAddresses, into: &buf) FfiConverterSequenceData.write(value.installationIds, into: &buf) } } @@ -1630,11 +2135,12 @@ extension FfiListConversationsOptions: Equatable, Hashable { public struct FfiConverterTypeFfiListConversationsOptions: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiListConversationsOptions { - return try FfiListConversationsOptions( - createdAfterNs: FfiConverterOptionInt64.read(from: &buf), - createdBeforeNs: FfiConverterOptionInt64.read(from: &buf), - limit: FfiConverterOptionInt64.read(from: &buf) - ) + return + try FfiListConversationsOptions( + createdAfterNs: FfiConverterOptionInt64.read(from: &buf), + createdBeforeNs: FfiConverterOptionInt64.read(from: &buf), + limit: FfiConverterOptionInt64.read(from: &buf) + ) } public static func write(_ value: FfiListConversationsOptions, into buf: inout [UInt8]) { @@ -1695,12 +2201,13 @@ extension FfiListMessagesOptions: Equatable, Hashable { public struct FfiConverterTypeFfiListMessagesOptions: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiListMessagesOptions { - return try FfiListMessagesOptions( - sentBeforeNs: FfiConverterOptionInt64.read(from: &buf), - sentAfterNs: FfiConverterOptionInt64.read(from: &buf), - limit: FfiConverterOptionInt64.read(from: &buf), - deliveryStatus: FfiConverterOptionTypeFfiDeliveryStatus.read(from: &buf) - ) + return + try FfiListMessagesOptions( + sentBeforeNs: FfiConverterOptionInt64.read(from: &buf), + sentAfterNs: FfiConverterOptionInt64.read(from: &buf), + limit: FfiConverterOptionInt64.read(from: &buf), + deliveryStatus: FfiConverterOptionTypeFfiDeliveryStatus.read(from: &buf) + ) } public static func write(_ value: FfiListMessagesOptions, into buf: inout [UInt8]) { @@ -1723,18 +2230,18 @@ public struct FfiMessage { public var id: Data public var sentAtNs: Int64 public var convoId: Data - public var addrFrom: String + public var senderInboxId: String public var content: Data public var kind: FfiGroupMessageKind public var deliveryStatus: FfiDeliveryStatus // Default memberwise initializers are never public by default, so we // declare one manually. - public init(id: Data, sentAtNs: Int64, convoId: Data, addrFrom: String, content: Data, kind: FfiGroupMessageKind, deliveryStatus: FfiDeliveryStatus) { + public init(id: Data, sentAtNs: Int64, convoId: Data, senderInboxId: String, content: Data, kind: FfiGroupMessageKind, deliveryStatus: FfiDeliveryStatus) { self.id = id self.sentAtNs = sentAtNs self.convoId = convoId - self.addrFrom = addrFrom + self.senderInboxId = senderInboxId self.content = content self.kind = kind self.deliveryStatus = deliveryStatus @@ -1752,7 +2259,7 @@ extension FfiMessage: Equatable, Hashable { if lhs.convoId != rhs.convoId { return false } - if lhs.addrFrom != rhs.addrFrom { + if lhs.senderInboxId != rhs.senderInboxId { return false } if lhs.content != rhs.content { @@ -1771,7 +2278,7 @@ extension FfiMessage: Equatable, Hashable { hasher.combine(id) hasher.combine(sentAtNs) hasher.combine(convoId) - hasher.combine(addrFrom) + hasher.combine(senderInboxId) hasher.combine(content) hasher.combine(kind) hasher.combine(deliveryStatus) @@ -1780,22 +2287,23 @@ extension FfiMessage: Equatable, Hashable { public struct FfiConverterTypeFfiMessage: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiMessage { - return try FfiMessage( - id: FfiConverterData.read(from: &buf), - sentAtNs: FfiConverterInt64.read(from: &buf), - convoId: FfiConverterData.read(from: &buf), - addrFrom: FfiConverterString.read(from: &buf), - content: FfiConverterData.read(from: &buf), - kind: FfiConverterTypeFfiGroupMessageKind.read(from: &buf), - deliveryStatus: FfiConverterTypeFfiDeliveryStatus.read(from: &buf) - ) + return + try FfiMessage( + id: FfiConverterData.read(from: &buf), + sentAtNs: FfiConverterInt64.read(from: &buf), + convoId: FfiConverterData.read(from: &buf), + senderInboxId: FfiConverterString.read(from: &buf), + content: FfiConverterData.read(from: &buf), + kind: FfiConverterTypeFfiGroupMessageKind.read(from: &buf), + deliveryStatus: FfiConverterTypeFfiDeliveryStatus.read(from: &buf) + ) } public static func write(_ value: FfiMessage, into buf: inout [UInt8]) { FfiConverterData.write(value.id, into: &buf) FfiConverterInt64.write(value.sentAtNs, into: &buf) FfiConverterData.write(value.convoId, into: &buf) - FfiConverterString.write(value.addrFrom, into: &buf) + FfiConverterString.write(value.senderInboxId, into: &buf) FfiConverterData.write(value.content, into: &buf) FfiConverterTypeFfiGroupMessageKind.write(value.kind, into: &buf) FfiConverterTypeFfiDeliveryStatus.write(value.deliveryStatus, into: &buf) @@ -1847,11 +2355,12 @@ extension FfiPagingInfo: Equatable, Hashable { public struct FfiConverterTypeFfiPagingInfo: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiPagingInfo { - return try FfiPagingInfo( - limit: FfiConverterUInt32.read(from: &buf), - cursor: FfiConverterOptionTypeFfiCursor.read(from: &buf), - direction: FfiConverterTypeFfiSortDirection.read(from: &buf) - ) + return + try FfiPagingInfo( + limit: FfiConverterUInt32.read(from: &buf), + cursor: FfiConverterOptionTypeFfiCursor.read(from: &buf), + direction: FfiConverterTypeFfiSortDirection.read(from: &buf) + ) } public static func write(_ value: FfiPagingInfo, into buf: inout [UInt8]) { @@ -1894,9 +2403,10 @@ extension FfiPublishRequest: Equatable, Hashable { public struct FfiConverterTypeFfiPublishRequest: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiPublishRequest { - return try FfiPublishRequest( - envelopes: FfiConverterSequenceTypeFfiEnvelope.read(from: &buf) - ) + return + try FfiPublishRequest( + envelopes: FfiConverterSequenceTypeFfiEnvelope.read(from: &buf) + ) } public static func write(_ value: FfiPublishRequest, into buf: inout [UInt8]) { @@ -1937,9 +2447,10 @@ extension FfiV2BatchQueryRequest: Equatable, Hashable { public struct FfiConverterTypeFfiV2BatchQueryRequest: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2BatchQueryRequest { - return try FfiV2BatchQueryRequest( - requests: FfiConverterSequenceTypeFfiV2QueryRequest.read(from: &buf) - ) + return + try FfiV2BatchQueryRequest( + requests: FfiConverterSequenceTypeFfiV2QueryRequest.read(from: &buf) + ) } public static func write(_ value: FfiV2BatchQueryRequest, into buf: inout [UInt8]) { @@ -1980,9 +2491,10 @@ extension FfiV2BatchQueryResponse: Equatable, Hashable { public struct FfiConverterTypeFfiV2BatchQueryResponse: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2BatchQueryResponse { - return try FfiV2BatchQueryResponse( - responses: FfiConverterSequenceTypeFfiV2QueryResponse.read(from: &buf) - ) + return + try FfiV2BatchQueryResponse( + responses: FfiConverterSequenceTypeFfiV2QueryResponse.read(from: &buf) + ) } public static func write(_ value: FfiV2BatchQueryResponse, into buf: inout [UInt8]) { @@ -2041,12 +2553,13 @@ extension FfiV2QueryRequest: Equatable, Hashable { public struct FfiConverterTypeFfiV2QueryRequest: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2QueryRequest { - return try FfiV2QueryRequest( - contentTopics: FfiConverterSequenceString.read(from: &buf), - startTimeNs: FfiConverterUInt64.read(from: &buf), - endTimeNs: FfiConverterUInt64.read(from: &buf), - pagingInfo: FfiConverterOptionTypeFfiPagingInfo.read(from: &buf) - ) + return + try FfiV2QueryRequest( + contentTopics: FfiConverterSequenceString.read(from: &buf), + startTimeNs: FfiConverterUInt64.read(from: &buf), + endTimeNs: FfiConverterUInt64.read(from: &buf), + pagingInfo: FfiConverterOptionTypeFfiPagingInfo.read(from: &buf) + ) } public static func write(_ value: FfiV2QueryRequest, into buf: inout [UInt8]) { @@ -2096,10 +2609,11 @@ extension FfiV2QueryResponse: Equatable, Hashable { public struct FfiConverterTypeFfiV2QueryResponse: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2QueryResponse { - return try FfiV2QueryResponse( - envelopes: FfiConverterSequenceTypeFfiEnvelope.read(from: &buf), - pagingInfo: FfiConverterOptionTypeFfiPagingInfo.read(from: &buf) - ) + return + try FfiV2QueryResponse( + envelopes: FfiConverterSequenceTypeFfiEnvelope.read(from: &buf), + pagingInfo: FfiConverterOptionTypeFfiPagingInfo.read(from: &buf) + ) } public static func write(_ value: FfiV2QueryResponse, into buf: inout [UInt8]) { @@ -2141,9 +2655,10 @@ extension FfiV2SubscribeRequest: Equatable, Hashable { public struct FfiConverterTypeFfiV2SubscribeRequest: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiV2SubscribeRequest { - return try FfiV2SubscribeRequest( - contentTopics: FfiConverterSequenceString.read(from: &buf) - ) + return + try FfiV2SubscribeRequest( + contentTopics: FfiConverterSequenceString.read(from: &buf) + ) } public static func write(_ value: FfiV2SubscribeRequest, into buf: inout [UInt8]) { @@ -2161,6 +2676,7 @@ public func FfiConverterTypeFfiV2SubscribeRequest_lower(_ value: FfiV2SubscribeR // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum FfiDeliveryStatus { case unpublished case published @@ -2209,6 +2725,7 @@ extension FfiDeliveryStatus: Equatable, Hashable {} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum FfiGroupMessageKind { case application case membershipChange @@ -2251,6 +2768,7 @@ extension FfiGroupMessageKind: Equatable, Hashable {} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum FfiSortDirection { case unspecified case ascending @@ -2298,36 +2816,27 @@ public func FfiConverterTypeFfiSortDirection_lower(_ value: FfiSortDirection) -> extension FfiSortDirection: Equatable, Hashable {} public enum GenericError { - // Simple error enums only carry a message case Client(message: String) - // Simple error enums only carry a message case ClientBuilder(message: String) - // Simple error enums only carry a message case Storage(message: String) - // Simple error enums only carry a message case ApiError(message: String) - // Simple error enums only carry a message case GroupError(message: String) - // Simple error enums only carry a message case Signature(message: String) - // Simple error enums only carry a message case GroupMetadata(message: String) - // Simple error enums only carry a message case GroupMutablePermissions(message: String) - // Simple error enums only carry a message case Generic(message: String) - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeGenericError.lift(error) - } + case SignatureRequestError(message: String) + + case Erc1271SignatureError(message: String) } public struct FfiConverterTypeGenericError: FfiConverterRustBuffer { @@ -2372,6 +2881,14 @@ public struct FfiConverterTypeGenericError: FfiConverterRustBuffer { message: FfiConverterString.read(from: &buf) ) + case 10: return try .SignatureRequestError( + message: FfiConverterString.read(from: &buf) + ) + + case 11: return try .Erc1271SignatureError( + message: FfiConverterString.read(from: &buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } @@ -2396,6 +2913,10 @@ public struct FfiConverterTypeGenericError: FfiConverterRustBuffer { writeInt(&buf, Int32(8)) case .Generic(_ /* message is ignored*/ ): writeInt(&buf, Int32(9)) + case .SignatureRequestError(_ /* message is ignored*/ ): + writeInt(&buf, Int32(10)) + case .Erc1271SignatureError(_ /* message is ignored*/ ): + writeInt(&buf, Int32(11)) } } } @@ -2406,6 +2927,7 @@ extension GenericError: Error {} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + public enum GroupPermissions { case everyoneIsAdmin case groupCreatorIsAdmin @@ -2448,6 +2970,14 @@ extension GroupPermissions: Equatable, Hashable {} // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * XMTP SDK's may embed libxmtp (v3) alongside existing v2 protocol logic + * for backwards-compatibility purposes. In this case, the client may already + * have a wallet-signed v2 key. Depending on the source of this key, + * libxmtp may choose to bootstrap v3 installation keys using the existing + * legacy key. + */ + public enum LegacyIdentitySource { case none case `static` @@ -2501,12 +3031,7 @@ public func FfiConverterTypeLegacyIdentitySource_lower(_ value: LegacyIdentitySo extension LegacyIdentitySource: Equatable, Hashable {} public enum SigningError { - // Simple error enums only carry a message case Generic(message: String) - - fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { - return try FfiConverterTypeSigningError.lift(error) - } } public struct FfiConverterTypeSigningError: FfiConverterRustBuffer { @@ -2535,61 +3060,8 @@ extension SigningError: Equatable, Hashable {} extension SigningError: Error {} -private extension NSLock { - func withLock(f: () throws -> T) rethrows -> T { - lock() - defer { self.unlock() } - return try f() - } -} - -private typealias UniFFICallbackHandle = UInt64 -private class UniFFICallbackHandleMap { - private var leftMap: [UniFFICallbackHandle: T] = [:] - private var counter: [UniFFICallbackHandle: UInt64] = [:] - private var rightMap: [ObjectIdentifier: UniFFICallbackHandle] = [:] - - private let lock = NSLock() - private var currentHandle: UniFFICallbackHandle = 0 - private let stride: UniFFICallbackHandle = 1 - - func insert(obj: T) -> UniFFICallbackHandle { - lock.withLock { - let id = ObjectIdentifier(obj as AnyObject) - let handle = rightMap[id] ?? { - currentHandle += stride - let handle = currentHandle - leftMap[handle] = obj - rightMap[id] = handle - return handle - }() - counter[handle] = (counter[handle] ?? 0) + 1 - return handle - } - } - - func get(handle: UniFFICallbackHandle) -> T? { - lock.withLock { - leftMap[handle] - } - } - - func delete(handle: UniFFICallbackHandle) { - remove(handle: handle) - } - - @discardableResult - func remove(handle: UniFFICallbackHandle) -> T? { - lock.withLock { - defer { counter[handle] = (counter[handle] ?? 1) - 1 } - guard counter[handle] == 1 else { return leftMap[handle] } - let obj = leftMap.removeValue(forKey: handle) - if let obj = obj { - rightMap.removeValue(forKey: ObjectIdentifier(obj as AnyObject)) - } - return obj - } - } +public protocol FfiConversationCallback: AnyObject { + func onConversation(conversation: FfiGroup) } // Magic number for the Rust proxy to call using the same mechanism as every other method, @@ -2600,443 +3072,314 @@ private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0 private let UNIFFI_CALLBACK_ERROR: Int32 = 1 private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2 -// Declaration and FfiConverters for FfiConversationCallback Callback Interface +// Put the implementation in a struct so we don't pollute the top-level namespace +private enum UniffiCallbackInterfaceFfiConversationCallback { + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceFfiConversationCallback = .init( + onConversation: { ( + uniffiHandle: UInt64, + conversation: UnsafeMutableRawPointer, + _: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws in + guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiConversationCallback.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return try uniffiObj.onConversation( + conversation: FfiConverterTypeFfiGroup.lift(conversation) + ) + } -public protocol FfiConversationCallback: AnyObject { - func onConversation(conversation: FfiGroup) + let writeReturn = { () } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn + ) + }, + uniffiFree: { (uniffiHandle: UInt64) in + let result = try? FfiConverterCallbackInterfaceFfiConversationCallback.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface FfiConversationCallback: handle missing in uniffiFree") + } + } + ) } -// The ForeignCallback that is passed to Rust. -private let foreignCallbackCallbackInterfaceFfiConversationCallback: ForeignCallback = { (handle: UniFFICallbackHandle, method: Int32, argsData: UnsafePointer, argsLen: Int32, out_buf: UnsafeMutablePointer) -> Int32 in - - func invokeOnConversation(_ swiftCallbackInterface: FfiConversationCallback, _ argsData: UnsafePointer, _ argsLen: Int32, _: UnsafeMutablePointer) throws -> Int32 { - var reader = createReader(data: Data(bytes: argsData, count: Int(argsLen))) - func makeCall() throws -> Int32 { - try swiftCallbackInterface.onConversation( - conversation: FfiConverterTypeFfiGroup.read(from: &reader) - ) - return UNIFFI_CALLBACK_SUCCESS - } - return try makeCall() - } - - switch method { - case IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceFfiConversationCallback.drop(handle: handle) - // Sucessful return - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS - case 1: - let cb: FfiConversationCallback - do { - cb = try FfiConverterCallbackInterfaceFfiConversationCallback.lift(handle) - } catch { - out_buf.pointee = FfiConverterString.lower("FfiConversationCallback: Invalid handle") - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - do { - return try invokeOnConversation(cb, argsData, argsLen, out_buf) - } catch { - out_buf.pointee = FfiConverterString.lower(String(describing: error)) - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - - // This should never happen, because an out of bounds method index won't - // ever be used. Once we can catch errors, we should return an InternalError. - // https://github.com/mozilla/uniffi-rs/issues/351 - default: - // An unexpected error happened. - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } +private func uniffiCallbackInitFfiConversationCallback() { + uniffi_xmtpv3_fn_init_callback_vtable_fficonversationcallback(&UniffiCallbackInterfaceFfiConversationCallback.vtable) } // FfiConverter protocol for callback interfaces private enum FfiConverterCallbackInterfaceFfiConversationCallback { - private static let initCallbackOnce: () = { - // Swift ensures this initializer code will once run once, even when accessed by multiple threads. - try! rustCall { (err: UnsafeMutablePointer) in - uniffi_xmtpv3_fn_init_callback_fficonversationcallback(foreignCallbackCallbackInterfaceFfiConversationCallback, err) - } - }() - - private static func ensureCallbackinitialized() { - _ = initCallbackOnce - } - - static func drop(handle: UniFFICallbackHandle) { - handleMap.remove(handle: handle) - } - - private static var handleMap = UniFFICallbackHandleMap() + fileprivate static var handleMap = UniffiHandleMap() } extension FfiConverterCallbackInterfaceFfiConversationCallback: FfiConverter { typealias SwiftType = FfiConversationCallback - // We can use Handle as the FfiType because it's a typealias to UInt64 - typealias FfiType = UniFFICallbackHandle + typealias FfiType = UInt64 - public static func lift(_ handle: UniFFICallbackHandle) throws -> SwiftType { - ensureCallbackinitialized() - guard let callback = handleMap.get(handle: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return callback + public static func lift(_ handle: UInt64) throws -> SwiftType { + try handleMap.get(handle: handle) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - ensureCallbackinitialized() - let handle: UniFFICallbackHandle = try readInt(&buf) + let handle: UInt64 = try readInt(&buf) return try lift(handle) } - public static func lower(_ v: SwiftType) -> UniFFICallbackHandle { - ensureCallbackinitialized() + public static func lower(_ v: SwiftType) -> UInt64 { return handleMap.insert(obj: v) } public static func write(_ v: SwiftType, into buf: inout [UInt8]) { - ensureCallbackinitialized() writeInt(&buf, lower(v)) } } -// Declaration and FfiConverters for FfiInboxOwner Callback Interface - public protocol FfiInboxOwner: AnyObject { func getAddress() -> String + func sign(text: String) throws -> Data } -// The ForeignCallback that is passed to Rust. -private let foreignCallbackCallbackInterfaceFfiInboxOwner: ForeignCallback = { (handle: UniFFICallbackHandle, method: Int32, argsData: UnsafePointer, argsLen: Int32, out_buf: UnsafeMutablePointer) -> Int32 in +// Put the implementation in a struct so we don't pollute the top-level namespace +private enum UniffiCallbackInterfaceFfiInboxOwner { + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceFfiInboxOwner = .init( + getAddress: { ( + uniffiHandle: UInt64, + uniffiOutReturn: UnsafeMutablePointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws -> String in + guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiInboxOwner.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return uniffiObj.getAddress( + ) + } - func invokeGetAddress(_ swiftCallbackInterface: FfiInboxOwner, _: UnsafePointer, _: Int32, _ out_buf: UnsafeMutablePointer) throws -> Int32 { - func makeCall() throws -> Int32 { - let result = swiftCallbackInterface.getAddress( + let writeReturn = { uniffiOutReturn.pointee = FfiConverterString.lower($0) } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn ) - var writer = [UInt8]() - FfiConverterString.write(result, into: &writer) - out_buf.pointee = RustBuffer(bytes: writer) - return UNIFFI_CALLBACK_SUCCESS - } - return try makeCall() - } + }, + sign: { ( + uniffiHandle: UInt64, + text: RustBuffer, + uniffiOutReturn: UnsafeMutablePointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws -> Data in + guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiInboxOwner.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return try uniffiObj.sign( + text: FfiConverterString.lift(text) + ) + } - func invokeSign(_ swiftCallbackInterface: FfiInboxOwner, _ argsData: UnsafePointer, _ argsLen: Int32, _ out_buf: UnsafeMutablePointer) throws -> Int32 { - var reader = createReader(data: Data(bytes: argsData, count: Int(argsLen))) - func makeCall() throws -> Int32 { - let result = try swiftCallbackInterface.sign( - text: FfiConverterString.read(from: &reader) + let writeReturn = { uniffiOutReturn.pointee = FfiConverterData.lower($0) } + uniffiTraitInterfaceCallWithError( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn, + lowerError: FfiConverterTypeSigningError.lower ) - var writer = [UInt8]() - FfiConverterData.write(result, into: &writer) - out_buf.pointee = RustBuffer(bytes: writer) - return UNIFFI_CALLBACK_SUCCESS - } - do { - return try makeCall() - } catch let error as SigningError { - out_buf.pointee = FfiConverterTypeSigningError.lower(error) - return UNIFFI_CALLBACK_ERROR - } - } - - switch method { - case IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceFfiInboxOwner.drop(handle: handle) - // Sucessful return - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS - case 1: - let cb: FfiInboxOwner - do { - cb = try FfiConverterCallbackInterfaceFfiInboxOwner.lift(handle) - } catch { - out_buf.pointee = FfiConverterString.lower("FfiInboxOwner: Invalid handle") - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - do { - return try invokeGetAddress(cb, argsData, argsLen, out_buf) - } catch { - out_buf.pointee = FfiConverterString.lower(String(describing: error)) - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - case 2: - let cb: FfiInboxOwner - do { - cb = try FfiConverterCallbackInterfaceFfiInboxOwner.lift(handle) - } catch { - out_buf.pointee = FfiConverterString.lower("FfiInboxOwner: Invalid handle") - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - do { - return try invokeSign(cb, argsData, argsLen, out_buf) - } catch { - out_buf.pointee = FfiConverterString.lower(String(describing: error)) - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - - // This should never happen, because an out of bounds method index won't - // ever be used. Once we can catch errors, we should return an InternalError. - // https://github.com/mozilla/uniffi-rs/issues/351 - default: - // An unexpected error happened. - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } + }, + uniffiFree: { (uniffiHandle: UInt64) in + let result = try? FfiConverterCallbackInterfaceFfiInboxOwner.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface FfiInboxOwner: handle missing in uniffiFree") + } + } + ) +} + +private func uniffiCallbackInitFfiInboxOwner() { + uniffi_xmtpv3_fn_init_callback_vtable_ffiinboxowner(&UniffiCallbackInterfaceFfiInboxOwner.vtable) } // FfiConverter protocol for callback interfaces private enum FfiConverterCallbackInterfaceFfiInboxOwner { - private static let initCallbackOnce: () = { - // Swift ensures this initializer code will once run once, even when accessed by multiple threads. - try! rustCall { (err: UnsafeMutablePointer) in - uniffi_xmtpv3_fn_init_callback_ffiinboxowner(foreignCallbackCallbackInterfaceFfiInboxOwner, err) - } - }() - - private static func ensureCallbackinitialized() { - _ = initCallbackOnce - } - - static func drop(handle: UniFFICallbackHandle) { - handleMap.remove(handle: handle) - } - - private static var handleMap = UniFFICallbackHandleMap() + fileprivate static var handleMap = UniffiHandleMap() } extension FfiConverterCallbackInterfaceFfiInboxOwner: FfiConverter { typealias SwiftType = FfiInboxOwner - // We can use Handle as the FfiType because it's a typealias to UInt64 - typealias FfiType = UniFFICallbackHandle + typealias FfiType = UInt64 - public static func lift(_ handle: UniFFICallbackHandle) throws -> SwiftType { - ensureCallbackinitialized() - guard let callback = handleMap.get(handle: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return callback + public static func lift(_ handle: UInt64) throws -> SwiftType { + try handleMap.get(handle: handle) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - ensureCallbackinitialized() - let handle: UniFFICallbackHandle = try readInt(&buf) + let handle: UInt64 = try readInt(&buf) return try lift(handle) } - public static func lower(_ v: SwiftType) -> UniFFICallbackHandle { - ensureCallbackinitialized() + public static func lower(_ v: SwiftType) -> UInt64 { return handleMap.insert(obj: v) } public static func write(_ v: SwiftType, into buf: inout [UInt8]) { - ensureCallbackinitialized() writeInt(&buf, lower(v)) } } -// Declaration and FfiConverters for FfiLogger Callback Interface - public protocol FfiLogger: AnyObject { func log(level: UInt32, levelLabel: String, message: String) } -// The ForeignCallback that is passed to Rust. -private let foreignCallbackCallbackInterfaceFfiLogger: ForeignCallback = { (handle: UniFFICallbackHandle, method: Int32, argsData: UnsafePointer, argsLen: Int32, out_buf: UnsafeMutablePointer) -> Int32 in +// Put the implementation in a struct so we don't pollute the top-level namespace +private enum UniffiCallbackInterfaceFfiLogger { + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceFfiLogger = .init( + log: { ( + uniffiHandle: UInt64, + level: UInt32, + levelLabel: RustBuffer, + message: RustBuffer, + _: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws in + guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiLogger.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return try uniffiObj.log( + level: FfiConverterUInt32.lift(level), + levelLabel: FfiConverterString.lift(levelLabel), + message: FfiConverterString.lift(message) + ) + } - func invokeLog(_ swiftCallbackInterface: FfiLogger, _ argsData: UnsafePointer, _ argsLen: Int32, _: UnsafeMutablePointer) throws -> Int32 { - var reader = createReader(data: Data(bytes: argsData, count: Int(argsLen))) - func makeCall() throws -> Int32 { - try swiftCallbackInterface.log( - level: FfiConverterUInt32.read(from: &reader), - levelLabel: FfiConverterString.read(from: &reader), - message: FfiConverterString.read(from: &reader) + let writeReturn = { () } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn ) - return UNIFFI_CALLBACK_SUCCESS - } - return try makeCall() - } - - switch method { - case IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceFfiLogger.drop(handle: handle) - // Sucessful return - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS - case 1: - let cb: FfiLogger - do { - cb = try FfiConverterCallbackInterfaceFfiLogger.lift(handle) - } catch { - out_buf.pointee = FfiConverterString.lower("FfiLogger: Invalid handle") - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - do { - return try invokeLog(cb, argsData, argsLen, out_buf) - } catch { - out_buf.pointee = FfiConverterString.lower(String(describing: error)) - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - - // This should never happen, because an out of bounds method index won't - // ever be used. Once we can catch errors, we should return an InternalError. - // https://github.com/mozilla/uniffi-rs/issues/351 - default: - // An unexpected error happened. - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } + }, + uniffiFree: { (uniffiHandle: UInt64) in + let result = try? FfiConverterCallbackInterfaceFfiLogger.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface FfiLogger: handle missing in uniffiFree") + } + } + ) +} + +private func uniffiCallbackInitFfiLogger() { + uniffi_xmtpv3_fn_init_callback_vtable_ffilogger(&UniffiCallbackInterfaceFfiLogger.vtable) } // FfiConverter protocol for callback interfaces private enum FfiConverterCallbackInterfaceFfiLogger { - private static let initCallbackOnce: () = { - // Swift ensures this initializer code will once run once, even when accessed by multiple threads. - try! rustCall { (err: UnsafeMutablePointer) in - uniffi_xmtpv3_fn_init_callback_ffilogger(foreignCallbackCallbackInterfaceFfiLogger, err) - } - }() - - private static func ensureCallbackinitialized() { - _ = initCallbackOnce - } - - static func drop(handle: UniFFICallbackHandle) { - handleMap.remove(handle: handle) - } - - private static var handleMap = UniFFICallbackHandleMap() + fileprivate static var handleMap = UniffiHandleMap() } extension FfiConverterCallbackInterfaceFfiLogger: FfiConverter { typealias SwiftType = FfiLogger - // We can use Handle as the FfiType because it's a typealias to UInt64 - typealias FfiType = UniFFICallbackHandle + typealias FfiType = UInt64 - public static func lift(_ handle: UniFFICallbackHandle) throws -> SwiftType { - ensureCallbackinitialized() - guard let callback = handleMap.get(handle: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return callback + public static func lift(_ handle: UInt64) throws -> SwiftType { + try handleMap.get(handle: handle) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - ensureCallbackinitialized() - let handle: UniFFICallbackHandle = try readInt(&buf) + let handle: UInt64 = try readInt(&buf) return try lift(handle) } - public static func lower(_ v: SwiftType) -> UniFFICallbackHandle { - ensureCallbackinitialized() + public static func lower(_ v: SwiftType) -> UInt64 { return handleMap.insert(obj: v) } public static func write(_ v: SwiftType, into buf: inout [UInt8]) { - ensureCallbackinitialized() writeInt(&buf, lower(v)) } } -// Declaration and FfiConverters for FfiMessageCallback Callback Interface - public protocol FfiMessageCallback: AnyObject { func onMessage(message: FfiMessage) } -// The ForeignCallback that is passed to Rust. -private let foreignCallbackCallbackInterfaceFfiMessageCallback: ForeignCallback = { (handle: UniFFICallbackHandle, method: Int32, argsData: UnsafePointer, argsLen: Int32, out_buf: UnsafeMutablePointer) -> Int32 in +// Put the implementation in a struct so we don't pollute the top-level namespace +private enum UniffiCallbackInterfaceFfiMessageCallback { + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. + static var vtable: UniffiVTableCallbackInterfaceFfiMessageCallback = .init( + onMessage: { ( + uniffiHandle: UInt64, + message: RustBuffer, + _: UnsafeMutableRawPointer, + uniffiCallStatus: UnsafeMutablePointer + ) in + let makeCall = { + () throws in + guard let uniffiObj = try? FfiConverterCallbackInterfaceFfiMessageCallback.handleMap.get(handle: uniffiHandle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return try uniffiObj.onMessage( + message: FfiConverterTypeFfiMessage.lift(message) + ) + } - func invokeOnMessage(_ swiftCallbackInterface: FfiMessageCallback, _ argsData: UnsafePointer, _ argsLen: Int32, _: UnsafeMutablePointer) throws -> Int32 { - var reader = createReader(data: Data(bytes: argsData, count: Int(argsLen))) - func makeCall() throws -> Int32 { - try swiftCallbackInterface.onMessage( - message: FfiConverterTypeFfiMessage.read(from: &reader) + let writeReturn = { () } + uniffiTraitInterfaceCall( + callStatus: uniffiCallStatus, + makeCall: makeCall, + writeReturn: writeReturn ) - return UNIFFI_CALLBACK_SUCCESS - } - return try makeCall() - } - - switch method { - case IDX_CALLBACK_FREE: - FfiConverterCallbackInterfaceFfiMessageCallback.drop(handle: handle) - // Sucessful return - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_SUCCESS - case 1: - let cb: FfiMessageCallback - do { - cb = try FfiConverterCallbackInterfaceFfiMessageCallback.lift(handle) - } catch { - out_buf.pointee = FfiConverterString.lower("FfiMessageCallback: Invalid handle") - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - do { - return try invokeOnMessage(cb, argsData, argsLen, out_buf) - } catch { - out_buf.pointee = FfiConverterString.lower(String(describing: error)) - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } - - // This should never happen, because an out of bounds method index won't - // ever be used. Once we can catch errors, we should return an InternalError. - // https://github.com/mozilla/uniffi-rs/issues/351 - default: - // An unexpected error happened. - // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs` - return UNIFFI_CALLBACK_UNEXPECTED_ERROR - } + }, + uniffiFree: { (uniffiHandle: UInt64) in + let result = try? FfiConverterCallbackInterfaceFfiMessageCallback.handleMap.remove(handle: uniffiHandle) + if result == nil { + print("Uniffi callback interface FfiMessageCallback: handle missing in uniffiFree") + } + } + ) +} + +private func uniffiCallbackInitFfiMessageCallback() { + uniffi_xmtpv3_fn_init_callback_vtable_ffimessagecallback(&UniffiCallbackInterfaceFfiMessageCallback.vtable) } // FfiConverter protocol for callback interfaces private enum FfiConverterCallbackInterfaceFfiMessageCallback { - private static let initCallbackOnce: () = { - // Swift ensures this initializer code will once run once, even when accessed by multiple threads. - try! rustCall { (err: UnsafeMutablePointer) in - uniffi_xmtpv3_fn_init_callback_ffimessagecallback(foreignCallbackCallbackInterfaceFfiMessageCallback, err) - } - }() - - private static func ensureCallbackinitialized() { - _ = initCallbackOnce - } - - static func drop(handle: UniFFICallbackHandle) { - handleMap.remove(handle: handle) - } - - private static var handleMap = UniFFICallbackHandleMap() + fileprivate static var handleMap = UniffiHandleMap() } extension FfiConverterCallbackInterfaceFfiMessageCallback: FfiConverter { typealias SwiftType = FfiMessageCallback - // We can use Handle as the FfiType because it's a typealias to UInt64 - typealias FfiType = UniFFICallbackHandle + typealias FfiType = UInt64 - public static func lift(_ handle: UniFFICallbackHandle) throws -> SwiftType { - ensureCallbackinitialized() - guard let callback = handleMap.get(handle: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return callback + public static func lift(_ handle: UInt64) throws -> SwiftType { + try handleMap.get(handle: handle) } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - ensureCallbackinitialized() - let handle: UniFFICallbackHandle = try readInt(&buf) + let handle: UInt64 = try readInt(&buf) return try lift(handle) } - public static func lower(_ v: SwiftType) -> UniFFICallbackHandle { - ensureCallbackinitialized() + public static func lower(_ v: SwiftType) -> UInt64 { return handleMap.insert(obj: v) } public static func write(_ v: SwiftType, into buf: inout [UInt8]) { - ensureCallbackinitialized() writeInt(&buf, lower(v)) } } @@ -3104,6 +3447,27 @@ private struct FfiConverterOptionData: FfiConverterRustBuffer { } } +private struct FfiConverterOptionTypeFfiSignatureRequest: FfiConverterRustBuffer { + typealias SwiftType = FfiSignatureRequest? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeFfiSignatureRequest.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeFfiSignatureRequest.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + private struct FfiConverterOptionTypeFfiCursor: FfiConverterRustBuffer { typealias SwiftType = FfiCursor? @@ -3390,11 +3754,13 @@ private struct FfiConverterDictionaryStringBool: FfiConverterRustBuffer { private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0 private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1 +private let uniffiContinuationHandleMap = UniffiHandleMap>() + private func uniffiRustCallAsync( - rustFutureFunc: () -> UnsafeMutableRawPointer, - pollFunc: (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void, - completeFunc: (UnsafeMutableRawPointer, UnsafeMutablePointer) -> F, - freeFunc: (UnsafeMutableRawPointer) -> Void, + rustFutureFunc: () -> UInt64, + pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> Void, + completeFunc: (UInt64, UnsafeMutablePointer) -> F, + freeFunc: (UInt64) -> Void, liftFunc: (F) throws -> T, errorHandler: ((RustBuffer) throws -> Error)? ) async throws -> T { @@ -3408,7 +3774,11 @@ private func uniffiRustCallAsync( var pollResult: Int8 repeat { pollResult = await withUnsafeContinuation { - pollFunc(rustFuture, ContinuationHolder($0).toOpaque()) + pollFunc( + rustFuture, + uniffiFutureContinuationCallback, + uniffiContinuationHandleMap.insert(obj: $0) + ) } } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY @@ -3420,201 +3790,169 @@ private func uniffiRustCallAsync( // Callback handlers for an async calls. These are invoked by Rust when the future is ready. They // lift the return value or error and resume the suspended function. -private func uniffiFutureContinuationCallback(ptr: UnsafeMutableRawPointer, pollResult: Int8) { - ContinuationHolder.fromOpaque(ptr).resume(pollResult) -} - -// Wraps UnsafeContinuation in a class so that we can use reference counting when passing it across -// the FFI -private class ContinuationHolder { - let continuation: UnsafeContinuation - - init(_ continuation: UnsafeContinuation) { - self.continuation = continuation - } - - func resume(_ pollResult: Int8) { +private func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { + if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { continuation.resume(returning: pollResult) + } else { + print("uniffiFutureContinuationCallback invalid handle") } - - func toOpaque() -> UnsafeMutableRawPointer { - return Unmanaged.passRetained(self).toOpaque() - } - - static func fromOpaque(_ ptr: UnsafeRawPointer) -> ContinuationHolder { - return Unmanaged.fromOpaque(ptr).takeRetainedValue() - } -} - -private func uniffiInitContinuationCallback() { - ffi_xmtpv3_rust_future_continuation_callback_set(uniffiFutureContinuationCallback) } public func createClient(logger: FfiLogger, host: String, isSecure: Bool, db: String?, encryptionKey: Data?, accountAddress: String, legacyIdentitySource: LegacyIdentitySource, legacySignedPrivateKeyProto: Data?) async throws -> FfiXmtpClient { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_func_create_client( - FfiConverterCallbackInterfaceFfiLogger.lower(logger), - FfiConverterString.lower(host), - FfiConverterBool.lower(isSecure), - FfiConverterOptionString.lower(db), - FfiConverterOptionData.lower(encryptionKey), - FfiConverterString.lower(accountAddress), - FfiConverterTypeLegacyIdentitySource.lower(legacyIdentitySource), - FfiConverterOptionData.lower(legacySignedPrivateKeyProto) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiXmtpClient.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_func_create_client(FfiConverterCallbackInterfaceFfiLogger.lower(logger), FfiConverterString.lower(host), FfiConverterBool.lower(isSecure), FfiConverterOptionString.lower(db), FfiConverterOptionData.lower(encryptionKey), FfiConverterString.lower(accountAddress), FfiConverterTypeLegacyIdentitySource.lower(legacyIdentitySource), FfiConverterOptionData.lower(legacySignedPrivateKeyProto)) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiXmtpClient.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } public func createV2Client(host: String, isSecure: Bool) async throws -> FfiV2ApiClient { - return try await uniffiRustCallAsync( - rustFutureFunc: { - uniffi_xmtpv3_fn_func_create_v2_client( - FfiConverterString.lower(host), - FfiConverterBool.lower(isSecure) - ) - }, - pollFunc: ffi_xmtpv3_rust_future_poll_pointer, - completeFunc: ffi_xmtpv3_rust_future_complete_pointer, - freeFunc: ffi_xmtpv3_rust_future_free_pointer, - liftFunc: FfiConverterTypeFfiV2ApiClient.lift, - errorHandler: FfiConverterTypeGenericError.lift - ) + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_func_create_v2_client(FfiConverterString.lower(host), FfiConverterBool.lower(isSecure)) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_pointer, + completeFunc: ffi_xmtpv3_rust_future_complete_pointer, + freeFunc: ffi_xmtpv3_rust_future_free_pointer, + liftFunc: FfiConverterTypeFfiV2ApiClient.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } public func diffieHellmanK256(privateKeyBytes: Data, publicKeyBytes: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_diffie_hellman_k256( - FfiConverterData.lower(privateKeyBytes), - FfiConverterData.lower(publicKeyBytes), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_diffie_hellman_k256( + FfiConverterData.lower(privateKeyBytes), + FfiConverterData.lower(publicKeyBytes), $0 + ) + }) +} + +public func generateInboxId(accountAddress: String, nonce: UInt64) -> String { + return try! FfiConverterString.lift(try! rustCall { + uniffi_xmtpv3_fn_func_generate_inbox_id( + FfiConverterString.lower(accountAddress), + FfiConverterUInt64.lower(nonce), $0 + ) + }) } public func generatePrivatePreferencesTopicIdentifier(privateKey: Data) throws -> String { - return try FfiConverterString.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_generate_private_preferences_topic_identifier( - FfiConverterData.lower(privateKey), $0 - ) - } - ) + return try FfiConverterString.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_generate_private_preferences_topic_identifier( + FfiConverterData.lower(privateKey), $0 + ) + }) +} + +public func getInboxIdForAddress(logger: FfiLogger, host: String, isSecure: Bool, accountAddress: String) async throws -> String? { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_func_get_inbox_id_for_address(FfiConverterCallbackInterfaceFfiLogger.lower(logger), FfiConverterString.lower(host), FfiConverterBool.lower(isSecure), FfiConverterString.lower(accountAddress)) + }, + pollFunc: ffi_xmtpv3_rust_future_poll_rust_buffer, + completeFunc: ffi_xmtpv3_rust_future_complete_rust_buffer, + freeFunc: ffi_xmtpv3_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionString.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) } public func getVersionInfo() -> String { - return try! FfiConverterString.lift( - try! rustCall { - uniffi_xmtpv3_fn_func_get_version_info($0) - } - ) + return try! FfiConverterString.lift(try! rustCall { + uniffi_xmtpv3_fn_func_get_version_info($0 + ) + }) } public func keccak256(input: Data) -> Data { - return try! FfiConverterData.lift( - try! rustCall { - uniffi_xmtpv3_fn_func_keccak256( - FfiConverterData.lower(input), $0 - ) - } - ) + return try! FfiConverterData.lift(try! rustCall { + uniffi_xmtpv3_fn_func_keccak256( + FfiConverterData.lower(input), $0 + ) + }) } public func publicKeyFromPrivateKeyK256(privateKeyBytes: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_public_key_from_private_key_k256( - FfiConverterData.lower(privateKeyBytes), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_public_key_from_private_key_k256( + FfiConverterData.lower(privateKeyBytes), $0 + ) + }) } public func recoverAddress(signatureBytes: Data, predigestMessage: String) throws -> String { - return try FfiConverterString.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_recover_address( - FfiConverterData.lower(signatureBytes), - FfiConverterString.lower(predigestMessage), $0 - ) - } - ) + return try FfiConverterString.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_recover_address( + FfiConverterData.lower(signatureBytes), + FfiConverterString.lower(predigestMessage), $0 + ) + }) } public func recoverPublicKeyK256Keccak256(message: Data, signature: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_recover_public_key_k256_keccak256( - FfiConverterData.lower(message), - FfiConverterData.lower(signature), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_recover_public_key_k256_keccak256( + FfiConverterData.lower(message), + FfiConverterData.lower(signature), $0 + ) + }) } public func recoverPublicKeyK256Sha256(message: Data, signature: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_recover_public_key_k256_sha256( - FfiConverterData.lower(message), - FfiConverterData.lower(signature), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_recover_public_key_k256_sha256( + FfiConverterData.lower(message), + FfiConverterData.lower(signature), $0 + ) + }) } public func sha256(input: Data) -> Data { - return try! FfiConverterData.lift( - try! rustCall { - uniffi_xmtpv3_fn_func_sha256( - FfiConverterData.lower(input), $0 - ) - } - ) + return try! FfiConverterData.lift(try! rustCall { + uniffi_xmtpv3_fn_func_sha256( + FfiConverterData.lower(input), $0 + ) + }) } public func userPreferencesDecrypt(publicKey: Data, privateKey: Data, message: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_user_preferences_decrypt( - FfiConverterData.lower(publicKey), - FfiConverterData.lower(privateKey), - FfiConverterData.lower(message), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_user_preferences_decrypt( + FfiConverterData.lower(publicKey), + FfiConverterData.lower(privateKey), + FfiConverterData.lower(message), $0 + ) + }) } public func userPreferencesEncrypt(publicKey: Data, privateKey: Data, message: Data) throws -> Data { - return try FfiConverterData.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_user_preferences_encrypt( - FfiConverterData.lower(publicKey), - FfiConverterData.lower(privateKey), - FfiConverterData.lower(message), $0 - ) - } - ) + return try FfiConverterData.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_user_preferences_encrypt( + FfiConverterData.lower(publicKey), + FfiConverterData.lower(privateKey), + FfiConverterData.lower(message), $0 + ) + }) } public func verifyK256Sha256(signedBy: Data, message: Data, signature: Data, recoveryId: UInt8) throws -> Bool { - return try FfiConverterBool.lift( - rustCallWithError(FfiConverterTypeGenericError.lift) { - uniffi_xmtpv3_fn_func_verify_k256_sha256( - FfiConverterData.lower(signedBy), - FfiConverterData.lower(message), - FfiConverterData.lower(signature), - FfiConverterUInt8.lower(recoveryId), $0 - ) - } - ) + return try FfiConverterBool.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_func_verify_k256_sha256( + FfiConverterData.lower(signedBy), + FfiConverterData.lower(message), + FfiConverterData.lower(signature), + FfiConverterUInt8.lower(recoveryId), $0 + ) + }) } private enum InitializationResult { @@ -3627,197 +3965,224 @@ private enum InitializationResult { // the code inside is only computed once. private var initializationResult: InitializationResult { // Get the bindings contract version from our ComponentInterface - let bindings_contract_version = 24 + let bindings_contract_version = 26 // Get the scaffolding contract version by calling the into the dylib let scaffolding_contract_version = ffi_xmtpv3_uniffi_contract_version() if bindings_contract_version != scaffolding_contract_version { return InitializationResult.contractVersionMismatch } - if uniffi_xmtpv3_checksum_func_create_client() != 20422 { + if uniffi_xmtpv3_checksum_func_create_client() != 30339 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_create_v2_client() != 48060 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_diffie_hellman_k256() != 37475 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_generate_inbox_id() != 2184 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier() != 59124 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_get_inbox_id_for_address() != 36898 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_get_version_info() != 29277 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_keccak256() != 61901 { + return InitializationResult.apiChecksumMismatch + } + if uniffi_xmtpv3_checksum_func_public_key_from_private_key_k256() != 22921 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_create_v2_client() != 49516 { + if uniffi_xmtpv3_checksum_func_recover_address() != 48606 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_diffie_hellman_k256() != 23225 { + if uniffi_xmtpv3_checksum_func_recover_public_key_k256_keccak256() != 45215 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_generate_private_preferences_topic_identifier() != 5952 { + if uniffi_xmtpv3_checksum_func_recover_public_key_k256_sha256() != 42303 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_get_version_info() != 3533 { + if uniffi_xmtpv3_checksum_func_sha256() != 32492 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_keccak256() != 17749 { + if uniffi_xmtpv3_checksum_func_user_preferences_decrypt() != 43766 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_public_key_from_private_key_k256() != 2943 { + if uniffi_xmtpv3_checksum_func_user_preferences_encrypt() != 184 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_recover_address() != 45923 { + if uniffi_xmtpv3_checksum_func_verify_k256_sha256() != 25521 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_recover_public_key_k256_keccak256() != 59591 { + if uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 1475 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_recover_public_key_k256_sha256() != 13070 { + if uniffi_xmtpv3_checksum_method_fficonversations_list() != 10804 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_sha256() != 62964 { + if uniffi_xmtpv3_checksum_method_fficonversations_process_streamed_welcome_message() != 38198 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_user_preferences_decrypt() != 4361 { + if uniffi_xmtpv3_checksum_method_fficonversations_stream() != 42948 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_user_preferences_encrypt() != 47149 { + if uniffi_xmtpv3_checksum_method_fficonversations_stream_all_messages() != 8742 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_func_verify_k256_sha256() != 31332 { + if uniffi_xmtpv3_checksum_method_fficonversations_sync() != 9054 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 16460 { + if uniffi_xmtpv3_checksum_method_ffigroup_add_members() != 27666 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_list() != 44067 { + if uniffi_xmtpv3_checksum_method_ffigroup_add_members_by_inbox_id() != 23290 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_process_streamed_welcome_message() != 55636 { + if uniffi_xmtpv3_checksum_method_ffigroup_added_by_inbox_id() != 37220 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_stream() != 60583 { + if uniffi_xmtpv3_checksum_method_ffigroup_created_at_ns() != 4894 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_stream_all_messages() != 65211 { + if uniffi_xmtpv3_checksum_method_ffigroup_find_messages() != 14930 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversations_sync() != 62598 { + if uniffi_xmtpv3_checksum_method_ffigroup_group_metadata() != 13139 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_add_members() != 24978 { + if uniffi_xmtpv3_checksum_method_ffigroup_group_name() != 61525 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_added_by_address() != 5368 { + if uniffi_xmtpv3_checksum_method_ffigroup_id() != 36764 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_created_at_ns() != 58515 { + if uniffi_xmtpv3_checksum_method_ffigroup_is_active() != 33848 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_find_messages() != 61973 { + if uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 61034 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_group_metadata() != 3690 { + if uniffi_xmtpv3_checksum_method_ffigroup_process_streamed_group_message() != 19069 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_group_name() != 3391 { + if uniffi_xmtpv3_checksum_method_ffigroup_remove_members() != 24336 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_id() != 35243 { + if uniffi_xmtpv3_checksum_method_ffigroup_remove_members_by_inbox_id() != 45424 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_is_active() != 27808 { + if uniffi_xmtpv3_checksum_method_ffigroup_send() != 37701 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_list_members() != 15786 { + if uniffi_xmtpv3_checksum_method_ffigroup_stream() != 45558 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_process_streamed_group_message() != 54382 { + if uniffi_xmtpv3_checksum_method_ffigroup_sync() != 24219 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_remove_members() != 1645 { + if uniffi_xmtpv3_checksum_method_ffigroup_update_group_name() != 550 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_send() != 2523 { + if uniffi_xmtpv3_checksum_method_ffigroupmetadata_conversation_type() != 30827 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_stream() != 7482 { + if uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_inbox_id() != 26872 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_sync() != 9422 { + if uniffi_xmtpv3_checksum_method_ffigrouppermissions_policy_type() != 12694 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroup_update_group_name() != 29940 { + if uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_ecdsa_signature() != 8706 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroupmetadata_conversation_type() != 37015 { + if uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_erc1271_signature() != 27040 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigroupmetadata_creator_account_address() != 1906 { + if uniffi_xmtpv3_checksum_method_ffisignaturerequest_missing_address_signatures() != 34688 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffigrouppermissions_policy_type() != 43161 { + if uniffi_xmtpv3_checksum_method_ffisignaturerequest_signature_text() != 60472 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 47211 { + if uniffi_xmtpv3_checksum_method_ffistreamcloser_end() != 57139 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed() != 37884 { + if uniffi_xmtpv3_checksum_method_ffistreamcloser_is_closed() != 62423 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query() != 10812 { + if uniffi_xmtpv3_checksum_method_ffiv2apiclient_batch_query() != 26551 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2apiclient_publish() != 13419 { + if uniffi_xmtpv3_checksum_method_ffiv2apiclient_publish() != 3309 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2apiclient_query() != 7220 { + if uniffi_xmtpv3_checksum_method_ffiv2apiclient_query() != 58821 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2apiclient_set_app_version() != 23872 { + if uniffi_xmtpv3_checksum_method_ffiv2apiclient_set_app_version() != 28472 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2apiclient_subscribe() != 36355 { + if uniffi_xmtpv3_checksum_method_ffiv2apiclient_subscribe() != 31004 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2subscription_end() != 47726 { + if uniffi_xmtpv3_checksum_method_ffiv2subscription_end() != 54394 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2subscription_next() != 47515 { + if uniffi_xmtpv3_checksum_method_ffiv2subscription_next() != 27536 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiv2subscription_update() != 52988 { + if uniffi_xmtpv3_checksum_method_ffiv2subscription_update() != 16562 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_account_address() != 65151 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_can_message() != 53502 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_can_message() != 28768 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_conversations() != 47463 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_conversations() != 31628 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_db_reconnect() != 6707 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_db_reconnect() != 33037 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_inbox_id() != 25128 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_installation_id() != 62523 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_installation_id() != 37173 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_register_identity() != 64634 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_register_identity() != 42003 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_release_db_connection() != 12677 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_release_db_connection() != 11067 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffixmtpclient_text_to_sign() != 25727 { + if uniffi_xmtpv3_checksum_method_ffixmtpclient_signature_request() != 18270 { return InitializationResult.apiChecksumMismatch } if uniffi_xmtpv3_checksum_method_ffiinboxowner_get_address() != 2205 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffiinboxowner_sign() != 47939 { + if uniffi_xmtpv3_checksum_method_ffiinboxowner_sign() != 30268 { return InitializationResult.apiChecksumMismatch } if uniffi_xmtpv3_checksum_method_ffilogger_log() != 56011 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_fficonversationcallback_on_conversation() != 1220 { + if uniffi_xmtpv3_checksum_method_fficonversationcallback_on_conversation() != 42 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffimessagecallback_on_message() != 13573 { + if uniffi_xmtpv3_checksum_method_ffimessagecallback_on_message() != 5286 { return InitializationResult.apiChecksumMismatch } - uniffiInitContinuationCallback() + uniffiCallbackInitFfiConversationCallback() + uniffiCallbackInitFfiInboxOwner() + uniffiCallbackInitFfiLogger() + uniffiCallbackInitFfiMessageCallback() return InitializationResult.ok } @@ -3831,3 +4196,5 @@ private func uniffiEnsureInitialized() { fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } } + +// swiftlint:enable all