convenience: new Privkey(bn)
This commit is contained in:
parent
ef3a89f254
commit
6f56c8d1fc
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue