You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expect to treat "0xbf" as a string and hash it as a string.
Actual behavior
Invalid UTF-8 detected.
Steps to reproduce the behavior
web3.eth.accounts.hashMessage("0xbf")
Error Logs
Invalid UTF-8 detected
Versions
Remix v0.7.5, Web3.js v1.0.0, Chrome, MacOS
Comment:
When the argument to web3.eth.accounts.hashMessage() starts from 0x, the function assumes that it was generated by hex-encoding from UTF-8 and it tries to decode it back to UTF-8. If it's a different hex number, the function fails. Is it really a desired behavior? What if we want to hash a different hex message? For example what if we want to hash a message which itself is a hash?
It is quite a headache if you have a message (which is some hash value, starting from 0x) and you want to sign it in web3.js and then verify the signature in Solidity. To have the same numbers on both sides you need to either:
accept hex values to be signed in web3.js (which is impossible because of this hashMessage issue),
or
manually modify the hex string to not start with 0x (which is inconvenient in Solidity).
The text was updated successfully, but these errors were encountered:
Hi @nivida , can you please reopen the issue? The issue didn't disappear and now I think I used the correct template. If something is wrong with this issue, please let me know.
Expected behavior
If I run:
I expect to treat
"0xbf"
as a string and hash it as a string.Actual behavior
Invalid UTF-8 detected
.Steps to reproduce the behavior
Error Logs
Invalid UTF-8 detected
Versions
Remix v0.7.5, Web3.js v1.0.0, Chrome, MacOS
Comment:
When the argument to
web3.eth.accounts.hashMessage()
starts from0x
, the function assumes that it was generated by hex-encoding from UTF-8 and it tries to decode it back to UTF-8. If it's a different hex number, the function fails. Is it really a desired behavior? What if we want to hash a different hex message? For example what if we want to hash a message which itself is a hash?It is quite a headache if you have a message (which is some hash value, starting from
0x
) and you want to sign it in web3.js and then verify the signature in Solidity. To have the same numbers on both sides you need to either:or
0x
(which is inconvenient in Solidity).The text was updated successfully, but these errors were encountered: