Decrypting for external accounts. (#5581)

This commit is contained in:
Tomasz Drwięga
2017-05-15 18:59:41 +02:00
committed by GitHub
parent 4df1772078
commit 879195397e
8 changed files with 103 additions and 15 deletions

View File

@@ -103,6 +103,12 @@ export default class SignerMiddleware {
return this.confirmRawRequest(store, id, signature);
}
confirmDecryptedMsg (store, id, decrypted) {
const { msg } = decrypted;
return this.confirmRawRequest(store, id, msg);
}
confirmSignedTransaction (store, id, txSigned) {
const { netVersion } = store.getState().nodeStatus;
const { signature, tx } = txSigned;
@@ -153,7 +159,7 @@ export default class SignerMiddleware {
}
onConfirmStart = (store, action) => {
const { condition, gas = 0, gasPrice = 0, id, password, payload, txSigned, dataSigned, wallet } = action.payload;
const { condition, gas = 0, gasPrice = 0, id, password, payload, txSigned, dataSigned, decrypted, wallet } = action.payload;
const handlePromise = this._createConfirmPromiseHandler(store, id);
const transaction = payload.sendTransaction || payload.signTransaction;
@@ -176,10 +182,14 @@ export default class SignerMiddleware {
}
}
// TODO [ToDr] Support eth_sign for external wallet (wallet && !transction)
// TODO [ToDr] Support eth_sign for external wallet (wallet && dataSigned)
if (dataSigned) {
return this.confirmSignedData(store, id, dataSigned);
}
// TODO [ToDr] Support parity_decrypt for external wallet (wallet && decrypted)
if (decrypted) {
return this.confirmDecryptedMsg(store, id, decrypted);
}
return handlePromise(this._api.signer.confirmRequest(id, { gas, gasPrice, condition }, password));
}

View File

@@ -121,6 +121,16 @@ export function generateDataQr (data) {
});
}
export function generateDecryptQr (data) {
return Promise.resolve({
decrypt: data,
value: JSON.stringify({
action: 'decrypt',
data
})
});
}
export function generateTxQr (api, netVersion, transaction) {
return createUnsignedTx(api, netVersion, transaction)
.then((qr) => {

View File

@@ -114,7 +114,7 @@ class DecryptRequest extends Component {
}
renderActions () {
const { accounts, address, focus, isFinished, status } = this.props;
const { accounts, address, focus, isFinished, status, data } = this.props;
const account = accounts[address];
if (isFinished) {
@@ -153,15 +153,16 @@ class DecryptRequest extends Component {
onConfirm={ this.onConfirm }
onReject={ this.onReject }
className={ styles.actions }
dataToSign={ { decrypt: data } }
/>
);
}
onConfirm = (data) => {
const { id } = this.props;
const { password } = data;
const { password, decrypted, wallet } = data;
this.props.onConfirm({ id, password });
this.props.onConfirm({ id, password, decrypted, wallet });
}
onReject = () => {

View File

@@ -40,6 +40,12 @@ const PAYLOAD_SIGN = {
const PAYLOAD_SIGNTX = {
signTransaction: TRANSACTION
};
const PAYLOAD_DECRYPT = {
decrypt: {
address: ADDRESS,
msg: 'testing'
}
};
let component;
let onConfirm;
@@ -109,4 +115,18 @@ describe('views/Signer/RequestPending', () => {
expect(component.find('Connect(TransactionPending)')).to.have.length(1);
});
});
describe('decrypt', () => {
beforeEach(() => {
render(PAYLOAD_DECRYPT);
});
it('renders defaults', () => {
expect(component).to.be.ok;
});
it('renders DecryptRequest component', () => {
expect(component.find('Connect(DecryptRequest)')).to.have.length(1);
});
});
});

View File

@@ -22,7 +22,7 @@ import { FormattedMessage } from 'react-intl';
import ReactTooltip from 'react-tooltip';
import { Form, Input, IdentityIcon, QrCode, QrScan } from '~/ui';
import { generateTxQr, generateDataQr } from '~/util/qrscan';
import { generateTxQr, generateDataQr, generateDecryptQr } from '~/util/qrscan';
import styles from './transactionPendingFormConfirm.css';
@@ -352,7 +352,7 @@ export default class TransactionPendingFormConfirm extends Component {
return (
<QrScan
className={ styles.camera }
onScan={ this.onScanTx }
onScan={ this.onScan }
/>
);
}
@@ -404,8 +404,8 @@ export default class TransactionPendingFormConfirm extends Component {
);
}
onScanTx = (signature) => {
const { chainId, rlp, tx, data } = this.state.qr;
onScan = (signature) => {
const { chainId, rlp, tx, data, decrypt } = this.state.qr;
if (signature && signature.substr(0, 2) !== '0x') {
signature = `0x${signature}`;
@@ -425,6 +425,16 @@ export default class TransactionPendingFormConfirm extends Component {
return;
}
if (decrypt) {
this.props.onConfirm({
decrypted: {
decrypt,
msg: signature
}
});
return;
}
this.props.onConfirm({
dataSigned: {
data,
@@ -499,7 +509,7 @@ export default class TransactionPendingFormConfirm extends Component {
generateQr = () => {
const { api } = this.context;
const { netVersion, dataToSign } = this.props;
const { transaction, data } = dataToSign;
const { transaction, data, decrypt } = dataToSign;
const setState = qr => {
this.setState({ qr });
};
@@ -509,6 +519,11 @@ export default class TransactionPendingFormConfirm extends Component {
return;
}
if (decrypt) {
generateDecryptQr(decrypt).then(setState);
return;
}
generateDataQr(data).then(setState);
}
@@ -547,7 +562,7 @@ export default class TransactionPendingFormConfirm extends Component {
const { account, dataToSign } = this.props;
const { qr } = this.state;
if (dataToSign.data && qr && !qr.value) {
if ((dataToSign.data || dataToSign.decrypt) && qr && !qr.value) {
this.generateQr();
return;
}

View File

@@ -40,6 +40,9 @@ export default class TransactionPendingForm extends Component {
}),
PropTypes.shape({
data: PropTypes.string.isRequired
}),
PropTypes.shape({
decrypt: PropTypes.string.isRequired
})
]).isRequired
};