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鈥檒l 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
Projects

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)

@cgewecke cgewecke added 1.x 1.0 related issues Bug Addressing a bug labels May 19, 2020
@cgewecke cgewecke self-assigned this May 19, 2020
@cgewecke cgewecke added this to To do in v1.2.9 May 19, 2020
@ryanio ryanio moved this from To do to In progress in v1.2.9 May 19, 2020
@cgewecke cgewecke removed their assignment May 20, 2020
@cgewecke cgewecke moved this from In progress to In Review in v1.2.9 May 22, 2020
@cgewecke cgewecke moved this from In Review to Done in v1.2.9 May 22, 2020
@ryanio ryanio mentioned this issue Jun 2, 2020
13 tasks
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
No open projects
v1.2.9
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants