bitpay / bitcore-lib

A pure and powerful JavaScript Bitcoin library
https://bitcore.io/
Other
611 stars 1.03k forks source link

Bug in HDPrivateKey._getDerivationIndexes #46

Open fanatid opened 8 years ago

fanatid commented 8 years ago
var bitcore = require('bitcore-lib')
console.log(bitcore.HDPrivateKey._getDerivationIndexes('m/2.1/3')) // [ 2.1, 3 ]

Instead [ 2.1, 3 ] result should be null

Discussion in bitcoinjs-lib: https://github.com/bitcoinjs/bitcoinjs-lib/pull/538

braydonf commented 8 years ago

Shouldn't it throw with an invalid argument?

fanatid commented 8 years ago

No. If _getDerivationIndexes return null, _deriveFromString throw error on checking path: https://github.com/bitpay/bitcore-lib/blob/4430479cea370ea07ed02272776932f76bcd2908/lib/hdprivatekey.js#L211

braydonf commented 8 years ago

It looks like the behavior currently is that hdPrivateKey.derive('m/2/3') and hdPrivateKey.derive('m/2.1/3') will generate the same key.