Skip to content

Commit

Permalink
Assert that the crypto module is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Jan 6, 2025
1 parent b20579d commit 24c537c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ export function ChangeRecoveryKey({
const [state, setState] = useState<State>(isSetupFlow ? "inform_user" : "save_key_change_flow");

// We create a new recovery key, the recovery key will be displayed to the user
const recoveryKey = useAsyncMemo(() => {
const crypto = matrixClient.getCrypto();
if (!crypto) return Promise.resolve(undefined);

return crypto.createRecoveryKeyFromPassphrase();
}, []);

const recoveryKey = useAsyncMemo(() => matrixClient.getCrypto()!.createRecoveryKeyFromPassphrase(), []);
if (!recoveryKey?.encodedPrivateKey) return null;

let content: JSX.Element;
Expand Down
3 changes: 1 addition & 2 deletions src/components/views/settings/encryption/RecoveryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export function RecoveryPanel({ onSetUpRecoveryClick, onChangingRecoveryKeyClick
const matrixClient = useMatrixClientContext();

const checkEncryption = useCallback(async () => {
const crypto = matrixClient.getCrypto();
if (!crypto) return;
const crypto = matrixClient.getCrypto()!;

// Check if the user has a backup
const hasBackup = Boolean(await crypto.checkKeyBackupAndEnable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ function useVerificationRequired(setState: (state: State) => void): () => Promis
const matrixClient = useMatrixClientContext();

const checkVerificationRequired = useCallback(async () => {
const crypto = matrixClient.getCrypto();
if (!crypto) return;

const crypto = matrixClient.getCrypto()!;
const isCrossSigningReady = await crypto.isCrossSigningReady();
if (isCrossSigningReady) setState("main");
else setState("verification_required");
Expand Down

0 comments on commit 24c537c

Please sign in to comment.