From 04be13c4f0460909ae5c045ba69c92c5847289b0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 26 Mar 2016 17:49:49 +0000 Subject: [PATCH] Raise error in HDKey.privateExtendedKey if it is not present To be changed in line with https://github.com/cryptocoinjs/hdkey/issues/7 --- hdkey.js | 4 ++++ test/hdkey.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hdkey.js b/hdkey.js index 1dc8fd3..3fa830e 100644 --- a/hdkey.js +++ b/hdkey.js @@ -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 } diff --git a/test/hdkey.js b/test/hdkey.js index bdc8e4e..4f02e24 100644 --- a/test/hdkey.js +++ b/test/hdkey.js @@ -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')