bn.js 4.11.5 → 4.11.9

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/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
- number
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.pmod(b)` - reduce `a` modulo `b`, returning positive value
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
- * `a.isBN(object)` - returns true if the supplied `object` is a BN.js instance
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][1]. `.mont()` is generally faster than
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,7 +50,7 @@
50
50
 
51
51
  var Buffer;
52
52
  try {
53
- Buffer = require('buf' + 'fer').Buffer;
53
+ Buffer = require('buffer').Buffer;
54
54
  } catch (e) {
55
55
  }
56
56
 
@@ -2101,6 +2101,10 @@
2101
2101
 
2102
2102
  assert(this.negative === 0, 'imaskn works only with positive numbers');
2103
2103
 
2104
+ if (this.length <= s) {
2105
+ return this;
2106
+ }
2107
+
2104
2108
  if (r !== 0) {
2105
2109
  s++;
2106
2110
  }
@@ -2968,7 +2972,13 @@
2968
2972
  } else if (cmp > 0) {
2969
2973
  r.isub(this.p);
2970
2974
  } else {
2971
- r.strip();
2975
+ if (r.strip !== undefined) {
2976
+ // r is BN v4 instance
2977
+ r.strip();
2978
+ } else {
2979
+ // r is BN v5 instance
2980
+ r._strip();
2981
+ }
2972
2982
  }
2973
2983
 
2974
2984
  return r;
@@ -3283,7 +3293,7 @@
3283
3293
  };
3284
3294
 
3285
3295
  Red.prototype.pow = function pow (a, num) {
3286
- if (num.isZero()) return new BN(1);
3296
+ if (num.isZero()) return new BN(1).toRed(this);
3287
3297
  if (num.cmpn(1) === 0) return a.clone();
3288
3298
 
3289
3299
  var windowSize = 4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bn.js",
3
- "version": "4.11.5",
3
+ "version": "4.11.9",
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",
package/.npmignore DELETED
@@ -1,6 +0,0 @@
1
- benchmarks/
2
- coverage/
3
- node_modules/
4
- npm-debug.log
5
- 1.js
6
- logo.png
package/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- sudo: false
2
- language: node_js
3
- node_js:
4
- - "0.10"
5
- - "0.12"
6
- - "4"
7
- - "5"
8
- env:
9
- matrix:
10
- - TEST_SUITE=unit
11
- matrix:
12
- include:
13
- - node_js: "4"
14
- env: TEST_SUITE=lint
15
- script: npm run $TEST_SUITE