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

web3.eth.accounts.privateKeyToAccount accepts private key without "0x" prefix but returns incorrect result #3041

Closed
3sGgpQ8H opened this issue Aug 19, 2019 · 3 comments · Fixed by #3316
Labels
1.x 1.0 related issues Enhancement Includes improvements or optimizations

Comments

@3sGgpQ8H
Copy link

Description

According to the example in the documentation, function web3.eth.accounts.privateKeyToAccount expects private key to be passed to hexadecimal string prefixed with "0x". If private key is passed without "0x" prefix, the function silently returns incorrect result.

Expected behavior

Function web3.eth.accounts.privateKeyToAccount throws on incorrect private key format, and always returns correct result on correctly formatted private keys. Whether hexadecimal private key without "0x" prefix is correct or not is discussible.

Actual behavior

On hexadecimal private key without "0x" prefix function web3.eth.accounts.privateKeyToAccount silently returns incorrect result.

Steps to reproduce the behavior

Call function web3.eth.accounts.privateKeyToAccount with parameters 0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709 and 348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709 and compare the results.

Versions

  • web3.js: 1.0.0-beta.55
@DalderupMaurice
Copy link

same for web3.js version 1.2.1
It returns a faulty result WITHOUT the 0x prefix

@lekkas
Copy link

lekkas commented Sep 2, 2019

@3sGgpQ8H @DalderupMaurice I had the same issue, it looks like the fix has already landed in the web3@2.0.0-alpha.1 pre-release (fixed in #2929) so this should be fixed in the next release.

@DalderupMaurice
Copy link

DalderupMaurice commented Sep 2, 2019

@3sGgpQ8H @DalderupMaurice I had the same issue, it looks like the fix has already landed in the web3@2.0.0-alpha.1 pre-release (fixed in #2929) so this should be fixed in the next release.

Yes! I saw it was mentioned in the release notes afterward.
It should be an easy backport until the v2 goes live though

@nivida nivida added 1.x 1.0 related issues Enhancement Includes improvements or optimizations labels Sep 5, 2019
@nivida nivida mentioned this issue Nov 21, 2019
7 tasks
@ryanio ryanio mentioned this issue Apr 15, 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 Enhancement Includes improvements or optimizations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants