matrixlib.devices module

Device-related functionality

class matrixlib.devices.DeviceKeysManager(c: Client, key: bytes)

Manages a device’s keys for end-to-end encryption



the client object


a 32-byte binary used to encrypt the objects in storage

property fingerprint_key: str
property identity_key: str
sign_json(json_object: dict) dict

Sign a JSON object using the device’s signing key

The input object is modified to include the signature.

class matrixlib.devices.DeviceTracker(c: Client)

Tracks user devices to reduce the number of queries required



the client object

async get_device_keys(users: Iterable[str], force_download=False, timeout: int | None = None) dict[str, matrixlib.devices.UserDeviceKeysResult]

Get the device keys for the given users.



the user IDs to fetch device keys for


whether to ignore the cache and force downloading of all device keys from the server


a timeout in milliseconds for the homeserver to wait for responses from remote homeservers

Returns a dict mapping the user IDs to a UserDeviceKeysResult.

class matrixlib.devices.UserDeviceKeysResult(device_keys: dict[str, dict])

The return value of DeviceTracker.get_device_keys for a user

Create new instance of UserDeviceKeysResult(device_keys,)

device_keys: dict[str, dict]

mapping from device ID to device keys

matrixlib.devices.verify_json_ed25519(signature_key: str, user_id: str, device_id: str, json_object: dict) None

Verify a signed JSON object using a public key


  • signature_key: the public part of the key used to sign the object

  • user_id: the ID of the user who signed the object

  • device_id: the ID of the device used to sign the object

  • json_object: the signed JSON object