Skip to content

Commit

Permalink
Add ability to view the currently loaded account's private key if unl…
Browse files Browse the repository at this point in the history
…ocked
  • Loading branch information
aaroncox committed Jan 29, 2019
1 parent bc71b78 commit f9d1163
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion app/shared/containers/Global/Account/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import { translate } from 'react-i18next';
import compose from 'lodash/fp/compose';
import { Form, Header, Message, Modal, Select } from 'semantic-ui-react';

import { decrypt } from '../../../actions/wallet';

import GlobalFormFieldAccount from '../../../components/Global/Form/Field/Account';
import GlobalFormFieldKeyPublic from '../../../components/Global/Form/Field/Key/Public';
// import GlobalFormFieldKeyPrivate from '../../../components/Global/Form/Field/Key/Private';
import GlobalFormFieldKeyPrivate from '../../../components/Global/Form/Field/Key/Private';
// import GlobalFormFieldGeneric from '../../../components/Global/Form/Field/Generic';

const CryptoJS = require('crypto-js');
const ecc = require('eosjs-ecc');

const authOptions = [
{ key: 'active', text: 'active', value: 'active' },
{ key: 'owner', text: 'owner', value: 'owner' },
Expand All @@ -24,6 +29,38 @@ const walletOptions = [
];

class GlobalAccountEdit extends Component<Props> {
constructor(props) {
super(props);
const {
connection,
data,
settings,
} = this.props;
const {
account,
authorization,
chainId
} = data;
const state = {};
if (
account === settings.account
&& authorization === settings.authorization
&& chainId === settings.chainId
&& connection.keyProviderObfuscated
) {
const {
hash,
key
} = connection.keyProviderObfuscated;
if (hash && key) {
const wif = decrypt(key, hash, 1).toString(CryptoJS.enc.Utf8);
if (ecc.isValidPrivate(wif) === true) {
state.wif = wif;
}
}
}
this.state = state;
}
onClose = () => {
this.props.onClose();
}
Expand Down Expand Up @@ -60,6 +97,7 @@ class GlobalAccountEdit extends Component<Props> {
data,
t,
} = this.props;
const { wif } = this.state;
return (
<Modal
centered={false}
Expand Down Expand Up @@ -106,6 +144,20 @@ class GlobalAccountEdit extends Component<Props> {
name="pubkey"
onChange={this.onChange}
/>
{(wif)
? (
<GlobalFormFieldKeyPrivate
autoFocus
connection={connection}
label={t('global_account_import_private_key')}
name="key"
placeholder={t('welcome:welcome_key_compare_placeholder')}
onChange={this.onChange}
value={wif}
/>
)
: false
}
</Form>
<Message
content={t('tools:tools_form_account_edit_nosave')}
Expand All @@ -120,6 +172,7 @@ class GlobalAccountEdit extends Component<Props> {
function mapStateToProps(state) {
return {
connection: state.connection,
keys: state.keys,
settings: state.settings,
};
}
Expand Down

0 comments on commit f9d1163

Please sign in to comment.