Skip to content

Commit 51792fd

Browse files
author
Guru
committed
fix: condition enable MFA
1 parent 519fb4b commit 51792fd

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

demo/redirect-flow-example/src/components/mfa-cards/authenticator/AuthenticatorScan.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const AuthenticatorQRCodeCard: React.FC = () => {
125125
const totpURL = otpauthURL({
126126
secret: key,
127127
label: userInfo?.verifierId,
128-
issuer: "trust wallet",
128+
issuer: "MPC Core kit",
129129
encoding: "base32",
130130
});
131131
return { url, key, totpURL };
@@ -204,21 +204,23 @@ const AuthenticatorQRCodeCard: React.FC = () => {
204204
setIsLoading(false);
205205
}
206206
};
207-
208207
const creatAuthFactor = async (): Promise<void> => {
209208
if (!coreKitInstance || !secretKey) {
210209
throw new Error("required fields are not set");
211210
}
212211

213-
// await coreKitInstance.createFactor({
214-
// shareType: TssShareType.DEVICE,
215-
// factorKey: factorKey?.private,
216-
// });
217-
await coreKitInstance.enableMFA({
218-
factorKey: factorKey?.private,
219-
additionalMetadata: { shareType: TssShareType.RECOVERY.toString() },
220-
shareDescription: FactorKeyTypeShareDescription.Other,
221-
});
212+
if (coreKitInstance.getTssFactorPub().length === 1) {
213+
await coreKitInstance.enableMFA({
214+
factorKey: factorKey?.private,
215+
additionalMetadata: { shareType: TssShareType.RECOVERY.toString() },
216+
shareDescription: FactorKeyTypeShareDescription.Other,
217+
});
218+
} else {
219+
await coreKitInstance.createFactor({
220+
shareType: TssShareType.DEVICE,
221+
factorKey: factorKey?.private,
222+
});
223+
}
222224

223225
if (coreKitInstance.status === COREKIT_STATUS.LOGGED_IN) {
224226
await coreKitInstance.commitChanges();

demo/redirect-flow-example/src/components/mfa-cards/mnemonic/CreateMnemonic.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ const CreateMnemonicPhraseCard: React.FC = () => {
2525
throw new Error("required fields are not set");
2626
}
2727

28-
// await coreKitInstance.createFactor({
29-
// shareType: TssShareType.RECOVERY,
30-
// factorKey: factorKey,
31-
// });
32-
await coreKitInstance.enableMFA({
33-
factorKey: factorKey,
34-
additionalMetadata: { shareType: TssShareType.RECOVERY.toString() },
35-
shareDescription: FactorKeyTypeShareDescription.SeedPhrase,
36-
});
28+
if (coreKitInstance.getTssFactorPub().length === 1) {
29+
await coreKitInstance.enableMFA({
30+
factorKey: factorKey,
31+
additionalMetadata: { shareType: TssShareType.RECOVERY.toString() },
32+
shareDescription: FactorKeyTypeShareDescription.SeedPhrase,
33+
});
34+
} else {
35+
await coreKitInstance.createFactor({
36+
shareType: TssShareType.RECOVERY,
37+
factorKey: factorKey,
38+
});
39+
}
40+
3741
// await coreKitInstance.enableMFA({}, false)
3842

3943
console.log("created mnemonice factor share");

demo/redirect-flow-example/src/components/mfa-cards/password/CreatePassword.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Card } from "../../Card";
44
import { TextField } from "../../TextField";
55
import { useCoreKit } from "../../../composibles/useCoreKit";
66
import { COREKIT_STATUS, FactorKeyTypeShareDescription, TssSecurityQuestion, TssShareType } from "@web3auth/mpc-core-kit";
7-
import { BN } from "bn.js";
87

98
const GetPasswordCard: React.FC = () => {
109
const { coreKitInstance, setDrawerHeading, setDrawerInfo } = useCoreKit();
@@ -22,6 +21,9 @@ const GetPasswordCard: React.FC = () => {
2221
if (!coreKitInstance) {
2322
throw new Error("coreKitInstance is not set");
2423
}
24+
if (coreKitInstance.getTssFactorPub().length === 1) {
25+
await coreKitInstance.enableMFA({}, false);
26+
}
2527
const factorKey = await securityQuestion.setSecurityQuestion({
2628
mpcCoreKit: coreKitInstance,
2729
question,

0 commit comments

Comments
 (0)