Add ".publicKey" property to PrivateKey
This commit is contained in:
parent
5f4eb204b4
commit
baf6a24d23
|
@ -82,6 +82,16 @@ var PrivateKey = function PrivateKey(data, network, compressed) {
|
||||||
value: info.network
|
value: info.network
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'publicKey', {
|
||||||
|
configurable: false,
|
||||||
|
get: function() {
|
||||||
|
if (!info.publicKey) {
|
||||||
|
info.publicKey = this.toPublicKey();
|
||||||
|
}
|
||||||
|
return info.publicKey;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -261,6 +261,13 @@ describe('PrivateKey', function() {
|
||||||
pubkey.toString().should.equal(pubhex);
|
pubkey.toString().should.equal(pubhex);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a "publicKey" property', function() {
|
||||||
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
|
||||||
|
var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
|
||||||
|
var privkey = new PrivateKey(BN(new Buffer(privhex, 'hex')));
|
||||||
|
privkey.publicKey.toString().should.equal(pubhex);
|
||||||
|
});
|
||||||
|
|
||||||
it('should convert this known PrivateKey to known PublicKey and preserve compressed=true', function() {
|
it('should convert this known PrivateKey to known PublicKey and preserve compressed=true', function() {
|
||||||
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
|
||||||
var privkey = new PrivateKey(BN(new Buffer(privhex, 'hex')), 'livenet', true);
|
var privkey = new PrivateKey(BN(new Buffer(privhex, 'hex')), 'livenet', true);
|
||||||
|
|
Loading…
Reference in New Issue