2017-07-04 03:21:19 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-05-31 23:54:47 +00:00
|
|
|
import translate from 'translations';
|
2017-06-08 02:30:25 +00:00
|
|
|
import wallet from 'ethereumjs-wallet';
|
|
|
|
import ethUtil from 'ethereumjs-util';
|
2017-05-31 23:54:47 +00:00
|
|
|
|
|
|
|
export default class KeystoreDecrypt extends Component {
|
2017-07-04 03:21:19 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
2017-06-08 02:30:25 +00:00
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
handleFileSelection = event => {
|
|
|
|
const fileReader = new FileReader();
|
|
|
|
const inputFile = event.target.files[0];
|
2017-06-08 02:30:25 +00:00
|
|
|
|
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-06-08 02:30:25 +00:00
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
fileReader.readAsText(inputFile, 'utf-8');
|
|
|
|
};
|
2017-06-08 02:30:25 +00:00
|
|
|
|
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-05-31 23:54:47 +00:00
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|