|
|
@ -1,16 +1,16 @@ |
|
|
|
var _bnjs = require('bn.js'); |
|
|
|
var _BN = require('bn.js'); |
|
|
|
|
|
|
|
var bnjs = function bnjs_extended(n) { |
|
|
|
if (!(this instanceof bnjs_extended)) { |
|
|
|
return new bnjs(n); |
|
|
|
var BN = function BN_extended(n) { |
|
|
|
if (!(this instanceof BN_extended)) { |
|
|
|
return new BN(n); |
|
|
|
} |
|
|
|
arguments[0] = n; |
|
|
|
return _bnjs.apply(this, arguments); |
|
|
|
return _BN.apply(this, arguments); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = bnjs; |
|
|
|
module.exports = BN; |
|
|
|
|
|
|
|
bnjs.prototype = _bnjs.prototype; |
|
|
|
BN.prototype = _BN.prototype; |
|
|
|
|
|
|
|
var reversebuf = function(buf, nbuf) { |
|
|
|
for (var i = 0; i < buf.length; i++) { |
|
|
@ -18,13 +18,13 @@ var reversebuf = function(buf, nbuf) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
bnjs.prototype.fromString = function(str) { |
|
|
|
var bn = bnjs(str); |
|
|
|
BN.prototype.fromString = function(str) { |
|
|
|
var bn = BN(str); |
|
|
|
bn.copy(this); |
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
bnjs.fromBuffer = function(buf, opts) { |
|
|
|
BN.fromBuffer = function(buf, opts) { |
|
|
|
if (typeof opts !== 'undefined' && opts.endian === 'little') { |
|
|
|
var nbuf = new Buffer(buf.length); |
|
|
|
reversebuf(buf, nbuf); |
|
|
@ -33,18 +33,18 @@ bnjs.fromBuffer = function(buf, opts) { |
|
|
|
var hex = buf.toString('hex'); |
|
|
|
if (hex.length % 2) |
|
|
|
hex = "0" + hex; |
|
|
|
var bn = new bnjs(hex, 16); |
|
|
|
var bn = new BN(hex, 16); |
|
|
|
return bn; |
|
|
|
}; |
|
|
|
|
|
|
|
bnjs.prototype.fromBuffer = function(buf, opts) { |
|
|
|
var bn = bnjs.fromBuffer(buf, opts); |
|
|
|
BN.prototype.fromBuffer = function(buf, opts) { |
|
|
|
var bn = BN.fromBuffer(buf, opts); |
|
|
|
bn.copy(this); |
|
|
|
|
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
bnjs.prototype.toBuffer = function(opts) { |
|
|
|
BN.prototype.toBuffer = function(opts) { |
|
|
|
var buf; |
|
|
|
if (opts && opts.size) { |
|
|
|
var hex = this.toString(16); |
|
|
@ -87,22 +87,22 @@ bnjs.prototype.toBuffer = function(opts) { |
|
|
|
}; |
|
|
|
|
|
|
|
function decorate(name) { |
|
|
|
bnjs.prototype['_' + name] = _bnjs.prototype[name]; |
|
|
|
BN.prototype['_' + name] = _BN.prototype[name]; |
|
|
|
var f = function(b) { |
|
|
|
if (typeof b === 'string') |
|
|
|
b = new _bnjs(b); |
|
|
|
b = new _BN(b); |
|
|
|
else if (typeof b === 'number') |
|
|
|
b = new _bnjs(b.toString()); |
|
|
|
b = new _BN(b.toString()); |
|
|
|
return this['_' + name](b); |
|
|
|
}; |
|
|
|
bnjs.prototype[name] = f; |
|
|
|
BN.prototype[name] = f; |
|
|
|
}; |
|
|
|
|
|
|
|
_bnjs.prototype.gt = function(b) { |
|
|
|
_BN.prototype.gt = function(b) { |
|
|
|
return this.cmp(b) > 0; |
|
|
|
}; |
|
|
|
|
|
|
|
_bnjs.prototype.lt = function(b) { |
|
|
|
_BN.prototype.lt = function(b) { |
|
|
|
return this.cmp(b) < 0; |
|
|
|
}; |
|
|
|
|
|
|
@ -115,8 +115,8 @@ decorate('cmp'); |
|
|
|
decorate('gt'); |
|
|
|
decorate('lt'); |
|
|
|
|
|
|
|
bnjs.prototype.toNumber = function() { |
|
|
|
BN.prototype.toNumber = function() { |
|
|
|
return parseInt(this['toString'](10), 10); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = bnjs; |
|
|
|
module.exports = BN; |
|
|
|