Browse Source

bugfix: private key less than 32 bytes in derive(), pad out with zeros

master
JP Richardson 11 years ago
parent
commit
7af6fdcb98
  1. 5
      CHANGELOG.md
  2. 5
      lib/hdkey.js
  3. 11
      test/hdkey.test.js

5
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 0.2.0 / 2014-06-25
------------------ ------------------
- upgraded `"ecurve": "^0.8.0"` to `"ecurve": "^1.0.0"` - upgraded `"ecurve": "^0.8.0"` to `"ecurve": "^1.0.0"`

5
lib/hdkey.js

@ -136,7 +136,8 @@ HDKey.prototype.deriveChild = function(index) {
return this.derive(index + 1) 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 // Public parent key -> public child key
} else { } else {
@ -149,8 +150,6 @@ HDKey.prototype.deriveChild = function(index) {
return this.derive(index + 1) return this.derive(index + 1)
} }
//hd.pub = new ECPubKey(Ki, true)
//this._publicPoint = Ki
hd.publicKey = Ki.getEncoded(true) hd.publicKey = Ki.getEncoded(true)
} }

11
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)
})
})
}) })

Loading…
Cancel
Save