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: demo for recover, export and import tss key #106

Closed
wants to merge 16 commits into from
Closed
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
6 changes: 3 additions & 3 deletions demo/redirect-flow-example/package-lock.json

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

2 changes: 1 addition & 1 deletion demo/redirect-flow-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^16.18.48",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@web3auth/mpc-core-kit": "file://../../",
"@web3auth/mpc-core-kit": "file:../..",
"browserify-zlib": "^0.2.0",
"copy-webpack-plugin": "^11.0.0",
"html-webpack-plugin": "^5.5.3",
Expand Down
75 changes: 74 additions & 1 deletion demo/redirect-flow-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const coreKitInstance = new Web3AuthMPCCoreKit(
web3AuthNetwork: selectedNetwork,
uxMode: 'redirect',
manualSync: true,
setupProviderOnInit: false
setupProviderOnInit: false,
// sessionTime: 3600, // <== can provide variable session time based on user subscribed plan
}
);

Expand Down Expand Up @@ -512,6 +513,78 @@ function App() {
await coreKitInstance.commitChanges();
}

const exportTssKey= async () => {
if (!coreKitInstance) {
throw new Error("coreKitInstance is not set");
}
const key = await coreKitInstance._UNSAFE_exportTssKey();
let web3Local = new Web3()
let account = web3Local.eth.accounts.privateKeyToAccount(key)
let signedTx = await account.signTransaction({ to: "0x2E464670992574A613f10F7682D5057fB507Cc21", value: "1000000000000000000" })
console.log(signedTx)
return key
}

const importTssKey = async (newOauthLogin: string, importTssKey: string) => {
// import key to new instance
let { idToken, parsedToken } = await mockLogin(newOauthLogin);

const newCoreKitInstance = new Web3AuthMPCCoreKit(
{
web3AuthClientId: 'BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ',
web3AuthNetwork: selectedNetwork,
uxMode: 'redirect',
manualSync: true,
setupProviderOnInit: false,
// sessionTime: 3600, // <== can provide variable session time based on user subscribed plan
}
);
newCoreKitInstance.init({ handleRedirectResult: false, rehydrate :false });

uiConsole("TSS Private Key: ", importTssKey);

await newCoreKitInstance.loginWithJWT({
verifier: 'torus-test-health',
verifierId: parsedToken.email,
idToken: idToken,
importTssKey: importTssKey
});
uiConsole("TSS Private Key: ", importTssKey);
}


const recoverTssKey = async (factorKeys: string[], newOauthLogin: string) => {
const recoverMpcInstance = new Web3AuthMPCCoreKit(
{
web3AuthClientId: 'BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ',
web3AuthNetwork: selectedNetwork,
uxMode: 'redirect',
manualSync: true,
setupProviderOnInit: false,
// sessionTime: 3600, // <== can provide variable session time based on user subscribed plan
}
);
await recoverMpcInstance.init({ handleRedirectResult: false, rehydrate: false });

let recoveredTssKey = await recoverMpcInstance._UNSAFE_recoverTssKey(factorKeys);
uiConsole("Recovered TSS Private Key: ", recoveredTssKey);
let web3Local = new Web3()
let account = web3Local.eth.accounts.privateKeyToAccount(recoveredTssKey)
let signedTx = await account.signTransaction({ to: "0x2E464670992574A613f10F7682D5057fB507Cc21", value: "1000000000000000000" })
console.log(signedTx)
return recoveredTssKey
}

const exportTssKeyImportTssKey = async (newOauthLogin: string) => {
let key = await exportTssKey();
await importTssKey(newOauthLogin, key);
}

const recoverTssKeyImportTssKey = async (factorKeys: string[], newOauthLogin: string) => {
let key = await recoverTssKey(factorKeys, newOauthLogin);
await importTssKey(newOauthLogin, key);
}

const loggedInView = (
<>
<h2 className="subtitle">Account Details</h2>
Expand Down
Loading
Loading