bn.js 4.11.4 → 4.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +2 -0
- package/README.md +7 -5
- package/lib/bn.js +11 -3
- package/package.json +4 -1
- package/.travis.yml +0 -15
- package/test/arithmetic-test.js +0 -635
- package/test/binary-test.js +0 -228
- package/test/constructor-test.js +0 -149
- package/test/fixtures.js +0 -264
- package/test/pummel/dh-group-test.js +0 -23
- package/test/red-test.js +0 -263
- package/test/utils-test.js +0 -345
package/.npmignore
CHANGED
package/README.md
CHANGED
|
@@ -40,12 +40,12 @@ is the list of them in the order of appearance in the function name:
|
|
|
40
40
|
The only available postfix at the moment is:
|
|
41
41
|
|
|
42
42
|
* `n` - which means that the argument of the function must be a plain JavaScript
|
|
43
|
-
|
|
43
|
+
Number. Decimals are not supported.
|
|
44
44
|
|
|
45
45
|
### Examples
|
|
46
46
|
|
|
47
47
|
* `a.iadd(b)` - perform addition on `a` and `b`, storing the result in `a`
|
|
48
|
-
* `a.
|
|
48
|
+
* `a.umod(b)` - reduce `a` modulo `b`, returning positive value
|
|
49
49
|
* `a.iushln(13)` - shift bits of `a` left by 13
|
|
50
50
|
|
|
51
51
|
## Instructions
|
|
@@ -63,7 +63,9 @@ either `le` (little-endian) or `be` (big-endian).
|
|
|
63
63
|
pad to length, throwing if already exceeding
|
|
64
64
|
* `a.toArrayLike(type, endian, length)` - convert to an instance of `type`,
|
|
65
65
|
which must behave like an `Array`
|
|
66
|
-
* `a.toBuffer(endian, length)` - convert to Node.js Buffer (if available)
|
|
66
|
+
* `a.toBuffer(endian, length)` - convert to Node.js Buffer (if available). For
|
|
67
|
+
compatibility with browserify and similar tools, use this instead:
|
|
68
|
+
`a.toArrayLike(Buffer, endian, length)`
|
|
67
69
|
* `a.bitLength()` - get number of bits occupied
|
|
68
70
|
* `a.zeroBits()` - return number of less-significant consequent zero bits
|
|
69
71
|
(example: `1010000` has 4 zero bits)
|
|
@@ -81,7 +83,7 @@ either `le` (little-endian) or `be` (big-endian).
|
|
|
81
83
|
* `a.eq(b)` - `a` equals `b` (`n`)
|
|
82
84
|
* `a.toTwos(width)` - convert to two's complement representation, where `width` is bit width
|
|
83
85
|
* `a.fromTwos(width)` - convert from two's complement representation, where `width` is the bit width
|
|
84
|
-
* `
|
|
86
|
+
* `BN.isBN(object)` - returns true if the supplied `object` is a BN.js instance
|
|
85
87
|
|
|
86
88
|
### Arithmetics
|
|
87
89
|
|
|
@@ -150,7 +152,7 @@ Or:
|
|
|
150
152
|
var red = BN.mont(num);
|
|
151
153
|
```
|
|
152
154
|
|
|
153
|
-
To reduce numbers with [Montgomery trick][
|
|
155
|
+
To reduce numbers with [Montgomery trick][0]. `.mont()` is generally faster than
|
|
154
156
|
`.red(num)`, but slower than `BN.red(primeName)`.
|
|
155
157
|
|
|
156
158
|
### Converting numbers
|
package/lib/bn.js
CHANGED
|
@@ -50,13 +50,17 @@
|
|
|
50
50
|
|
|
51
51
|
var Buffer;
|
|
52
52
|
try {
|
|
53
|
-
Buffer = require('
|
|
53
|
+
Buffer = require('buffer').Buffer;
|
|
54
54
|
} catch (e) {
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
BN.isBN = function isBN (num) {
|
|
58
|
+
if (num instanceof BN) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
return num !== null && typeof num === 'object' &&
|
|
59
|
-
num.constructor.
|
|
63
|
+
num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
BN.max = function max (left, right) {
|
|
@@ -2097,6 +2101,10 @@
|
|
|
2097
2101
|
|
|
2098
2102
|
assert(this.negative === 0, 'imaskn works only with positive numbers');
|
|
2099
2103
|
|
|
2104
|
+
if (this.length <= s) {
|
|
2105
|
+
return this;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2100
2108
|
if (r !== 0) {
|
|
2101
2109
|
s++;
|
|
2102
2110
|
}
|
|
@@ -3279,7 +3287,7 @@
|
|
|
3279
3287
|
};
|
|
3280
3288
|
|
|
3281
3289
|
Red.prototype.pow = function pow (a, num) {
|
|
3282
|
-
if (num.isZero()) return new BN(1);
|
|
3290
|
+
if (num.isZero()) return new BN(1).toRed(this);
|
|
3283
3291
|
if (num.cmpn(1) === 0) return a.clone();
|
|
3284
3292
|
|
|
3285
3293
|
var windowSize = 4;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bn.js",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.8",
|
|
4
4
|
"description": "Big number implementation in pure javascript",
|
|
5
5
|
"main": "lib/bn.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"url": "https://github.com/indutny/bn.js/issues"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/indutny/bn.js",
|
|
28
|
+
"browser": {
|
|
29
|
+
"buffer": false
|
|
30
|
+
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"istanbul": "^0.3.5",
|
|
30
33
|
"mocha": "^2.1.0",
|