0

I'm trying to follow this tutorial: https://programtheblockchain.com/posts/2018/02/17/signing-and-verifying-messages-in-ethereum/ But I cant seem to get it to work:

The following method doesnt make sense to me:

function signPayment(recipient, amount, nonce, contractAddress, callback) {
  var hash = "0x" + ethereumjs.ABI.soliditySHA3(
    ["address", "uint256", "uint256", "address"],
    [recipient, amount, nonce, contractAddress]
  ).toString("hex");

  web3.personal.sign(hash, web3.eth.defaultAccount, callback);
}

It would seem that var hash variable is going to be greater than 32 bytes and thus can never be the same value as:

keccak256(msg.sender, amount, nonce, this)

Has anyone been able to get his tutorial to work? Or explain how those two values are the same? Is there an alternative to soliditySHA3() that matches the functionality of keccak256()?

1 Answer 1

1

That all seems very convoluted for something that is extremely simple, but I feel your frustration. I spent a good week or two searching for answers because nothing worked. However I have constructed a set of solidity contracts, and a python program that demonstrate how to sign messages, verify the signer, verify the original message which was signed, as well as parsing the signature to retrieve the v,r,s information.

When signing messages they get prepended with the following data: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L12

I also have a python script which can be used to sign messages: https://github.com/postables/Postables-Payment-Channel/blob/develop/python/signer.py

The following solidity function details how to verify the ORIGINAL message that was signed, along with the signer of the signed message: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L257

The following solidity function details how to verify the signer of a message: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L192

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.