Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plaintext heads for encryption and V3 consent #67

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LibXMTP.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/LibXMTP/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -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
184 changes: 178 additions & 6 deletions Sources/LibXMTP/xmtpv3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand All @@ -2712,6 +2768,9 @@ extension FfiGroupMember: Equatable, Hashable {
if lhs.permissionLevel != rhs.permissionLevel {
return false
}
if lhs.consentState != rhs.consentState {
return false
}
return true
}

Expand All @@ -2720,6 +2779,7 @@ extension FfiGroupMember: Equatable, Hashable {
hasher.combine(accountAddresses)
hasher.combine(installationIds)
hasher.combine(permissionLevel)
hasher.combine(consentState)
}
}

Expand All @@ -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)
)
}

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down