From d60d8cf2bc0d93ecadfcb364d169ef992f8780da Mon Sep 17 00:00:00 2001 From: Utente Date: Wed, 3 Jun 2015 12:23:01 -0700 Subject: [PATCH 1/2] fixed PrivateKey initialization from JSON --- lib/privatekey.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/privatekey.js b/lib/privatekey.js index 26c31eb..8560f68 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -247,9 +247,10 @@ PrivateKey._transformJSON = function(json) { json = JSON.parse(json); } var bn = new BN(json.bn, 'hex'); + var network = Networks.get(json.network); return { bn: bn, - network: json.network, + network: network, compressed: json.compressed }; }; From 0d2784eb1e74baa5d4a5b49d5f151b2883354b29 Mon Sep 17 00:00:00 2001 From: mpolci Date: Fri, 5 Jun 2015 01:51:27 -0700 Subject: [PATCH 2/2] created test to verify correct network initialization in PrivateKey.fromJSON() --- test/privatekey.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/privatekey.js b/test/privatekey.js index 5d072d1..03aad24 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -177,6 +177,17 @@ describe('PrivateKey', function() { PrivateKey.fromJSON(json).toJSON().should.deep.equal(json); }); + it('input json should correctly initialize network field', function() { + ['livenet', 'testnet', 'mainnet'].forEach(function (net) { + var pk = PrivateKey.fromJSON(JSON.stringify({ + bn: '96c132224121b509b7d0a16245e957d9192609c5637c6228311287b1be21627a', + compressed: false, + network: net + })); + pk.network.should.be.deep.equal(Networks.get(net)); + }); + }); + it('an object with private key info can be also used as argument for "fromJSON"', function() { expect(PrivateKey._isJSON({bn: true, network: true})).to.equal(true); });