1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Implement experimental encrypted state events. (#4994)

* feat: Implement experimental encrypted state events.

Signed-off-by: Skye Elliot <actuallyori@gmail.com>

* fix: Add cast from StateEvents[K] to IContent.

---------

Signed-off-by: Skye Elliot <actuallyori@gmail.com>
This commit is contained in:
Skye Elliot
2025-09-24 12:44:17 +01:00
committed by GitHub
parent dbe441de33
commit a08a2737e1
17 changed files with 594 additions and 144 deletions

View File

@@ -162,6 +162,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
/** Crypto callbacks provided by the application */
private readonly cryptoCallbacks: CryptoCallbacks,
/** Enable support for encrypted state events under MSC3414. */
private readonly enableEncryptedStateEvents: boolean = false,
) {
super();
this.outgoingRequestProcessor = new OutgoingRequestProcessor(logger, olmMachine, http);
@@ -421,6 +424,16 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
return Boolean(roomSettings?.algorithm);
}
/**
* Implementation of {@link CryptoApi#isStateEncryptionEnabledInRoom}.
*/
public async isStateEncryptionEnabledInRoom(roomId: string): Promise<boolean> {
const roomSettings: RustSdkCryptoJs.RoomSettings | undefined = await this.olmMachine.getRoomSettings(
new RustSdkCryptoJs.RoomId(roomId),
);
return Boolean(roomSettings?.encryptStateEvents);
}
/**
* Implementation of {@link CryptoApi#getOwnDeviceKeys}.
*/
@@ -1717,7 +1730,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
await this.receiveSyncChanges({ devices });
}
/** called by the sync loop on m.room.encrypted events
/** called by the sync loop on m.room.encryption events
*
* @param room - in which the event was received
* @param event - encryption event to be processed
@@ -1734,6 +1747,11 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
return;
}
if (config["io.element.msc3414.encrypt_state_events"] && this.enableEncryptedStateEvents) {
this.logger.info("crypto Enabling state event encryption...");
settings.encryptStateEvents = true;
}
try {
settings.sessionRotationPeriodMs = config.rotation_period_ms;
settings.sessionRotationPeriodMessages = config.rotation_period_msgs;