From 432d4ac9f1396ee719a01516327e40d8ddbd4d41 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 13 Sep 2024 11:45:07 -0600 Subject: [PATCH] make bindings with the new v3 consent work --- LibXMTP.podspec | 4 +- Package.swift | 4 +- Sources/LibXMTP/libxmtp-version.txt | 4 +- Sources/LibXMTP/xmtpv3.swift | 184 +++++++++++++++++++++++++++- 4 files changed, 184 insertions(+), 12 deletions(-) diff --git a/LibXMTP.podspec b/LibXMTP.podspec index bb4ae0a..ae51723 100644 --- a/LibXMTP.podspec +++ b/LibXMTP.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LibXMTP' - s.version = '0.5.8-beta4' + s.version = '0.5.8-beta5' 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, '14.0', :macos, '11.0' s.swift_version = '5.3' - s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-c446f94/LibXMTPSwiftFFI.zip", :type => :zip } + s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-7e70ad4/LibXMTPSwiftFFI.zip", :type => :zip } s.vendored_frameworks = 'LibXMTPSwiftFFI.xcframework' s.source_files = 'Sources/LibXMTP/**/*' end diff --git a/Package.swift b/Package.swift index 721ec0f..8b575c1 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-c446f94/LibXMTPSwiftFFI.zip", - checksum: "534329216e1ba15211d7728c62fd26522269d9943f98972408141719227d9263" + url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-7e70ad4/LibXMTPSwiftFFI.zip", + checksum: "41a1bb49815416e3e19c6f629c6142a4623f2408ea1bb46facf65170b7c2d055" ), .testTarget(name: "LibXMTPTests", dependencies: ["LibXMTP"]), ] diff --git a/Sources/LibXMTP/libxmtp-version.txt b/Sources/LibXMTP/libxmtp-version.txt index 240e0b0..01524aa 100644 --- a/Sources/LibXMTP/libxmtp-version.txt +++ b/Sources/LibXMTP/libxmtp-version.txt @@ -1,3 +1,3 @@ -Version: c446f94d +Version: 7e70ad48 Branch: main -Date: 2024-09-09 14:36:53 +0000 +Date: 2024-09-13 15:56:37 +0000 diff --git a/Sources/LibXMTP/xmtpv3.swift b/Sources/LibXMTP/xmtpv3.swift index c09cf44..04e55c5 100644 --- a/Sources/LibXMTP/xmtpv3.swift +++ b/Sources/LibXMTP/xmtpv3.swift @@ -732,6 +732,8 @@ public protocol FfiGroupProtocol: AnyObject { func adminList() throws -> [String] + func consentState() throws -> FfiConsentState + func createdAtNs() -> Int64 func findMessages(opts: FfiListMessagesOptions) throws -> [FfiMessage] @@ -786,6 +788,8 @@ public protocol FfiGroupProtocol: AnyObject { func sync() async throws + func updateConsentState(state: FfiConsentState) throws + func updateGroupDescription(groupDescription: String) async throws func updateGroupImageUrlSquare(groupImageUrlSquare: String) async throws @@ -917,6 +921,12 @@ open class FfiGroup: }) } + open func consentState() throws -> FfiConsentState { + return try FfiConverterTypeFfiConsentState.lift(rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_consent_state(self.uniffiClonePointer(), $0) + }) + } + open func createdAtNs() -> Int64 { return try! FfiConverterInt64.lift(try! rustCall { uniffi_xmtpv3_fn_method_ffigroup_created_at_ns(self.uniffiClonePointer(), $0) @@ -1168,6 +1178,12 @@ open class FfiGroup: ) } + open func updateConsentState(state: FfiConsentState) throws { try rustCallWithError(FfiConverterTypeGenericError.lift) { + uniffi_xmtpv3_fn_method_ffigroup_update_consent_state(self.uniffiClonePointer(), + FfiConverterTypeFfiConsentState.lower(state), $0) + } + } + open func updateGroupDescription(groupDescription: String) async throws { return try await uniffiRustCallAsync( @@ -1489,7 +1505,7 @@ public func FfiConverterTypeFfiGroupPermissions_lower(_ value: FfiGroupPermissio public protocol FfiSignatureRequestProtocol: AnyObject { func addEcdsaSignature(signatureBytes: Data) async throws - func addScwSignature(signatureBytes: Data, address: String, chainRpcUrl: String) async throws + func addScwSignature(signatureBytes: Data, address: String, chainId: UInt64, blockNumber: UInt64) async throws func isReady() async -> Bool @@ -1558,13 +1574,13 @@ open class FfiSignatureRequest: ) } - open func addScwSignature(signatureBytes: Data, address: String, chainRpcUrl: String) async throws { + open func addScwSignature(signatureBytes: Data, address: String, chainId: UInt64, blockNumber: UInt64) async throws { return try await uniffiRustCallAsync( rustFutureFunc: { uniffi_xmtpv3_fn_method_ffisignaturerequest_add_scw_signature( self.uniffiClonePointer(), - FfiConverterData.lower(signatureBytes), FfiConverterString.lower(address), FfiConverterString.lower(chainRpcUrl) + FfiConverterData.lower(signatureBytes), FfiConverterString.lower(address), FfiConverterUInt64.lower(chainId), FfiConverterUInt64.lower(blockNumber) ) }, pollFunc: ffi_xmtpv3_rust_future_poll_void, @@ -2128,6 +2144,8 @@ public protocol FfiXmtpClientProtocol: AnyObject { func findInboxId(address: String) async throws -> String? + func getConsentState(entityType: FfiConsentEntityType, entity: String) async throws -> FfiConsentState + func getLatestInboxState(inboxId: String) async throws -> FfiInboxState func group(groupId: Data) throws -> FfiGroup @@ -2162,6 +2180,8 @@ public protocol FfiXmtpClientProtocol: AnyObject { */ func revokeWallet(walletAddress: String) async throws -> FfiSignatureRequest + func setConsentState(state: FfiConsentState, entityType: FfiConsentEntityType, entity: String) async throws + func signatureRequest() -> FfiSignatureRequest? } @@ -2298,6 +2318,23 @@ open class FfiXmtpClient: ) } + open func getConsentState(entityType: FfiConsentEntityType, entity: String) async throws -> FfiConsentState { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffixmtpclient_get_consent_state( + self.uniffiClonePointer(), + FfiConverterTypeFfiConsentEntityType.lower(entityType), FfiConverterString.lower(entity) + ) + }, + 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: FfiConverterTypeFfiConsentState.lift, + errorHandler: FfiConverterTypeGenericError.lift + ) + } + open func getLatestInboxState(inboxId: String) async throws -> FfiInboxState { return try await uniffiRustCallAsync( @@ -2441,6 +2478,23 @@ open class FfiXmtpClient: ) } + open func setConsentState(state: FfiConsentState, entityType: FfiConsentEntityType, entity: String) async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_xmtpv3_fn_method_ffixmtpclient_set_consent_state( + self.uniffiClonePointer(), + FfiConverterTypeFfiConsentState.lower(state), FfiConverterTypeFfiConsentEntityType.lower(entityType), FfiConverterString.lower(entity) + ) + }, + 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 signatureRequest() -> FfiSignatureRequest? { return try! FfiConverterOptionTypeFfiSignatureRequest.lift(try! rustCall { uniffi_xmtpv3_fn_method_ffixmtpclient_signature_request(self.uniffiClonePointer(), $0) @@ -2687,14 +2741,16 @@ public struct FfiGroupMember { public var accountAddresses: [String] public var installationIds: [Data] public var permissionLevel: FfiPermissionLevel + public var consentState: FfiConsentState // Default memberwise initializers are never public by default, so we // declare one manually. - public init(inboxId: String, accountAddresses: [String], installationIds: [Data], permissionLevel: FfiPermissionLevel) { + public init(inboxId: String, accountAddresses: [String], installationIds: [Data], permissionLevel: FfiPermissionLevel, consentState: FfiConsentState) { self.inboxId = inboxId self.accountAddresses = accountAddresses self.installationIds = installationIds self.permissionLevel = permissionLevel + self.consentState = consentState } } @@ -2712,6 +2768,9 @@ extension FfiGroupMember: Equatable, Hashable { if lhs.permissionLevel != rhs.permissionLevel { return false } + if lhs.consentState != rhs.consentState { + return false + } return true } @@ -2720,6 +2779,7 @@ extension FfiGroupMember: Equatable, Hashable { hasher.combine(accountAddresses) hasher.combine(installationIds) hasher.combine(permissionLevel) + hasher.combine(consentState) } } @@ -2730,7 +2790,8 @@ public struct FfiConverterTypeFfiGroupMember: FfiConverterRustBuffer { inboxId: FfiConverterString.read(from: &buf), accountAddresses: FfiConverterSequenceString.read(from: &buf), installationIds: FfiConverterSequenceData.read(from: &buf), - permissionLevel: FfiConverterTypeFfiPermissionLevel.read(from: &buf) + permissionLevel: FfiConverterTypeFfiPermissionLevel.read(from: &buf), + consentState: FfiConverterTypeFfiConsentState.read(from: &buf) ) } @@ -2739,6 +2800,7 @@ public struct FfiConverterTypeFfiGroupMember: FfiConverterRustBuffer { FfiConverterSequenceString.write(value.accountAddresses, into: &buf) FfiConverterSequenceData.write(value.installationIds, into: &buf) FfiConverterTypeFfiPermissionLevel.write(value.permissionLevel, into: &buf) + FfiConverterTypeFfiConsentState.write(value.consentState, into: &buf) } } @@ -3497,6 +3559,104 @@ 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 FfiConsentEntityType { + case groupId + case inboxId + case address +} + +public struct FfiConverterTypeFfiConsentEntityType: FfiConverterRustBuffer { + typealias SwiftType = FfiConsentEntityType + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiConsentEntityType { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return .groupId + + case 2: return .inboxId + + case 3: return .address + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: FfiConsentEntityType, into buf: inout [UInt8]) { + switch value { + case .groupId: + writeInt(&buf, Int32(1)) + + case .inboxId: + writeInt(&buf, Int32(2)) + + case .address: + writeInt(&buf, Int32(3)) + } + } +} + +public func FfiConverterTypeFfiConsentEntityType_lift(_ buf: RustBuffer) throws -> FfiConsentEntityType { + return try FfiConverterTypeFfiConsentEntityType.lift(buf) +} + +public func FfiConverterTypeFfiConsentEntityType_lower(_ value: FfiConsentEntityType) -> RustBuffer { + return FfiConverterTypeFfiConsentEntityType.lower(value) +} + +extension FfiConsentEntityType: 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 FfiConsentState { + case unknown + case allowed + case denied +} + +public struct FfiConverterTypeFfiConsentState: FfiConverterRustBuffer { + typealias SwiftType = FfiConsentState + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiConsentState { + let variant: Int32 = try readInt(&buf) + switch variant { + case 1: return .unknown + + case 2: return .allowed + + case 3: return .denied + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: FfiConsentState, into buf: inout [UInt8]) { + switch value { + case .unknown: + writeInt(&buf, Int32(1)) + + case .allowed: + writeInt(&buf, Int32(2)) + + case .denied: + writeInt(&buf, Int32(3)) + } + } +} + +public func FfiConverterTypeFfiConsentState_lift(_ buf: RustBuffer) throws -> FfiConsentState { + return try FfiConverterTypeFfiConsentState.lift(buf) +} + +public func FfiConverterTypeFfiConsentState_lower(_ value: FfiConsentState) -> RustBuffer { + return FfiConverterTypeFfiConsentState.lower(value) +} + +extension FfiConsentState: 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 FfiDeliveryStatus { case unpublished case published @@ -5197,6 +5357,9 @@ private var initializationResult: InitializationResult = { if uniffi_xmtpv3_checksum_method_ffigroup_admin_list() != 51010 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffigroup_consent_state() != 11630 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffigroup_created_at_ns() != 4894 { return InitializationResult.apiChecksumMismatch } @@ -5269,6 +5432,9 @@ private var initializationResult: InitializationResult = { if uniffi_xmtpv3_checksum_method_ffigroup_sync() != 24219 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffigroup_update_consent_state() != 48124 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffigroup_update_group_description() != 34006 { return InitializationResult.apiChecksumMismatch } @@ -5299,7 +5465,7 @@ private var initializationResult: InitializationResult = { if uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_ecdsa_signature() != 8706 { return InitializationResult.apiChecksumMismatch } - if uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_scw_signature() != 59425 { + if uniffi_xmtpv3_checksum_method_ffisignaturerequest_add_scw_signature() != 23994 { return InitializationResult.apiChecksumMismatch } if uniffi_xmtpv3_checksum_method_ffisignaturerequest_is_ready() != 65051 { @@ -5362,6 +5528,9 @@ private var initializationResult: InitializationResult = { if uniffi_xmtpv3_checksum_method_ffixmtpclient_find_inbox_id() != 59020 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffixmtpclient_get_consent_state() != 58208 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffixmtpclient_get_latest_inbox_state() != 3165 { return InitializationResult.apiChecksumMismatch } @@ -5395,6 +5564,9 @@ private var initializationResult: InitializationResult = { if uniffi_xmtpv3_checksum_method_ffixmtpclient_revoke_wallet() != 12211 { return InitializationResult.apiChecksumMismatch } + if uniffi_xmtpv3_checksum_method_ffixmtpclient_set_consent_state() != 36178 { + return InitializationResult.apiChecksumMismatch + } if uniffi_xmtpv3_checksum_method_ffixmtpclient_signature_request() != 18270 { return InitializationResult.apiChecksumMismatch }