Comparing version 3.0.1 to 3.1.0
@@ -440,4 +440,5 @@ (function (module, exports) { | ||
BN.prototype.toArray = function toArray(endian) { | ||
BN.prototype.toArray = function toArray(endian, padTo) { | ||
this.strip(); | ||
var littleEndian = endian === 'le'; | ||
var res = new Array(this.byteLength()); | ||
@@ -447,3 +448,3 @@ res[0] = 0; | ||
var q = this.clone(); | ||
if (endian !== 'le') { | ||
if (!littleEndian) { | ||
// Assume big-endian | ||
@@ -457,3 +458,2 @@ for (var i = 0; q.cmpn(0) !== 0; i++) { | ||
} else { | ||
// Assume little-endian | ||
for (var i = 0; q.cmpn(0) !== 0; i++) { | ||
@@ -467,2 +467,11 @@ var b = q.andln(0xff); | ||
if (padTo) { | ||
while (res.length < padTo) { | ||
if (littleEndian) | ||
res.push(0); | ||
else | ||
res.unshift(0); | ||
} | ||
} | ||
return res; | ||
@@ -469,0 +478,0 @@ }; |
{ | ||
"name": "bn.js", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Big number implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/bn.js", |
@@ -60,2 +60,10 @@ var assert = require('assert'); | ||
describe('.toArray()', function() { | ||
it('should zero pad to desired lengths', function() { | ||
var n = new BN(0x123456); | ||
assert.deepEqual(n.toArray('be', 5), [ 0x00, 0x00, 0x12, 0x34, 0x56 ]); | ||
assert.deepEqual(n.toArray('le', 5), [ 0x56, 0x34, 0x12, 0x00, 0x00 ]); | ||
}); | ||
}); | ||
describe('.zeroBits()', function() { | ||
@@ -62,0 +70,0 @@ it('should return proper zeroBits', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118225
3175