fix #1096: PrivateKey#toAddress(network)

This commit is contained in:
Manuel Araoz 2015-02-24 15:26:48 -03:00
parent a194c6ded1
commit c4666044e9
2 changed files with 10 additions and 2 deletions

View File

@ -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);
};
/**

View File

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