According to https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

The sign method calculates an Ethereum specific signature with:

sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message)))

It does not, however, specify how the len function works. If you give it a string containing emojis and zero width joiners, for example, how is the length calculated? Is it a count of code points, code units, graphemes or glyphs? (https://stackoverflow.com/a/27331885/879046)

1 Answer 1


message is actually just a byte array. The prefix string only contains ASCII-7 characters, so it doesn't really matter how you encode it because ASCII-7, ASCII, UTF-8, UTF-16, etc. will all encode it the same. You then take the encoded bytes of that and append the message length (which is just a byte array, so a simple .length will work) and turn that number into a string and encode it just like the prefix. Then append the bytes that make up the message on the end.

The code referenced code snippet makes it look like message is a string but it is just pseudocode and probably won't actually compile unless your language does implicit casting of strings to arrays.

Your Answer

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

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