matrix-js-sdk 31.2.0 → 31.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/CHANGELOG.md +1 -0
- package/git-revision.txt +1 -1
- package/lib/@types/extensible_events.d.ts.map +1 -1
- package/lib/@types/extensible_events.js.map +1 -1
- package/lib/client.d.ts +22 -2
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +87 -55
- package/lib/client.js.map +1 -1
- package/lib/content-repo.d.ts +4 -1
- package/lib/content-repo.d.ts.map +1 -1
- package/lib/content-repo.js +8 -1
- package/lib/content-repo.js.map +1 -1
- package/lib/crypto/OlmDevice.d.ts +1 -1
- package/lib/crypto/OlmDevice.d.ts.map +1 -1
- package/lib/crypto/OlmDevice.js.map +1 -1
- package/lib/crypto/index.d.ts +4 -0
- package/lib/crypto/index.d.ts.map +1 -1
- package/lib/crypto/index.js +7 -0
- package/lib/crypto/index.js.map +1 -1
- package/lib/crypto/store/base.d.ts +3 -1
- package/lib/crypto/store/base.d.ts.map +1 -1
- package/lib/crypto/store/base.js +1 -0
- package/lib/crypto/store/base.js.map +1 -1
- package/lib/crypto-api.d.ts +12 -1
- package/lib/crypto-api.d.ts.map +1 -1
- package/lib/crypto-api.js.map +1 -1
- package/lib/matrixrtc/CallMembership.d.ts +2 -1
- package/lib/matrixrtc/CallMembership.d.ts.map +1 -1
- package/lib/matrixrtc/CallMembership.js +28 -5
- package/lib/matrixrtc/CallMembership.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +4 -0
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/models/event-timeline-set.d.ts.map +1 -1
- package/lib/models/event-timeline-set.js.map +1 -1
- package/lib/models/event.d.ts +1 -1
- package/lib/models/event.js +1 -1
- package/lib/models/event.js.map +1 -1
- package/lib/models/read-receipt.d.ts +1 -1
- package/lib/models/read-receipt.d.ts.map +1 -1
- package/lib/models/read-receipt.js.map +1 -1
- package/lib/models/room.d.ts +17 -7
- package/lib/models/room.d.ts.map +1 -1
- package/lib/models/room.js +29 -7
- package/lib/models/room.js.map +1 -1
- package/lib/models/thread.d.ts +7 -1
- package/lib/models/thread.d.ts.map +1 -1
- package/lib/models/thread.js +10 -6
- package/lib/models/thread.js.map +1 -1
- package/lib/rendezvous/MSC3906Rendezvous.d.ts +3 -5
- package/lib/rendezvous/MSC3906Rendezvous.d.ts.map +1 -1
- package/lib/rendezvous/MSC3906Rendezvous.js +25 -22
- package/lib/rendezvous/MSC3906Rendezvous.js.map +1 -1
- package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -1
- package/lib/rust-crypto/RoomEncryptor.js +2 -1
- package/lib/rust-crypto/RoomEncryptor.js.map +1 -1
- package/lib/rust-crypto/backup.d.ts.map +1 -1
- package/lib/rust-crypto/backup.js +2 -2
- package/lib/rust-crypto/backup.js.map +1 -1
- package/lib/rust-crypto/index.d.ts.map +1 -1
- package/lib/rust-crypto/index.js +12 -2
- package/lib/rust-crypto/index.js.map +1 -1
- package/lib/rust-crypto/libolm_migration.d.ts +16 -0
- package/lib/rust-crypto/libolm_migration.d.ts.map +1 -1
- package/lib/rust-crypto/libolm_migration.js +102 -10
- package/lib/rust-crypto/libolm_migration.js.map +1 -1
- package/lib/rust-crypto/rust-crypto.d.ts +44 -2
- package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
- package/lib/rust-crypto/rust-crypto.js +44 -1
- package/lib/rust-crypto/rust-crypto.js.map +1 -1
- package/lib/rust-crypto/verification.d.ts +17 -4
- package/lib/rust-crypto/verification.d.ts.map +1 -1
- package/lib/rust-crypto/verification.js +64 -22
- package/lib/rust-crypto/verification.js.map +1 -1
- package/lib/sliding-sync-sdk.js +1 -1
- package/lib/sliding-sync-sdk.js.map +1 -1
- package/lib/store/indexeddb.d.ts +1 -1
- package/lib/store/indexeddb.d.ts.map +1 -1
- package/lib/store/indexeddb.js +2 -2
- package/lib/store/indexeddb.js.map +1 -1
- package/lib/sync.js +2 -2
- package/lib/sync.js.map +1 -1
- package/lib/webrtc/call.d.ts.map +1 -1
- package/lib/webrtc/call.js.map +1 -1
- package/package.json +5 -5
- package/src/@types/extensible_events.ts +2 -3
- package/src/client.ts +124 -90
- package/src/content-repo.ts +9 -0
- package/src/crypto/OlmDevice.ts +1 -1
- package/src/crypto/index.ts +7 -0
- package/src/crypto/store/base.ts +3 -0
- package/src/crypto-api.ts +13 -1
- package/src/matrixrtc/CallMembership.ts +31 -6
- package/src/matrixrtc/MatrixRTCSession.ts +3 -0
- package/src/models/event-timeline-set.ts +3 -2
- package/src/models/event.ts +1 -1
- package/src/models/read-receipt.ts +1 -1
- package/src/models/room.ts +30 -14
- package/src/models/thread.ts +10 -6
- package/src/rendezvous/MSC3906Rendezvous.ts +28 -34
- package/src/rust-crypto/RoomEncryptor.ts +2 -1
- package/src/rust-crypto/backup.ts +12 -9
- package/src/rust-crypto/index.ts +13 -1
- package/src/rust-crypto/libolm_migration.ts +118 -10
- package/src/rust-crypto/rust-crypto.ts +77 -1
- package/src/rust-crypto/verification.ts +74 -32
- package/src/sliding-sync-sdk.ts +1 -1
- package/src/store/indexeddb.ts +4 -2
- package/src/sync.ts +2 -2
- package/src/webrtc/call.ts +6 -4
package/lib/client.js
CHANGED
|
@@ -186,7 +186,12 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
186
186
|
(0, _defineProperty2.default)(this, "turnServersExpiry", 0);
|
|
187
187
|
(0, _defineProperty2.default)(this, "txnCtr", 0);
|
|
188
188
|
(0, _defineProperty2.default)(this, "mediaHandler", new _mediaHandler.MediaHandler(this));
|
|
189
|
-
|
|
189
|
+
/** IDs of events which are currently being encrypted.
|
|
190
|
+
*
|
|
191
|
+
* This is part of the cancellation mechanism: if the event is no longer listed here when encryption completes,
|
|
192
|
+
* that tells us that it has been cancelled, and we should not send it.
|
|
193
|
+
*/
|
|
194
|
+
(0, _defineProperty2.default)(this, "eventsBeingEncrypted", new Set());
|
|
190
195
|
(0, _defineProperty2.default)(this, "useE2eForGroupCall", true);
|
|
191
196
|
(0, _defineProperty2.default)(this, "startCallEventHandler", () => {
|
|
192
197
|
if (this.isInitialSyncComplete()) {
|
|
@@ -327,7 +332,7 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
327
332
|
// correctly handle notification counts on encrypted rooms.
|
|
328
333
|
// This fixes https://github.com/vector-im/element-web/issues/9421
|
|
329
334
|
this.on(_room.RoomEvent.Receipt, (event, room) => {
|
|
330
|
-
if (room &&
|
|
335
|
+
if (room !== null && room !== void 0 && room.hasEncryptionStateEvent()) {
|
|
331
336
|
// Figure out if we've read something or if it's just informational
|
|
332
337
|
const content = event.getContent();
|
|
333
338
|
const isSelf = Object.keys(content).filter(eid => {
|
|
@@ -1099,7 +1104,7 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
1099
1104
|
});
|
|
1100
1105
|
|
|
1101
1106
|
// re-emit the events emitted by the crypto impl
|
|
1102
|
-
this.reEmitter.reEmit(rustCrypto, [_crypto.CryptoEvent.VerificationRequestReceived, _crypto.CryptoEvent.UserTrustStatusChanged, _crypto.CryptoEvent.KeyBackupStatus, _crypto.CryptoEvent.KeyBackupSessionsRemaining, _crypto.CryptoEvent.KeyBackupFailed, _crypto.CryptoEvent.KeyBackupDecryptionKeyCached]);
|
|
1107
|
+
this.reEmitter.reEmit(rustCrypto, [_crypto.CryptoEvent.VerificationRequestReceived, _crypto.CryptoEvent.UserTrustStatusChanged, _crypto.CryptoEvent.KeyBackupStatus, _crypto.CryptoEvent.KeyBackupSessionsRemaining, _crypto.CryptoEvent.KeyBackupFailed, _crypto.CryptoEvent.KeyBackupDecryptionKeyCached, _crypto.CryptoEvent.KeysChanged, _crypto.CryptoEvent.DevicesUpdated, _crypto.CryptoEvent.WillUpdateDevices]);
|
|
1103
1108
|
}
|
|
1104
1109
|
|
|
1105
1110
|
/**
|
|
@@ -1977,6 +1982,9 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
1977
1982
|
* @param roomId - The room ID to enable encryption in.
|
|
1978
1983
|
* @param config - The encryption config for the room.
|
|
1979
1984
|
* @returns A promise that will resolve when encryption is set up.
|
|
1985
|
+
*
|
|
1986
|
+
* @deprecated Not supported for Rust Cryptography. To enable encryption in a room, send an `m.room.encryption`
|
|
1987
|
+
* state event.
|
|
1980
1988
|
*/
|
|
1981
1989
|
setRoomEncryption(roomId, config) {
|
|
1982
1990
|
if (!this.crypto) {
|
|
@@ -1989,6 +1997,9 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
1989
1997
|
* Whether encryption is enabled for a room.
|
|
1990
1998
|
* @param roomId - the room id to query.
|
|
1991
1999
|
* @returns whether encryption is enabled.
|
|
2000
|
+
*
|
|
2001
|
+
* @deprecated Not correctly supported for Rust Cryptography. Use {@link CryptoApi.isEncryptionEnabledInRoom} and/or
|
|
2002
|
+
* {@link Room.hasEncryptionStateEvent}.
|
|
1992
2003
|
*/
|
|
1993
2004
|
isRoomEncrypted(roomId) {
|
|
1994
2005
|
var _this$crypto$isRoomEn, _this$crypto3;
|
|
@@ -2001,8 +2012,7 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
2001
2012
|
|
|
2002
2013
|
// if there is an 'm.room.encryption' event in this room, it should be
|
|
2003
2014
|
// encrypted (independently of whether we actually support encryption)
|
|
2004
|
-
|
|
2005
|
-
if (ev) {
|
|
2015
|
+
if (room.hasEncryptionStateEvent()) {
|
|
2006
2016
|
return true;
|
|
2007
2017
|
}
|
|
2008
2018
|
|
|
@@ -2995,9 +3005,10 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
2995
3005
|
throw new Error("cannot cancel an event with status " + event.status);
|
|
2996
3006
|
}
|
|
2997
3007
|
|
|
2998
|
-
//
|
|
3008
|
+
// If the event is currently being encrypted then remove it from the pending list, to indicate that it should
|
|
3009
|
+
// not be sent.
|
|
2999
3010
|
if (event.status === _event.EventStatus.ENCRYPTING) {
|
|
3000
|
-
this.
|
|
3011
|
+
this.eventsBeingEncrypted.delete(event.getId());
|
|
3001
3012
|
} else if (this.scheduler && event.status === _event.EventStatus.QUEUED) {
|
|
3002
3013
|
// tell the scheduler to forget about it, if it's queued
|
|
3003
3014
|
this.scheduler.removeEventFromQueue(event);
|
|
@@ -3263,27 +3274,25 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
3263
3274
|
* encrypts the event if necessary; adds the event to the queue, or sends it; marks the event as sent/unsent
|
|
3264
3275
|
* @returns returns a promise which resolves with the result of the send request
|
|
3265
3276
|
*/
|
|
3266
|
-
encryptAndSendEvent(room, event) {
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3277
|
+
async encryptAndSendEvent(room, event) {
|
|
3278
|
+
try {
|
|
3279
|
+
let cancelled;
|
|
3280
|
+
this.eventsBeingEncrypted.add(event.getId());
|
|
3281
|
+
try {
|
|
3282
|
+
await this.encryptEventIfNeeded(event, room !== null && room !== void 0 ? room : undefined);
|
|
3283
|
+
} finally {
|
|
3284
|
+
cancelled = !this.eventsBeingEncrypted.delete(event.getId());
|
|
3285
|
+
}
|
|
3286
|
+
if (cancelled) {
|
|
3287
|
+
// cancelled via MatrixClient::cancelPendingEvent
|
|
3288
|
+
return {};
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3291
|
+
// encryptEventIfNeeded may have updated the status from SENDING to ENCRYPTING. If so, we need
|
|
3292
|
+
// to put it back.
|
|
3293
|
+
if (event.status === _event.EventStatus.ENCRYPTING) {
|
|
3283
3294
|
this.updatePendingEventStatus(room, event, _event.EventStatus.SENDING);
|
|
3284
|
-
}
|
|
3285
|
-
}).then(() => {
|
|
3286
|
-
if (cancelled) return {};
|
|
3295
|
+
}
|
|
3287
3296
|
let promise = null;
|
|
3288
3297
|
if (this.scheduler) {
|
|
3289
3298
|
// if this returns a promise then the scheduler has control now and will
|
|
@@ -3306,9 +3315,9 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
3306
3315
|
});
|
|
3307
3316
|
}
|
|
3308
3317
|
}
|
|
3309
|
-
return promise;
|
|
3310
|
-
}
|
|
3311
|
-
this.logger.error("Error sending event", err
|
|
3318
|
+
return await promise;
|
|
3319
|
+
} catch (err) {
|
|
3320
|
+
this.logger.error("Error sending event", err);
|
|
3312
3321
|
try {
|
|
3313
3322
|
// set the error on the event before we update the status:
|
|
3314
3323
|
// updating the status emits the event, so the state should be
|
|
@@ -3316,34 +3325,43 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
3316
3325
|
event.error = err;
|
|
3317
3326
|
this.updatePendingEventStatus(room, event, _event.EventStatus.NOT_SENT);
|
|
3318
3327
|
} catch (e) {
|
|
3319
|
-
this.logger.error("Exception in error handler!", e
|
|
3328
|
+
this.logger.error("Exception in error handler!", e);
|
|
3320
3329
|
}
|
|
3321
3330
|
if (err instanceof _httpApi.MatrixError) {
|
|
3322
3331
|
err.event = event;
|
|
3323
3332
|
}
|
|
3324
3333
|
throw err;
|
|
3325
|
-
}
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
async encryptEventIfNeeded(event, room) {
|
|
3337
|
+
// If the room is unknown, we cannot encrypt for it
|
|
3338
|
+
if (!room) return;
|
|
3339
|
+
if (!(await this.shouldEncryptEventForRoom(event, room))) return;
|
|
3340
|
+
if (!this.cryptoBackend && this.usingExternalCrypto) {
|
|
3341
|
+
// The client has opted to allow sending messages to encrypted
|
|
3342
|
+
// rooms even if the room is encrypted, and we haven't set up
|
|
3343
|
+
// crypto. This is useful for users of matrix-org/pantalaimon
|
|
3344
|
+
return;
|
|
3345
|
+
}
|
|
3346
|
+
if (!this.cryptoBackend) {
|
|
3347
|
+
throw new Error("This room is configured to use encryption, but your client does not support encryption.");
|
|
3348
|
+
}
|
|
3349
|
+
this.updatePendingEventStatus(room, event, _event.EventStatus.ENCRYPTING);
|
|
3350
|
+
await this.cryptoBackend.encryptEvent(event, room);
|
|
3326
3351
|
}
|
|
3327
|
-
|
|
3352
|
+
|
|
3353
|
+
/**
|
|
3354
|
+
* Determine whether a given event should be encrypted when we send it to the given room.
|
|
3355
|
+
*
|
|
3356
|
+
* This takes into account event type and room configuration.
|
|
3357
|
+
*/
|
|
3358
|
+
async shouldEncryptEventForRoom(event, room) {
|
|
3359
|
+
var _this$cryptoBackend2;
|
|
3328
3360
|
if (event.isEncrypted()) {
|
|
3329
3361
|
// this event has already been encrypted; this happens if the
|
|
3330
3362
|
// encryption step succeeded, but the send step failed on the first
|
|
3331
3363
|
// attempt.
|
|
3332
|
-
return
|
|
3333
|
-
}
|
|
3334
|
-
if (event.isRedaction()) {
|
|
3335
|
-
// Redactions do not support encryption in the spec at this time,
|
|
3336
|
-
// whilst it mostly worked in some clients, it wasn't compliant.
|
|
3337
|
-
return null;
|
|
3338
|
-
}
|
|
3339
|
-
if (!room || !this.isRoomEncrypted(event.getRoomId())) {
|
|
3340
|
-
return null;
|
|
3341
|
-
}
|
|
3342
|
-
if (!this.cryptoBackend && this.usingExternalCrypto) {
|
|
3343
|
-
// The client has opted to allow sending messages to encrypted
|
|
3344
|
-
// rooms even if the room is encrypted, and we haven't setup
|
|
3345
|
-
// crypto. This is useful for users of matrix-org/pantalaimon
|
|
3346
|
-
return null;
|
|
3364
|
+
return false;
|
|
3347
3365
|
}
|
|
3348
3366
|
if (event.getType() === _event2.EventType.Reaction) {
|
|
3349
3367
|
// For reactions, there is a very little gained by encrypting the entire
|
|
@@ -3356,12 +3374,22 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
3356
3374
|
// The reaction key / content / emoji value does warrant encrypting, but
|
|
3357
3375
|
// this will be handled separately by encrypting just this value.
|
|
3358
3376
|
// See https://github.com/matrix-org/matrix-doc/pull/1849#pullrequestreview-248763642
|
|
3359
|
-
return
|
|
3377
|
+
return false;
|
|
3360
3378
|
}
|
|
3361
|
-
if (
|
|
3362
|
-
|
|
3379
|
+
if (event.isRedaction()) {
|
|
3380
|
+
// Redactions do not support encryption in the spec at this time.
|
|
3381
|
+
// Whilst it mostly worked in some clients, it wasn't compliant.
|
|
3382
|
+
return false;
|
|
3363
3383
|
}
|
|
3364
|
-
|
|
3384
|
+
|
|
3385
|
+
// If the room has an m.room.encryption event, we should encrypt.
|
|
3386
|
+
if (room.hasEncryptionStateEvent()) return true;
|
|
3387
|
+
|
|
3388
|
+
// If we have a crypto impl, and *it* thinks we should encrypt, then we should.
|
|
3389
|
+
if (await ((_this$cryptoBackend2 = this.cryptoBackend) === null || _this$cryptoBackend2 === void 0 ? void 0 : _this$cryptoBackend2.isEncryptionEnabledInRoom(room.roomId))) return true;
|
|
3390
|
+
|
|
3391
|
+
// Otherwise, no need to encrypt.
|
|
3392
|
+
return false;
|
|
3365
3393
|
}
|
|
3366
3394
|
|
|
3367
3395
|
/**
|
|
@@ -3372,8 +3400,9 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
3372
3400
|
* @returns the event type taking encryption into account
|
|
3373
3401
|
*/
|
|
3374
3402
|
getEncryptedIfNeededEventType(roomId, eventType) {
|
|
3403
|
+
var _this$getRoom3;
|
|
3375
3404
|
if (eventType === _event2.EventType.Reaction) return eventType;
|
|
3376
|
-
return this.
|
|
3405
|
+
return (_this$getRoom3 = this.getRoom(roomId)) !== null && _this$getRoom3 !== void 0 && _this$getRoom3.hasEncryptionStateEvent() ? _event2.EventType.RoomMessageEncrypted : eventType;
|
|
3377
3406
|
}
|
|
3378
3407
|
updatePendingEventStatus(room, event, newStatus) {
|
|
3379
3408
|
if (room) {
|
|
@@ -4120,10 +4149,13 @@ class MatrixClient extends _typedEventEmitter.TypedEventEmitter {
|
|
|
4120
4149
|
* @param allowDirectLinks - If true, return any non-mxc URLs
|
|
4121
4150
|
* directly. Fetching such URLs will leak information about the user to
|
|
4122
4151
|
* anyone they share a room with. If false, will return null for such URLs.
|
|
4152
|
+
* @param allowRedirects - If true, the caller supports the URL being 307 or
|
|
4153
|
+
* 308 redirected to another resource upon request. If false, redirects
|
|
4154
|
+
* are not expected.
|
|
4123
4155
|
* @returns the avatar URL or null.
|
|
4124
4156
|
*/
|
|
4125
|
-
mxcUrlToHttp(mxcUrl, width, height, resizeMethod, allowDirectLinks) {
|
|
4126
|
-
return (0, _contentRepo.getHttpUriForMxc)(this.baseUrl, mxcUrl, width, height, resizeMethod, allowDirectLinks);
|
|
4157
|
+
mxcUrlToHttp(mxcUrl, width, height, resizeMethod, allowDirectLinks, allowRedirects) {
|
|
4158
|
+
return (0, _contentRepo.getHttpUriForMxc)(this.baseUrl, mxcUrl, width, height, resizeMethod, allowDirectLinks, allowRedirects);
|
|
4127
4159
|
}
|
|
4128
4160
|
|
|
4129
4161
|
/**
|