web3.eth.accounts.privateKeyToAccount generates different accounts from the same privatekey
web3.eth.accounts.privateKeyToAccount treats '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' and 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' as different private keys.
It's a bug in eth-lib, would you please add a patch to Account Module until the pr is merged?
Hi there, hopefully this helps https://dev.to/yukkurisinai/big-trap-of-web3js-ffi
@Jason-Soo Thanks, that's almost what I PRed in eth-lib.
@Keith-CY I recently tried using ethers.js not as big community but its quite simple as well do check them out and I used this very simple amateur code to solve it haha
if (key.substring(0, 2) !== '0x') {
key = '0x' + key; //checking
}
+1, spent some time to figure out why my public address isn't valid. When you create account from the private key without 0x - everything will be executed without error. But later on will crash, for exmaple because:
var sig = secp256k1.sign(msgHash, privateKey);
^
RangeError: private key length is invalid
Also, according to documentation https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#privatekeytoaccount input should always start from 0x therefore private key correct format checking is necessary.
Closed because of the answer from @lebed2045