MyCrypto/common/components/WalletDecrypt/Keystore.jsx

64 lines
1.7 KiB
React
Raw Normal View History

2017-07-04 03:21:19 +00:00
import React, { Component } from 'react';
import translate from 'translations';
import wallet from 'ethereumjs-wallet';
import ethUtil from 'ethereumjs-util';
export default class KeystoreDecrypt extends Component {
2017-07-04 03:21:19 +00:00
constructor(props) {
super(props);
}
2017-07-04 03:21:19 +00:00
handleFileSelection = event => {
const fileReader = new FileReader();
const inputFile = event.target.files[0];
2017-07-04 03:21:19 +00:00
fileReader.onload = () => {
try {
const keyStoreString = fileReader.result;
const decryptedWallet = wallet.fromV3(
keyStoreString,
'asdfasdfasdf',
true
);
const privateHex = ethUtil.bufferToHex(decryptedWallet._privKey);
const publicHex = ethUtil.bufferToHex(
ethUtil.privateToAddress(decryptedWallet._privKey)
);
console.log(privateHex, publicHex); // TODO: Remove console log, it's only here to let Travis pass
} catch (e) {
console.error('Could not parse Keystore file.', e);
}
};
2017-07-04 03:21:19 +00:00
fileReader.readAsText(inputFile, 'utf-8');
};
2017-07-04 03:21:19 +00:00
render() {
return (
<section className="col-md-4 col-sm-6">
<div id="selectedUploadKey">
<h4>{translate('ADD_Radio_2_alt')}</h4>
2017-07-04 03:21:19 +00:00
<div className="form-group">
<input
type="file"
id="fselector"
onChange={this.handleFileSelection}
/>
<label htmlFor="fselector">
<a
className="btn-file marg-v-sm"
id="aria1"
tabIndex="0"
role="button"
>
{translate('ADD_Radio_2_short')}
</a>
</label>
</div>
</div>
</section>
);
}
}