Fix eth_sign/parity_postSign (#4432)

* Fix dispatch for signing.

* Remove console log

* Fix signing & tests.
This commit is contained in:
Gav Wood 2017-02-04 16:00:28 +01:00 committed by Arkadiy Paronyan
parent b4c24d5ab3
commit 4553f517ce
4 changed files with 19 additions and 14 deletions

View File

@ -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;

View File

@ -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,14 @@ pub fn execute<C, M>(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];
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)
.map(ConfirmationResponse::Signature)
)

View File

@ -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]

View File

@ -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);
}