Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account.hashMessage is incorrect with non-ASCII characters #3523

Closed
odanado opened this issue May 16, 2020 · 1 comment · Fixed by #3526
Closed

account.hashMessage is incorrect with non-ASCII characters #3523

odanado opened this issue May 16, 2020 · 1 comment · Fixed by #3526
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@odanado
Copy link
Contributor

odanado commented May 16, 2020

Expected behavior

  const web3 = new Web3(null);
  const message = "🤗";
  console.log(web3.eth.accounts.hashMessage(message));
  // => 0xd21b04463b76fb09777ca0c59f4de0e02895b0847bf547b3df67ca7b67bb8f66
  console.log(web3.eth.accounts.hashMessage(web3.utils.utf8ToHex(message)));
  // => 0x716ce69c5d2d629c168bc02e24a961456bdc5a362d366119305aea73978a0332

Actual behavior

The two hash values should be the same.

I think you should use web3.utils.utf8ToHex on this line.
https://github.com/ethereum/web3.js/blob/4ec98d48096007b113d38f634243cf99df6702cd/packages/web3-eth-accounts/src/index.js#L296

Steps to reproduce the behavior

  1. git clone https://github.com/odan-sandbox/eth-ecRecover-compare
  2. yarn install
  3. yarn ts-node src/app.ts

Environment

web3: 1.2.7
nodejs: 12.11.1

@cokia
Copy link
Contributor

cokia commented May 19, 2020

I found the same problem as you, and the solution you suggested works!

(I tested at ubuntu 18.04 / OSX 10.15.4 and node version is 13.5.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants