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.
- package/git-revision.txt +1 -1
- package/lib/@types/global.d.js.map +1 -1
- package/lib/@types/requests.d.ts +37 -0
- package/lib/@types/requests.d.ts.map +1 -1
- package/lib/@types/requests.js +28 -1
- package/lib/@types/requests.js.map +1 -1
- package/lib/client.d.ts +48 -4
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +412 -257
- package/lib/client.js.map +1 -1
- package/lib/crypto/algorithms/base.d.ts +0 -2
- package/lib/crypto/algorithms/base.d.ts.map +1 -1
- package/lib/crypto/algorithms/base.js +0 -4
- package/lib/crypto/algorithms/base.js.map +1 -1
- package/lib/digest.d.ts +10 -0
- package/lib/digest.d.ts.map +1 -0
- package/lib/digest.js +40 -0
- package/lib/digest.js.map +1 -0
- package/lib/embedded.d.ts +24 -1
- package/lib/embedded.d.ts.map +1 -1
- package/lib/embedded.js +84 -26
- package/lib/embedded.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +2 -0
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +44 -15
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/matrixrtc/index.d.ts +7 -0
- package/lib/matrixrtc/index.d.ts.map +1 -0
- package/lib/matrixrtc/index.js +23 -0
- package/lib/matrixrtc/index.js.map +1 -0
- package/lib/models/event.js.map +1 -1
- package/lib/oidc/authorize.d.ts.map +1 -1
- package/lib/oidc/authorize.js +4 -3
- package/lib/oidc/authorize.js.map +1 -1
- package/lib/rust-crypto/RoomEncryptor.d.ts +1 -1
- package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -1
- package/lib/rust-crypto/RoomEncryptor.js +6 -2
- package/lib/rust-crypto/RoomEncryptor.js.map +1 -1
- package/lib/rust-crypto/index.js +1 -0
- package/lib/rust-crypto/index.js.map +1 -1
- package/lib/rust-crypto/rust-crypto.d.ts +9 -0
- package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
- package/lib/rust-crypto/rust-crypto.js +83 -58
- package/lib/rust-crypto/rust-crypto.js.map +1 -1
- package/lib/sync-accumulator.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js.map +1 -1
- package/package.json +6 -6
- package/src/@types/global.d.ts +0 -45
- package/src/@types/requests.ts +50 -0
- package/src/client.ts +237 -46
- package/src/crypto/algorithms/base.ts +0 -4
- package/src/digest.ts +34 -0
- package/src/embedded.ts +109 -5
- package/src/matrixrtc/MatrixRTCSession.ts +52 -20
- package/src/matrixrtc/index.ts +22 -0
- package/src/models/event.ts +1 -1
- package/src/oidc/authorize.ts +4 -7
- package/src/rust-crypto/RoomEncryptor.ts +10 -6
- package/src/rust-crypto/index.ts +3 -0
- package/src/rust-crypto/rust-crypto.ts +51 -24
- package/src/sync-accumulator.ts +1 -1
- 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
|
|
1437
|
+
var _this52 = this;
|
|
1409
1438
|
return _asyncToGenerator(function* () {
|
|
1410
|
-
var newVerification = yield
|
|
1411
|
-
|
|
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() ===
|
|
1416
|
-
|
|
1417
|
-
yield
|
|
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
|
|
1462
|
+
var _this53 = this;
|
|
1434
1463
|
return _asyncToGenerator(function* () {
|
|
1435
|
-
|
|
1436
|
-
|
|
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
|
|
1482
|
+
var _this54 = this;
|
|
1454
1483
|
return _asyncToGenerator(function* () {
|
|
1455
|
-
|
|
1484
|
+
_this54.logger.debug("onReceiveSecret: Received secret ".concat(name));
|
|
1456
1485
|
if (name === "m.megolm_backup.v1") {
|
|
1457
|
-
return yield
|
|
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
|
|
1504
|
+
var _this55 = this;
|
|
1476
1505
|
return _asyncToGenerator(function* () {
|
|
1477
|
-
var pendingValues = yield
|
|
1506
|
+
var pendingValues = yield _this55.olmMachine.getSecretsFromInbox(name);
|
|
1478
1507
|
for (var value of pendingValues) {
|
|
1479
|
-
if (yield
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
1548
|
-
yield
|
|
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
|
-
|
|
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
|
-
|
|
1562
|
-
|
|
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
|
|
1603
|
+
var _this58 = this;
|
|
1575
1604
|
return _asyncToGenerator(function* () {
|
|
1576
|
-
return yield
|
|
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
|
|
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
|
|
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
|
-
|
|
1628
|
+
_this59.addEventToPendingList(event);
|
|
1600
1629
|
try {
|
|
1601
|
-
var res = yield
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
1696
|
-
return rustEncryptionInfoToJsEncryptionInfo(
|
|
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(
|
|
1708
|
-
var
|
|
1709
|
-
if (!
|
|
1710
|
-
var sessionPendingEvents =
|
|
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
|
-
|
|
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
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
var
|
|
1724
|
-
var sessionPendingEvents =
|
|
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
|
|
1733
|
-
|
|
1734
|
-
var
|
|
1735
|
-
|
|
1736
|
-
|
|
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
|
-
|
|
1744
|
-
if (
|
|
1745
|
-
this.eventsPendingKey.delete(
|
|
1768
|
+
roomPendingEvents.delete(event.getWireContent().session_id);
|
|
1769
|
+
if (roomPendingEvents.size === 0) {
|
|
1770
|
+
this.eventsPendingKey.delete(roomId);
|
|
1746
1771
|
}
|
|
1747
1772
|
}
|
|
1748
1773
|
}
|