Skip to content

Commit

Permalink
Raise error in HDKey.privateExtendedKey if it is not present
Browse files Browse the repository at this point in the history
To be changed in line with cryptocoinjs/hdkey#7
  • Loading branch information
axic committed Mar 26, 2016
1 parent 197e006 commit 04be13c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hdkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ EthereumHDKey.fromExtendedKey = function (base58key) {
}

EthereumHDKey.prototype.privateExtendedKey = function () {
// FIXME: change this according to the outcome of https://github.com/cryptocoinjs/hdkey/issues/7
if (!this._hdkey._privateKey) {
throw new Error('Private key is not available')
}
return this._hdkey.privateExtendedKey
}

Expand Down
2 changes: 1 addition & 1 deletion test/hdkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('.fromExtendedKey()', function () {
assert.equal(hdnode.publicExtendedKey(), 'xpub661MyMwAqRbcGout4B6s29b6gGQsowyoiF6UgXBEr7eFCWYfXuZDvRxP9zEh1Kwq3TLqDQMbkbaRpSnoC28oWvjLeshoQz1StZ9YHM1EpcJ')
assert.throws(function () {
hdnode.privateExtendedKey()
}) // FIXME: check for assert message(s)
}, /^Error: Private key is not available$/)
})
it('should work with private', function () {
var hdnode = HDKey.fromExtendedKey('xprv9s21ZrQH143K4KqQx9Zrf1eN8EaPQVFxM2Ast8mdHn7GKiDWzNEyNdduJhWXToy8MpkGcKjxeFWd8oBSvsz4PCYamxR7TX49pSpp3bmHVAY')
Expand Down

0 comments on commit 04be13c

Please sign in to comment.