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

# 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 45

Methods

# clientDeviceId() → {string}

The device ID for the MatrixClient.

View Source e2ee/CryptoClient.ts, line 271

string

# 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 383

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 363

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

# 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 374

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 352

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

# 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 279

boolean

# 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 315

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

# async onRoomEvent(roomId, event)

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

View Source e2ee/CryptoClient.ts, line 297

# async onRoomJoin(roomId)

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

View Source e2ee/CryptoClient.ts, line 306

# 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 287

# 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 337

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 328

Resolves when complete.
Promise.<void>