I have a code that is working:
solidity
function checkSignature(bytes32 h, uint8 v, bytes32 r, bytes32 s) public pure returns (address signer) {
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix,h));
signer = ecrecover(prefixedHash, v, r, s);
}
javascript
const message = "Hello";
const h = web3.utils.soliditySha3(message);
console.log(h.length);
let signature = await web3.eth.sign(h, second);
var r = signature.slice(0, 66);
var s = "0x" + signature.slice(66, 130);
var v = "0x" + signature.slice(130, 132);
v = web3.utils.toDecimal(v);
v = v + 27;
const result = await multisig.checkSignature(h, v, r, s);
//result === second
The logged length of h
is 66. 512bit hash should be 64bytes. The first 2 bytes(0x)denotes this is a hex value.
I am sending it as a solidity bytes32 variable which has a fixed length of 32. How is the code working?
I might be missing something very obvious. Please point it out. Thanks in advance.