Skip to content

Commit

Permalink
add revokaction ability and inbox state
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Aug 21, 2024
1 parent 0896eea commit da823d9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,4 +603,27 @@ public final class Client {
}
try await client.requestHistorySync()
}

public func revokeAllOtherInstallations(signingKey: SigningKey) async throws {
guard let client = v3Client else {
throw ClientError.noV3Client("Error: No V3 client initialized")
}

if let signatureRequest = try await client.revokeAllOtherInstallations() {
do {
let signedData = try await signingKey.sign(message: signatureRequest.signatureText())
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
try await client.registerIdentity(signatureRequest: signatureRequest)
} catch {
throw ClientError.creationError("Failed to sign the message: \(error.localizedDescription)")
}
}
}

public func inboxState(refreshFromNetwork: Bool) async throws -> InboxState {
guard let client = v3Client else {
throw ClientError.noV3Client("Error: No V3 client initialized")
}
return InboxState(ffiInboxState: client.inboxState(refreshFromNetwork: refreshFromNetwork))
}
}
34 changes: 34 additions & 0 deletions Sources/XMTPiOS/Mls/InboxState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// InboxState.swift
//
//
// Created by Naomi Plasterer on 8/21/24.
//

import Foundation
import LibXMTP

public struct InboxState {
var ffiInboxState: FfiInboxState

init(ffiInboxState: FfiInboxState) {
self.ffiInboxState = ffiInboxState
}

public var inboxId: String {
ffiInboxState.inboxId
}

public var addresses: [String] {
ffiInboxState.accountAddresses
}

public var installationIds: [String] {
ffiInboxState.installationIds.map { id in id.toHex}
}

public var recoveryAddress: String {
ffiInboxState.recoveryAddress
}

}

0 comments on commit da823d9

Please sign in to comment.