From f95bebe465ae73b470209cb30ed44a9ea25bf377 Mon Sep 17 00:00:00 2001 From: antonmazhuto Date: Mon, 21 Oct 2024 16:37:44 +0300 Subject: [PATCH] Export account private key --- src/routes/Settings/Settings.tsx | 33 +++++++++++++++++++++++++ src/stores/AccountStore/AccountStore.ts | 10 ++++++++ 2 files changed, 43 insertions(+) diff --git a/src/routes/Settings/Settings.tsx b/src/routes/Settings/Settings.tsx index 9537f468..56650cab 100644 --- a/src/routes/Settings/Settings.tsx +++ b/src/routes/Settings/Settings.tsx @@ -57,6 +57,10 @@ export const Settings = () => { setExportPassword(''); }; + const handleExportPrivateKey = () => { + downloadFile(accountStore.exportPrivateKey(), `${cereAddress}-privateKey.json`); + }; + useEffect(() => { authenticationStore .getRedirectUrl({ callbackUrl: accountUrl, forceMfa: true, emailHint: accountStore.user?.email, skipIntro: true }) @@ -137,6 +141,35 @@ export const Settings = () => { + + + + + } + /> + + + + + + This downloadable file contains your private key, which allows you to gain full access to your + account. + + + Export private key + + + + + ); diff --git a/src/stores/AccountStore/AccountStore.ts b/src/stores/AccountStore/AccountStore.ts index 9006453b..69a80604 100644 --- a/src/stores/AccountStore/AccountStore.ts +++ b/src/stores/AccountStore/AccountStore.ts @@ -63,6 +63,16 @@ export class AccountStore { return URL.createObjectURL(accountBlob); } + exportPrivateKey() { + if (!this.privateKey) { + throw new Error('No private key found!'); + } + const privateKeyBlob = new Blob([JSON.stringify(this.privateKey)], { + type: 'application/json', + }); + return URL.createObjectURL(privateKeyBlob); + } + getAccount(type: KeyType) { return this.accounts.find((account) => account.type === type); }