Merge pull request #637 from braydonf/feature/public-key-to-address
PublicKey: Added toAddress prototype. Closes #599
This commit is contained in:
commit
3d56ed3b4d
|
@ -2,6 +2,7 @@
|
|||
|
||||
var Point = require('./crypto/point');
|
||||
var BN = require('./crypto/bn');
|
||||
var Address = require('./address');
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -316,6 +317,16 @@ PublicKey.prototype.toDER = function(compressed) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Will return an address for the public key
|
||||
*
|
||||
* @returns {Address} An address generated from the public key
|
||||
*/
|
||||
PublicKey.prototype.toAddress = function(network) {
|
||||
return Address.fromPublicKey(this, network || 'livenet');
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Will output the PublicKey to a DER encoded hex string
|
||||
|
|
|
@ -256,6 +256,22 @@ describe('PublicKey', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#toAddress', function() {
|
||||
|
||||
it('should output this known mainnet address correctly', function() {
|
||||
var pk = new PublicKey('03c87bd0e162f26969da8509cafcb7b8c8d202af30b928c582e263dd13ee9a9781');
|
||||
var address = pk.toAddress('mainnet');
|
||||
address.toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
|
||||
});
|
||||
|
||||
it('should output this known testnet address correctly', function() {
|
||||
var pk = new PublicKey('0293126ccc927c111b88a0fe09baa0eca719e2a3e087e8a5d1059163f5c566feef');
|
||||
var address = pk.toAddress('testnet');
|
||||
address.toString().should.equal('mtX8nPZZdJ8d3QNLRJ1oJTiEi26Sj6LQXS');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#toString', function() {
|
||||
|
||||
it('should print this known public key', function() {
|
||||
|
|
Loading…
Reference in New Issue