eth_sign RPC now hashes given data

This commit is contained in:
Tomasz Drwięga 2016-12-10 20:01:04 +01:00
parent a6fcd8a0d9
commit 76a93d4eff
5 changed files with 18 additions and 14 deletions

View File

@ -18,7 +18,7 @@
use std::sync::{Arc, Weak};
use transient_hashmap::TransientHashMap;
use util::{U256, Mutex};
use util::{U256, Mutex, Hashable};
use ethcore::account_provider::AccountProvider;
use ethcore::miner::MinerService;
@ -180,7 +180,8 @@ impl<C: 'static, M: 'static> EthSigning for SigningQueueClient<C, M> where
C: MiningBlockChainClient,
M: MinerService,
{
fn sign(&self, ready: Ready<RpcH520>, address: RpcH160, hash: RpcH256) {
fn sign(&self, ready: Ready<RpcH520>, address: RpcH160, data: RpcBytes) {
let hash = data.0.sha3().into();
let res = self.active().and_then(|_| self.dispatch(RpcConfirmationPayload::Signature((address, hash).into())));
self.handle_dispatch(res, |response| {
match response {

View File

@ -17,6 +17,7 @@
//! Unsafe Signing RPC implementation.
use std::sync::{Arc, Weak};
use util::Hashable;
use ethcore::account_provider::AccountProvider;
use ethcore::miner::MinerService;
@ -83,7 +84,8 @@ impl<C: 'static, M: 'static> EthSigning for SigningUnsafeClient<C, M> where
C: MiningBlockChainClient,
M: MinerService,
{
fn sign(&self, ready: Ready<RpcH520>, address: RpcH160, hash: RpcH256) {
fn sign(&self, ready: Ready<RpcH520>, address: RpcH160, data: RpcBytes) {
let hash = data.0.sha3().into();
let result = match self.handle(RpcConfirmationPayload::Signature((address, hash).into())) {
Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature),
Err(e) => Err(e),

View File

@ -18,11 +18,11 @@ use std::str::FromStr;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Instant, Duration};
use rustc_serialize::hex::ToHex;
use rustc_serialize::hex::{FromHex, ToHex};
use time::get_time;
use rlp;
use util::{Uint, U256, Address, H256, FixedHash, Mutex};
use util::{Uint, U256, Address, H256, FixedHash, Mutex, Hashable};
use ethcore::account_provider::AccountProvider;
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
@ -294,8 +294,8 @@ fn rpc_eth_sign() {
let account = tester.accounts_provider.new_account("abcd").unwrap();
tester.accounts_provider.unlock_account_permanently(account, "abcd".into()).unwrap();
let message = H256::from("0x0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f");
let signed = tester.accounts_provider.sign(account, None, message).unwrap();
let message = "0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f".from_hex().unwrap();
let signed = tester.accounts_provider.sign(account, None, message.sha3()).unwrap();
let req = r#"{
"jsonrpc": "2.0",

View File

@ -26,7 +26,7 @@ use v1::types::ConfirmationResponse;
use v1::tests::helpers::TestMinerService;
use v1::tests::mocked::parity;
use util::{Address, FixedHash, Uint, U256, H256, ToPretty};
use util::{Address, FixedHash, Uint, U256, ToPretty, Hashable};
use ethcore::account_provider::AccountProvider;
use ethcore::client::TestBlockChainClient;
use ethcore::transaction::{Transaction, Action};
@ -186,11 +186,11 @@ fn should_check_status_of_request_when_its_resolved() {
fn should_sign_if_account_is_unlocked() {
// given
let tester = eth_signing();
let hash: H256 = 5.into();
let data = vec![5u8];
let acc = tester.accounts.new_account("test").unwrap();
tester.accounts.unlock_account_permanently(acc, "test".into()).unwrap();
let signature = tester.accounts.sign(acc, None, hash).unwrap();
let signature = tester.accounts.sign(acc, None, data.sha3()).unwrap();
// when
let request = r#"{
@ -198,10 +198,11 @@ fn should_sign_if_account_is_unlocked() {
"method": "eth_sign",
"params": [
""#.to_owned() + format!("0x{:?}", acc).as_ref() + r#"",
""# + format!("0x{:?}", hash).as_ref() + r#""
""# + format!("0x{}", data.to_hex()).as_ref() + r#""
],
"id": 1
}"#;
println!("{:?}", request);
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{}", signature).as_ref() + r#"","id":1}"#;
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
assert_eq!(tester.signer.requests().len(), 0);

View File

@ -17,14 +17,14 @@
//! Eth rpc interface.
use v1::helpers::auto_args::{WrapAsync, Ready};
use v1::types::{H160, H256, H520, TransactionRequest, RichRawTransaction};
use v1::types::{Bytes, H160, H256, H520, TransactionRequest, RichRawTransaction};
build_rpc_trait! {
/// Signing methods implementation relying on unlocked accounts.
pub trait EthSigning {
/// Signs the data with given address signature.
/// Signs the hash of data with given address signature.
#[rpc(async, name = "eth_sign")]
fn sign(&self, Ready<H520>, H160, H256);
fn sign(&self, Ready<H520>, H160, Bytes);
/// Sends transaction; will block waiting for signer to return the
/// transaction hash.