fix #1096: PrivateKey#toAddress(network)
This commit is contained in:
parent
a194c6ded1
commit
c4666044e9
|
@ -368,12 +368,14 @@ PrivateKey.prototype.toPublicKey = function(){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return an address for the private key
|
* 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
|
* @returns {Address} An address generated from the private key
|
||||||
*/
|
*/
|
||||||
PrivateKey.prototype.toAddress = function() {
|
PrivateKey.prototype.toAddress = function(network) {
|
||||||
var pubkey = this.toPublicKey();
|
var pubkey = this.toPublicKey();
|
||||||
return Address.fromPublicKey(pubkey, this.network);
|
return Address.fromPublicKey(pubkey, network || this.network);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -225,6 +225,12 @@ describe('PrivateKey', function() {
|
||||||
address.toString().should.equal('mtX8nPZZdJ8d3QNLRJ1oJTiEi26Sj6LQXS');
|
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() {
|
describe('#inspect', function() {
|
||||||
|
|
Loading…
Reference in New Issue