Browse Source

convenience: new Pubkey(point)

patch-2
Ryan X. Charles 10 years ago
parent
commit
a768755764
  1. 8
      lib/pubkey.js
  2. 7
      test/pubkey.js

8
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) {

7
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() {

Loading…
Cancel
Save