Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix eth_sign/parity_postSign #4432

Merged
merged 4 commits into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions js/src/redux/providers/signerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion rpc/src/v1/helpers/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
)
Expand Down
12 changes: 6 additions & 6 deletions rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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",
Expand All @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions rpc/src/v1/tests/mocked/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
Expand Down