Class

CryptoClient

CryptoClient()

Manages encryption for a MatrixClient. Get an instance from a MatrixClient directly rather than creating one manually.
Constructor

# new CryptoClient()

View Source e2ee/CryptoClient.ts, line 20

Classes

CryptoClient

Members

# clientDeviceEd25519

The device's Ed25519 identity

View Source e2ee/CryptoClient.ts, line 44

# clientDeviceId

The device ID for the MatrixClient.

View Source e2ee/CryptoClient.ts, line 38

# isReady

Whether or not the crypto client is ready to be used. If not ready, prepare() should be called.
See:
  • prepare

View Source e2ee/CryptoClient.ts, line 51

Methods

# clientDeviceEd25519() → {string}

The device's Ed25519 identity

View Source e2ee/CryptoClient.ts, line 448

string

# clientDeviceId() → {string}

The device ID for the MatrixClient.

View Source e2ee/CryptoClient.ts, line 441

string

# async confirmIdentityWithRecoveryKey(key) → {Promise.<void>}

Confirm's the bot's identity by using a recovery key or passphrase.
Parameters:
Name Type Description
key The recovery key or passphrase.

View Source e2ee/CryptoClient.ts, line 581

Promise.<void>

# async createIdentity(key)

Creates the bot's cryptographic identity. Note: only works if the bot does not have an existing cryptographic identity, since this doesn't yet perform user interactive auth.
Parameters:
Name Type Description
key The recovery key or passphrase. If omitted, a new recovery key will be created and set as the default recovery key.

View Source e2ee/CryptoClient.ts, line 609

The recovery key.

# async decryptMedia(file) → {Promise.<Buffer>}

Decrypts a previously-uploaded encrypted file, validating the fields along the way.
Parameters:
Name Type Description
file EncryptedFile The file to decrypt.

View Source e2ee/CryptoClient.ts, line 571

Resolves to the decrypted file contents.
Promise.<Buffer>

# async decryptRoomEvent(event, roomId) → {Promise.<RoomEvent.<unknown>>}

Decrypts a room event. Currently only supports Megolm-encrypted events (default for this SDK).
Parameters:
Name Type Description
event EncryptedRoomEvent The encrypted event.
roomId string The room ID where the event was sent.

View Source e2ee/CryptoClient.ts, line 551

Resolves to a decrypted room event, or rejects/throws with an error if the event is undecryptable.
Promise.<RoomEvent.<unknown>>

# async disableKeyBackup() → {Promise.<void>}

Disable backing up of room keys.

View Source e2ee/CryptoClient.ts, line 639

Promise.<void>

# async enableKeyBackup(info) → {Promise.<void>}

Enable backing up of room keys.
Parameters:
Name Type Description
info IKeyBackupInfoRetrieved The configuration for key backup behaviour, as returned by MatrixClient#getKeyBackupVersion.

View Source e2ee/CryptoClient.ts, line 631

Resolves once backups have been enabled.
Promise.<void>

# async encryptMedia(file) → {Object}

Encrypts a file for uploading in a room, returning the encrypted data and information to include in a message event (except media URL) for sending.
Parameters:
Name Type Description
file Buffer The file to encrypt.

View Source e2ee/CryptoClient.ts, line 562

Resolves to the encrypted contents and file information.
Object

# async encryptRoomEvent(roomId, eventType, content) → {Promise.<IMegolmEncrypted>}

Encrypts the details of a room event, returning an encrypted payload to be sent in an `m.room.encrypted` event to the room. If needed, this function will send decryption keys to the appropriate devices in the room (this happens when the Megolm session rotates or gets created).
Parameters:
Name Type Description
roomId string The room ID to encrypt within. If the room is not encrypted, an error is thrown.
eventType string The event type being encrypted.
content any The event content being encrypted.

View Source e2ee/CryptoClient.ts, line 540

Resolves to the encrypted content for an `m.room.encrypted` event.
Promise.<IMegolmEncrypted>

# async exportRoomKeysForSession(roomId, sessionId)

Exports a set of keys for a given session.
Parameters:
Name Type Description
roomId The room ID for the session.
sessionId The session ID.

View Source e2ee/CryptoClient.ts, line 494

An array of session keys.

# async getDefaultSecretStorageKey(key)

Create a `SecretStorageKey` from the given key, assuming it is the default secret storage key.
Parameters:
Name Type Description
key The recovery key or passphrase.

View Source e2ee/CryptoClient.ts, line 352

The `SecretStorageKey`.

# isReady() → {boolean}

Whether or not the crypto client is ready to be used. If not ready, prepare() should be called.
See:
  • prepare

View Source e2ee/CryptoClient.ts, line 456

boolean

# async isRecoveryAvailable()

Has recovery been set up on this account. Checks whether the account has a default Secret Storage key set up, and has the cross-signing keys stored in Secret Storage. It does not check the validity of the stored keys.

View Source e2ee/CryptoClient.ts, line 594

Whether recovery has been set up on this account.

# async isRoomEncrypted(roomId) → {Promise.<boolean>}

Checks if a room is encrypted.
Parameters:
Name Type Description
roomId string The room ID to check.

View Source e2ee/CryptoClient.ts, line 503

Resolves to true if encrypted, false otherwise.
Promise.<boolean>

# async onRoomEvent(roomId, event) → {Promise.<void>}

Handles a room event.
Parameters:
Name Type Description
roomId The room ID.
event The event.

View Source e2ee/CryptoClient.ts, line 475

Promise.<void>

# async onRoomJoin(roomId)

Handles a room join.
Parameters:
Name Type Description
roomId The room ID.

View Source e2ee/CryptoClient.ts, line 484

# async prepare(roomIds)

Prepares the crypto client for usage.
Parameters:
Name Type Description
roomIds Array.<string> The room IDs the MatrixClient is joined to.

View Source e2ee/CryptoClient.ts, line 464

# async sign(obj) → {Promise.<Signatures>}

Signs an object using the device keys.
Parameters:
Name Type Description
obj object The object to sign.

View Source e2ee/CryptoClient.ts, line 525

The signatures for the object.
Promise.<Signatures>

# async updateSyncData(toDeviceMessages, otkCounts, unusedFallbackKeyAlgs, changedDeviceLists, leftDeviceLists) → {Promise.<void>}

Updates the client's sync-related data.
Parameters:
Name Type Description
toDeviceMessages Array.<IToDeviceMessage.<IOlmEncrypted>> The to-device messages received.
otkCounts OTKCounts The current OTK counts.
unusedFallbackKeyAlgs Array.<OTKAlgorithm> The unused fallback key algorithms.
changedDeviceLists Array.<string> The user IDs which had device list changes.
leftDeviceLists Array.<string> The user IDs which the server believes we no longer need to track.

View Source e2ee/CryptoClient.ts, line 516

Resolves when complete.
Promise.<void>