From a768755764e40c72d0b880cbfe62cb32cfd37fbe Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 1 Sep 2014 21:16:10 -0700 Subject: [PATCH] convenience: new Pubkey(point) --- lib/pubkey.js | 8 ++++++-- test/pubkey.js | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/pubkey.js b/lib/pubkey.js index 4642aa835..522b758fc 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 efee3b6b4..03e7534f7 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() {