Skip to content

Commit

Permalink
Merge pull request #93 from xmtp/np/hmac-keys-tweaks
Browse files Browse the repository at this point in the history
Hmac Key support
  • Loading branch information
nplasterer authored Dec 20, 2024
2 parents 9cf94ac + 0e0222e commit 2fd0b26
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 17 deletions.
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 = '3.0.14'
s.version = '3.0.15'
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-eccce06/LibXMTPSwiftFFI.zip", :type => :zip }
s.source = { :http => "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-7d863bd/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-eccce06/LibXMTPSwiftFFI.zip",
checksum: "50aa2f37ac40182d7c6ea1847a6a89c9eca72275552d932b11f022a2cd2882cd"
url: "https://github.com/xmtp/libxmtp/releases/download/swift-bindings-7d863bd/LibXMTPSwiftFFI.zip",
checksum: "0b496c3b016338b88d7b5b62828030b6107c0ee195bd869d0309507237a53bff"
),
.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: eccce061
Version: 7d863bde
Branch: main
Date: 2024-12-18 17:39:46 +0000
Date: 2024-12-20 22:46:38 +0000
193 changes: 182 additions & 11 deletions Sources/LibXMTP/xmtpv3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,105 @@ public func FfiConverterTypeFfiConversationCallback_lower(_ value: FfiConversati
return FfiConverterTypeFfiConversationCallback.lower(value)
}

public protocol FfiConversationListItemProtocol: AnyObject {}

open class FfiConversationListItem:
FfiConversationListItemProtocol
{
fileprivate let pointer: UnsafeMutableRawPointer!

/// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
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.
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public init(noPointer _: NoPointer) {
pointer = nil
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
return try! rustCall { uniffi_xmtpv3_fn_clone_fficonversationlistitem(self.pointer, $0) }
}

// No primary constructor declared for this class.

deinit {
guard let pointer = pointer else {
return
}

try! rustCall { uniffi_xmtpv3_fn_free_fficonversationlistitem(pointer, $0) }
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeFfiConversationListItem: FfiConverter {
typealias FfiType = UnsafeMutableRawPointer
typealias SwiftType = FfiConversationListItem

public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiConversationListItem {
return FfiConversationListItem(unsafeFromRawPointer: pointer)
}

public static func lower(_ value: FfiConversationListItem) -> UnsafeMutableRawPointer {
return value.uniffiClonePointer()
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiConversationListItem {
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: FfiConversationListItem, 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)))))
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFfiConversationListItem_lift(_ pointer: UnsafeMutableRawPointer) throws -> FfiConversationListItem {
return try FfiConverterTypeFfiConversationListItem.lift(pointer)
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeFfiConversationListItem_lower(_ value: FfiConversationListItem) -> UnsafeMutableRawPointer {
return FfiConverterTypeFfiConversationListItem.lower(value)
}

public protocol FfiConversationMetadataProtocol: AnyObject {
func conversationType() -> FfiConversationType

Expand Down Expand Up @@ -1701,10 +1800,14 @@ public protocol FfiConversationsProtocol: AnyObject {

func createGroup(accountAddresses: [String], opts: FfiCreateGroupOptions) async throws -> FfiConversation

func getHmacKeys() throws -> [Data: [FfiHmacKey]]

func getSyncGroup() throws -> FfiConversation

func list(opts: FfiListConversationsOptions) async throws -> [FfiConversation]

func listConversations() async throws -> [FfiConversationListItem]

func listDms(opts: FfiListConversationsOptions) async throws -> [FfiConversation]

func listGroups(opts: FfiListConversationsOptions) async throws -> [FfiConversation]
Expand Down Expand Up @@ -1825,6 +1928,12 @@ open class FfiConversations:
)
}

open func getHmacKeys() throws -> [Data: [FfiHmacKey]] {
return try FfiConverterDictionaryDataSequenceTypeFfiHmacKey.lift(rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_fficonversations_get_hmac_keys(self.uniffiClonePointer(), $0)
})
}

open func getSyncGroup() throws -> FfiConversation {
return try FfiConverterTypeFfiConversation.lift(rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_fficonversations_get_sync_group(self.uniffiClonePointer(), $0)
Expand All @@ -1848,6 +1957,22 @@ open class FfiConversations:
)
}

open func listConversations() async throws -> [FfiConversationListItem] {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_xmtpv3_fn_method_fficonversations_list_conversations(
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: FfiConverterSequenceTypeFfiConversationListItem.lift,
errorHandler: FfiConverterTypeGenericError.lift
)
}

open func listDms(opts: FfiListConversationsOptions) async throws -> [FfiConversation] {
return
try await uniffiRustCallAsync(
Expand Down Expand Up @@ -3554,8 +3679,6 @@ public protocol FfiXmtpClientProtocol: AnyObject {

func getConsentState(entityType: FfiConsentEntityType, entity: String) async throws -> FfiConsentState

func getHmacKeys() throws -> [FfiHmacKey]

func getLatestInboxState(inboxId: String) async throws -> FfiInboxState

func inboxId() -> String
Expand Down Expand Up @@ -3795,12 +3918,6 @@ open class FfiXmtpClient:
)
}

open func getHmacKeys() throws -> [FfiHmacKey] {
return try FfiConverterSequenceTypeFfiHmacKey.lift(rustCallWithError(FfiConverterTypeGenericError.lift) {
uniffi_xmtpv3_fn_method_ffixmtpclient_get_hmac_keys(self.uniffiClonePointer(), $0)
})
}

open func getLatestInboxState(inboxId: String) async throws -> FfiInboxState {
return
try await uniffiRustCallAsync(
Expand Down Expand Up @@ -7082,6 +7199,31 @@ private struct FfiConverterSequenceTypeFfiConversation: FfiConverterRustBuffer {
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
private struct FfiConverterSequenceTypeFfiConversationListItem: FfiConverterRustBuffer {
typealias SwiftType = [FfiConversationListItem]

public static func write(_ value: [FfiConversationListItem], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeFfiConversationListItem.write(item, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [FfiConversationListItem] {
let len: Int32 = try readInt(&buf)
var seq = [FfiConversationListItem]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
try seq.append(FfiConverterTypeFfiConversationListItem.read(from: &buf))
}
return seq
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
Expand Down Expand Up @@ -7358,6 +7500,32 @@ private struct FfiConverterDictionaryStringBool: FfiConverterRustBuffer {
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
private struct FfiConverterDictionaryDataSequenceTypeFfiHmacKey: FfiConverterRustBuffer {
public static func write(_ value: [Data: [FfiHmacKey]], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for (key, value) in value {
FfiConverterData.write(key, into: &buf)
FfiConverterSequenceTypeFfiHmacKey.write(value, into: &buf)
}
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Data: [FfiHmacKey]] {
let len: Int32 = try readInt(&buf)
var dict = [Data: [FfiHmacKey]]()
dict.reserveCapacity(Int(len))
for _ in 0 ..< len {
let key = try FfiConverterData.read(from: &buf)
let value = try FfiConverterSequenceTypeFfiHmacKey.read(from: &buf)
dict[key] = value
}
return dict
}
}

private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1

Expand Down Expand Up @@ -7805,12 +7973,18 @@ private var initializationResult: InitializationResult = {
if uniffi_xmtpv3_checksum_method_fficonversations_create_group() != 7282 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_get_hmac_keys() != 44064 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_get_sync_group() != 42973 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_list() != 42790 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_list_conversations() != 29098 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_fficonversations_list_dms() != 41576 {
return InitializationResult.apiChecksumMismatch
}
Expand Down Expand Up @@ -7958,9 +8132,6 @@ private var initializationResult: InitializationResult = {
if uniffi_xmtpv3_checksum_method_ffixmtpclient_get_consent_state() != 58208 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffixmtpclient_get_hmac_keys() != 36015 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_xmtpv3_checksum_method_ffixmtpclient_get_latest_inbox_state() != 3165 {
return InitializationResult.apiChecksumMismatch
}
Expand Down

0 comments on commit 2fd0b26

Please sign in to comment.