matrix-js-sdk 42.3.0 → 42.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/@types/json.d.ts.map +1 -1
  3. package/lib/@types/json.js.map +1 -1
  4. package/lib/client.d.ts +74 -5
  5. package/lib/client.d.ts.map +1 -1
  6. package/lib/client.js +83 -7
  7. package/lib/client.js.map +1 -1
  8. package/lib/common-crypto/CryptoBackend.d.ts +42 -23
  9. package/lib/common-crypto/CryptoBackend.d.ts.map +1 -1
  10. package/lib/common-crypto/CryptoBackend.js +7 -0
  11. package/lib/common-crypto/CryptoBackend.js.map +1 -1
  12. package/lib/embedded.d.ts +35 -1
  13. package/lib/embedded.d.ts.map +1 -1
  14. package/lib/embedded.js +49 -1
  15. package/lib/embedded.js.map +1 -1
  16. package/lib/http-api/fetch.d.ts +0 -1
  17. package/lib/http-api/fetch.d.ts.map +1 -1
  18. package/lib/http-api/fetch.js +3 -22
  19. package/lib/http-api/fetch.js.map +1 -1
  20. package/lib/http-api/logging.d.ts +10 -0
  21. package/lib/http-api/logging.d.ts.map +1 -0
  22. package/lib/http-api/logging.js +46 -0
  23. package/lib/http-api/logging.js.map +1 -0
  24. package/lib/matrixrtc/EncryptionManager.d.ts +5 -0
  25. package/lib/matrixrtc/EncryptionManager.d.ts.map +1 -1
  26. package/lib/matrixrtc/EncryptionManager.js.map +1 -1
  27. package/lib/matrixrtc/LivekitTransport.d.ts +82 -0
  28. package/lib/matrixrtc/LivekitTransport.d.ts.map +1 -1
  29. package/lib/matrixrtc/LivekitTransport.js +25 -0
  30. package/lib/matrixrtc/LivekitTransport.js.map +1 -1
  31. package/lib/matrixrtc/MatrixRTCSession.d.ts +41 -2
  32. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
  33. package/lib/matrixrtc/MatrixRTCSession.js +59 -1
  34. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  35. package/lib/matrixrtc/MembershipManager.js +7 -4
  36. package/lib/matrixrtc/MembershipManager.js.map +1 -1
  37. package/lib/matrixrtc/RTCEncryptionManager.d.ts +17 -0
  38. package/lib/matrixrtc/RTCEncryptionManager.d.ts.map +1 -1
  39. package/lib/matrixrtc/RTCEncryptionManager.js +68 -29
  40. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
  41. package/lib/models/room-receipts.d.ts +9 -3
  42. package/lib/models/room-receipts.d.ts.map +1 -1
  43. package/lib/models/room-receipts.js +51 -11
  44. package/lib/models/room-receipts.js.map +1 -1
  45. package/lib/oauth/authorize.d.ts +7 -2
  46. package/lib/oauth/authorize.d.ts.map +1 -1
  47. package/lib/oauth/authorize.js +10 -4
  48. package/lib/oauth/authorize.js.map +1 -1
  49. package/lib/oauth/fetch.d.ts +17 -0
  50. package/lib/oauth/fetch.d.ts.map +1 -0
  51. package/lib/oauth/fetch.js +47 -0
  52. package/lib/oauth/fetch.js.map +1 -0
  53. package/lib/oauth/index.d.ts +15 -2
  54. package/lib/oauth/index.d.ts.map +1 -1
  55. package/lib/oauth/index.js +33 -12
  56. package/lib/oauth/index.js.map +1 -1
  57. package/lib/rust-crypto/index.d.ts +17 -0
  58. package/lib/rust-crypto/index.d.ts.map +1 -1
  59. package/lib/rust-crypto/index.js +4 -2
  60. package/lib/rust-crypto/index.js.map +1 -1
  61. package/lib/rust-crypto/rust-crypto.d.ts +6 -26
  62. package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
  63. package/lib/rust-crypto/rust-crypto.js +19 -54
  64. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  65. package/lib/sliding-sync-sdk.d.ts.map +1 -1
  66. package/lib/sliding-sync-sdk.js +65 -27
  67. package/lib/sliding-sync-sdk.js.map +1 -1
  68. package/lib/sliding-sync.d.ts +17 -0
  69. package/lib/sliding-sync.d.ts.map +1 -1
  70. package/lib/sliding-sync.js +21 -9
  71. package/lib/sliding-sync.js.map +1 -1
  72. package/lib/sync.d.ts +9 -1
  73. package/lib/sync.d.ts.map +1 -1
  74. package/lib/sync.js +54 -29
  75. package/lib/sync.js.map +1 -1
  76. package/package.json +5 -5
  77. package/src/@types/json.ts +11 -2
  78. package/src/client.ts +126 -11
  79. package/src/common-crypto/CryptoBackend.ts +45 -23
  80. package/src/embedded.ts +67 -4
  81. package/src/http-api/fetch.ts +2 -23
  82. package/src/http-api/logging.ts +46 -0
  83. package/src/matrixrtc/EncryptionManager.ts +6 -0
  84. package/src/matrixrtc/LivekitTransport.ts +86 -0
  85. package/src/matrixrtc/MatrixRTCSession.ts +81 -1
  86. package/src/matrixrtc/MembershipManager.ts +7 -7
  87. package/src/matrixrtc/RTCEncryptionManager.ts +80 -31
  88. package/src/models/room-receipts.ts +54 -10
  89. package/src/oauth/authorize.ts +10 -2
  90. package/src/oauth/fetch.ts +54 -0
  91. package/src/oauth/index.ts +29 -10
  92. package/src/rust-crypto/index.ts +23 -0
  93. package/src/rust-crypto/rust-crypto.ts +25 -67
  94. package/src/sliding-sync-sdk.ts +73 -33
  95. package/src/sliding-sync.ts +31 -14
  96. package/src/sync.ts +58 -35
@@ -179,12 +179,12 @@ export class RustCrypto extends TypedEventEmitter {
179
179
  async decryptEvent(event) {
180
180
  const roomId = event.getRoomId();
181
181
  if (!roomId) {
182
- // presumably, a to-device message. These are normally decrypted in preprocessToDeviceMessages
182
+ // presumably, a to-device message. These are normally decrypted in processSyncChanges
183
183
  // so the fact it has come back here suggests that decryption failed.
184
184
  //
185
185
  // once we drop support for the libolm crypto implementation, we can stop passing to-device messages
186
186
  // through decryptEvent and hence get rid of this case.
187
- throw new Error("to-device event was not decrypted in preprocessToDeviceMessages");
187
+ throw new Error("to-device event was not decrypted in processSyncChanges");
188
188
  }
189
189
  return await this.eventDecryptor.attemptEventDecryption(event, this.deviceIsolationMode);
190
190
  }
@@ -1353,33 +1353,26 @@ export class RustCrypto extends TypedEventEmitter {
1353
1353
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1354
1354
 
1355
1355
  /**
1356
- * Apply sync changes to the olm machine
1357
- * @param events - the received to-device messages
1358
- * @param oneTimeKeysCounts - the received one time key counts
1359
- * @param unusedFallbackKeys - the received unused fallback keys
1360
- * @param devices - the received device list updates
1361
- * @returns A list of processed to-device messages.
1356
+ * Implementation of {@link SyncCryptoCallbacks.processSyncChanges}.
1357
+ *
1358
+ * Passes all of the encryption-relevant data from a sync response to the OlmMachine in a single call, and
1359
+ * post-processes the resulting to-device messages.
1362
1360
  */
1363
- async receiveSyncChanges({
1364
- events,
1365
- oneTimeKeysCounts = new Map(),
1361
+ async processSyncChanges({
1362
+ toDeviceEvents,
1363
+ deviceLists,
1364
+ oneTimeKeysCounts,
1366
1365
  unusedFallbackKeys,
1367
- devices = new RustSdkCryptoJs.DeviceLists()
1366
+ useMsc4186 = false
1368
1367
  }) {
1369
- return await this.olmMachine.receiveSyncChanges(events ? JSON.stringify(events) : "[]", devices, oneTimeKeysCounts, unusedFallbackKeys);
1370
- }
1371
-
1372
- /** called by the sync loop to preprocess incoming to-device messages
1373
- *
1374
- * @param events - the received to-device messages
1375
- * @returns A list of preprocessed to-device messages.
1376
- */
1377
- async preprocessToDeviceMessages(events) {
1378
- // send the received to-device messages into receiveSyncChanges. We have no info on device-list changes,
1379
- // one-time-keys, or fallback keys, so just pass empty data.
1380
- const processed = await this.receiveSyncChanges({
1381
- events
1382
- });
1368
+ const events = JSON.stringify(toDeviceEvents);
1369
+ const devices = new RustSdkCryptoJs.DeviceLists(deviceLists?.changed?.map(userId => new RustSdkCryptoJs.UserId(userId)), deviceLists?.left?.map(userId => new RustSdkCryptoJs.UserId(userId)));
1370
+ const counts = new Map(Object.entries(oneTimeKeysCounts ?? {}));
1371
+ const fallbackKeys = unusedFallbackKeys && new Set(unusedFallbackKeys);
1372
+
1373
+ // The two variants differ only in how they treat a missing one-time key count: zero keys on the server (sync
1374
+ // v2) versus unchanged (sliding sync).
1375
+ const processed = useMsc4186 ? await this.olmMachine.receiveSyncChangesMsc4186(events, devices, counts, fallbackKeys) : await this.olmMachine.receiveSyncChanges(events, devices, counts, fallbackKeys);
1383
1376
  const received = [];
1384
1377
  for (const message of processed) {
1385
1378
  const parsedMessage = JSON.parse(message.rawEvent);
@@ -1450,34 +1443,6 @@ export class RustCrypto extends TypedEventEmitter {
1450
1443
  return received;
1451
1444
  }
1452
1445
 
1453
- /** called by the sync loop to process one time key counts and unused fallback keys
1454
- *
1455
- * @param oneTimeKeysCounts - the received one time key counts
1456
- * @param unusedFallbackKeys - the received unused fallback keys
1457
- */
1458
- async processKeyCounts(oneTimeKeysCounts, unusedFallbackKeys) {
1459
- const mapOneTimeKeysCount = oneTimeKeysCounts && new Map(Object.entries(oneTimeKeysCounts));
1460
- const setUnusedFallbackKeys = unusedFallbackKeys && new Set(unusedFallbackKeys);
1461
- if (mapOneTimeKeysCount !== undefined || setUnusedFallbackKeys !== undefined) {
1462
- await this.receiveSyncChanges({
1463
- oneTimeKeysCounts: mapOneTimeKeysCount,
1464
- unusedFallbackKeys: setUnusedFallbackKeys
1465
- });
1466
- }
1467
- }
1468
-
1469
- /** called by the sync loop to process the notification that device lists have
1470
- * been changed.
1471
- *
1472
- * @param deviceLists - device_lists field from /sync
1473
- */
1474
- async processDeviceLists(deviceLists) {
1475
- const devices = new RustSdkCryptoJs.DeviceLists(deviceLists.changed?.map(userId => new RustSdkCryptoJs.UserId(userId)), deviceLists.left?.map(userId => new RustSdkCryptoJs.UserId(userId)));
1476
- await this.receiveSyncChanges({
1477
- devices
1478
- });
1479
- }
1480
-
1481
1446
  /** called by the sync loop on m.room.encryption events
1482
1447
  *
1483
1448
  * @param room - in which the event was received