Skip to content

Commit 0185f30

Browse files
authored
Remove usage of legacy crypto in embedded.ts (#4668)
The interface of `encryptAndSendToDevices` changes because `DeviceInfo` is from the legacy crypto. In fact `encryptAndSendToDevices` only need pairs of userId and deviceId.
1 parent bca2582 commit 0185f30

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

spec/unit/embedded.spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import { SyncState } from "../../src/sync";
4040
import { ICapabilities, RoomWidgetClient } from "../../src/embedded";
4141
import { MatrixEvent } from "../../src/models/event";
4242
import { ToDeviceBatch } from "../../src/models/ToDeviceMessage";
43-
import { DeviceInfo } from "../../src/crypto/deviceinfo";
4443
import { sleep } from "../../src/utils";
4544

4645
const testOIDCToken = {
@@ -731,8 +730,8 @@ describe("RoomWidgetClient", () => {
731730
const embeddedClient = client as RoomWidgetClient;
732731
await embeddedClient.encryptAndSendToDevices(
733732
[
734-
{ userId: "@alice:example.org", deviceInfo: new DeviceInfo("aliceWeb") },
735-
{ userId: "@bob:example.org", deviceInfo: new DeviceInfo("bobDesktop") },
733+
{ userId: "@alice:example.org", deviceId: "aliceWeb" },
734+
{ userId: "@bob:example.org", deviceId: "bobDesktop" },
736735
],
737736
payload,
738737
);

src/embedded.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ import { MatrixError } from "./http-api/errors.ts";
5454
import { User } from "./models/user.ts";
5555
import { Room } from "./models/room.ts";
5656
import { ToDeviceBatch, ToDevicePayload } from "./models/ToDeviceMessage.ts";
57-
import { DeviceInfo } from "./crypto/deviceinfo.ts";
58-
import { IOlmDevice } from "./crypto/algorithms/megolm.ts";
5957
import { MapWithDefault, recursiveMapToObject } from "./utils.ts";
6058
import { TypedEventEmitter } from "./matrix.ts";
6159

@@ -64,6 +62,17 @@ interface IStateEventRequest {
6462
stateKey?: string;
6563
}
6664

65+
export interface OlmDevice {
66+
/**
67+
* The user ID of the device owner.
68+
*/
69+
userId: string;
70+
/**
71+
* The device ID of the device.
72+
*/
73+
deviceId: string;
74+
}
75+
6776
export interface ICapabilities {
6877
/**
6978
* Event types that this client expects to send.
@@ -128,6 +137,7 @@ export enum RoomWidgetClientEvent {
128137
PendingEventsChanged = "PendingEvent.pendingEventsChanged",
129138
}
130139
export type EventHandlerMap = { [RoomWidgetClientEvent.PendingEventsChanged]: () => void };
140+
131141
/**
132142
* A MatrixClient that routes its requests through the widget API instead of the
133143
* real CS API.
@@ -466,13 +476,10 @@ export class RoomWidgetClient extends MatrixClient {
466476
await this.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
467477
}
468478

469-
public async encryptAndSendToDevices(userDeviceInfoArr: IOlmDevice<DeviceInfo>[], payload: object): Promise<void> {
479+
public async encryptAndSendToDevices(userDeviceInfoArr: OlmDevice[], payload: object): Promise<void> {
470480
// map: user Id → device Id → payload
471481
const contentMap: MapWithDefault<string, Map<string, object>> = new MapWithDefault(() => new Map());
472-
for (const {
473-
userId,
474-
deviceInfo: { deviceId },
475-
} of userDeviceInfoArr) {
482+
for (const { userId, deviceId } of userDeviceInfoArr) {
476483
contentMap.getOrCreate(userId).set(deviceId, payload);
477484
}
478485

0 commit comments

Comments
 (0)