End-to-end encryption (E2EE) inDocumentation 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.
matrix-js-sdk ensures that message contents are only readable by the intended recipients. The SDK’s encryption support is built on the WebAssembly bindings of the Rust matrix-sdk-crypto library.
Rust crypto stack
The current encryption backend is the Rust crypto stack:matrix-sdk-crypto compiled to WebAssembly. It supersedes the older JavaScript-based implementation and is the only supported backend for new integrations.
The Rust stack provides:
- Megolm-based room message encryption
- Olm-based to-device messages
- Cross-signing for device and user verification
- Server-side key backup
- Secret storage (4S) integration
The
MatrixClient.crypto property from the legacy stack is no longer available. Use MatrixClient.getCrypto() to obtain a CryptoApi instance.Initializing encryption
CallinitRustCrypto() on the MatrixClient after creating it, before calling startClient().
Initialize Rust crypto
initRustCrypto() attempts to use IndexedDB (available in browsers) as the crypto store. When running in Node.js or another environment without IndexedDB, pass useIndexedDB: false to use an ephemeral in-memory store:Thread safety
CryptoApi interface
getCrypto() returns a CryptoApi object, which is the primary interface for encryption operations. Key methods include:
Encryption state
Encryption state
isEncryptionEnabledInRoom(roomId)— Returnstrueif the room is configured for encryption.getVersion()— Returns the current version string of the crypto module (e.g.Rust SDK 0.x.x (...), Vodozemac 0.x.x).getOwnDeviceKeys()— Returns the public Ed25519 and Curve25519 keys for the current device.
Trust and verification
Trust and verification
getUserVerificationStatus(userId)— Returns aUserVerificationStatusfor the given user.getDeviceVerificationStatus(userId, deviceId)— Returns aDeviceVerificationStatusornull.bootstrapCrossSigning(opts)— Sets up cross-signing keys. See Cross-signing.
Secret storage
Secret storage
bootstrapSecretStorage(opts)— Sets up server-side secret storage. See Secret storage.isSecretStorageReady()— Returnstrueif secret storage is fully configured.
Key backup
Key backup
checkKeyBackupAndEnable()— Checks the server for a trusted backup and enables it.resetKeyBackup()— Creates a new key backup version. See Key backup.
CryptoEvent enum
TheMatrixClient emits crypto-related events defined in the CryptoEvent enum:
| Event | Description |
|---|---|
CryptoEvent.UserTrustStatusChanged | The trust status of a user has changed. Payload: (userId, UserVerificationStatus). |
CryptoEvent.KeyBackupStatus | Key backup enabled/disabled. Payload: boolean. |
CryptoEvent.KeyBackupFailed | Key backup upload failed. Payload: error code string. |
CryptoEvent.KeyBackupSessionsRemaining | Number of sessions awaiting backup changed. Payload: number. |
CryptoEvent.KeyBackupDecryptionKeyCached | A new valid backup decryption key is in cache. Payload: backup version string. |
CryptoEvent.VerificationRequestReceived | An incoming verification request. Payload: VerificationRequest. |
CryptoEvent.DevicesUpdated | Stored devices for one or more users have been updated. Payload: (userIds, initialFetch). |
CryptoEvent.KeysChanged | Cross-signing keys changed or enabled/disabled. |
CryptoEvent.LegacyCryptoStoreMigrationProgress | Migration progress from legacy crypto. Payload: (progress, total). |
Complete setup example
The following is a full initialization flow including secret storage and cross-signing:Migrating from legacy crypto
If your application previously calledMatrixClient.initLegacyCrypto(), migration to the Rust stack happens automatically when you switch to initRustCrypto(). You must supply the legacy cryptoStore and pickleKey to createClient so the migration can read the existing data:
LegacyCryptoStoreMigrationProgress event. When progress === total === -1, migration is complete: