Browse Source

(Closes #7) fix when privateKeyExtended when privateKey is null

master
JP Richardson 9 years ago
parent
commit
2b6f9ac826
  1. 3
      lib/hdkey.js
  2. 16
      test/hdkey.test.js

3
lib/hdkey.js

@ -57,7 +57,8 @@ Object.defineProperty(HDKey.prototype, 'publicKey', {
Object.defineProperty(HDKey.prototype, 'privateExtendedKey', {
get: function () {
return cs.encode(serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey])))
if (this._privateKey) return cs.encode(serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey])))
else return null
}
})

16
test/hdkey.test.js

@ -139,4 +139,20 @@ describe('hdkey', function () {
assert(HDKey.HARDENED_OFFSET)
})
})
describe('> when private key is null', function () {
it('privateExtendedKey should return null and not throw', function () {
var seed = '000102030405060708090a0b0c0d0e0f'
var masterKey = HDKey.fromMasterSeed(new Buffer(seed, 'hex'))
assert.ok(masterKey.privateExtendedKey, 'xpriv is truthy')
masterKey._privateKey = null
assert.doesNotThrow(function () {
masterKey.privateExtendedKey
})
assert.ok(!masterKey.privateExtendedKey, 'xpriv is falsy')
})
})
})

Loading…
Cancel
Save