Documentation Index
Fetch the complete documentation index at: https://mintlify.com/matrix-org/matrix-js-sdk/llms.txt
Use this file to discover all available pages before exploring further.
CryptoApi is the public interface for end-to-end encryption in matrix-js-sdk. Obtain
an instance via client.getCrypto(). Returns undefined if the client was not
initialized with crypto support.
Global Settings
When
true, the client will refuse to send encrypted messages to any unverified
device. This is the global default; individual rooms can override it.Methods
Setup
bootstrapSecretStorage(opts)
bootstrapCrossSigning(opts)
isSecretStorageReady()
true if secret storage is set up and storing cross-signing keys (and the
key backup key, if a backup is enabled).
isCrossSigningReady()
true if cross-signing is enabled, trusted, and has private keys available
either in local storage or in secret storage.
Key Backup
checkKeyBackupAndEnable()
null if there is no backup on the server.
resetKeyBackup()
getActiveSessionBackupVersion()
null if automatic
key backup is not enabled.
restoreKeyBackup(opts?)
storeSessionBackupPrivateKey
or loaded via loadSessionBackupPrivateKeyFromSecretStorage.
Device & User Trust
getUserVerificationStatus(userId)
getDeviceVerificationStatus(userId, deviceId)
null if the device is unknown or has not published encryption keys.
Otherwise returns the device’s verification status.
setDeviceVerified(userId, deviceId, verified?)
verified defaults to true). This has the same
effect as receiving a cross-signing signature for the device.
getUserDeviceInfo(userIds, downloadUncached?)
Map<userId, Map<deviceId, Device>> of all known devices. Set
downloadUncached: true to fetch devices for users whose device lists are not
currently being tracked.
Cross-signing
getCrossSigningKeyId(type?)
CrossSigningKey.Master by default), if both the private and public parts are
available locally. Returns null otherwise.
crossSignDevice(deviceId)
Dehydration
isDehydrationSupported()
true if MSC3814 device dehydration is supported by both the crypto backend
and the server. Always call this before startDehydration.
startDehydration(opts?)
Export / Import Room Keys
exportRoomKeys()
exportRoomKeysAsJson()
exportRoomKeys() but serialised to a JSON string.
importRoomKeys(keys, opts?)
exportRoomKeys().
importRoomKeysAsJson(keys, opts?)
exportRoomKeysAsJson().
Encryption Info
isEncryptionEnabledInRoom(roomId)
true if the room has been configured for encryption. The setting persists
even if the encryption event is later removed from room state (downgrade protection).
getEncryptionInfoForEvent(event)
null if the event is not encrypted
or has not been successfully decrypted.
getVersion()
"Rust SDK 0.7.0 (abc1234), Vodozemac 0.5.0".
CryptoEvent Enum
Cryptography-related events emitted byMatrixClient. Listen via
client.on(CryptoEvent.X, handler):
| Value | String | Description |
|---|---|---|
CryptoEvent.UserTrustStatusChanged | "userTrustStatusChanged" | A user’s trust status changed. Payload: (userId, trustLevel). |
CryptoEvent.KeyBackupStatus | "crypto.keyBackupStatus" | Key backup was enabled or disabled. Payload: boolean. |
CryptoEvent.KeyBackupFailed | "crypto.keyBackupFailed" | A key backup operation failed. Payload: error code string. |
CryptoEvent.KeyBackupSessionsRemaining | "crypto.keyBackupSessionsRemaining" | Number of sessions awaiting backup changed. |
CryptoEvent.KeyBackupDecryptionKeyCached | "crypto.keyBackupDecryptionKeyCached" | A valid backup decryption key was cached. Payload: backup version. |
CryptoEvent.VerificationRequestReceived | "crypto.verificationRequestReceived" | An incoming verification request was received. Payload: VerificationRequest. |
CryptoEvent.DevicesUpdated | "crypto.devicesUpdated" | Stored device info for one or more users was updated. |
CryptoEvent.KeysChanged | "crossSigning.keysChanged" | Cross-signing keys changed or cross-signing was toggled. |
CryptoEvent.LegacyCryptoStoreMigrationProgress | "crypto.legacyCryptoStoreMigrationProgress" | Migration progress from legacy to Rust crypto. Payload: (progress, total). |
CryptoEvent.DehydratedDeviceCreated | "dehydration.DehydratedDeviceCreated" | A new dehydrated device was created locally. |
CryptoEvent.DehydratedDeviceUploaded | "dehydration.DehydratedDeviceUploaded" | A dehydrated device was successfully uploaded to the server. |
CryptoEvent.RehydrationStarted | "dehydration.RehydrationStarted" | Rehydration of a dehydrated device has started. |
CryptoEvent.RehydrationProgress | "dehydration.RehydrationProgress" | Rehydration progress update. Payload: [roomKeyCount, toDeviceCount]. |
CryptoEvent.RehydrationCompleted | "dehydration.RehydrationCompleted" | Rehydration completed successfully. |
CryptoEvent.RehydrationError | "dehydration.RehydrationError" | An error occurred during rehydration. Payload: error string. |
CryptoEvent.DehydrationKeyCached | "dehydration.DehydrationKeyCached" | A dehydrated device key was cached in the local database. |
CryptoEvent.DehydratedDeviceRotationError | "dehydration.DehydratedDeviceRotationError" | An error occurred during periodic dehydrated device rotation. |