Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Generated private key is 31 bytes instead of 32. #47

Open
coder5876 opened this issue Feb 25, 2016 · 2 comments
Open

Generated private key is 31 bytes instead of 32. #47

coder5876 opened this issue Feb 25, 2016 · 2 comments
Milestone

Comments

@coder5876
Copy link

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: Consensys/eth-lightwallet#60

fanatid added a commit to fanatid/bitcore-lib that referenced this issue Feb 25, 2016
@fanatid
Copy link
Contributor

fanatid commented Feb 25, 2016

@christianlundkvist while PR not merged/released, you can use privateKey.bn.toBuffer({size:32}) as hack

@coder5876
Copy link
Author

@fanatid Good tip, thanks! 👍

@braydonf braydonf added this to the 1.0.0 milestone Sep 12, 2016
iancoleman pushed a commit to iancoleman/bips that referenced this issue Feb 23, 2017
These additional test vectors will ensure all future implementations are
interoperable.
See iancoleman/bip39#58
and bitpay/bitcore-lib#47
hypo-test added a commit to hypo-test/BitcoinBips-713993353 that referenced this issue Nov 25, 2018
These additional test vectors will ensure all future implementations are
interoperable.
See iancoleman/bip39#58
and bitpay/bitcore-lib#47
gitsucker added a commit to gitsucker/better-Bitcoin-improvement-proposals that referenced this issue Nov 25, 2018
These additional test vectors will ensure all future implementations are
interoperable.
See iancoleman/bip39#58
and bitpay/bitcore-lib#47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants