matrix-js-sdk 34.2.0 → 34.3.0-rc.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 (63) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/@types/global.d.js.map +1 -1
  3. package/lib/@types/requests.d.ts +37 -0
  4. package/lib/@types/requests.d.ts.map +1 -1
  5. package/lib/@types/requests.js +28 -1
  6. package/lib/@types/requests.js.map +1 -1
  7. package/lib/client.d.ts +48 -4
  8. package/lib/client.d.ts.map +1 -1
  9. package/lib/client.js +412 -257
  10. package/lib/client.js.map +1 -1
  11. package/lib/crypto/algorithms/base.d.ts +0 -2
  12. package/lib/crypto/algorithms/base.d.ts.map +1 -1
  13. package/lib/crypto/algorithms/base.js +0 -4
  14. package/lib/crypto/algorithms/base.js.map +1 -1
  15. package/lib/digest.d.ts +10 -0
  16. package/lib/digest.d.ts.map +1 -0
  17. package/lib/digest.js +40 -0
  18. package/lib/digest.js.map +1 -0
  19. package/lib/embedded.d.ts +24 -1
  20. package/lib/embedded.d.ts.map +1 -1
  21. package/lib/embedded.js +84 -26
  22. package/lib/embedded.js.map +1 -1
  23. package/lib/matrixrtc/MatrixRTCSession.d.ts +2 -0
  24. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
  25. package/lib/matrixrtc/MatrixRTCSession.js +44 -15
  26. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  27. package/lib/matrixrtc/index.d.ts +7 -0
  28. package/lib/matrixrtc/index.d.ts.map +1 -0
  29. package/lib/matrixrtc/index.js +23 -0
  30. package/lib/matrixrtc/index.js.map +1 -0
  31. package/lib/models/event.js.map +1 -1
  32. package/lib/oidc/authorize.d.ts.map +1 -1
  33. package/lib/oidc/authorize.js +4 -3
  34. package/lib/oidc/authorize.js.map +1 -1
  35. package/lib/rust-crypto/RoomEncryptor.d.ts +1 -1
  36. package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -1
  37. package/lib/rust-crypto/RoomEncryptor.js +6 -2
  38. package/lib/rust-crypto/RoomEncryptor.js.map +1 -1
  39. package/lib/rust-crypto/index.js +1 -0
  40. package/lib/rust-crypto/index.js.map +1 -1
  41. package/lib/rust-crypto/rust-crypto.d.ts +9 -0
  42. package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
  43. package/lib/rust-crypto/rust-crypto.js +83 -58
  44. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  45. package/lib/sync-accumulator.js.map +1 -1
  46. package/lib/sync.d.ts.map +1 -1
  47. package/lib/sync.js.map +1 -1
  48. package/package.json +6 -6
  49. package/src/@types/global.d.ts +0 -45
  50. package/src/@types/requests.ts +50 -0
  51. package/src/client.ts +237 -46
  52. package/src/crypto/algorithms/base.ts +0 -4
  53. package/src/digest.ts +34 -0
  54. package/src/embedded.ts +109 -5
  55. package/src/matrixrtc/MatrixRTCSession.ts +52 -20
  56. package/src/matrixrtc/index.ts +22 -0
  57. package/src/models/event.ts +1 -1
  58. package/src/oidc/authorize.ts +4 -7
  59. package/src/rust-crypto/RoomEncryptor.ts +10 -6
  60. package/src/rust-crypto/index.ts +3 -0
  61. package/src/rust-crypto/rust-crypto.ts +51 -24
  62. package/src/sync-accumulator.ts +1 -1
  63. package/src/sync.ts +3 -1
@@ -1374,7 +1374,7 @@ export class RustCrypto extends TypedEventEmitter {
1374
1374
  var _this50 = this;
1375
1375
  if (this.stopped) return;
1376
1376
  this.logger.debug("Got update for session ".concat(key.senderKey.toBase64(), "|").concat(key.sessionId, " in ").concat(key.roomId.toString()));
1377
- var pendingList = this.eventDecryptor.getEventsPendingRoomKey(key);
1377
+ var pendingList = this.eventDecryptor.getEventsPendingRoomKey(key.roomId.toString(), key.sessionId);
1378
1378
  if (pendingList.length === 0) return;
1379
1379
  this.logger.debug("Retrying decryption on events:", pendingList.map(e => "".concat(e.getId())));
1380
1380
 
@@ -1396,6 +1396,35 @@ export class RustCrypto extends TypedEventEmitter {
1396
1396
  }
1397
1397
  }
1398
1398
 
1399
+ /**
1400
+ * Callback for `OlmMachine.registerRoomKeyWithheldCallback`.
1401
+ *
1402
+ * Called by the rust sdk whenever we are told that a key has been withheld. We see if we had any events that
1403
+ * failed to decrypt for the given session, and update their status if so.
1404
+ *
1405
+ * @param withheld - Details of the withheld sessions.
1406
+ */
1407
+ onRoomKeysWithheld(withheld) {
1408
+ var _this51 = this;
1409
+ return _asyncToGenerator(function* () {
1410
+ for (var session of withheld) {
1411
+ _this51.logger.debug("Got withheld message for session ".concat(session.sessionId, " in ").concat(session.roomId.toString()));
1412
+ var pendingList = _this51.eventDecryptor.getEventsPendingRoomKey(session.roomId.toString(), session.sessionId);
1413
+ if (pendingList.length === 0) return;
1414
+
1415
+ // The easiest way to update the status of the event is to have another go at decrypting it.
1416
+ _this51.logger.debug("Retrying decryption on events:", pendingList.map(e => "".concat(e.getId())));
1417
+ for (var ev of pendingList) {
1418
+ ev.attemptDecryption(_this51, {
1419
+ isRetry: true
1420
+ }).catch(_e => {
1421
+ // It's somewhat expected that we still can't decrypt here.
1422
+ });
1423
+ }
1424
+ }
1425
+ })();
1426
+ }
1427
+
1399
1428
  /**
1400
1429
  * Callback for `OlmMachine.registerUserIdentityUpdatedCallback`
1401
1430
  *
@@ -1405,16 +1434,16 @@ export class RustCrypto extends TypedEventEmitter {
1405
1434
  * @param userId - the user with the updated identity
1406
1435
  */
1407
1436
  onUserIdentityUpdated(userId) {
1408
- var _this51 = this;
1437
+ var _this52 = this;
1409
1438
  return _asyncToGenerator(function* () {
1410
- var newVerification = yield _this51.getUserVerificationStatus(userId.toString());
1411
- _this51.emit(CryptoEvent.UserTrustStatusChanged, userId.toString(), newVerification);
1439
+ var newVerification = yield _this52.getUserVerificationStatus(userId.toString());
1440
+ _this52.emit(CryptoEvent.UserTrustStatusChanged, userId.toString(), newVerification);
1412
1441
 
1413
1442
  // If our own user identity has changed, we may now trust the key backup where we did not before.
1414
1443
  // So, re-check the key backup status and enable it if available.
1415
- if (userId.toString() === _this51.userId) {
1416
- _this51.emit(CryptoEvent.KeysChanged, {});
1417
- yield _this51.checkKeyBackupAndEnable();
1444
+ if (userId.toString() === _this52.userId) {
1445
+ _this52.emit(CryptoEvent.KeysChanged, {});
1446
+ yield _this52.checkKeyBackupAndEnable();
1418
1447
  }
1419
1448
  })();
1420
1449
  }
@@ -1430,10 +1459,10 @@ export class RustCrypto extends TypedEventEmitter {
1430
1459
  * @param userIds - an array of user IDs of users whose devices have updated.
1431
1460
  */
1432
1461
  onDevicesUpdated(userIds) {
1433
- var _this52 = this;
1462
+ var _this53 = this;
1434
1463
  return _asyncToGenerator(function* () {
1435
- _this52.emit(CryptoEvent.WillUpdateDevices, userIds, false);
1436
- _this52.emit(CryptoEvent.DevicesUpdated, userIds, false);
1464
+ _this53.emit(CryptoEvent.WillUpdateDevices, userIds, false);
1465
+ _this53.emit(CryptoEvent.DevicesUpdated, userIds, false);
1437
1466
  })();
1438
1467
  }
1439
1468
 
@@ -1450,11 +1479,11 @@ export class RustCrypto extends TypedEventEmitter {
1450
1479
  * @param value - the secret value
1451
1480
  */
1452
1481
  handleSecretReceived(name, value) {
1453
- var _this53 = this;
1482
+ var _this54 = this;
1454
1483
  return _asyncToGenerator(function* () {
1455
- _this53.logger.debug("onReceiveSecret: Received secret ".concat(name));
1484
+ _this54.logger.debug("onReceiveSecret: Received secret ".concat(name));
1456
1485
  if (name === "m.megolm_backup.v1") {
1457
- return yield _this53.backupManager.handleBackupSecretReceived(value);
1486
+ return yield _this54.backupManager.handleBackupSecretReceived(value);
1458
1487
  // XXX at this point we should probably try to download the backup and import the keys,
1459
1488
  // or at least retry for the current decryption failures?
1460
1489
  // Maybe add some signaling when a new secret is received, and let clients handle it?
@@ -1472,11 +1501,11 @@ export class RustCrypto extends TypedEventEmitter {
1472
1501
  * @param name - The name of the secret received.
1473
1502
  */
1474
1503
  checkSecrets(name) {
1475
- var _this54 = this;
1504
+ var _this55 = this;
1476
1505
  return _asyncToGenerator(function* () {
1477
- var pendingValues = yield _this54.olmMachine.getSecretsFromInbox(name);
1506
+ var pendingValues = yield _this55.olmMachine.getSecretsFromInbox(name);
1478
1507
  for (var value of pendingValues) {
1479
- if (yield _this54.handleSecretReceived(name, value)) {
1508
+ if (yield _this55.handleSecretReceived(name, value)) {
1480
1509
  // If we have a valid secret for that name there is no point of processing the other secrets values.
1481
1510
  // It's probably the same secret shared by another device.
1482
1511
  break;
@@ -1484,7 +1513,7 @@ export class RustCrypto extends TypedEventEmitter {
1484
1513
  }
1485
1514
 
1486
1515
  // Important to call this after handling the secrets as good hygiene.
1487
- yield _this54.olmMachine.deleteSecretsFromInbox(name);
1516
+ yield _this55.olmMachine.deleteSecretsFromInbox(name);
1488
1517
  })();
1489
1518
  }
1490
1519
 
@@ -1495,7 +1524,7 @@ export class RustCrypto extends TypedEventEmitter {
1495
1524
  * @param event - live event
1496
1525
  */
1497
1526
  onLiveEventFromSync(event) {
1498
- var _this55 = this;
1527
+ var _this56 = this;
1499
1528
  return _asyncToGenerator(function* () {
1500
1529
  // Ignore state event or remote echo
1501
1530
  // transaction_id is provided in case of remote echo {@link https://spec.matrix.org/v1.7/client-server-api/#local-echo}
@@ -1504,7 +1533,7 @@ export class RustCrypto extends TypedEventEmitter {
1504
1533
  var _ref4 = _asyncToGenerator(function* (evt) {
1505
1534
  // Process only verification event
1506
1535
  if (isVerificationEvent(event)) {
1507
- yield _this55.onKeyVerificationEvent(evt);
1536
+ yield _this56.onKeyVerificationEvent(evt);
1508
1537
  }
1509
1538
  });
1510
1539
  return function processEvent(_x) {
@@ -1538,14 +1567,14 @@ export class RustCrypto extends TypedEventEmitter {
1538
1567
  * @param event - a key validation request event.
1539
1568
  */
1540
1569
  onKeyVerificationEvent(event) {
1541
- var _this56 = this;
1570
+ var _this57 = this;
1542
1571
  return _asyncToGenerator(function* () {
1543
1572
  var roomId = event.getRoomId();
1544
1573
  if (!roomId) {
1545
1574
  throw new Error("missing roomId in the event");
1546
1575
  }
1547
- _this56.logger.debug("Incoming verification event ".concat(event.getId(), " type ").concat(event.getType(), " from ").concat(event.getSender()));
1548
- yield _this56.olmMachine.receiveVerificationEvent(JSON.stringify({
1576
+ _this57.logger.debug("Incoming verification event ".concat(event.getId(), " type ").concat(event.getType(), " from ").concat(event.getSender()));
1577
+ yield _this57.olmMachine.receiveVerificationEvent(JSON.stringify({
1549
1578
  event_id: event.getId(),
1550
1579
  type: event.getType(),
1551
1580
  sender: event.getSender(),
@@ -1554,12 +1583,12 @@ export class RustCrypto extends TypedEventEmitter {
1554
1583
  origin_server_ts: event.getTs()
1555
1584
  }), new RustSdkCryptoJs.RoomId(roomId));
1556
1585
  if (event.getType() === EventType.RoomMessage && event.getContent().msgtype === MsgType.KeyVerificationRequest) {
1557
- _this56.onIncomingKeyVerificationRequest(event.getSender(), event.getId());
1586
+ _this57.onIncomingKeyVerificationRequest(event.getSender(), event.getId());
1558
1587
  }
1559
1588
 
1560
1589
  // that may have caused us to queue up outgoing requests, so make sure we send them.
1561
- _this56.outgoingRequestsManager.doProcessOutgoingRequests().catch(e => {
1562
- _this56.logger.warn("onKeyVerificationRequest: Error processing outgoing requests", e);
1590
+ _this57.outgoingRequestsManager.doProcessOutgoingRequests().catch(e => {
1591
+ _this57.logger.warn("onKeyVerificationRequest: Error processing outgoing requests", e);
1563
1592
  });
1564
1593
  })();
1565
1594
  }
@@ -1571,9 +1600,9 @@ export class RustCrypto extends TypedEventEmitter {
1571
1600
  * Used during migration from legacy js-crypto to update local trust if needed.
1572
1601
  */
1573
1602
  getOwnIdentity() {
1574
- var _this57 = this;
1603
+ var _this58 = this;
1575
1604
  return _asyncToGenerator(function* () {
1576
- return yield _this57.olmMachine.getIdentity(new RustSdkCryptoJs.UserId(_this57.userId));
1605
+ return yield _this58.olmMachine.getIdentity(new RustSdkCryptoJs.UserId(_this58.userId));
1577
1606
  })();
1578
1607
  }
1579
1608
  }
@@ -1585,24 +1614,24 @@ class EventDecryptor {
1585
1614
  /**
1586
1615
  * Events which we couldn't decrypt due to unknown sessions / indexes.
1587
1616
  *
1588
- * Map from senderKey to sessionId to Set of MatrixEvents
1617
+ * Map from roomId to sessionId to Set of MatrixEvents
1589
1618
  */
1590
1619
  _defineProperty(this, "eventsPendingKey", new MapWithDefault(() => new MapWithDefault(() => new Set())));
1591
1620
  }
1592
1621
  attemptEventDecryption(event) {
1593
- var _this58 = this;
1622
+ var _this59 = this;
1594
1623
  return _asyncToGenerator(function* () {
1595
1624
  // add the event to the pending list *before* attempting to decrypt.
1596
1625
  // then, if the key turns up while decryption is in progress (and
1597
1626
  // decryption fails), we will schedule a retry.
1598
1627
  // (fixes https://github.com/vector-im/element-web/issues/5001)
1599
- _this58.addEventToPendingList(event);
1628
+ _this59.addEventToPendingList(event);
1600
1629
  try {
1601
- var res = yield _this58.olmMachine.decryptRoomEvent(stringifyEvent(event), new RustSdkCryptoJs.RoomId(event.getRoomId()));
1630
+ var res = yield _this59.olmMachine.decryptRoomEvent(stringifyEvent(event), new RustSdkCryptoJs.RoomId(event.getRoomId()));
1602
1631
 
1603
1632
  // Success. We can remove the event from the pending list, if
1604
1633
  // that hasn't already happened.
1605
- _this58.removeEventFromPendingList(event);
1634
+ _this59.removeEventFromPendingList(event);
1606
1635
  return {
1607
1636
  clearEvent: JSON.parse(res.event),
1608
1637
  claimedEd25519Key: res.senderClaimedEd25519Key,
@@ -1611,7 +1640,7 @@ class EventDecryptor {
1611
1640
  };
1612
1641
  } catch (err) {
1613
1642
  if (err instanceof RustSdkCryptoJs.MegolmDecryptionError) {
1614
- _this58.onMegolmDecryptionError(event, err, yield _this58.perSessionBackupDownloader.getServerBackupInfo());
1643
+ _this59.onMegolmDecryptionError(event, err, yield _this59.perSessionBackupDownloader.getServerBackupInfo());
1615
1644
  } else {
1616
1645
  throw new DecryptionError(DecryptionFailureCode.UNKNOWN_ERROR, "Unknown error");
1617
1646
  }
@@ -1678,7 +1707,7 @@ class EventDecryptor {
1678
1707
  }
1679
1708
  }
1680
1709
  getEncryptionInfoForEvent(event) {
1681
- var _this59 = this;
1710
+ var _this60 = this;
1682
1711
  return _asyncToGenerator(function* () {
1683
1712
  if (!event.getClearContent() || event.isDecryptionFailure()) {
1684
1713
  // not successfully decrypted
@@ -1692,8 +1721,8 @@ class EventDecryptor {
1692
1721
  shieldReason: null
1693
1722
  };
1694
1723
  }
1695
- var encryptionInfo = yield _this59.olmMachine.getRoomEventEncryptionInfo(stringifyEvent(event), new RustSdkCryptoJs.RoomId(event.getRoomId()));
1696
- return rustEncryptionInfoToJsEncryptionInfo(_this59.logger, encryptionInfo);
1724
+ var encryptionInfo = yield _this60.olmMachine.getRoomEventEncryptionInfo(stringifyEvent(event), new RustSdkCryptoJs.RoomId(event.getRoomId()));
1725
+ return rustEncryptionInfoToJsEncryptionInfo(_this60.logger, encryptionInfo);
1697
1726
  })();
1698
1727
  }
1699
1728
 
@@ -1701,27 +1730,24 @@ class EventDecryptor {
1701
1730
  * Look for events which are waiting for a given megolm session
1702
1731
  *
1703
1732
  * Returns a list of events which were encrypted by `session` and could not be decrypted
1704
- *
1705
- * @param session -
1706
1733
  */
1707
- getEventsPendingRoomKey(session) {
1708
- var senderPendingEvents = this.eventsPendingKey.get(session.senderKey.toBase64());
1709
- if (!senderPendingEvents) return [];
1710
- var sessionPendingEvents = senderPendingEvents.get(session.sessionId);
1734
+ getEventsPendingRoomKey(roomId, sessionId) {
1735
+ var roomPendingEvents = this.eventsPendingKey.get(roomId);
1736
+ if (!roomPendingEvents) return [];
1737
+ var sessionPendingEvents = roomPendingEvents.get(sessionId);
1711
1738
  if (!sessionPendingEvents) return [];
1712
- var roomId = session.roomId.toString();
1713
- return [...sessionPendingEvents].filter(ev => ev.getRoomId() === roomId);
1739
+ return [...sessionPendingEvents];
1714
1740
  }
1715
1741
 
1716
1742
  /**
1717
1743
  * Add an event to the list of those awaiting their session keys.
1718
1744
  */
1719
1745
  addEventToPendingList(event) {
1720
- var content = event.getWireContent();
1721
- var senderKey = content.sender_key;
1722
- var sessionId = content.session_id;
1723
- var senderPendingEvents = this.eventsPendingKey.getOrCreate(senderKey);
1724
- var sessionPendingEvents = senderPendingEvents.getOrCreate(sessionId);
1746
+ var roomId = event.getRoomId();
1747
+ // We shouldn't have events without a room id here.
1748
+ if (!roomId) return;
1749
+ var roomPendingEvents = this.eventsPendingKey.getOrCreate(roomId);
1750
+ var sessionPendingEvents = roomPendingEvents.getOrCreate(event.getWireContent().session_id);
1725
1751
  sessionPendingEvents.add(event);
1726
1752
  }
1727
1753
 
@@ -1729,20 +1755,19 @@ class EventDecryptor {
1729
1755
  * Remove an event from the list of those awaiting their session keys.
1730
1756
  */
1731
1757
  removeEventFromPendingList(event) {
1732
- var content = event.getWireContent();
1733
- var senderKey = content.sender_key;
1734
- var sessionId = content.session_id;
1735
- var senderPendingEvents = this.eventsPendingKey.get(senderKey);
1736
- if (!senderPendingEvents) return;
1737
- var sessionPendingEvents = senderPendingEvents.get(sessionId);
1758
+ var roomId = event.getRoomId();
1759
+ if (!roomId) return;
1760
+ var roomPendingEvents = this.eventsPendingKey.getOrCreate(roomId);
1761
+ if (!roomPendingEvents) return;
1762
+ var sessionPendingEvents = roomPendingEvents.get(event.getWireContent().session_id);
1738
1763
  if (!sessionPendingEvents) return;
1739
1764
  sessionPendingEvents.delete(event);
1740
1765
 
1741
1766
  // also clean up the higher-level maps if they are now empty
1742
1767
  if (sessionPendingEvents.size === 0) {
1743
- senderPendingEvents.delete(sessionId);
1744
- if (senderPendingEvents.size === 0) {
1745
- this.eventsPendingKey.delete(senderKey);
1768
+ roomPendingEvents.delete(event.getWireContent().session_id);
1769
+ if (roomPendingEvents.size === 0) {
1770
+ this.eventsPendingKey.delete(roomId);
1746
1771
  }
1747
1772
  }
1748
1773
  }