Skip to content

Commit

Permalink
Export private key in account management
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Sep 5, 2023
1 parent f6397ac commit ebf5792
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/app/components/Toolbar/Features/Account/ManageableAccount.tsx
Expand Up @@ -10,6 +10,7 @@ import { Wallet } from '../../../../state/wallet/types'
import { ResponsiveLayer } from '../../../ResponsiveLayer'
import { Tabs } from 'grommet/es6/components/Tabs'
import { DerivationFormatter } from './DerivationFormatter'
import { uintToBase64, hex2uint } from '../../../../lib/helpers'
import { AddressBox } from '../../../AddressBox'

export const ManageableAccount = ({
Expand Down Expand Up @@ -55,6 +56,16 @@ export const ManageableAccount = ({
<DerivationFormatter pathDisplay={wallet.pathDisplay} type={wallet.type} />
</Text>
</Box>
<Button
label={t('toolbar.settings.exportPrivateKey', 'Export Private Key')}
disabled={!wallet.privateKey}
onClick={() => {
prompt(
t('toolbar.settings.exportPrivateKey', 'Export Private Key'),
uintToBase64(hex2uint(wallet.privateKey!)),
)
}}
/>
<Box direction="row" justify="between" pad={{ top: 'large' }}>
<Button
secondary
Expand Down
3 changes: 2 additions & 1 deletion src/app/lib/helpers.ts
@@ -1,13 +1,14 @@
import { bech32 } from 'bech32'
import { quantity, staking, types } from '@oasisprotocol/client'
import { decode as base64decode } from 'base64-arraybuffer'
import { decode as base64decode, encode as base64encode } from 'base64-arraybuffer'
import BigNumber from 'bignumber.js'
import { StringifiedBigInt } from 'types/StringifiedBigInt'
import { consensusDecimals, type ParaTimeConfig } from '../../config'

export const uint2hex = (uint: Uint8Array) => Buffer.from(uint).toString('hex')
export const hex2uint = (hex: string) => new Uint8Array(Buffer.from(hex, 'hex'))
export const base64ToUint = (value: string) => new Uint8Array(base64decode(value))
export const uintToBase64 = (value: Uint8Array) => base64encode(value)

export const shortPublicKey = async (publicKey: Uint8Array) => {
return await staking.addressFromPublicKey(publicKey)
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Expand Up @@ -384,6 +384,7 @@
},
"settings": {
"cancel": "Cancel",
"exportPrivateKey": "Export Private Key",
"manageAccount": "Manage",
"myAccountsTab": "My Accounts"
},
Expand Down

0 comments on commit ebf5792

Please sign in to comment.