convenience: new Pubkey(point)

This commit is contained in:
Ryan X. Charles 2014-09-01 21:16:10 -07:00
parent 6f56c8d1fc
commit a768755764
2 changed files with 13 additions and 2 deletions

View File

@ -2,11 +2,15 @@ var Point = require('./point');
var bn = require('./bn');
var privkey = require('./privkey');
var Pubkey = function Pubkey(obj) {
var Pubkey = function Pubkey(point) {
if (!(this instanceof Pubkey))
return new Pubkey(obj);
if (obj)
if (point instanceof Point)
this.point = point;
else if (point) {
var obj = point;
this.set(obj);
}
};
Pubkey.prototype.set = function(obj) {

View File

@ -17,6 +17,13 @@ describe('Pubkey', function() {
should.exist(pk.point);
});
it('should create a public key with a point with this convenient method', function() {
var p = Point();
var pk = new Pubkey(p);
should.exist(pk.point);
pk.point.toString().should.equal(p.toString());
});
describe('#set', function() {
it('should make a public key from a point', function() {