diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index 409d2d6e4..01a5a1b94 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -352,7 +352,16 @@ class MatrixAdapter(BasePlatformAdapter): from mautrix.crypto import OlmMachine from mautrix.crypto.store import MemoryCryptoStore - crypto_store = MemoryCryptoStore() + # account_id and pickle_key are required by mautrix ≥0.21. + # Use the Matrix user ID as account_id for stable identity. + # pickle_key secures in-memory serialisation; derive from + # the same user_id:device_id pair used for the on-disk HMAC. + _acct_id = self._user_id or "hermes" + _pickle_key = f"{_acct_id}:{self._device_id}" + crypto_store = MemoryCryptoStore( + account_id=_acct_id, + pickle_key=_pickle_key, + ) # Restore persisted crypto state from a previous run. # Uses HMAC to verify integrity before unpickling. diff --git a/tests/gateway/test_matrix.py b/tests/gateway/test_matrix.py index 469bae030..6bf9862f0 100644 --- a/tests/gateway/test_matrix.py +++ b/tests/gateway/test_matrix.py @@ -157,7 +157,9 @@ def _make_fake_mautrix(): mautrix_crypto_store = types.ModuleType("mautrix.crypto.store") class MemoryCryptoStore: - pass + def __init__(self, account_id="", pickle_key=""): + self.account_id = account_id + self.pickle_key = pickle_key mautrix_crypto_store.MemoryCryptoStore = MemoryCryptoStore