diff --git a/lib/pubkey.js b/lib/pubkey.js index 4642aa8..522b758 100644 --- a/lib/pubkey.js +++ b/lib/pubkey.js @@ -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) { diff --git a/test/pubkey.js b/test/pubkey.js index efee3b6..03e7534 100644 --- a/test/pubkey.js +++ b/test/pubkey.js @@ -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() {