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() {