From 7cbfd48873c0f0039e3371d1a68b29adc088cc1a Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 24 May 2023 15:14:48 +0100 Subject: [PATCH] Fixes and comments --- src/components/views/settings/devices/types.ts | 8 +++++++- src/utils/device/isDeviceVerified.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/devices/types.ts b/src/components/views/settings/devices/types.ts index 36343cf22c03..5b073831733d 100644 --- a/src/components/views/settings/devices/types.ts +++ b/src/components/views/settings/devices/types.ts @@ -18,7 +18,13 @@ import { IMyDevice } from "matrix-js-sdk/src/matrix"; import { ExtendedDeviceInformation } from "../../../../utils/device/parseUserAgent"; -export type DeviceWithVerification = IMyDevice & { isVerified: boolean | null }; +export type DeviceWithVerification = IMyDevice & { + /** + * `null` if the device is unknown or has not published encryption keys; otherwise a boolean + * indicating whether the device has been cross-signed by a cross-signing key we trust. + */ + isVerified: boolean | null; +}; export type ExtendedDeviceAppInfo = { // eg Element Web appName?: string; diff --git a/src/utils/device/isDeviceVerified.ts b/src/utils/device/isDeviceVerified.ts index 1671fa01a303..3aabf264db14 100644 --- a/src/utils/device/isDeviceVerified.ts +++ b/src/utils/device/isDeviceVerified.ts @@ -22,13 +22,17 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; * @param client - reference to the MatrixClient * @param deviceId - ID of the device to be checked * - * @returns `true` if the device has been correctly cross-signed. `false` if the device is unknown or not correctly - * cross-signed. `null` if there was an error fetching the device info. + * @returns `null` if the device is unknown or has not published encryption keys; otherwise a boolean + * indicating whether the device has been cross-signed by a cross-signing key we trust. */ export const isDeviceVerified = async (client: MatrixClient, deviceId: string): Promise => { try { const trustLevel = await client.getCrypto()?.getDeviceVerificationStatus(client.getSafeUserId(), deviceId); - return trustLevel?.crossSigningVerified ?? false; + if (!trustLevel) { + // either no crypto, or an unknown/no-e2e device + return null; + } + return trustLevel.crossSigningVerified; } catch (e) { console.error("Error getting device cross-signing info", e); return null;