From daafb9794e60a7329c7d5825fceab71e17f6f0a7 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Sep 2015 17:37:21 +1000 Subject: [PATCH] ECPair/HDNode: adds getNetwork --- src/ecpair.js | 4 ++++ src/hdnode.js | 4 ++++ test/ecpair.js | 11 +++++++++++ test/hdnode.js | 9 +++++++++ 4 files changed, 28 insertions(+) diff --git a/src/ecpair.js b/src/ecpair.js index 701b6df..17d19e1 100644 --- a/src/ecpair.js +++ b/src/ecpair.js @@ -105,6 +105,10 @@ ECPair.prototype.getAddress = function () { return bs58check.encode(payload) } +ECPair.prototype.getNetwork = function () { + return this.network +} + ECPair.prototype.getPublicKeyBuffer = function () { return this.Q.getEncoded(this.compressed) } diff --git a/src/hdnode.js b/src/hdnode.js index 576dff0..80ae630 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -136,6 +136,10 @@ HDNode.prototype.getFingerprint = function () { return this.getIdentifier().slice(0, 4) } +HDNode.prototype.getNetwork = function () { + return this.keyPair.getNetwork() +} + HDNode.prototype.getPublicKeyBuffer = function () { return this.keyPair.getPublicKeyBuffer() } diff --git a/test/ecpair.js b/test/ecpair.js index 2421f5f..b7edbd0 100644 --- a/test/ecpair.js +++ b/test/ecpair.js @@ -167,6 +167,17 @@ describe('ECPair', function () { }) }) + describe('getNetwork', function () { + fixtures.valid.forEach(function (f) { + it('returns ' + f.network + ' for ' + f.WIF, function () { + var network = NETWORKS[f.network] + var keyPair = ECPair.fromWIF(f.WIF, NETWORKS_LIST) + + assert.strictEqual(keyPair.getNetwork(), network) + }) + }) + }) + describe('ecdsa wrappers', function () { var keyPair, hash diff --git a/test/hdnode.js b/test/hdnode.js index da0b697..afa9887 100644 --- a/test/hdnode.js +++ b/test/hdnode.js @@ -121,6 +121,15 @@ describe('HDNode', function () { })) }) + describe('getNetwork', function () { + it('wraps keyPair.getNetwork', sinon.test(function () { + this.mock(keyPair).expects('getNetwork') + .once().withArgs().returns('network') + + assert.strictEqual(hd.getNetwork(), 'network') + })) + }) + describe('getPublicKeyBuffer', function () { it('wraps keyPair.getPublicKeyBuffer', sinon.test(function () { this.mock(keyPair).expects('getPublicKeyBuffer')