Skip to content

Commit

Permalink
Export account private key
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhutoanton committed Oct 21, 2024
1 parent 5c5fc45 commit f95bebe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/routes/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -137,6 +141,35 @@ export const Settings = () => {
</Stack>
</CardContent>
</Card>
<Card>
<SectionHeader
title="Export Your Private key"
avatar={
<IconButton variant="filled" size="medium">
<DownloadIcon />
</IconButton>
}
/>

<CardContent>
<Stack spacing={1}>
<Stack direction={isMobile ? 'column' : 'row'} spacing={2} paddingTop={2}>
<Typography flex={1} variant="body2" color="text.secondary">
This downloadable file contains your private key, which allows you to gain full access to your
account.
</Typography>
<SectionButton
disabled={!cereAddress}
fullWidth={isMobile}
variant="contained"
onClick={handleExportPrivateKey}
>
Export private key
</SectionButton>
</Stack>
</Stack>
</CardContent>
</Card>
</Stack>
</>
);
Expand Down
10 changes: 10 additions & 0 deletions src/stores/AccountStore/AccountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit f95bebe

Please sign in to comment.