Assert that the crypto module is defined

florianduros/encryption-tab
Florian Duros 2025-01-06 14:35:41 +01:00
parent b20579d796
commit 24c537cdb7
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15
3 changed files with 3 additions and 12 deletions

View File

@ -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;

View File

@ -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());

View File

@ -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");