CoreCryptoContext

The CoreCryptoContext holds the primary CoreCrypto APIs.

An instance of this struct is provided to the closure passed to CoreCryptoFfi::transaction.

Every mutable operation is done through this struct. Operations are buffered in memory and persisted to the keystore when the transaction completes.

Constructors

Link copied to clipboard
constructor(pointer: Pointer)
constructor(noPointer: NoPointer)

This constructor can be used to instantiate a fake object. Only used for tests. Any attempt to actually use an object constructed this way will fail as there is no connected Rust object.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun addClientsToConversation(conversationId: ConversationId, keyPackages: List<Keypackage>)

Adds members to the conversation using their key packages, sending the resulting commit via the transport.

Link copied to clipboard
open suspend override fun addCredential(credential: Credential): CredentialRef

Adds a Credential to this client.

Link copied to clipboard
open override fun close()
Link copied to clipboard
open suspend override fun commitPendingProposals(conversationId: ConversationId)

Commits all pending proposals in the conversation, sending the resulting commit via the transport.

Link copied to clipboard
open suspend override fun conversationCiphersuite(conversationId: ConversationId): Ciphersuite

Returns the ciphersuite in use for the given conversation.

Link copied to clipboard
open suspend override fun conversationCredential(conversationId: ConversationId): CredentialRef

Get the credential ref for the given conversation.

Link copied to clipboard
open suspend override fun conversationEpoch(conversationId: ConversationId): ULong

Returns the current MLS epoch of the given conversation.

Link copied to clipboard
open suspend override fun conversationExists(conversationId: ConversationId): Boolean

Returns true if a conversation with the given id exists in the local state.

Link copied to clipboard
open suspend override fun createConversation(conversationId: ConversationId, credentialRef: CredentialRef, externalSender: ExternalSenderKey?)

Creates a new MLS group with the given conversation ID, using the specified credential.

Link copied to clipboard
open suspend override fun decryptMessage(conversationId: ConversationId, payload: ByteArray): DecryptedMessage

Decrypts an MLS message received in the given conversation.

Link copied to clipboard
open override fun destroy()
Link copied to clipboard
open suspend override fun disableHistorySharing(conversationId: ConversationId)

Disables history sharing for the given conversation.

Link copied to clipboard
open suspend override fun e2eiConversationState(conversationId: ConversationId): E2eiConversationState

Returns the end-to-end identity verification state of the given conversation.

Link copied to clipboard
open suspend override fun e2eiIsEnabled(ciphersuite: Ciphersuite): Boolean

Returns true if end-to-end identity is enabled for the given ciphersuite.

Link copied to clipboard
open suspend override fun e2eiIsPkiEnvSetup(): Boolean

Returns true if the PKI environment has been set up.

Link copied to clipboard
open suspend override fun enableHistorySharing(conversationId: ConversationId)

Enables history sharing for the given conversation.

Link copied to clipboard
open suspend override fun encryptMessage(conversationId: ConversationId, message: ByteArray): ByteArray

Encrypts a plaintext message for all members of the given conversation.

Link copied to clipboard
open suspend override fun exportSecretKey(conversationId: ConversationId, keyLength: UInt): SecretKey

Derives and exports a secret of key_length bytes for the given conversation.

Link copied to clipboard
open suspend override fun findCredentials(clientId: ClientId?, publicKey: ByteArray?, ciphersuite: Ciphersuite?, credentialType: CredentialType?, earliestValidity: ULong?): List<CredentialRef>

Get all credentials from this client which match the provided parameters.

Link copied to clipboard
open suspend override fun generateKeypackage(credentialRef: CredentialRef, lifetime: Duration?): Keypackage

Generate a KeyPackage from the referenced credential.

Link copied to clipboard
open suspend override fun getClientIds(conversationId: ConversationId): List<ClientId>

Returns the client ids of all members of the given conversation.

Link copied to clipboard
open suspend override fun getCredentials(): List<CredentialRef>

Get all credentials from this client.

Link copied to clipboard
open suspend override fun getData(): ByteArray?

Returns data previously stored by set_data, or None if no data has been stored.

Link copied to clipboard
open suspend override fun getDeviceIdentities(conversationId: ConversationId, deviceIds: List<ClientId>): List<WireIdentity>

Returns the E2EI identity claims for the specified devices in the given conversation.

Link copied to clipboard
open suspend override fun getExternalSender(conversationId: ConversationId): ExternalSenderKey

Returns the serialized public key of the external sender for the given conversation.

Link copied to clipboard
open suspend override fun getKeypackages(): List<KeypackageRef>

Get a reference to each KeyPackage in the database.

Link copied to clipboard
open suspend override fun getUserIdentities(conversationId: ConversationId, userIds: List<String>): Map<String, List<WireIdentity>>

Returns the E2EI identity claims for the specified users in the given conversation, grouped by user ID.

Link copied to clipboard
open suspend override fun joinByExternalCommit(groupInfo: GroupInfo, credentialRef: CredentialRef): ConversationId

Joins an existing conversation by constructing an external commit from the given group info.

Link copied to clipboard
open suspend override fun mlsInit(clientId: ClientId, transport: MlsTransport)

Initializes the MLS client with the given client ID and message transport.

Link copied to clipboard
open suspend override fun processWelcomeMessage(welcomeMessage: Welcome): ConversationId

Joins a conversation by processing an MLS Welcome message, returning the new conversation's ID.

Link copied to clipboard
open suspend override fun proteusDecrypt(sessionId: String, ciphertext: ByteArray): ByteArray

Decrypts a Proteus ciphertext in the given session, returning the plaintext.

Link copied to clipboard
open suspend override fun proteusDecryptSafe(sessionId: String, ciphertext: ByteArray): ByteArray

Decrypt a message whether or not the proteus session already exists, and saves the session.

Link copied to clipboard
open suspend override fun proteusEncrypt(sessionId: String, plaintext: ByteArray): ByteArray

Encrypts a plaintext message in the given Proteus session.

Link copied to clipboard
open suspend override fun proteusEncryptBatched(sessions: List<String>, plaintext: ByteArray): Map<String, ByteArray>

Encrypts a plaintext message in multiple Proteus sessions, returning a map from session ID to ciphertext.

Link copied to clipboard
open suspend override fun proteusFingerprint(): String

Returns the hex-encoded public key fingerprint of this device's Proteus identity.

Link copied to clipboard
open suspend override fun proteusFingerprintLocal(sessionId: String): String

Returns the hex-encoded local public key fingerprint for the Proteus session with the given ID.

Link copied to clipboard
open suspend override fun proteusFingerprintRemote(sessionId: String): String

Returns the hex-encoded remote public key fingerprint for the Proteus session with the given ID.

Link copied to clipboard
open suspend override fun proteusInit()

Initializes the Proteus client.

Link copied to clipboard
open suspend override fun proteusLastResortPrekey(): ByteArray

Returns the CBOR-serialized last resort prekey bundle, creating it if it does not yet exist.

Link copied to clipboard
open suspend override fun proteusNewPrekey(prekeyId: UShort): ByteArray

Creates a new Proteus prekey with the given ID and returns its CBOR-serialized bundle.

Link copied to clipboard
open suspend override fun proteusNewPrekeyAuto(): ProteusAutoPrekeyBundle

Creates a new Proteus prekey with an automatically assigned ID and returns its CBOR-serialized bundle.

Link copied to clipboard
open suspend override fun proteusReloadSessions()

Reloads all Proteus sessions from the keystore into memory.

Link copied to clipboard
open suspend override fun proteusSessionDelete(sessionId: String)

Deletes the Proteus session with the given ID from local storage.

Link copied to clipboard
open suspend override fun proteusSessionExists(sessionId: String): Boolean

Returns true if a Proteus session with the given ID exists in local storage.

Link copied to clipboard
open suspend override fun proteusSessionFromMessage(sessionId: String, envelope: ByteArray): ByteArray

Creates a new Proteus session from an incoming encrypted message, returning the decrypted message payload.

Link copied to clipboard
open suspend override fun proteusSessionFromPrekey(sessionId: String, prekey: ByteArray)

Creates a new Proteus session from the given prekey bundle bytes, stored under the given session ID.

Link copied to clipboard
open suspend override fun proteusSessionSave(sessionId: String)

Saves the Proteus session with the given ID to the keystore.

Link copied to clipboard
open suspend override fun randomBytes(len: UInt): ByteArray

Generates len random bytes from the cryptographically secure RNG.

Link copied to clipboard
open suspend override fun removeClientsFromConversation(conversationId: ConversationId, clients: List<ClientId>)

Removes the specified clients from the conversation, sending the resulting commit via the transport.

Link copied to clipboard
open suspend override fun removeCredential(credentialRef: CredentialRef)

Removes a Credential from this client.

Link copied to clipboard
open suspend override fun removeKeypackage(kpRef: KeypackageRef)

Remove a KeyPackage from the database.

Link copied to clipboard
open suspend override fun removeKeypackagesFor(credentialRef: CredentialRef)

Remove all KeyPackages associated with this credential ref.

Link copied to clipboard
open suspend override fun setConversationCredential(conversationId: ConversationId, credentialRef: CredentialRef)

Set the credential ref for the given conversation.

Link copied to clipboard
open suspend override fun setData(data: ByteArray)

Stores arbitrary data to be used as a transaction checkpoint.

Link copied to clipboard
fun uniffiClonePointer(): Pointer
Link copied to clipboard
open suspend override fun updateKeyingMaterial(conversationId: ConversationId)

Updates this client's key material in the conversation by sending an update commit.

Link copied to clipboard
open suspend override fun wipeConversation(conversationId: ConversationId)

Destroys the local state of the given conversation; it can no longer be used locally after this call.