bitcore-lib
bitcore-lib copied to clipboard
Generated private key is 31 bytes instead of 32.
The derived() function sometimes returns 31 byte keys. In the derive() function here:
https://github.com/bitpay/bitcore-lib/blob/master/lib/hdprivatekey.js#L194
there is clearly the intention of having the Buffer padded to 32 bytes. But when testing the resulting private key is not padded. To replicate:
var Mnemonic = require('bitcore-mnemonic')
var seed = "erupt consider beyond twist bike enroll you salute weasel emerge divert hundred";
var hdprivkey = (new Mnemonic(seed)).toHDPrivateKey().derive("m/44'/60'/0'/0")
console.log(hdprivkey.privateKey.toBuffer().length) // prints 31
Related: https://github.com/ConsenSys/eth-lightwallet/issues/60
@christianlundkvist while PR not merged/released, you can use privateKey.bn.toBuffer({size:32}) as hack
@fanatid Good tip, thanks! :+1: