From d3323b76fe28564c2366ceec3d891de19884192f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 10 Aug 2017 15:35:44 +0200 Subject: [PATCH 1/4] Allow connections from firefox extension. --- parity/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index b978918ce4d..85231938112 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -195,7 +195,7 @@ usage! { or |c: &Config| otry!(c.websockets).interface.clone(), flag_ws_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore,shh,shh_pubsub", or |c: &Config| otry!(c.websockets).apis.as_ref().map(|vec| vec.join(",")), - flag_ws_origins: String = "chrome-extension://*", + flag_ws_origins: String = "chrome-extension://*,moz-extension://*", or |c: &Config| otry!(c.websockets).origins.as_ref().map(|vec| vec.join(",")), flag_ws_hosts: String = "none", or |c: &Config| otry!(c.websockets).hosts.as_ref().map(|vec| vec.join(",")), From abe53eab71119f995b7517646f0ed07e89ceae83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 10 Aug 2017 15:56:00 +0200 Subject: [PATCH 2/4] Displaying actual data that will be signed on hover. --- js/src/api/util/format.js | 5 +++- js/src/api/util/format.spec.js | 1 + js/src/api/util/index.js | 3 ++- .../components/SignRequest/signRequest.js | 27 ++++++++++++++++++- .../SignRequest/signRequest.spec.js | 11 ++++++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/js/src/api/util/format.js b/js/src/api/util/format.js index 61fc9d32ca9..6a4a81d4004 100644 --- a/js/src/api/util/format.js +++ b/js/src/api/util/format.js @@ -75,7 +75,10 @@ export function bytesToAscii (bytes) { } export function asciiToHex (string) { - return '0x' + string.split('').map((s) => s.charCodeAt(0).toString(16)).join(''); + return '0x' + string.split('') + .map(s => s.charCodeAt(0)) + .map(s => s < 0x10 ? '0' + s.toString(16) : s.toString(16)) + .join(''); } export function padRight (input, length) { diff --git a/js/src/api/util/format.spec.js b/js/src/api/util/format.spec.js index c372055694c..ba7a3994e04 100644 --- a/js/src/api/util/format.spec.js +++ b/js/src/api/util/format.spec.js @@ -67,6 +67,7 @@ describe('api/util/format', () => { it('correctly converts a non-empty string', () => { expect(asciiToHex('abc')).to.equal('0x616263'); + expect(asciiToHex('a\nb')).to.equal('0x610a62'); }); }); diff --git a/js/src/api/util/index.js b/js/src/api/util/index.js index cc8fc9b939f..30328856bd5 100644 --- a/js/src/api/util/index.js +++ b/js/src/api/util/index.js @@ -17,7 +17,7 @@ import { isAddress as isAddressValid, toChecksumAddress } from '../../abi/util/address'; import { abiDecode, decodeCallData, decodeMethodInput, methodToAbi } from './decode'; import { abiEncode, abiUnencode, abiSignature, encodeMethodCallAbi } from './encode'; -import { bytesToHex, hexToAscii, asciiToHex, cleanupValue } from './format'; +import { bytesToHex, hexToAscii, hexToBytes, asciiToHex, cleanupValue } from './format'; import { fromWei, toWei } from './wei'; import { sha3 } from './sha3'; import { isArray, isFunction, isHex, isInstanceOf, isString } from './types'; @@ -37,6 +37,7 @@ export default { isString, bytesToHex, hexToAscii, + hexToBytes, asciiToHex, createIdentityImg, decodeCallData, diff --git a/js/src/views/Signer/components/SignRequest/signRequest.js b/js/src/views/Signer/components/SignRequest/signRequest.js index 705b89965fa..a39a57b90fc 100644 --- a/js/src/views/Signer/components/SignRequest/signRequest.js +++ b/js/src/views/Signer/components/SignRequest/signRequest.js @@ -70,6 +70,10 @@ class SignRequest extends Component { } }; + state = { + hashToSign: null + }; + hardwareStore = HardwareStore.get(this.context.api); componentWillMount () { @@ -78,6 +82,26 @@ class SignRequest extends Component { signerStore.fetchBalance(address); } + componentDidMount () { + this.computeHashToSign(this.props.data); + } + + componentWillReceiveProps (nextProps) { + if (this.props.data !== nextProps.data) { + this.computeHashToSign(nextProps.data); + } + } + + computeHashToSign (data) { + console.log(this.context) + const { sha3, hexToBytes, asciiToHex } = this.context.api.util; + const bytes = hexToBytes(data); + const message = hexToBytes(asciiToHex(`\x19Ethereum Signed Message:\n${bytes.length}`)); + const hashToSign = sha3(message.concat(bytes)); + + this.setState({ hashToSign }); + } + render () { const { className } = this.props; @@ -113,6 +137,7 @@ class SignRequest extends Component { renderDetails () { const { api } = this.context; const { address, data, netVersion, origin, signerStore } = this.props; + const { hashToSign } = this.state; const { balances, externalLink } = signerStore; const balance = balances[address]; @@ -133,7 +158,7 @@ class SignRequest extends Component { /> -
+

, { context: { - store: reduxStore + store: reduxStore, + api: { + util: { + sha3: (x) => x, + hexToBytes: (x) => x, + asciiToHex: (x) => x + } + } } } ).find('SignRequest').shallow(); @@ -61,7 +68,7 @@ function render () { return component; } -describe('views/Signer/components/SignRequest', () => { +describe.only('views/Signer/components/SignRequest', () => { beforeEach(() => { render(); }); From 6e513af45be44f7872b0ab748a31173a0f6b8448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 11 Aug 2017 10:04:08 +0200 Subject: [PATCH 3/4] Display a tooltip. --- .../components/SignRequest/signRequest.js | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/js/src/views/Signer/components/SignRequest/signRequest.js b/js/src/views/Signer/components/SignRequest/signRequest.js index a39a57b90fc..2f97f140f5f 100644 --- a/js/src/views/Signer/components/SignRequest/signRequest.js +++ b/js/src/views/Signer/components/SignRequest/signRequest.js @@ -18,6 +18,7 @@ import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; +import ReactTooltip from 'react-tooltip'; import HardwareStore from '~/mobx/hardwareStore'; @@ -93,7 +94,6 @@ class SignRequest extends Component { } computeHashToSign (data) { - console.log(this.context) const { sha3, hexToBytes, asciiToHex } = this.context.api.util; const bytes = hexToBytes(data); const message = hexToBytes(asciiToHex(`\x19Ethereum Signed Message:\n${bytes.length}`)); @@ -146,6 +146,20 @@ class SignRequest extends Component { return

; } + const tooltip = [ + , +
, + + ]; + return (
@@ -158,7 +172,16 @@ class SignRequest extends Component { />
-
+ + { tooltip } + +

Date: Fri, 11 Aug 2017 11:26:34 +0200 Subject: [PATCH 4/4] Revert "Allow connections from firefox extension." This reverts commit d3323b76fe28564c2366ceec3d891de19884192f. --- parity/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 85231938112..b978918ce4d 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -195,7 +195,7 @@ usage! { or |c: &Config| otry!(c.websockets).interface.clone(), flag_ws_apis: String = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc,secretstore,shh,shh_pubsub", or |c: &Config| otry!(c.websockets).apis.as_ref().map(|vec| vec.join(",")), - flag_ws_origins: String = "chrome-extension://*,moz-extension://*", + flag_ws_origins: String = "chrome-extension://*", or |c: &Config| otry!(c.websockets).origins.as_ref().map(|vec| vec.join(",")), flag_ws_hosts: String = "none", or |c: &Config| otry!(c.websockets).hosts.as_ref().map(|vec| vec.join(",")),