Use
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
} from "ente-accounts/components/layouts/centered-paper";
|
||||
import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";
|
||||
import { sendOTT } from "ente-accounts/services/user";
|
||||
import { decryptUsingRecoveryKeyMnemonic } from "ente-accounts/utils/recovery-key";
|
||||
import { LinkButton } from "ente-base/components/LinkButton";
|
||||
import { useBaseContext } from "ente-base/context";
|
||||
import log from "ente-base/log";
|
||||
@@ -21,7 +22,6 @@ import type { KeyAttributes, User } from "ente-shared/user/types";
|
||||
import { t } from "i18next";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { decryptUsingRecoveryKeyMnemonic } from "../utils/recovery-key";
|
||||
|
||||
const Page: React.FC = () => {
|
||||
const { showMiniDialog } = useBaseContext();
|
||||
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
removeTwoFactor,
|
||||
type TwoFactorType,
|
||||
} from "ente-accounts/services/user";
|
||||
import { decryptUsingRecoveryKeyMnemonic } from "ente-accounts/utils/recovery-key";
|
||||
import { LinkButton } from "ente-base/components/LinkButton";
|
||||
import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";
|
||||
import { useBaseContext } from "ente-base/context";
|
||||
import { sharedCryptoWorker } from "ente-base/crypto";
|
||||
import type { B64EncryptionResult } from "ente-base/crypto/libsodium";
|
||||
import log from "ente-base/log";
|
||||
import SingleInputForm, {
|
||||
@@ -26,11 +26,6 @@ import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Trans } from "react-i18next";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const bip39 = require("bip39");
|
||||
// mobile client library only supports english.
|
||||
bip39.setDefaultWordlist("english");
|
||||
|
||||
export interface RecoverPageProps {
|
||||
twoFactorType: TwoFactorType;
|
||||
}
|
||||
@@ -95,26 +90,13 @@ const Page: React.FC<RecoverPageProps> = ({ twoFactorType }) => {
|
||||
setFieldError,
|
||||
) => {
|
||||
try {
|
||||
recoveryKey = recoveryKey
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map((part) => part.trim())
|
||||
.filter((part) => !!part)
|
||||
.join(" ");
|
||||
// check if user is entering mnemonic recovery key
|
||||
if (recoveryKey.indexOf(" ") > 0) {
|
||||
if (recoveryKey.split(" ").length !== 24) {
|
||||
throw new Error("recovery code should have 24 words");
|
||||
}
|
||||
recoveryKey = bip39.mnemonicToEntropy(recoveryKey);
|
||||
}
|
||||
const cryptoWorker = await sharedCryptoWorker();
|
||||
const { encryptedData, nonce } = encryptedTwoFactorSecret!;
|
||||
const twoFactorSecret = await cryptoWorker.decryptB64(
|
||||
const twoFactorSecret = await decryptUsingRecoveryKeyMnemonic(
|
||||
encryptedData,
|
||||
nonce,
|
||||
await cryptoWorker.fromHex(recoveryKey),
|
||||
recoveryKey,
|
||||
);
|
||||
|
||||
const resp = await removeTwoFactor(
|
||||
sessionID!,
|
||||
twoFactorSecret,
|
||||
|
||||
Reference in New Issue
Block a user