Raise error in HDKey.privateExtendedKey if it is not present

To be changed in line with https://github.com/cryptocoinjs/hdkey/issues/7
This commit is contained in:
Alex Beregszaszi 2016-03-26 17:49:49 +00:00
parent 197e0066eb
commit 04be13c4f0
2 changed files with 5 additions and 1 deletions

View File

@ -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
}

View File

@ -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')