From 7a659e134ff3b0267ede622c7dcfe71278a07d95 Mon Sep 17 00:00:00 2001 From: Gav Date: Thu, 2 Feb 2017 12:32:40 +0100 Subject: [PATCH 1/3] Fix dispatch for signing. --- rpc/src/v1/helpers/dispatch.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 5ef3e8cc180..66967a89b49 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -17,7 +17,7 @@ use std::fmt::Debug; use std::ops::Deref; use rlp; -use util::{Address, H256, U256, Uint, Bytes}; +use util::{Address, H520, H256, U256, Uint, Bytes}; use util::bytes::ToPretty; use util::sha3::Hashable; @@ -112,6 +112,13 @@ pub fn execute(client: &C, miner: &M, accounts: &AccountProvider, payload: ConfirmationPayload::Signature(address, data) => { signature(accounts, address, data.sha3(), pass) .map(|result| result + .map(|rsv| { + let mut vrs = [0u8; 65]; + vrs[0] = rsv[64]; + vrs[1..33].copy_from_slice(&rsv.0[0..32]); + vrs[33..65].copy_from_slice(&rsv.0[32..64]); + H520(vrs) + }) .map(RpcH520::from) .map(ConfirmationResponse::Signature) ) From ec5ffbee68c4a8dec98dc0b2affba7ef59d34f5f Mon Sep 17 00:00:00 2001 From: Gav Date: Thu, 2 Feb 2017 12:33:12 +0100 Subject: [PATCH 2/3] Remove console log --- js/src/redux/providers/signerMiddleware.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/src/redux/providers/signerMiddleware.js b/js/src/redux/providers/signerMiddleware.js index b2794595ecc..dc76a96abb4 100644 --- a/js/src/redux/providers/signerMiddleware.js +++ b/js/src/redux/providers/signerMiddleware.js @@ -57,8 +57,6 @@ export default class SignerMiddleware { const handlePromise = (promise) => { promise .then((txHash) => { - console.log('confirmRequest', id, txHash); - if (!txHash) { store.dispatch(actions.errorConfirmRequest({ id, err: 'Unable to confirm.' })); return; From b1feaa74bb730a0c0e09203d382e66665305e477 Mon Sep 17 00:00:00 2001 From: Gav Date: Thu, 2 Feb 2017 13:52:28 +0100 Subject: [PATCH 3/3] Fix signing & tests. --- rpc/src/v1/helpers/dispatch.rs | 7 ++++--- rpc/src/v1/tests/mocked/eth.rs | 12 ++++++------ rpc/src/v1/tests/mocked/signing.rs | 9 ++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 66967a89b49..22a72497ea1 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -114,9 +114,10 @@ pub fn execute(client: &C, miner: &M, accounts: &AccountProvider, payload: .map(|result| result .map(|rsv| { let mut vrs = [0u8; 65]; - vrs[0] = rsv[64]; - vrs[1..33].copy_from_slice(&rsv.0[0..32]); - vrs[33..65].copy_from_slice(&rsv.0[32..64]); + let rsv = rsv.as_ref(); + vrs[0] = rsv[64] + 27; + vrs[1..33].copy_from_slice(&rsv[0..32]); + vrs[33..65].copy_from_slice(&rsv[32..64]); H520(vrs) }) .map(RpcH520::from) diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index cc7beaf508a..d02c336cc43 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -22,7 +22,8 @@ use rustc_serialize::hex::{FromHex, ToHex}; use time::get_time; use rlp; -use util::{Uint, U256, Address, H256, FixedHash, Mutex, Hashable}; +use util::{Uint, U256, Address, H256, FixedHash, Mutex}; +use ethkey::Secret; use ethcore::account_provider::AccountProvider; use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId}; use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; @@ -296,10 +297,9 @@ fn rpc_eth_submit_hashrate() { fn rpc_eth_sign() { let tester = EthTester::default(); - let account = tester.accounts_provider.new_account("abcd").unwrap(); + let account = tester.accounts_provider.insert_account(Secret::from_slice(&[69u8; 32]).unwrap(), "abcd").unwrap(); tester.accounts_provider.unlock_account_permanently(account, "abcd".into()).unwrap(); - let message = "0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f".from_hex().unwrap(); - let signed = tester.accounts_provider.sign(account, None, message.sha3()).unwrap(); + let _message = "0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f".from_hex().unwrap(); let req = r#"{ "jsonrpc": "2.0", @@ -310,9 +310,9 @@ fn rpc_eth_sign() { ], "id": 1 }"#; - let res = r#"{"jsonrpc":"2.0","result":""#.to_owned() + &format!("0x{}", signed) + r#"","id":1}"#; + let res = r#"{"jsonrpc":"2.0","result":"0x1b5100b2be0aafd86271c8f49891262920bfbfeaeccb2ef1d0b2053aefc3ddb399483eb3c902ecf4add3156461a61f59e924a65eb5e6cdbab0a158d45db5f87cdf","id":1}"#; - assert_eq!(tester.io.handle_request_sync(&req), Some(res)); + assert_eq!(tester.io.handle_request_sync(&req), Some(res.into())); } #[test] diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index 7413acc215d..5b68cf5ffe2 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -27,7 +27,8 @@ use v1::types::ConfirmationResponse; use v1::tests::helpers::TestMinerService; use v1::tests::mocked::parity; -use util::{Address, FixedHash, Uint, U256, ToPretty, Hashable}; +use util::{Address, FixedHash, Uint, U256, ToPretty}; +use ethkey::Secret; use ethcore::account_provider::AccountProvider; use ethcore::client::TestBlockChainClient; use ethcore::transaction::{Transaction, Action, SignedTransaction}; @@ -186,11 +187,9 @@ fn should_sign_if_account_is_unlocked() { // given let tester = eth_signing(); let data = vec![5u8]; - let acc = tester.accounts.new_account("test").unwrap(); + let acc = tester.accounts.insert_account(Secret::from_slice(&[69u8; 32]).unwrap(), "test").unwrap(); tester.accounts.unlock_account_permanently(acc, "test".into()).unwrap(); - let signature = tester.accounts.sign(acc, None, data.sha3()).unwrap(); - // when let request = r#"{ "jsonrpc": "2.0", @@ -201,7 +200,7 @@ fn should_sign_if_account_is_unlocked() { ], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{}", signature).as_ref() + r#"","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x1bb3062482b0687e9c97c7609ea60c1649959dbb334f71b3d5cacd496e0848ba8137bc765756627722389c6c39bc77700ccdc8916916a0eb03bcf5191d4f74dc65","id":1}"#; assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned())); assert_eq!(tester.signer.requests().len(), 0); }