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 can import wallet with privateKey + 1 random character.
How to fix it?
let key = privateKey
if (key.startsWith('0x')) {
key = key.substring(2)
}
let buf = Buffer.from(key, 'hex')
let result = ethereumjs.fromPrivateKey(buf)
let publicKey = '0x' + result.getAddress().toString('hex')
if (publicKey.toLowerCase() === address.toLowerCase()) {
return privateKey
}
The text was updated successfully, but these errors were encountered:
That is, the function trims off the trailing character so that the input is the longest possible even number of hex characters. Note that Buffer.from also normalizes to lower case and the trimmed character/s may not even be valid hex. If the first two characters are not valid hex then you get an empty buffer, i.e. the same as Buffer.from('', 'hex').
There's nothing I see that ethereumjs-wallet can do to help in this situation since it's trimmed before fromPrivateKey is invoked.
I can import wallet with privateKey + 1 random character.
How to fix it?
The text was updated successfully, but these errors were encountered: