CoreCryptoContextInterface

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.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract suspend 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
abstract suspend fun addCredential(credential: Credential): CredentialRef

Adds a Credential to this client.

Link copied to clipboard
abstract suspend fun commitPendingProposals(conversationId: ConversationId)

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

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

Returns the ciphersuite in use for the given conversation.

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

Get the credential ref for the given conversation.

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

Returns the current MLS epoch of the given conversation.

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

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

Link copied to clipboard
abstract suspend fun createConversation(conversationId: ConversationId, credentialRef: CredentialRef, externalSender: ExternalSenderKey? = null)

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

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

Decrypts an MLS message received in the given conversation.

Link copied to clipboard
abstract suspend fun disableHistorySharing(conversationId: ConversationId)

Disables history sharing for the given conversation.

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

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

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

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

Link copied to clipboard
abstract suspend fun e2eiIsPkiEnvSetup(): Boolean

Returns true if the PKI environment has been set up.

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

Enables history sharing for the given conversation.

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

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

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

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

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

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

Link copied to clipboard
abstract suspend fun generateKeypackage(credentialRef: CredentialRef, lifetime: Duration? = null): Keypackage

Generate a KeyPackage from the referenced credential.

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

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

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

Get all credentials from this client.

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

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

Link copied to clipboard
abstract suspend 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
abstract suspend fun getExternalSender(conversationId: ConversationId): ExternalSenderKey

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

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

Get a reference to each KeyPackage in the database.

Link copied to clipboard
abstract suspend 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
abstract suspend 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
abstract suspend fun mlsInit(clientId: ClientId, transport: MlsTransport)

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

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

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

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

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

Link copied to clipboard
abstract suspend 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
abstract suspend fun proteusEncrypt(sessionId: String, plaintext: ByteArray): ByteArray

Encrypts a plaintext message in the given Proteus session.

Link copied to clipboard
abstract suspend 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
abstract suspend fun proteusFingerprint(): String

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

Link copied to clipboard
abstract suspend 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
abstract suspend 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
abstract suspend fun proteusInit()

Initializes the Proteus client.

Link copied to clipboard
abstract suspend fun proteusLastResortPrekey(): ByteArray

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

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

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

Link copied to clipboard

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

Link copied to clipboard
abstract suspend fun proteusReloadSessions()

Reloads all Proteus sessions from the keystore into memory.

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

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

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

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

Link copied to clipboard
abstract suspend 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
abstract suspend 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
abstract suspend fun proteusSessionSave(sessionId: String)

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

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

Generates len random bytes from the cryptographically secure RNG.

Link copied to clipboard
abstract suspend 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
abstract suspend fun removeCredential(credentialRef: CredentialRef)

Removes a Credential from this client.

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

Remove a KeyPackage from the database.

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

Remove all KeyPackages associated with this credential ref.

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

Set the credential ref for the given conversation.

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

Stores arbitrary data to be used as a transaction checkpoint.

Link copied to clipboard
abstract suspend fun updateKeyingMaterial(conversationId: ConversationId)

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

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

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