mirror of
https://github.com/element-hq/element-web
synced 2024-11-21 16:55:34 +03:00
Remove references to MatrixClient.crypto
(#28204)
* Remove `VerificationExplorer` * Remove `remakeolm` slash command * Remove call to `crypto.cancelAndResendAllOutgoingKeyRequests` * Remove crypto mock in `LoginWithQR-test.tsx` * Remove `StopGadWidgetDriver.sendToDevice` * Remove remaining mock
This commit is contained in:
parent
ea5cba3649
commit
7236953d07
12 changed files with 0 additions and 380 deletions
|
@ -736,34 +736,6 @@ export const Commands = [
|
|||
category: CommandCategories.advanced,
|
||||
renderingTypes: [TimelineRenderingType.Room],
|
||||
}),
|
||||
new Command({
|
||||
command: "remakeolm",
|
||||
description: _td("slash_command|remakeolm"),
|
||||
isEnabled: (cli) => {
|
||||
return SettingsStore.getValue("developerMode") && !isCurrentLocalRoom(cli);
|
||||
},
|
||||
runFn: (cli, roomId) => {
|
||||
try {
|
||||
const room = cli.getRoom(roomId);
|
||||
|
||||
cli.forceDiscardSession(roomId);
|
||||
|
||||
return success(
|
||||
room?.getEncryptionTargetMembers().then((members) => {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
cli.crypto?.ensureOlmSessionsForUsers(
|
||||
members.map((m) => m.userId),
|
||||
true,
|
||||
);
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
return reject(e instanceof Error ? e.message : e);
|
||||
}
|
||||
},
|
||||
category: CommandCategories.advanced,
|
||||
renderingTypes: [TimelineRenderingType.Room],
|
||||
}),
|
||||
new Command({
|
||||
command: "rainbow",
|
||||
description: _td("slash_command|rainbow"),
|
||||
|
|
|
@ -14,7 +14,6 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
|||
import BaseDialog from "./BaseDialog";
|
||||
import { TimelineEventEditor } from "./devtools/Event";
|
||||
import ServersInRoom from "./devtools/ServersInRoom";
|
||||
import VerificationExplorer from "./devtools/VerificationExplorer";
|
||||
import SettingExplorer from "./devtools/SettingExplorer";
|
||||
import { RoomStateExplorer } from "./devtools/RoomState";
|
||||
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./devtools/BaseTool";
|
||||
|
@ -45,7 +44,6 @@ const Tools: Record<Category, [label: TranslationKey, tool: Tool][]> = {
|
|||
[_td("devtools|explore_room_account_data"), RoomAccountDataExplorer],
|
||||
[_td("devtools|view_servers_in_room"), ServersInRoom],
|
||||
[_td("devtools|notifications_debug"), RoomNotifications],
|
||||
[_td("devtools|verification_explorer"), VerificationExplorer],
|
||||
[_td("devtools|active_widgets"), WidgetExplorer],
|
||||
],
|
||||
[Category.Other]: [
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2022 Michael Telatynski <7t3chguy@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
VerificationPhase as Phase,
|
||||
VerificationRequest,
|
||||
VerificationRequestEvent,
|
||||
CryptoEvent,
|
||||
} from "matrix-js-sdk/src/crypto-api";
|
||||
|
||||
import { useTypedEventEmitter, useTypedEventEmitterState } from "../../../../hooks/useEventEmitter";
|
||||
import { _t, _td, TranslationKey } from "../../../../languageHandler";
|
||||
import MatrixClientContext from "../../../../contexts/MatrixClientContext";
|
||||
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool";
|
||||
import { Tool } from "../DevtoolsDialog";
|
||||
|
||||
const PHASE_MAP: Record<Phase, TranslationKey> = {
|
||||
[Phase.Unsent]: _td("common|unsent"),
|
||||
[Phase.Requested]: _td("devtools|phase_requested"),
|
||||
[Phase.Ready]: _td("devtools|phase_ready"),
|
||||
[Phase.Done]: _td("action|done"),
|
||||
[Phase.Started]: _td("devtools|phase_started"),
|
||||
[Phase.Cancelled]: _td("devtools|phase_cancelled"),
|
||||
};
|
||||
|
||||
const VerificationRequestExplorer: React.FC<{
|
||||
txnId: string;
|
||||
request: VerificationRequest;
|
||||
}> = ({ txnId, request }) => {
|
||||
const [, updateState] = useState();
|
||||
const [timeout, setRequestTimeout] = useState(request.timeout);
|
||||
|
||||
/* Re-render if something changes state */
|
||||
useTypedEventEmitter(request, VerificationRequestEvent.Change, updateState);
|
||||
|
||||
/* Keep re-rendering if there's a timeout */
|
||||
useEffect(() => {
|
||||
if (request.timeout == 0) return;
|
||||
|
||||
/* Note that request.timeout is a getter, so its value changes */
|
||||
const id = window.setInterval(() => {
|
||||
setRequestTimeout(request.timeout);
|
||||
}, 500);
|
||||
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
};
|
||||
}, [request]);
|
||||
|
||||
return (
|
||||
<div className="mx_DevTools_VerificationRequest">
|
||||
<dl>
|
||||
<dt>{_t("devtools|phase_transaction")}</dt>
|
||||
<dd>{txnId}</dd>
|
||||
<dt>{_t("devtools|phase")}</dt>
|
||||
<dd>{PHASE_MAP[request.phase] ? _t(PHASE_MAP[request.phase]) : request.phase}</dd>
|
||||
<dt>{_t("devtools|timeout")}</dt>
|
||||
<dd>{timeout === null ? _t("devtools|timeout_none") : Math.floor(timeout / 1000)}</dd>
|
||||
<dt>{_t("devtools|methods")}</dt>
|
||||
<dd>{request.methods && request.methods.join(", ")}</dd>
|
||||
<dt>{_t("devtools|other_user")}</dt>
|
||||
<dd>{request.otherUserId}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const VerificationExplorer: Tool = ({ onBack }: IDevtoolsProps) => {
|
||||
const cli = useContext(MatrixClientContext);
|
||||
const context = useContext(DevtoolsContext);
|
||||
|
||||
const requests = useTypedEventEmitterState(cli, CryptoEvent.VerificationRequestReceived, () => {
|
||||
return (
|
||||
cli.crypto?.inRoomVerificationRequests["requestsByRoomId"]?.get(context.room.roomId) ??
|
||||
new Map<string, VerificationRequest>()
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<BaseTool onBack={onBack}>
|
||||
{Array.from(requests.entries())
|
||||
.reverse()
|
||||
.map(([txnId, request]) => (
|
||||
<VerificationRequestExplorer txnId={txnId} request={request} key={txnId} />
|
||||
))}
|
||||
{requests.size < 1 && _t("devtools|no_verification_requests_found")}
|
||||
</BaseTool>
|
||||
);
|
||||
};
|
||||
|
||||
export default VerificationExplorer;
|
|
@ -579,7 +579,6 @@
|
|||
"unmute": "Unmute",
|
||||
"unnamed_room": "Unnamed Room",
|
||||
"unnamed_space": "Unnamed Space",
|
||||
"unsent": "Unsent",
|
||||
"unverified": "Unverified",
|
||||
"updating": "Updating...",
|
||||
"user": "User",
|
||||
|
@ -764,20 +763,11 @@
|
|||
"low_bandwidth_mode": "Low bandwidth mode",
|
||||
"low_bandwidth_mode_description": "Requires compatible homeserver.",
|
||||
"main_timeline": "Main timeline",
|
||||
"methods": "Methods",
|
||||
"no_receipt_found": "No receipt found",
|
||||
"no_verification_requests_found": "No verification requests found",
|
||||
"notification_state": "Notification state is <strong>%(notificationState)s</strong>",
|
||||
"notifications_debug": "Notifications debug",
|
||||
"number_of_users": "Number of users",
|
||||
"original_event_source": "Original event source",
|
||||
"other_user": "Other user",
|
||||
"phase": "Phase",
|
||||
"phase_cancelled": "Cancelled",
|
||||
"phase_ready": "Ready",
|
||||
"phase_requested": "Requested",
|
||||
"phase_started": "Started",
|
||||
"phase_transaction": "Transaction",
|
||||
"room_encrypted": "Room is <strong>encrypted ✅</strong>",
|
||||
"room_id": "Room ID: %(roomId)s",
|
||||
"room_not_encrypted": "Room is <strong>not encrypted 🚨</strong>",
|
||||
|
@ -815,8 +805,6 @@
|
|||
"state_key": "State Key",
|
||||
"thread_root_id": "Thread Root ID: %(threadRootId)s",
|
||||
"threads_timeline": "Threads timeline",
|
||||
"timeout": "Timeout",
|
||||
"timeout_none": "None",
|
||||
"title": "Developer tools",
|
||||
"toggle_event": "toggle event",
|
||||
"toolbox": "Toolbox",
|
||||
|
@ -833,7 +821,6 @@
|
|||
"values_explicit_colon": "Values at explicit levels:",
|
||||
"values_explicit_room": "Values at explicit levels in this room",
|
||||
"values_explicit_this_room_colon": "Values at explicit levels in this room:",
|
||||
"verification_explorer": "Verification explorer",
|
||||
"view_servers_in_room": "View servers in room",
|
||||
"view_source_decrypted_event_source": "Decrypted event source",
|
||||
"view_source_decrypted_event_source_unavailable": "Decrypted source unavailable",
|
||||
|
@ -3038,7 +3025,6 @@
|
|||
"rageshake": "Send a bug report with logs",
|
||||
"rainbow": "Sends the given message coloured as a rainbow",
|
||||
"rainbowme": "Sends the given emote coloured as a rainbow",
|
||||
"remakeolm": "Developer command: Discards the current outbound group session and sets up new Olm sessions",
|
||||
"remove": "Removes user with given id from this room",
|
||||
"roomavatar": "Changes the avatar of the current room",
|
||||
"roomname": "Sets the room name",
|
||||
|
|
|
@ -284,8 +284,6 @@ export class SetupEncryptionStore extends EventEmitter {
|
|||
public done(): void {
|
||||
this.phase = Phase.Finished;
|
||||
this.emit("update");
|
||||
// async - ask other clients for keys, if necessary
|
||||
MatrixClientPeg.safeGet().crypto?.cancelAndResendAllOutgoingKeyRequests();
|
||||
}
|
||||
|
||||
private async setActiveVerificationRequest(request: VerificationRequest): Promise<void> {
|
||||
|
|
|
@ -414,55 +414,6 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
await client._unstable_updateDelayedEvent(delayId, action);
|
||||
}
|
||||
|
||||
public async sendToDevice(
|
||||
eventType: string,
|
||||
encrypted: boolean,
|
||||
contentMap: { [userId: string]: { [deviceId: string]: object } },
|
||||
): Promise<void> {
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
|
||||
if (encrypted) {
|
||||
const deviceInfoMap = await client.crypto!.deviceList.downloadKeys(Object.keys(contentMap), false);
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
|
||||
Object.entries(userContentMap).map(async ([deviceId, content]): Promise<void> => {
|
||||
const devices = deviceInfoMap.get(userId);
|
||||
if (!devices) return;
|
||||
|
||||
if (deviceId === "*") {
|
||||
// Send the message to all devices we have keys for
|
||||
await client.encryptAndSendToDevices(
|
||||
Array.from(devices.values()).map((deviceInfo) => ({
|
||||
userId,
|
||||
deviceInfo,
|
||||
})),
|
||||
content,
|
||||
);
|
||||
} else if (devices.has(deviceId)) {
|
||||
// Send the message to a specific device
|
||||
await client.encryptAndSendToDevices(
|
||||
[{ userId, deviceInfo: devices.get(deviceId)! }],
|
||||
content,
|
||||
);
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await client.queueToDevice({
|
||||
eventType,
|
||||
batch: Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
|
||||
Object.entries(userContentMap).map(([deviceId, content]) => ({
|
||||
userId,
|
||||
deviceId,
|
||||
payload: content,
|
||||
})),
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private pickRooms(roomIds?: (string | Symbols.AnyRoom)[]): Room[] {
|
||||
const client = MatrixClientPeg.get();
|
||||
if (!client) throw new Error("Not attached to a client");
|
||||
|
|
|
@ -119,11 +119,6 @@ export function createTestClient(): MatrixClient {
|
|||
removeRoom: jest.fn(),
|
||||
},
|
||||
|
||||
crypto: {
|
||||
deviceList: {
|
||||
downloadKeys: jest.fn(),
|
||||
},
|
||||
},
|
||||
getCrypto: jest.fn().mockReturnValue({
|
||||
getOwnDeviceKeys: jest.fn(),
|
||||
getUserDeviceInfo: jest.fn(),
|
||||
|
|
|
@ -236,50 +236,6 @@ describe("SlashCommands", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("/remakeolm", () => {
|
||||
beforeEach(() => {
|
||||
command = findCommand("remakeolm")!;
|
||||
});
|
||||
|
||||
describe("isEnabled", () => {
|
||||
describe("when developer mode is enabled", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
|
||||
if (settingName === "developerMode") return true;
|
||||
});
|
||||
});
|
||||
|
||||
it("should return true for Room", () => {
|
||||
setCurrentRoom();
|
||||
expect(command.isEnabled(client)).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for LocalRoom", () => {
|
||||
setCurrentLocalRoom();
|
||||
expect(command.isEnabled(client)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when developer mode is not enabled", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
|
||||
if (settingName === "developerMode") return false;
|
||||
});
|
||||
});
|
||||
|
||||
it("should return false for Room", () => {
|
||||
setCurrentRoom();
|
||||
expect(command.isEnabled(client)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false for LocalRoom", () => {
|
||||
setCurrentLocalRoom();
|
||||
expect(command.isEnabled(client)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("/part", () => {
|
||||
it("should part room matching alias if found", async () => {
|
||||
const room1 = new Room("room-id", client, client.getSafeUserId());
|
||||
|
|
|
@ -75,11 +75,6 @@ exports[`DevtoolsDialog renders the devtools dialog 1`] = `
|
|||
>
|
||||
Notifications debug
|
||||
</button>
|
||||
<button
|
||||
class="mx_DevTools_button"
|
||||
>
|
||||
Verification explorer
|
||||
</button>
|
||||
<button
|
||||
class="mx_DevTools_button"
|
||||
>
|
||||
|
|
|
@ -51,7 +51,6 @@ function makeClient() {
|
|||
},
|
||||
getClientWellKnown: jest.fn().mockReturnValue({}),
|
||||
getCrypto: jest.fn().mockReturnValue({}),
|
||||
crypto: {},
|
||||
} as unknown as MatrixClient);
|
||||
}
|
||||
|
||||
|
@ -194,7 +193,6 @@ describe("<LoginWithQR />", () => {
|
|||
});
|
||||
|
||||
test("approve - no crypto", async () => {
|
||||
(client as any).crypto = undefined;
|
||||
(client as any).getCrypto = () => undefined;
|
||||
const onFinished = jest.fn();
|
||||
render(getComponent({ client, onFinished }));
|
||||
|
|
|
@ -18,7 +18,6 @@ import {
|
|||
MsgType,
|
||||
RelationType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||
import {
|
||||
Widget,
|
||||
MatrixWidgetType,
|
||||
|
@ -171,54 +170,6 @@ describe("StopGapWidgetDriver", () => {
|
|||
expect(listener).toHaveBeenCalledWith(openIdUpdate);
|
||||
});
|
||||
|
||||
describe("sendToDevice", () => {
|
||||
const contentMap = {
|
||||
"@alice:example.org": {
|
||||
"*": {
|
||||
hello: "alice",
|
||||
},
|
||||
},
|
||||
"@bob:example.org": {
|
||||
bobDesktop: {
|
||||
hello: "bob",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let driver: WidgetDriver;
|
||||
|
||||
beforeEach(() => {
|
||||
driver = mkDefaultDriver();
|
||||
});
|
||||
|
||||
it("sends unencrypted messages", async () => {
|
||||
await driver.sendToDevice("org.example.foo", false, contentMap);
|
||||
expect(client.queueToDevice.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("sends encrypted messages", async () => {
|
||||
const aliceWeb = new DeviceInfo("aliceWeb");
|
||||
const aliceMobile = new DeviceInfo("aliceMobile");
|
||||
const bobDesktop = new DeviceInfo("bobDesktop");
|
||||
|
||||
mocked(client.crypto!.deviceList).downloadKeys.mockResolvedValue(
|
||||
new Map([
|
||||
[
|
||||
"@alice:example.org",
|
||||
new Map([
|
||||
["aliceWeb", aliceWeb],
|
||||
["aliceMobile", aliceMobile],
|
||||
]),
|
||||
],
|
||||
["@bob:example.org", new Map([["bobDesktop", bobDesktop]])],
|
||||
]),
|
||||
);
|
||||
|
||||
await driver.sendToDevice("org.example.foo", true, contentMap);
|
||||
expect(client.encryptAndSendToDevices.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getTurnServers", () => {
|
||||
let driver: WidgetDriver;
|
||||
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`StopGapWidgetDriver sendToDevice sends encrypted messages 1`] = `
|
||||
[
|
||||
[
|
||||
[
|
||||
{
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": [],
|
||||
"deviceId": "aliceWeb",
|
||||
"keys": {},
|
||||
"known": false,
|
||||
"signatures": {},
|
||||
"unsigned": {},
|
||||
"verified": 0,
|
||||
},
|
||||
"userId": "@alice:example.org",
|
||||
},
|
||||
{
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": [],
|
||||
"deviceId": "aliceMobile",
|
||||
"keys": {},
|
||||
"known": false,
|
||||
"signatures": {},
|
||||
"unsigned": {},
|
||||
"verified": 0,
|
||||
},
|
||||
"userId": "@alice:example.org",
|
||||
},
|
||||
],
|
||||
{
|
||||
"hello": "alice",
|
||||
},
|
||||
],
|
||||
[
|
||||
[
|
||||
{
|
||||
"deviceInfo": DeviceInfo {
|
||||
"algorithms": [],
|
||||
"deviceId": "bobDesktop",
|
||||
"keys": {},
|
||||
"known": false,
|
||||
"signatures": {},
|
||||
"unsigned": {},
|
||||
"verified": 0,
|
||||
},
|
||||
"userId": "@bob:example.org",
|
||||
},
|
||||
],
|
||||
{
|
||||
"hello": "bob",
|
||||
},
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`StopGapWidgetDriver sendToDevice sends unencrypted messages 1`] = `
|
||||
[
|
||||
[
|
||||
{
|
||||
"batch": [
|
||||
{
|
||||
"deviceId": "*",
|
||||
"payload": {
|
||||
"hello": "alice",
|
||||
},
|
||||
"userId": "@alice:example.org",
|
||||
},
|
||||
{
|
||||
"deviceId": "bobDesktop",
|
||||
"payload": {
|
||||
"hello": "bob",
|
||||
},
|
||||
"userId": "@bob:example.org",
|
||||
},
|
||||
],
|
||||
"eventType": "org.example.foo",
|
||||
},
|
||||
],
|
||||
]
|
||||
`;
|
Loading…
Reference in a new issue