bn.js 4.11.6 → 4.11.7
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 +2 -1
- package/package.json +1 -1
- package/.travis.yml +0 -15
- package/test/arithmetic-test.js +0 -635
- package/test/binary-test.js +0 -233
- 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,6 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
var Buffer;
|
|
52
52
|
try {
|
|
53
|
+
// Obfuscate that we require Buffer, to reduce size
|
|
53
54
|
Buffer = require('buf' + 'fer').Buffer;
|
|
54
55
|
} catch (e) {
|
|
55
56
|
}
|
|
@@ -3287,7 +3288,7 @@
|
|
|
3287
3288
|
};
|
|
3288
3289
|
|
|
3289
3290
|
Red.prototype.pow = function pow (a, num) {
|
|
3290
|
-
if (num.isZero()) return new BN(1);
|
|
3291
|
+
if (num.isZero()) return new BN(1).toRed(this);
|
|
3291
3292
|
if (num.cmpn(1) === 0) return a.clone();
|
|
3292
3293
|
|
|
3293
3294
|
var windowSize = 4;
|
package/package.json
CHANGED