From c4666044e9177d217f2f608a86fc344076f3f9ce Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 24 Feb 2015 15:26:48 -0300 Subject: [PATCH] fix #1096: PrivateKey#toAddress(network) --- lib/privatekey.js | 6 ++++-- test/privatekey.js | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/privatekey.js b/lib/privatekey.js index 822d2f57e..8747b2304 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -368,12 +368,14 @@ PrivateKey.prototype.toPublicKey = function(){ /** * Will return an address for the private key + * @param {Network=} network - optional parameter specifying + * the desired network for the address * * @returns {Address} An address generated from the private key */ -PrivateKey.prototype.toAddress = function() { +PrivateKey.prototype.toAddress = function(network) { var pubkey = this.toPublicKey(); - return Address.fromPublicKey(pubkey, this.network); + return Address.fromPublicKey(pubkey, network || this.network); }; /** diff --git a/test/privatekey.js b/test/privatekey.js index 5091d7d04..c701983a7 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -225,6 +225,12 @@ describe('PrivateKey', function() { address.toString().should.equal('mtX8nPZZdJ8d3QNLRJ1oJTiEi26Sj6LQXS'); }); + it('creates network specific address', function() { + var pk = PrivateKey.fromWIF('cR4qogdN9UxLZJXCNFNwDRRZNeLRWuds9TTSuLNweFVjiaE4gPaq'); + pk.toAddress(Networks.livenet).network.name.should.equal(Networks.livenet.name); + pk.toAddress(Networks.testnet).network.name.should.equal(Networks.testnet.name); + }); + }); describe('#inspect', function() {