I struggle heavy to actually recover the ethereum address from a hash and the {r, s, v}
from a signature with the ecRecover
-method in solidity.
What i want is to sign another ethereum-address. So i hash that address with sha3 and hex-encoding in web3, and sign it with my address. I then extract {r, s, v} from it and call my method. But i never get the correct result.
function recover(bytes32 _h, uint8 _v, bytes32 _r, bytes32 _s){
ecRecovery = ecrecover(_h, _v, _r, _s);
}
The address i want to sign is: 0x8CbaC5e4d803bE2A3A5cd3DbE7174504c6DD0c1C
The resulting hash for it for me is: 0x4d55361a8f362c8fc244dbd1e4968ca4b96d58e63a0f0c01a2cad1149106568a
After signing it, i get: 0x7709ac9c45926cc4d9791d868ad6c81883b624db44fbae1e62c0e6cc6c19784b74eb7f5ecdcf33f9c61946dc33b57964b1a0fee40ebf3b9c875424553cb865031b
From which i extract:
v = 27
r = 7709ac9c45926cc4d9791d868ad6c81883b624db44fbae1e62c0e6cc6c19784b
s = 74eb7f5ecdcf33f9c61946dc33b57964b1a0fee40ebf3b9c875424553cb86503
feeding that into my function, i get: 0x9a5aAF102C82FaB302923bF8838678728A520103
whis is wrong. What i expect is:
0x1b7fBea9e926B1eAfC299b9Fab8f7174f466244e
My first instinct was to add the prefix of "\x19Ethereum Signed Message:\n", but that doesn't work either. Probably because i'm doing it wrong. So, is anybody able to help me with that one?