Merge pull request #3800 from ethcore/eth-sign

eth_sign RPC now hashes given data instead of getting the hash
This commit is contained in:
Gav Wood 2016-12-12 04:12:27 +01:00 committed by GitHub
commit 2844a4e85e
5 changed files with 17 additions and 14 deletions

View File

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

View File

@ -17,6 +17,7 @@
//! Unsafe Signing RPC implementation. //! Unsafe Signing RPC implementation.
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use util::Hashable;
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
@ -83,7 +84,8 @@ impl<C: 'static, M: 'static> EthSigning for SigningUnsafeClient<C, M> where
C: MiningBlockChainClient, C: MiningBlockChainClient,
M: MinerService, 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())) { let result = match self.handle(RpcConfirmationPayload::Signature((address, hash).into())) {
Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature), Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature),
Err(e) => Err(e), Err(e) => Err(e),

View File

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

View File

@ -26,7 +26,7 @@ use v1::types::ConfirmationResponse;
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use v1::tests::mocked::parity; 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::account_provider::AccountProvider;
use ethcore::client::TestBlockChainClient; use ethcore::client::TestBlockChainClient;
use ethcore::transaction::{Transaction, Action}; 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() { fn should_sign_if_account_is_unlocked() {
// given // given
let tester = eth_signing(); let tester = eth_signing();
let hash: H256 = 5.into(); let data = vec![5u8];
let acc = tester.accounts.new_account("test").unwrap(); let acc = tester.accounts.new_account("test").unwrap();
tester.accounts.unlock_account_permanently(acc, "test".into()).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 // when
let request = r#"{ let request = r#"{
@ -198,7 +198,7 @@ fn should_sign_if_account_is_unlocked() {
"method": "eth_sign", "method": "eth_sign",
"params": [ "params": [
""#.to_owned() + format!("0x{:?}", acc).as_ref() + r#"", ""#.to_owned() + format!("0x{:?}", acc).as_ref() + r#"",
""# + format!("0x{:?}", hash).as_ref() + r#"" ""# + format!("0x{}", data.to_hex()).as_ref() + r#""
], ],
"id": 1 "id": 1
}"#; }"#;

View File

@ -17,14 +17,14 @@
//! Eth rpc interface. //! Eth rpc interface.
use v1::helpers::auto_args::{WrapAsync, Ready}; 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! { build_rpc_trait! {
/// Signing methods implementation relying on unlocked accounts. /// Signing methods implementation relying on unlocked accounts.
pub trait EthSigning { pub trait EthSigning {
/// Signs the data with given address signature. /// Signs the hash of data with given address signature.
#[rpc(async, name = "eth_sign")] #[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 /// Sends transaction; will block waiting for signer to return the
/// transaction hash. /// transaction hash.