diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c5bc98..0ff2d36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.3.0 / 2014-06-29 +------------------ +- bugfix: if private key was less than 32 bytes, pad out to 32 bytes with leading zeros (this happens in derive) + + 0.2.0 / 2014-06-25 ------------------ - upgraded `"ecurve": "^0.8.0"` to `"ecurve": "^1.0.0"` diff --git a/lib/hdkey.js b/lib/hdkey.js index 5bdecbc..7fe793f 100644 --- a/lib/hdkey.js +++ b/lib/hdkey.js @@ -136,7 +136,8 @@ HDKey.prototype.deriveChild = function(index) { return this.derive(index + 1) } - hd.privateKey = ki.toBuffer() + //if less than 32 bytes, pad with 0's + hd.privateKey = ki.toBuffer(32) // Public parent key -> public child key } else { @@ -149,8 +150,6 @@ HDKey.prototype.deriveChild = function(index) { return this.derive(index + 1) } - //hd.pub = new ECPubKey(Ki, true) - //this._publicPoint = Ki hd.publicKey = Ki.getEncoded(true) } diff --git a/test/hdkey.test.js b/test/hdkey.test.js index 3817daf..f6bff60 100644 --- a/test/hdkey.test.js +++ b/test/hdkey.test.js @@ -113,4 +113,15 @@ describe('hdkey', function() { }) }) + + describe('> when private key integer is less than 32 bytes', function() { + it('should work', function() { + var seed = "000102030405060708090a0b0c0d0e0f" + var masterKey = HDKey.fromMasterSeed(new Buffer(seed, 'hex')) + + var newKey = masterKey.derive("m/44'/6'/4'") + var expected = 'xprv9ymoag6W7cR6KBcJzhCM6qqTrb3rRVVwXKzwNqp1tDWcwierEv3BA9if3ARHMhMPh9u2jNoutcgpUBLMfq3kADDo7LzfoCnhhXMRGX3PXDx' + assert.equal(cs.encode(newKey.privateExtendedKey), expected) + }) + }) })