From d77f11b5d8b0bab6f0b63adb7cd6e856fa429e3f Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 22 Oct 2024 14:58:20 +0100 Subject: [PATCH 1/6] Rename CreateCrossSigningDialog to InitialCryptoSetup because it will soon encompass things other than just creating cross signing. --- src/components/structures/auth/E2eSetup.tsx | 4 ++-- ...gningDialog.tsx => InitialCryptoSetup.tsx} | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) rename src/components/views/dialogs/security/{CreateCrossSigningDialog.tsx => InitialCryptoSetup.tsx} (79%) diff --git a/src/components/structures/auth/E2eSetup.tsx b/src/components/structures/auth/E2eSetup.tsx index 80a135fe19f..d2fb046fe77 100644 --- a/src/components/structures/auth/E2eSetup.tsx +++ b/src/components/structures/auth/E2eSetup.tsx @@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import AuthPage from "../../views/auth/AuthPage"; import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody"; -import CreateCrossSigningDialog from "../../views/dialogs/security/CreateCrossSigningDialog"; +import InitialCryptoSetup from "../../views/dialogs/security/InitialCryptoSetup"; interface IProps { matrixClient: MatrixClient; @@ -25,7 +25,7 @@ export default class E2eSetup extends React.Component { return ( - = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { +const InitialCryptoSetup: React.FC = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { const [error, setError] = useState(false); - const bootstrapCrossSigning = useCallback(async () => { + const doSetup = useCallback(async () => { const cryptoApi = matrixClient.getCrypto(); if (!cryptoApi) return; @@ -40,6 +40,12 @@ const CreateCrossSigningDialog: React.FC = ({ matrixClient, accountPasswo try { await createCrossSigning(matrixClient, tokenLogin, accountPassword); + + const backupInfo = await matrixClient.getKeyBackupVersion(); + if (backupInfo === null) { + await cryptoApi.resetKeyBackup(); + } + onFinished(true); } catch (e) { if (tokenLogin) { @@ -58,8 +64,8 @@ const CreateCrossSigningDialog: React.FC = ({ matrixClient, accountPasswo }, [onFinished]); useEffect(() => { - bootstrapCrossSigning(); - }, [bootstrapCrossSigning]); + doSetup(); + }, [doSetup]); let content; if (error) { @@ -69,7 +75,7 @@ const CreateCrossSigningDialog: React.FC = ({ matrixClient, accountPasswo
@@ -96,4 +102,4 @@ const CreateCrossSigningDialog: React.FC = ({ matrixClient, accountPasswo ); }; -export default CreateCrossSigningDialog; +export default InitialCryptoSetup; From 865d994632c8f5b71d277c1c1419c6016965307a Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 22 Oct 2024 15:36:04 +0100 Subject: [PATCH 2/6] Fix name & tests --- src/components/structures/auth/E2eSetup.tsx | 4 ++-- ...ryptoSetup.tsx => InitialCryptoSetupDialog.tsx} | 4 ++-- ...-test.tsx => InitialCryptoSetupDialog-test.tsx} | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) rename src/components/views/dialogs/security/{InitialCryptoSetup.tsx => InitialCryptoSetupDialog.tsx} (95%) rename test/components/views/dialogs/security/{CreateCrossSigningDialog-test.tsx => InitialCryptoSetupDialog-test.tsx} (91%) diff --git a/src/components/structures/auth/E2eSetup.tsx b/src/components/structures/auth/E2eSetup.tsx index d2fb046fe77..4ba7be6e5ae 100644 --- a/src/components/structures/auth/E2eSetup.tsx +++ b/src/components/structures/auth/E2eSetup.tsx @@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import AuthPage from "../../views/auth/AuthPage"; import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody"; -import InitialCryptoSetup from "../../views/dialogs/security/InitialCryptoSetup"; +import InitialCryptoSetupDialog from "../../views/dialogs/security/InitialCryptoSetup"; interface IProps { matrixClient: MatrixClient; @@ -25,7 +25,7 @@ export default class E2eSetup extends React.Component { return ( - = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { +const InitialCryptoSetupDialog: React.FC = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { const [error, setError] = useState(false); const doSetup = useCallback(async () => { @@ -102,4 +102,4 @@ const InitialCryptoSetup: React.FC = ({ matrixClient, accountPassword, to ); }; -export default InitialCryptoSetup; +export default InitialCryptoSetupDialog; diff --git a/test/components/views/dialogs/security/CreateCrossSigningDialog-test.tsx b/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx similarity index 91% rename from test/components/views/dialogs/security/CreateCrossSigningDialog-test.tsx rename to test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx index 3e5dc4eb94e..199174a6343 100644 --- a/test/components/views/dialogs/security/CreateCrossSigningDialog-test.tsx +++ b/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx @@ -12,14 +12,14 @@ import { mocked } from "jest-mock"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { createCrossSigning } from "../../../../../src/CreateCrossSigning"; -import CreateCrossSigningDialog from "../../../../../src/components/views/dialogs/security/CreateCrossSigningDialog"; +import InitialCryptoSetupDialog from "../../../../../src/components/views/dialogs/security/InitialCryptoSetupDialog"; import { createTestClient } from "../../../../test-utils"; jest.mock("../../../../../src/CreateCrossSigning", () => ({ createCrossSigning: jest.fn(), })); -describe("CreateCrossSigningDialog", () => { +describe("InitialCryptoSetupDialog", () => { let client: MatrixClient; let createCrossSigningResolve: () => void; let createCrossSigningReject: (e: Error) => void; @@ -43,7 +43,7 @@ describe("CreateCrossSigningDialog", () => { const onFinished = jest.fn(); render( - { it("should display an error if createCrossSigning fails", async () => { render( - { const onFinished = jest.fn(); render( - { const onFinished = jest.fn(); render( - { it("should retry when the retry button is clicked", async () => { render( - Date: Tue, 22 Oct 2024 15:40:39 +0100 Subject: [PATCH 3/6] Fix import --- src/components/structures/auth/E2eSetup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/auth/E2eSetup.tsx b/src/components/structures/auth/E2eSetup.tsx index 4ba7be6e5ae..4063ae0252c 100644 --- a/src/components/structures/auth/E2eSetup.tsx +++ b/src/components/structures/auth/E2eSetup.tsx @@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import AuthPage from "../../views/auth/AuthPage"; import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody"; -import InitialCryptoSetupDialog from "../../views/dialogs/security/InitialCryptoSetup"; +import InitialCryptoSetupDialog from "../../views/dialogs/security/InitialCryptoSetupDialog"; interface IProps { matrixClient: MatrixClient; From 7eed864758431b8ec619d0977aad8009f329a515 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 5 Dec 2024 16:02:16 +0000 Subject: [PATCH 4/6] Remove code creating key backup Because this was split out from my key backup by default PR --- .../views/dialogs/security/InitialCryptoSetupDialog.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx index e9b58717946..514d863bc4e 100644 --- a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx +++ b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx @@ -41,11 +41,6 @@ const InitialCryptoSetupDialog: React.FC = ({ matrixClient, accountPasswo try { await createCrossSigning(matrixClient, tokenLogin, accountPassword); - const backupInfo = await matrixClient.getKeyBackupVersion(); - if (backupInfo === null) { - await cryptoApi.resetKeyBackup(); - } - onFinished(true); } catch (e) { if (tokenLogin) { From d05d0671bae9d4a2787709f1ac0beecf04150c85 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 5 Dec 2024 16:27:02 +0000 Subject: [PATCH 5/6] Fix comment --- .../views/dialogs/security/InitialCryptoSetupDialog.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx index 514d863bc4e..3b20c5d2634 100644 --- a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx +++ b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx @@ -25,8 +25,8 @@ interface Props { } /* - * Walks the user through the process of creating a cross-signing keys and setting - * up message key backup. In most cases, only a spinner is shown, but for more + * Walks the user through the process of creating a cross-signing keys. + * In most cases, only a spinner is shown, but for more * complex auth like SSO, the user may need to complete some steps to proceed. */ const InitialCryptoSetupDialog: React.FC = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { From f73eac1c385d7790fdb26e4a406c53b4ea1baeb2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 5 Dec 2024 16:56:59 +0000 Subject: [PATCH 6/6] Convert to named export --- src/components/structures/auth/E2eSetup.tsx | 2 +- .../views/dialogs/security/InitialCryptoSetupDialog.tsx | 9 ++++++--- .../dialogs/security/InitialCryptoSetupDialog-test.tsx | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/structures/auth/E2eSetup.tsx b/src/components/structures/auth/E2eSetup.tsx index 4063ae0252c..265905db107 100644 --- a/src/components/structures/auth/E2eSetup.tsx +++ b/src/components/structures/auth/E2eSetup.tsx @@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import AuthPage from "../../views/auth/AuthPage"; import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody"; -import InitialCryptoSetupDialog from "../../views/dialogs/security/InitialCryptoSetupDialog"; +import { InitialCryptoSetupDialog } from "../../views/dialogs/security/InitialCryptoSetupDialog"; interface IProps { matrixClient: MatrixClient; diff --git a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx index 3b20c5d2634..4ee69f17a48 100644 --- a/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx +++ b/src/components/views/dialogs/security/InitialCryptoSetupDialog.tsx @@ -29,7 +29,12 @@ interface Props { * In most cases, only a spinner is shown, but for more * complex auth like SSO, the user may need to complete some steps to proceed. */ -const InitialCryptoSetupDialog: React.FC = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => { +export const InitialCryptoSetupDialog: React.FC = ({ + matrixClient, + accountPassword, + tokenLogin, + onFinished, +}) => { const [error, setError] = useState(false); const doSetup = useCallback(async () => { @@ -96,5 +101,3 @@ const InitialCryptoSetupDialog: React.FC = ({ matrixClient, accountPasswo ); }; - -export default InitialCryptoSetupDialog; diff --git a/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx b/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx index 199174a6343..4d3d495a38d 100644 --- a/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx +++ b/test/components/views/dialogs/security/InitialCryptoSetupDialog-test.tsx @@ -12,7 +12,7 @@ import { mocked } from "jest-mock"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { createCrossSigning } from "../../../../../src/CreateCrossSigning"; -import InitialCryptoSetupDialog from "../../../../../src/components/views/dialogs/security/InitialCryptoSetupDialog"; +import { InitialCryptoSetupDialog } from "../../../../../src/components/views/dialogs/security/InitialCryptoSetupDialog"; import { createTestClient } from "../../../../test-utils"; jest.mock("../../../../../src/CreateCrossSigning", () => ({