bn.js 5.2.0 → 5.2.2
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 +11 -5
- package/lib/bn.js +6 -5
- package/package.json +1 -1
- package/CHANGELOG.md +0 -51
package/README.md
CHANGED
|
@@ -21,11 +21,17 @@ console.log(res.toString(10)); // 57047
|
|
|
21
21
|
|
|
22
22
|
**Note**: decimals are not supported in this library.
|
|
23
23
|
|
|
24
|
+
## Sponsors
|
|
25
|
+
|
|
26
|
+
[](https://scoutapm.com/)
|
|
27
|
+
My Open Source work is supported by [Scout APM](https://scoutapm.com/) and
|
|
28
|
+
[other sponsors](https://github.com/sponsors/indutny).
|
|
29
|
+
|
|
24
30
|
## Notation
|
|
25
31
|
|
|
26
32
|
### Prefixes
|
|
27
33
|
|
|
28
|
-
There are several prefixes to instructions that affect the way
|
|
34
|
+
There are several prefixes to instructions that affect the way they work. Here
|
|
29
35
|
is the list of them in the order of appearance in the function name:
|
|
30
36
|
|
|
31
37
|
* `i` - perform operation in-place, storing the result in the host object (on
|
|
@@ -38,7 +44,7 @@ is the list of them in the order of appearance in the function name:
|
|
|
38
44
|
### Postfixes
|
|
39
45
|
|
|
40
46
|
* `n` - the argument of the function must be a plain JavaScript
|
|
41
|
-
Number. Decimals are not supported.
|
|
47
|
+
Number. Decimals are not supported. The number passed must be smaller than 0x4000000 (67_108_864). Otherwise, an error is thrown.
|
|
42
48
|
* `rn` - both argument and return value of the function are plain JavaScript
|
|
43
49
|
Numbers. Decimals are not supported.
|
|
44
50
|
|
|
@@ -50,7 +56,7 @@ is the list of them in the order of appearance in the function name:
|
|
|
50
56
|
|
|
51
57
|
## Instructions
|
|
52
58
|
|
|
53
|
-
Prefixes/postfixes are put in parens at the of the line. `endian` - could be
|
|
59
|
+
Prefixes/postfixes are put in parens at the end of the line. `endian` - could be
|
|
54
60
|
either `le` (little-endian) or `be` (big-endian).
|
|
55
61
|
|
|
56
62
|
### Utilities
|
|
@@ -63,7 +69,7 @@ either `le` (little-endian) or `be` (big-endian).
|
|
|
63
69
|
pad to length, throwing if already exceeding
|
|
64
70
|
* `a.toArrayLike(type, endian, length)` - convert to an instance of `type`,
|
|
65
71
|
which must behave like an `Array`
|
|
66
|
-
* `a.toBuffer(endian, length)` - convert to Node.js Buffer (if available). For
|
|
72
|
+
* `a.toBuffer(endian, length)` - convert to Node.js Buffer (if available). `length` in bytes. For
|
|
67
73
|
compatibility with browserify and similar tools, use this instead:
|
|
68
74
|
`a.toArrayLike(Buffer, endian, length)`
|
|
69
75
|
* `a.bitLength()` - get number of bits occupied
|
|
@@ -129,7 +135,7 @@ for [Mersenne Prime][1].
|
|
|
129
135
|
|
|
130
136
|
### Reduction context
|
|
131
137
|
|
|
132
|
-
To enable this
|
|
138
|
+
To enable this trick one should create a reduction context:
|
|
133
139
|
|
|
134
140
|
```js
|
|
135
141
|
var red = BN.red(num);
|
package/lib/bn.js
CHANGED
|
@@ -480,16 +480,16 @@
|
|
|
480
480
|
var w = this.words[i];
|
|
481
481
|
var word = (((w << off) | carry) & 0xffffff).toString(16);
|
|
482
482
|
carry = (w >>> (24 - off)) & 0xffffff;
|
|
483
|
-
if (carry !== 0 || i !== this.length - 1) {
|
|
484
|
-
out = zeros[6 - word.length] + word + out;
|
|
485
|
-
} else {
|
|
486
|
-
out = word + out;
|
|
487
|
-
}
|
|
488
483
|
off += 2;
|
|
489
484
|
if (off >= 26) {
|
|
490
485
|
off -= 26;
|
|
491
486
|
i--;
|
|
492
487
|
}
|
|
488
|
+
if (carry !== 0 || i !== this.length - 1) {
|
|
489
|
+
out = zeros[6 - word.length] + word + out;
|
|
490
|
+
} else {
|
|
491
|
+
out = word + out;
|
|
492
|
+
}
|
|
493
493
|
}
|
|
494
494
|
if (carry !== 0) {
|
|
495
495
|
out = carry.toString(16) + out;
|
|
@@ -2008,6 +2008,7 @@
|
|
|
2008
2008
|
this.words[i] = carry;
|
|
2009
2009
|
this.length++;
|
|
2010
2010
|
}
|
|
2011
|
+
this.length = num === 0 ? 1 : this.length;
|
|
2011
2012
|
|
|
2012
2013
|
return isNegNum ? this.ineg() : this;
|
|
2013
2014
|
};
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
5.2.0 / 2021-02-23
|
|
2
|
-
------------------
|
|
3
|
-
|
|
4
|
-
- fix: Buffer not using global in browser (#260)
|
|
5
|
-
- Fix LE constructor for HEX (#265)
|
|
6
|
-
|
|
7
|
-
5.1.3 / 2020-08-14
|
|
8
|
-
------------------
|
|
9
|
-
|
|
10
|
-
- Add support for defined but not implemented Symbol.for (#252)
|
|
11
|
-
|
|
12
|
-
5.1.2 / 2020-05-20
|
|
13
|
-
------------------
|
|
14
|
-
|
|
15
|
-
- Fix BN v5/v4 interoperability issue (#249)
|
|
16
|
-
|
|
17
|
-
5.1.1 / 2019-12-24
|
|
18
|
-
------------------
|
|
19
|
-
|
|
20
|
-
- Temporary workaround for BN#_move (#236)
|
|
21
|
-
- Add eslintrc instead config in package.json (#237)
|
|
22
|
-
|
|
23
|
-
5.1.0 / 2019-12-23
|
|
24
|
-
------------------
|
|
25
|
-
|
|
26
|
-
- Benchmark for BigInt (#226)
|
|
27
|
-
- Add documentation for max/min (#232)
|
|
28
|
-
- Update BN#inspect for Symbols (#225)
|
|
29
|
-
- Improve performance of toArrayLike (#222)
|
|
30
|
-
- temporary disable jumboMulTo in BN#mulTo (#221)
|
|
31
|
-
- optimize toBitArray function (#212)
|
|
32
|
-
- fix iaddn sign issue (#216)
|
|
33
|
-
|
|
34
|
-
5.0.0 / 2019-07-04
|
|
35
|
-
------------------
|
|
36
|
-
|
|
37
|
-
- travis: update node versions (#205)
|
|
38
|
-
- Refactor buffer constructor (#200)
|
|
39
|
-
- lib: fix for negative numbers: imuln, modrn, idivn (#185)
|
|
40
|
-
- bn: fix Red#imod (#178)
|
|
41
|
-
- check unexpected high bits for invalid characters (#173)
|
|
42
|
-
- document support very large integers (#158)
|
|
43
|
-
- only define toBuffer if Buffer is defined (#172)
|
|
44
|
-
- lib: better validation of string input (#151)
|
|
45
|
-
- tests: reject decimal input in constructor (#91)
|
|
46
|
-
- bn: make .strip() an internal method (#105)
|
|
47
|
-
- lib: deprecate `.modn()` introduce `.modrn()` (#112 #129 #130)
|
|
48
|
-
- bn: don't accept invalid characters (#141)
|
|
49
|
-
- package: use `files` insteadof `.npmignore` (#152)
|
|
50
|
-
- bn: improve allocation speed for buffers (#167)
|
|
51
|
-
- toJSON to default to interoperable hex (length % 2) (#164)
|