From 810ec3558a2dd8a69a157fbcc70fc072333a1ba2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Feb 2017 16:09:59 -0500 Subject: [PATCH] Make signing compatible with geth. (#4468) --- rpc/src/v1/helpers/dispatch.rs | 8 ++++++-- rpc/src/v1/tests/mocked/eth.rs | 2 +- rpc/src/v1/tests/mocked/signing.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 126b26bc2..0f9e4619f 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -109,8 +109,12 @@ pub fn execute(client: &C, miner: &M, accounts: &AccountProvider, payload: .map(ConfirmationResponse::SignTransaction) ) }, - ConfirmationPayload::Signature(address, data) => { - signature(accounts, address, data.sha3(), pass) + ConfirmationPayload::Signature(address, mut data) => { + let mut message_data = + format!("\x19Ethereum Signed Message:\n{}", data.len()) + .into_bytes(); + message_data.append(&mut data); + signature(accounts, address, message_data.sha3(), pass) .map(|result| result .map(|rsv| { let mut vrs = [0u8; 65]; diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index c6476d16b..5f0e84389 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -310,7 +310,7 @@ fn rpc_eth_sign() { ], "id": 1 }"#; - let res = r#"{"jsonrpc":"2.0","result":"0x1b5100b2be0aafd86271c8f49891262920bfbfeaeccb2ef1d0b2053aefc3ddb399483eb3c902ecf4add3156461a61f59e924a65eb5e6cdbab0a158d45db5f87cdf","id":1}"#; + let res = r#"{"jsonrpc":"2.0","result":"0x1ba2870db1d0c26ef93c7b72d2a0830fa6b841e0593f7186bc6c7cc317af8cf3a42fda03bd589a49949aa05db83300cdb553116274518dbe9d90c65d0213f4af49","id":1}"#; assert_eq!(tester.io.handle_request_sync(&req), Some(res.into())); } diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index 6e971511d..c70ef6d3f 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -200,7 +200,7 @@ fn should_sign_if_account_is_unlocked() { ], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":"0x1bb3062482b0687e9c97c7609ea60c1649959dbb334f71b3d5cacd496e0848ba8137bc765756627722389c6c39bc77700ccdc8916916a0eb03bcf5191d4f74dc65","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x1bdb53b32e56cf3e9735377b7664d6de5a03e125b1bf8ec55715d253668b4238503b4ac931fe6af90add73e72a585e952665376b2b9afc5b6b239b7df74c734e12","id":1}"#; assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned())); assert_eq!(tester.signer.requests().len(), 0); }