Fix eth_sign signature encoding.

This commit is contained in:
Tomasz Drwięga
2017-05-11 12:18:20 +02:00
parent 28b66d1b58
commit fc3e1a4f18
6 changed files with 13 additions and 17 deletions

View File

@@ -511,7 +511,7 @@ pub fn execute<D: Dispatcher + 'static>(
let hash = eth_data_hash(data);
let res = signature(&accounts, address, hash, pass)
.map(|result| result
.map(|rsv| H520(rsv.into_vrs()))
.map(|rsv| H520(rsv.into_electrum()))
.map(RpcH520::from)
.map(ConfirmationResponse::Signature)
);

View File

@@ -194,7 +194,7 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
},
ConfirmationPayload::EthSignMessage(address, data) => {
let expected_hash = eth_data_hash(data);
let signature = ethkey::Signature::from_vrs(&bytes.0);
let signature = ethkey::Signature::from_electrum(&bytes.0);
match ethkey::verify_address(&address, &signature, &expected_hash) {
Ok(true) => Ok(ConfirmationResponse::Signature(bytes.0.as_slice().into())),
Ok(false) => Err(errors::invalid_params("Sender address does not match the signature.", ())),

View File

@@ -315,7 +315,7 @@ fn rpc_eth_sign() {
],
"id": 1
}"#;
let res = r#"{"jsonrpc":"2.0","result":"0x1ba2870db1d0c26ef93c7b72d2a0830fa6b841e0593f7186bc6c7cc317af8cf3a42fda03bd589a49949aa05db83300cdb553116274518dbe9d90c65d0213f4af49","id":1}"#;
let res = r#"{"jsonrpc":"2.0","result":"0xa2870db1d0c26ef93c7b72d2a0830fa6b841e0593f7186bc6c7cc317af8cf3a42fda03bd589a49949aa05db83300cdb553116274518dbe9d90c65d0213f4af491b","id":1}"#;
assert_eq!(tester.io.handle_request_sync(&req), Some(res.into()));
}

View File

@@ -492,7 +492,7 @@ fn should_confirm_data_sign_with_signature() {
assert_eq!(tester.signer.requests().len(), 1);
let data_hash = eth_data_hash(vec![1, 2, 3, 4].into());
let signature = H520(tester.accounts.sign(address, Some("test".into()), data_hash).unwrap().into_vrs());
let signature = H520(tester.accounts.sign(address, Some("test".into()), data_hash).unwrap().into_electrum());
let signature = format!("0x{:?}", signature);
// when

View File

@@ -213,7 +213,7 @@ fn should_sign_if_account_is_unlocked() {
],
"id": 1
}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x1bdb53b32e56cf3e9735377b7664d6de5a03e125b1bf8ec55715d253668b4238503b4ac931fe6af90add73e72a585e952665376b2b9afc5b6b239b7df74c734e12","id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0xdb53b32e56cf3e9735377b7664d6de5a03e125b1bf8ec55715d253668b4238503b4ac931fe6af90add73e72a585e952665376b2b9afc5b6b239b7df74c734e121b","id":1}"#;
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
assert_eq!(tester.signer.requests().len(), 0);
}