[Ethereum] Is the signature generated by “web3.personal.sign” different with “web3.eth.sign”

ecdsasignatureweb3js

Are web3.personal.sign and web3.eth.sign difference in value of generate signature ? Or both of them generate an equal output ?

I could test web3.eth.sign using testRPC, however web3.personal.sign with testRPC gives error and I could not compare the output of both method with the same input.

Best Answer

I think I had similar problem. I couldn't get correct address from ecrecover after message was signed with personal.sign, but it works fine after it was sign with eth.sign. Then I found this on web3 docs: https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#sign

"Signs data using a specific account. This data is before UTF-8 HEX decoded and enveloped as follows: "\x19Ethereum Signed Message:\n" + message.length + message."

After I added "\x19Ethereum Signed Message:\n" and message length to signed message, from which I want to recover address, it finally return correct address.

Related Topic