I am trying to use the OpenZeppelin ECRecovery library for a project I am working on.
Unfortunately I don't fully understand how it works and there's no documentation for it.
Let's say I want to sign the message 'hello'. First I hash it:
msg = web3.sha3('hello');
Then I sign it by using web3.eth.sign and metamask.
web3.eth.sign(web3.eth.accounts[0], msg, (err, res) => {
sig = res;
})
The returned signature is:
0xebb853cf9818c590e428bfa2b793b23e975d978bfefbb8aff164a282786c3eda0054113161b1a72f29f371a35b9a378413d689e49addcea34a8a617270c2bc951c
In the library code it says:
// Check the signature length
if (sig.length != 65) {
return (address(0));
}
So if I call the function with the hash and the above signature it will fail because this signature has a length of 132.
I also thought about using the r or the s value of the signature only by splitting it in JavaScript: (even though I don't even know what these values represent, as there is absolutely no information in the solidity documentation)
var r = sig.substr(0,66);
var s = "0x" + sig.substr(66,64);
But both have a length of 66 and fail as well.
Has anyone ever used their library and can help me out?