CoreCryptoContext
open class CoreCryptoContext : CoreCryptoContextProtocol, @unchecked Sendable
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.
-
Adds members to the conversation using their key packages, sending the resulting commit via the transport.
Declaration
Swift
open func addClientsToConversation(conversationId: ConversationId, keyPackages: [Keypackage]) async throws -
addCredential(credential:Asynchronous) Adds a
Credentialto this client.Note that while an arbitrary number of credentials can be generated, those which are added to a CoreCrypto instance must be distinct in credential type, signature scheme, and the timestamp of creation. This timestamp has only 1 second of resolution, limiting the number of credentials which can be added. This is a known limitation and will be relaxed in the future.
Declaration
Swift
open func addCredential(credential: Credential) async throws -> CredentialRef -
commitPendingProposals(conversationId:Asynchronous) Commits all pending proposals in the conversation, sending the resulting commit via the transport.
Declaration
Swift
open func commitPendingProposals(conversationId: ConversationId) async throws -
conversationCiphersuite(conversationId:Asynchronous) Returns the ciphersuite in use for the given conversation.
Declaration
Swift
open func conversationCiphersuite(conversationId: ConversationId) async throws -> Ciphersuite -
conversationCredential(conversationId:Asynchronous) Get the credential ref for the given conversation.
Declaration
Swift
open func conversationCredential(conversationId: ConversationId) async throws -> CredentialRef -
conversationEpoch(conversationId:Asynchronous) Returns the current MLS epoch of the given conversation.
Declaration
Swift
open func conversationEpoch(conversationId: ConversationId) async throws -> UInt64 -
conversationExists(conversationId:Asynchronous) Returns true if a conversation with the given id exists in the local state.
Declaration
Swift
open func conversationExists(conversationId: ConversationId) async throws -> Bool -
Creates a new MLS group with the given conversation ID, using the specified credential.
Declaration
Swift
open func createConversation(conversationId: ConversationId, credentialRef: CredentialRef, externalSender: ExternalSenderKey? = nil) async throws -
decryptMessage(conversationId:Asynchronouspayload: ) Decrypts an MLS message received in the given conversation.
Declaration
Swift
open func decryptMessage(conversationId: ConversationId, payload: Data) async throws -> DecryptedMessage -
disableHistorySharing(conversationId:Asynchronous) Disables history sharing for the given conversation.
Declaration
Swift
open func disableHistorySharing(conversationId: ConversationId) async throws -
e2eiConversationState(conversationId:Asynchronous) Returns the end-to-end identity verification state of the given conversation.
Declaration
Swift
open func e2eiConversationState(conversationId: ConversationId) async throws -> E2eiConversationState -
e2eiIsEnabled(ciphersuite:Asynchronous) Returns true if end-to-end identity is enabled for the given ciphersuite.
Declaration
Swift
open func e2eiIsEnabled(ciphersuite: Ciphersuite) async throws -> Bool -
e2eiIsPkiEnvSetup()AsynchronousReturns true if the PKI environment has been set up.
Declaration
Swift
open func e2eiIsPkiEnvSetup() async -> Bool -
enableHistorySharing(conversationId:Asynchronous) Enables history sharing for the given conversation.
Declaration
Swift
open func enableHistorySharing(conversationId: ConversationId) async throws -
encryptMessage(conversationId:Asynchronousmessage: ) Encrypts a plaintext message for all members of the given conversation.
Declaration
Swift
open func encryptMessage(conversationId: ConversationId, message: Data) async throws -> Data -
exportSecretKey(conversationId:AsynchronouskeyLength: ) Derives and exports a secret of
key_lengthbytes for the given conversation.The secret is derived from the MLS key schedule’s exporter mechanism (RFC 9420 §8.5), which produces output bound to the current group state and epoch. The exported value changes whenever the epoch advances.
Declaration
Swift
open func exportSecretKey(conversationId: ConversationId, keyLength: UInt32) async throws -> SecretKey -
Get all credentials from this client which match the provided parameters.
Parameters which are unset or
Nonematch anything. Those with a particular value find only credentials matching that value.Declaration
Swift
open func findCredentials(clientId: ClientId? = nil, publicKey: Data? = nil, ciphersuite: Ciphersuite? = nil, credentialType: CredentialType? = nil, earliestValidity: UInt64? = nil) async throws -> [CredentialRef] -
generateKeypackage(credentialRef:Asynchronouslifetime: ) Generate a
KeyPackagefrom the referenced credential.Makes no attempt to look up or prune existing keypackages.
If
lifetimeis set, the keypackages will expire that span into the future. If it is unset, a default lifetime of approximately 3 months is used.Declaration
Swift
open func generateKeypackage(credentialRef: CredentialRef, lifetime: TimeInterval? = nil) async throws -> Keypackage -
getClientIds(conversationId:Asynchronous) Returns the client ids of all members of the given conversation.
Declaration
Swift
open func getClientIds(conversationId: ConversationId) async throws -> [ClientId] -
getCredentials()AsynchronousGet all credentials from this client.
Declaration
Swift
open func getCredentials() async throws -> [CredentialRef] -
getData()AsynchronousReturns data previously stored by
set_data, orNoneif no data has been stored.Declaration
Swift
open func getData() async throws -> Data? -
getDeviceIdentities(conversationId:AsynchronousdeviceIds: ) Returns the E2EI identity claims for the specified devices in the given conversation.
Declaration
Swift
open func getDeviceIdentities(conversationId: ConversationId, deviceIds: [ClientId]) async throws -> [WireIdentity] -
getExternalSender(conversationId:Asynchronous) Returns the serialized public key of the external sender for the given conversation.
Declaration
Swift
open func getExternalSender(conversationId: ConversationId) async throws -> ExternalSenderKey -
getKeypackages()AsynchronousGet a reference to each
KeyPackagein the database.Declaration
Swift
open func getKeypackages() async throws -> [KeypackageRef] -
getUserIdentities(conversationId:AsynchronoususerIds: ) Returns the E2EI identity claims for the specified users in the given conversation, grouped by user ID.
Declaration
Swift
open func getUserIdentities(conversationId: ConversationId, userIds: [String]) async throws -> [String : [WireIdentity]] -
joinByExternalCommit(groupInfo:AsynchronouscredentialRef: ) Joins an existing conversation by constructing an external commit from the given group info.
Declaration
Swift
open func joinByExternalCommit(groupInfo: GroupInfo, credentialRef: CredentialRef) async throws -> ConversationId -
mlsInit(clientId:Asynchronoustransport: ) Initializes the MLS client with the given client ID and message transport.
Declaration
Swift
open func mlsInit(clientId: ClientId, transport: MlsTransport) async throws -
processWelcomeMessage(welcomeMessage:Asynchronous) Joins a conversation by processing an MLS Welcome message, returning the new conversation’s ID.
Declaration
Swift
open func processWelcomeMessage(welcomeMessage: Welcome) async throws -> ConversationId -
proteusDecrypt(sessionId:Asynchronousciphertext: ) Decrypts a Proteus ciphertext in the given session, returning the plaintext.
Declaration
Swift
open func proteusDecrypt(sessionId: String, ciphertext: Data) async throws -> Data -
proteusDecryptSafe(sessionId:Asynchronousciphertext: ) Decrypt a message whether or not the proteus session already exists, and saves the session.
This is intended to replace simple usages of
proteusDecrypt.However, when decrypting large numbers of messages in a single session, the existing methods may be more efficient.
Declaration
Swift
open func proteusDecryptSafe(sessionId: String, ciphertext: Data) async throws -> Data -
proteusEncrypt(sessionId:Asynchronousplaintext: ) Encrypts a plaintext message in the given Proteus session.
Declaration
Swift
open func proteusEncrypt(sessionId: String, plaintext: Data) async throws -> Data -
proteusEncryptBatched(sessions:Asynchronousplaintext: ) Encrypts a plaintext message in multiple Proteus sessions, returning a map from session ID to ciphertext.
Declaration
Swift
open func proteusEncryptBatched(sessions: [String], plaintext: Data) async throws -> [String : Data] -
proteusFingerprint()AsynchronousReturns the hex-encoded public key fingerprint of this device’s Proteus identity.
Declaration
Swift
open func proteusFingerprint() async throws -> String -
proteusFingerprintLocal(sessionId:Asynchronous) Returns the hex-encoded local public key fingerprint for the Proteus session with the given ID.
Declaration
Swift
open func proteusFingerprintLocal(sessionId: String) async throws -> String -
proteusFingerprintRemote(sessionId:Asynchronous) Returns the hex-encoded remote public key fingerprint for the Proteus session with the given ID.
Declaration
Swift
open func proteusFingerprintRemote(sessionId: String) async throws -> String -
proteusInit()AsynchronousInitializes the Proteus client.
Declaration
Swift
open func proteusInit() async throws -
proteusLastResortPrekey()AsynchronousReturns the CBOR-serialized last resort prekey bundle, creating it if it does not yet exist.
Declaration
Swift
open func proteusLastResortPrekey() async throws -> Data -
proteusNewPrekey(prekeyId:Asynchronous) Creates a new Proteus prekey with the given ID and returns its CBOR-serialized bundle.
Warning: the Proteus client must be initialized with
proteus_initfirst or an error will be returned.Declaration
Swift
open func proteusNewPrekey(prekeyId: UInt16) async throws -> Data -
proteusNewPrekeyAuto()AsynchronousCreates a new Proteus prekey with an automatically assigned ID and returns its CBOR-serialized bundle.
Warning: the Proteus client must be initialized with
proteus_initfirst or an error will be returned.Declaration
Swift
open func proteusNewPrekeyAuto() async throws -> ProteusAutoPrekeyBundle -
proteusReloadSessions()AsynchronousReloads all Proteus sessions from the keystore into memory.
Declaration
Swift
open func proteusReloadSessions() async throws -
proteusSessionDelete(sessionId:Asynchronous) Deletes the Proteus session with the given ID from local storage.
Declaration
Swift
open func proteusSessionDelete(sessionId: String) async throws -
proteusSessionExists(sessionId:Asynchronous) Returns true if a Proteus session with the given ID exists in local storage.
Declaration
Swift
open func proteusSessionExists(sessionId: String) async throws -> Bool -
proteusSessionFromMessage(sessionId:Asynchronousenvelope: ) Creates a new Proteus session from an incoming encrypted message, returning the decrypted message payload.
Declaration
Swift
open func proteusSessionFromMessage(sessionId: String, envelope: Data) async throws -> Data -
proteusSessionFromPrekey(sessionId:Asynchronousprekey: ) Creates a new Proteus session from the given prekey bundle bytes, stored under the given session ID.
Declaration
Swift
open func proteusSessionFromPrekey(sessionId: String, prekey: Data) async throws -
proteusSessionSave(sessionId:Asynchronous) Saves the Proteus session with the given ID to the keystore.
Note: this is not usually needed, as sessions are persisted automatically when decrypting or encrypting messages and when initializing sessions.
Declaration
Swift
open func proteusSessionSave(sessionId: String) async throws -
randomBytes(len:Asynchronous) Generates
lenrandom bytes from the cryptographically secure RNG.Declaration
Swift
open func randomBytes(len: UInt32) async throws -> Data -
Removes the specified clients from the conversation, sending the resulting commit via the transport.
Declaration
Swift
open func removeClientsFromConversation(conversationId: ConversationId, clients: [ClientId]) async throws -
removeCredential(credentialRef:Asynchronous) Removes a
Credentialfrom this client.Declaration
Swift
open func removeCredential(credentialRef: CredentialRef) async throws -
removeKeypackage(kpRef:Asynchronous) Remove a
KeyPackagefrom the database.Declaration
Swift
open func removeKeypackage(kpRef: KeypackageRef) async throws -
removeKeypackagesFor(credentialRef:Asynchronous) Remove all
KeyPackages associated with this credential ref.Declaration
Swift
open func removeKeypackagesFor(credentialRef: CredentialRef) async throws -
Set the credential ref for the given conversation.
Declaration
Swift
open func setConversationCredential(conversationId: ConversationId, credentialRef: CredentialRef) async throws -
setData(data:Asynchronous) Stores arbitrary data to be used as a transaction checkpoint.
The stored data can be retrieved via
get_data. Keep the data size reasonable; this is not a general-purpose key-value store.Declaration
Swift
open func setData(data: Data) async throws -
updateKeyingMaterial(conversationId:Asynchronous) Updates this client’s key material in the conversation by sending an update commit.
Declaration
Swift
open func updateKeyingMaterial(conversationId: ConversationId) async throws -
wipeConversation(conversationId:Asynchronous) Destroys the local state of the given conversation; it can no longer be used locally after this call.
Declaration
Swift
open func wipeConversation(conversationId: ConversationId) async throws