matrix-js-sdk 41.0.0 → 41.1.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 +8 -0
- package/lib/@types/event.d.ts +1 -1
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +250 -246
- package/lib/client.js.map +1 -1
- package/lib/crypto-api/index.d.ts +13 -2
- package/lib/crypto-api/index.d.ts.map +1 -1
- package/lib/crypto-api/index.js +11 -0
- package/lib/crypto-api/index.js.map +1 -1
- package/lib/logger.d.ts +5 -5
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/matrixrtc/CallMembership.d.ts +49 -145
- package/lib/matrixrtc/CallMembership.d.ts.map +1 -1
- package/lib/matrixrtc/CallMembership.js +157 -265
- package/lib/matrixrtc/CallMembership.js.map +1 -1
- package/lib/matrixrtc/EncryptionManager.d.ts +1 -85
- package/lib/matrixrtc/EncryptionManager.d.ts.map +1 -1
- package/lib/matrixrtc/EncryptionManager.js +0 -317
- package/lib/matrixrtc/EncryptionManager.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +18 -22
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +48 -76
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +2 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +3 -2
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -1
- package/lib/matrixrtc/MembershipManager.d.ts +10 -4
- package/lib/matrixrtc/MembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/MembershipManager.js +10 -4
- package/lib/matrixrtc/MembershipManager.js.map +1 -1
- package/lib/matrixrtc/RTCEncryptionManager.d.ts +6 -7
- package/lib/matrixrtc/RTCEncryptionManager.d.ts.map +1 -1
- package/lib/matrixrtc/RTCEncryptionManager.js +4 -7
- package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
- package/lib/matrixrtc/index.d.ts +1 -0
- package/lib/matrixrtc/index.d.ts.map +1 -1
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/membershipData/common.d.ts +8 -0
- package/lib/matrixrtc/membershipData/common.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/common.js +26 -0
- package/lib/matrixrtc/membershipData/common.js.map +1 -0
- package/lib/matrixrtc/membershipData/index.d.ts +4 -0
- package/lib/matrixrtc/membershipData/index.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/index.js +20 -0
- package/lib/matrixrtc/membershipData/index.js.map +1 -0
- package/lib/matrixrtc/membershipData/rtc.d.ts +33 -0
- package/lib/matrixrtc/membershipData/rtc.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/rtc.js +137 -0
- package/lib/matrixrtc/membershipData/rtc.js.map +1 -0
- package/lib/matrixrtc/membershipData/session.d.ts +77 -0
- package/lib/matrixrtc/membershipData/session.d.ts.map +1 -0
- package/lib/matrixrtc/membershipData/session.js +62 -0
- package/lib/matrixrtc/membershipData/session.js.map +1 -0
- package/lib/matrixrtc/types.d.ts +23 -0
- package/lib/matrixrtc/types.d.ts.map +1 -1
- package/lib/matrixrtc/types.js +9 -1
- package/lib/matrixrtc/types.js.map +1 -1
- package/lib/matrixrtc/utils.d.ts +11 -1
- package/lib/matrixrtc/utils.d.ts.map +1 -1
- package/lib/matrixrtc/utils.js +24 -1
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/rust-crypto/rust-crypto.d.ts.map +1 -1
- package/lib/rust-crypto/rust-crypto.js +2 -2
- package/lib/rust-crypto/rust-crypto.js.map +1 -1
- package/package.json +5 -7
- package/src/@types/event.ts +2 -2
- package/src/client.ts +5 -3
- package/src/crypto-api/index.ts +17 -2
- package/src/logger.ts +5 -5
- package/src/matrixrtc/CallMembership.ts +159 -373
- package/src/matrixrtc/EncryptionManager.ts +1 -417
- package/src/matrixrtc/MatrixRTCSession.ts +82 -122
- package/src/matrixrtc/MatrixRTCSessionManager.ts +5 -3
- package/src/matrixrtc/MembershipManager.ts +14 -17
- package/src/matrixrtc/RTCEncryptionManager.ts +7 -10
- package/src/matrixrtc/index.ts +1 -0
- package/src/matrixrtc/membershipData/common.ts +27 -0
- package/src/matrixrtc/membershipData/index.ts +19 -0
- package/src/matrixrtc/membershipData/rtc.ts +156 -0
- package/src/matrixrtc/membershipData/session.ts +146 -0
- package/src/matrixrtc/types.ts +27 -1
- package/src/matrixrtc/utils.ts +24 -2
- package/src/rust-crypto/rust-crypto.ts +4 -1
- package/lib/matrixrtc/RoomKeyTransport.d.ts +0 -25
- package/lib/matrixrtc/RoomKeyTransport.d.ts.map +0 -1
- package/lib/matrixrtc/RoomKeyTransport.js +0 -152
- package/lib/matrixrtc/RoomKeyTransport.js.map +0 -1
- package/src/matrixrtc/RoomKeyTransport.ts +0 -189
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2025 The Matrix.org Foundation C.I.C.
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type { MatrixClient } from "../client.ts";
|
|
18
|
-
import { type EncryptionKeysEventContent, type ParticipantDeviceInfo, type Statistics } from "./types.ts";
|
|
19
|
-
import { EventType } from "../@types/event.ts";
|
|
20
|
-
import { type MatrixError } from "../http-api/errors.ts";
|
|
21
|
-
import { logger as rootLogger, type Logger } from "../logger.ts";
|
|
22
|
-
import { KeyTransportEvents, type KeyTransportEventsHandlerMap, type IKeyTransport } from "./IKeyTransport.ts";
|
|
23
|
-
import { type MatrixEvent } from "../models/event.ts";
|
|
24
|
-
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
|
|
25
|
-
import { type Room, RoomEvent } from "../models/room.ts";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated This is depreacted and not used anymore. use the ToDeviceTransport
|
|
29
|
-
*/
|
|
30
|
-
export class RoomKeyTransport
|
|
31
|
-
extends TypedEventEmitter<KeyTransportEvents, KeyTransportEventsHandlerMap>
|
|
32
|
-
implements IKeyTransport
|
|
33
|
-
{
|
|
34
|
-
private logger: Logger = rootLogger;
|
|
35
|
-
public setParentLogger(parentLogger: Logger): void {
|
|
36
|
-
this.logger = parentLogger.getChild(`[RoomKeyTransport]`);
|
|
37
|
-
}
|
|
38
|
-
public constructor(
|
|
39
|
-
private room: Pick<Room, "on" | "off" | "roomId">,
|
|
40
|
-
private client: Pick<
|
|
41
|
-
MatrixClient,
|
|
42
|
-
"sendEvent" | "getDeviceId" | "getUserId" | "cancelPendingEvent" | "decryptEventIfNeeded"
|
|
43
|
-
>,
|
|
44
|
-
private statistics: Statistics,
|
|
45
|
-
parentLogger?: Logger,
|
|
46
|
-
) {
|
|
47
|
-
super();
|
|
48
|
-
this.setParentLogger(parentLogger ?? rootLogger);
|
|
49
|
-
}
|
|
50
|
-
public start(): void {
|
|
51
|
-
this.room.on(RoomEvent.Timeline, (ev) => void this.consumeCallEncryptionEvent(ev));
|
|
52
|
-
}
|
|
53
|
-
public stop(): void {
|
|
54
|
-
this.room.off(RoomEvent.Timeline, (ev) => void this.consumeCallEncryptionEvent(ev));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private async consumeCallEncryptionEvent(event: MatrixEvent, isRetry = false): Promise<void> {
|
|
58
|
-
await this.client.decryptEventIfNeeded(event);
|
|
59
|
-
|
|
60
|
-
if (event.isDecryptionFailure()) {
|
|
61
|
-
if (!isRetry) {
|
|
62
|
-
this.logger.warn(
|
|
63
|
-
`Decryption failed for event ${event.getId()}: ${event.decryptionFailureReason} will retry once only`,
|
|
64
|
-
);
|
|
65
|
-
// retry after 1 second. After this we give up.
|
|
66
|
-
setTimeout(() => void this.consumeCallEncryptionEvent(event, true), 1000);
|
|
67
|
-
} else {
|
|
68
|
-
this.logger.warn(`Decryption failed for event ${event.getId()}: ${event.decryptionFailureReason}`);
|
|
69
|
-
}
|
|
70
|
-
return;
|
|
71
|
-
} else if (isRetry) {
|
|
72
|
-
this.logger.info(`Decryption succeeded for event ${event.getId()} after retry`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (event.getType() !== EventType.CallEncryptionKeysPrefix) return Promise.resolve();
|
|
76
|
-
|
|
77
|
-
if (!this.room) {
|
|
78
|
-
this.logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);
|
|
79
|
-
return Promise.resolve();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.onEncryptionEvent(event);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** implements {@link IKeyTransport#sendKey} */
|
|
86
|
-
public async sendKey(keyBase64Encoded: string, index: number, members: ParticipantDeviceInfo[]): Promise<void> {
|
|
87
|
-
// members not used in room transports as the keys are sent to all room members
|
|
88
|
-
const content: EncryptionKeysEventContent = {
|
|
89
|
-
keys: [
|
|
90
|
-
{
|
|
91
|
-
index: index,
|
|
92
|
-
key: keyBase64Encoded,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
device_id: this.client.getDeviceId()!,
|
|
96
|
-
call_id: "",
|
|
97
|
-
sent_ts: Date.now(),
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
await this.client.sendEvent(this.room.roomId, EventType.CallEncryptionKeysPrefix, content);
|
|
102
|
-
} catch (error) {
|
|
103
|
-
this.logger.error("Failed to send call encryption keys", error);
|
|
104
|
-
const matrixError = error as MatrixError;
|
|
105
|
-
if (matrixError.event) {
|
|
106
|
-
// cancel the pending event: we'll just generate a new one with our latest
|
|
107
|
-
// keys when we resend
|
|
108
|
-
this.client.cancelPendingEvent(matrixError.event);
|
|
109
|
-
}
|
|
110
|
-
throw error;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public onEncryptionEvent(event: MatrixEvent): void {
|
|
115
|
-
const userId = event.getSender();
|
|
116
|
-
const content = event.getContent<EncryptionKeysEventContent>();
|
|
117
|
-
|
|
118
|
-
const deviceId = content["device_id"];
|
|
119
|
-
const callId = content["call_id"];
|
|
120
|
-
|
|
121
|
-
if (!userId) {
|
|
122
|
-
this.logger.warn(`Received m.call.encryption_keys with no userId: callId=${callId}`);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// We currently only handle callId = "" (which is the default for room scoped calls)
|
|
127
|
-
if (callId !== "") {
|
|
128
|
-
this.logger.warn(
|
|
129
|
-
`Received m.call.encryption_keys with unsupported callId: userId=${userId}, deviceId=${deviceId}, callId=${callId}`,
|
|
130
|
-
);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!Array.isArray(content.keys)) {
|
|
135
|
-
this.logger.warn(`Received m.call.encryption_keys where keys wasn't an array: callId=${callId}`);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (userId === this.client.getUserId() && deviceId === this.client.getDeviceId()) {
|
|
140
|
-
// We store our own sender key in the same set along with keys from others, so it's
|
|
141
|
-
// important we don't allow our own keys to be set by one of these events (apart from
|
|
142
|
-
// the fact that we don't need it anyway because we already know our own keys).
|
|
143
|
-
this.logger.info("Ignoring our own keys event");
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
this.statistics.counters.roomEventEncryptionKeysReceived += 1;
|
|
148
|
-
const age = Date.now() - (typeof content.sent_ts === "number" ? content.sent_ts : event.getTs());
|
|
149
|
-
this.statistics.totals.roomEventEncryptionKeysReceivedTotalAge += age;
|
|
150
|
-
|
|
151
|
-
for (const key of content.keys) {
|
|
152
|
-
if (!key) {
|
|
153
|
-
this.logger.info("Ignoring false-y key in keys event");
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const encryptionKey = key.key;
|
|
158
|
-
const encryptionKeyIndex = key.index;
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
!encryptionKey ||
|
|
162
|
-
encryptionKeyIndex === undefined ||
|
|
163
|
-
encryptionKeyIndex === null ||
|
|
164
|
-
callId === undefined ||
|
|
165
|
-
callId === null ||
|
|
166
|
-
typeof deviceId !== "string" ||
|
|
167
|
-
typeof callId !== "string" ||
|
|
168
|
-
typeof encryptionKey !== "string" ||
|
|
169
|
-
typeof encryptionKeyIndex !== "number"
|
|
170
|
-
) {
|
|
171
|
-
this.logger.warn(
|
|
172
|
-
`Malformed call encryption_key: userId=${userId}, deviceId=${deviceId}, encryptionKeyIndex=${encryptionKeyIndex} callId=${callId}`,
|
|
173
|
-
);
|
|
174
|
-
} else {
|
|
175
|
-
this.logger.debug(
|
|
176
|
-
`onCallEncryption userId=${userId}:${deviceId} encryptionKeyIndex=${encryptionKeyIndex} age=${age}ms`,
|
|
177
|
-
);
|
|
178
|
-
this.emit(
|
|
179
|
-
KeyTransportEvents.ReceivedKeys,
|
|
180
|
-
// Using `${userId}:${deviceId}` makes no sense (but works). It does not matter since the RoomKeyTransport is deprecated
|
|
181
|
-
{ userId, deviceId, memberId: `${userId}:${deviceId}` },
|
|
182
|
-
encryptionKey,
|
|
183
|
-
encryptionKeyIndex,
|
|
184
|
-
event.getTs(),
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|