Skip to content

Commit

Permalink
(Closes #7) fix when privateKeyExtended when privateKey is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed May 26, 2016
1 parent 81b3e62 commit 2b6f9ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/hdkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand Down
16 changes: 16 additions & 0 deletions test/hdkey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})

0 comments on commit 2b6f9ac

Please sign in to comment.