Signature without Prefix – Sign Without \u201C\x19Ethereum Signed Message\u201D Prefix

go-ethereumjavascriptsignatureweb3js

I understood that web3.eth.sign(...) will add “\x19Ethereum Signed Message” prefix to a message and hash with keccak256. Is there anyway to remove the prefix before signing? Or any library I can use to do a simple signing without prefix?

Best Answer

ethereumjs-util has the hashPersonalMessage method which adds the prefix and signs it.

You can look at the codebase and see how this is implemented:

exports.hashPersonalMessage = function (message) {
  var prefix = exports.toBuffer('\u0019Ethereum Signed Message:\n' + message.length.toString())
  return exports.sha3(Buffer.concat([prefix, message]))
}

It is fairly apparent how you can modify this code snippet to not prepend the prefix :)