Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/mfa flow setup #101

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/redirect-flow-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions demo/redirect-flow-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,23 @@ function App() {
setProvider(coreKitInstance.provider);
}
else {
coreKitInstance.setupProvider({ chainConfig: DEFAULT_CHAIN_CONFIG }).then((provider) => {
if (coreKitInstance.status === COREKIT_STATUS.LOGGED_IN) {
coreKitInstance.setupProvider({ chainConfig: DEFAULT_CHAIN_CONFIG }).then((provider) => {

setProvider(coreKitInstance.provider);
});
setProvider(coreKitInstance.provider);
});
}
}
setCoreKitStatus(coreKitInstance.status);


try {
let result = securityQuestion.getQuestion(coreKitInstance!);
setQuestion(result);
} catch (e) {
setQuestion(undefined);
uiConsole(e);
}
} catch (error: unknown) {
console.error(error);
}
Expand All @@ -180,8 +191,7 @@ function App() {
if (!mockEmail) {
throw new Error('mockEmail not found');
}
const { idToken, parsedToken } = await mockLogin(mockEmail);
await flow({ selectedNetwork, manualSync: true, setupProviderOnInit: false, verifier: 'torus-test-health', verifierId: parsedToken.email, idToken });
await flow({ selectedNetwork, manualSync: true, setupProviderOnInit: false, verifier: 'torus-test-health', verifierId: mockEmail });
}
catch (error: unknown) {
console.error(error);
Expand Down Expand Up @@ -225,14 +235,20 @@ function App() {
throw new Error("backupFactorKey not found");
}
const factorKey = new BN(backupFactorKey, "hex")
console.log(factorKey)
await coreKitInstance.inputFactorKey(factorKey);
console.log(coreKitInstance)

setCoreKitStatus(coreKitInstance.status);

if (coreKitInstance.status === COREKIT_STATUS.REQUIRED_SHARE) {
uiConsole("required more shares even after inputing backup factor key, please enter your backup/ device factor key, or reset account [unrecoverable once reset, please use it with caution]");
}

if (coreKitInstance.provider) {
setProvider(coreKitInstance.provider);
} else if (coreKitInstance.status === COREKIT_STATUS.LOGGED_IN) {
await coreKitInstance.setupProvider({ chainConfig: DEFAULT_CHAIN_CONFIG })
}
}

Expand Down
54 changes: 45 additions & 9 deletions demo/redirect-flow-example/src/flow.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@

import { WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCoreKit, TssSecurityQuestion } from "@web3auth/mpc-core-kit";
import BN from "bn.js";
import { mockLogin } from "./App";

export const flow = async (params: { selectedNetwork: WEB3AUTH_NETWORK_TYPE, manualSync: boolean, setupProviderOnInit: boolean, verifier: string, verifierId: string, idToken: string }) => {
const startTime = Date.now();
console.log("startTime", startTime);

export const flow = async (params: { selectedNetwork: WEB3AUTH_NETWORK_TYPE, manualSync: boolean, setupProviderOnInit: boolean, verifier: string, verifierId: string }) => {
const { idToken } = await mockLogin(params.verifierId);
const initStart = Date.now();
console.log("initStart", initStart);
const web3AuthClientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ";
const coreKitInstance = new Web3AuthMPCCoreKit(
{
web3AuthClientId: 'BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ',
web3AuthClientId,
web3AuthNetwork: params.selectedNetwork,
uxMode: 'redirect',
manualSync: params.manualSync,
setupProviderOnInit: params.setupProviderOnInit,
disableHashedFactorKey: true,
}
);

// init can be called before login is triggered, should it is excluded from the login time
await coreKitInstance.init({ handleRedirectResult: false, rehydrate: false });
const startTime = Date.now();
console.log("done init", startTime);


console.log("init", startTime - initStart);

console.log("startTime", startTime);
await coreKitInstance.loginWithJWT({
verifier: params.verifier,
verifierId: params.verifierId,
idToken: params.idToken,
}, { prefetchTssPublicKeys: 2 });
idToken: idToken,
}, { prefetchTssPublicKeys: 2});

let loggedInTime = Date.now();
console.log("logged Time :", loggedInTime);
Expand All @@ -45,7 +55,33 @@ export const flow = async (params: { selectedNetwork: WEB3AUTH_NETWORK_TYPE, man
console.log("commit :", commitTime);
console.log(commitTime - SqFactorTime);

console.log("total time", commitTime - startTime);
console.log("total login time", commitTime - startTime);



// relogin on new instance ( device )
const instance2 = new Web3AuthMPCCoreKit(
{
web3AuthClientId,
web3AuthNetwork: params.selectedNetwork,
uxMode: 'redirect',
manualSync: params.manualSync,
setupProviderOnInit: params.setupProviderOnInit,
disableHashedFactorKey: true,
}
);

const { idToken: idToken2 } = await mockLogin(params.verifierId);
await instance2.init({ handleRedirectResult: false, rehydrate: false });

await instance2.loginWithJWT({
verifier: params.verifier,
verifierId: params.verifierId,
idToken: idToken2,
});
const sqInstance2 = new TssSecurityQuestion();
const sqFactor = await sqInstance2.recoverFactor(instance2, "answer");
await instance2.inputFactorKey(new BN(sqFactor, "hex"));
console.log(instance2.status);

}
Loading