mirror of
https://github.com/vector-im/element-web.git
synced 2025-09-04 21:31:08 +02:00
Minor cleanups to initialiseDehydration
(#29261)
* dehydration: fix documentation * initialiseDehydration: improve name ... to make it clearer that it does nothing if dehydration is disabled * initialiseDehydration: remove dependency on MatrixClientPeg We're trying to move away from relying on `MatrixClientPeg` everywhere, and this is a particularly easy win.
This commit is contained in:
parent
c47ce59478
commit
09db599fe0
@ -41,7 +41,7 @@ import PlatformPeg from "./PlatformPeg";
|
|||||||
import { formatList } from "./utils/FormattingUtils";
|
import { formatList } from "./utils/FormattingUtils";
|
||||||
import SdkConfig from "./SdkConfig";
|
import SdkConfig from "./SdkConfig";
|
||||||
import { setDeviceIsolationMode } from "./settings/controllers/DeviceIsolationModeController.ts";
|
import { setDeviceIsolationMode } from "./settings/controllers/DeviceIsolationModeController.ts";
|
||||||
import { initialiseDehydration } from "./utils/device/dehydration";
|
import { initialiseDehydrationIfEnabled } from "./utils/device/dehydration";
|
||||||
|
|
||||||
export interface IMatrixClientCreds {
|
export interface IMatrixClientCreds {
|
||||||
homeserverUrl: string;
|
homeserverUrl: string;
|
||||||
@ -347,7 +347,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
|
|||||||
// is a new login, we will start dehydration after Secret Storage is
|
// is a new login, we will start dehydration after Secret Storage is
|
||||||
// unlocked.
|
// unlocked.
|
||||||
try {
|
try {
|
||||||
await initialiseDehydration({ onlyIfKeyCached: true, rehydrate: false }, this.matrixClient);
|
await initialiseDehydrationIfEnabled(this.matrixClient, { onlyIfKeyCached: true, rehydrate: false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// We may get an error dehydrating, such as if cross-signing and
|
// We may get an error dehydrating, such as if cross-signing and
|
||||||
// SSSS are not set up yet. Just log the error and continue.
|
// SSSS are not set up yet. Just log the error and continue.
|
||||||
|
@ -37,7 +37,7 @@ import Spinner from "../../../../components/views/elements/Spinner";
|
|||||||
import InteractiveAuthDialog from "../../../../components/views/dialogs/InteractiveAuthDialog";
|
import InteractiveAuthDialog from "../../../../components/views/dialogs/InteractiveAuthDialog";
|
||||||
import { type IValidationResult } from "../../../../components/views/elements/Validation";
|
import { type IValidationResult } from "../../../../components/views/elements/Validation";
|
||||||
import PassphraseConfirmField from "../../../../components/views/auth/PassphraseConfirmField";
|
import PassphraseConfirmField from "../../../../components/views/auth/PassphraseConfirmField";
|
||||||
import { initialiseDehydration } from "../../../../utils/device/dehydration";
|
import { initialiseDehydrationIfEnabled } from "../../../../utils/device/dehydration";
|
||||||
|
|
||||||
// I made a mistake while converting this and it has to be fixed!
|
// I made a mistake while converting this and it has to be fixed!
|
||||||
enum Phase {
|
enum Phase {
|
||||||
@ -273,7 +273,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
|
|||||||
setupNewKeyBackup: !backupInfo,
|
setupNewKeyBackup: !backupInfo,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await initialiseDehydration({ createNewKey: true });
|
await initialiseDehydrationIfEnabled(cli, { createNewKey: true });
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
phase: Phase.Stored,
|
phase: Phase.Stored,
|
||||||
|
@ -20,7 +20,7 @@ import { type Device, type SecretStorage } from "matrix-js-sdk/src/matrix";
|
|||||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||||
import { AccessCancelledError, accessSecretStorage } from "../SecurityManager";
|
import { AccessCancelledError, accessSecretStorage } from "../SecurityManager";
|
||||||
import { asyncSome } from "../utils/arrays";
|
import { asyncSome } from "../utils/arrays";
|
||||||
import { initialiseDehydration } from "../utils/device/dehydration";
|
import { initialiseDehydrationIfEnabled } from "../utils/device/dehydration";
|
||||||
|
|
||||||
export enum Phase {
|
export enum Phase {
|
||||||
Loading = 0,
|
Loading = 0,
|
||||||
@ -149,7 +149,7 @@ export class SetupEncryptionStore extends EventEmitter {
|
|||||||
);
|
);
|
||||||
resolve();
|
resolve();
|
||||||
|
|
||||||
await initialiseDehydration();
|
await initialiseDehydrationIfEnabled(cli);
|
||||||
|
|
||||||
if (backupInfo) {
|
if (backupInfo) {
|
||||||
await cli.getCrypto()?.loadSessionBackupPrivateKeyFromSecretStorage();
|
await cli.getCrypto()?.loadSessionBackupPrivateKeyFromSecretStorage();
|
||||||
|
@ -10,7 +10,6 @@ import { logger } from "matrix-js-sdk/src/logger";
|
|||||||
import { type CryptoApi, type StartDehydrationOpts } from "matrix-js-sdk/src/crypto-api";
|
import { type CryptoApi, type StartDehydrationOpts } from "matrix-js-sdk/src/crypto-api";
|
||||||
|
|
||||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if device dehydration is enabled.
|
* Check if device dehydration is enabled.
|
||||||
@ -38,11 +37,13 @@ async function deviceDehydrationEnabled(client: MatrixClient, crypto: CryptoApi
|
|||||||
* the configuration), rehydrate a device (if available) and create
|
* the configuration), rehydrate a device (if available) and create
|
||||||
* a new dehydrated device.
|
* a new dehydrated device.
|
||||||
*
|
*
|
||||||
* @param createNewKey: force a new dehydration key to be created, even if one
|
* @param client - MatrixClient to use for the operation
|
||||||
* already exists. This is used when we reset secret storage.
|
* @param opts - options for the startDehydration operation, if one is performed.
|
||||||
*/
|
*/
|
||||||
export async function initialiseDehydration(opts: StartDehydrationOpts = {}, client?: MatrixClient): Promise<void> {
|
export async function initialiseDehydrationIfEnabled(
|
||||||
client = client || MatrixClientPeg.safeGet();
|
client: MatrixClient,
|
||||||
|
opts: StartDehydrationOpts = {},
|
||||||
|
): Promise<void> {
|
||||||
const crypto = client.getCrypto();
|
const crypto = client.getCrypto();
|
||||||
if (await deviceDehydrationEnabled(client, crypto)) {
|
if (await deviceDehydrationEnabled(client, crypto)) {
|
||||||
logger.log("Device dehydration enabled");
|
logger.log("Device dehydration enabled");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user