diff --git a/lib/privkey.js b/lib/privkey.js index e102bf3..c0fc0d6 100644 --- a/lib/privkey.js +++ b/lib/privkey.js @@ -4,11 +4,15 @@ var constants = require('./constants'); var base58check = require('./base58check'); var Random = require('./random'); -var Privkey = function Privkey(obj) { +var Privkey = function Privkey(bn) { if (!(this instanceof Privkey)) return new Privkey(obj); - if (obj) + if (bn instanceof BN) + this.bn = bn; + else if (bn) { + var obj = bn; this.set(obj); + } }; Privkey.prototype.set = function(obj) { diff --git a/test/privkey.js b/test/privkey.js index 24f9568..f9cb48e 100644 --- a/test/privkey.js +++ b/test/privkey.js @@ -17,6 +17,12 @@ describe('Privkey', function() { should.exist(privkey); }); + it('should create a 0 private key with this convenience method', function() { + var bn = BN(0); + var privkey = new Privkey(bn); + privkey.bn.toString().should.equal(bn.toString()); + }); + it('should create a mainnet private key', function() { var privkey = new Privkey({bn: BN.fromBuffer(buf), networkstr: 'mainnet', compressed: true}); privkey.toString().should.equal(encmainnet);