@bsv/sdk 1.5.3 → 1.6.1
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/overlay-tools/LookupResolver.js +0 -4
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +0 -2
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/cjs/src/primitives/AESGCM.js +113 -137
- package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +1019 -3947
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/K256.js +53 -37
- package/dist/cjs/src/primitives/K256.js.map +1 -1
- package/dist/cjs/src/primitives/Mersenne.js +16 -21
- package/dist/cjs/src/primitives/Mersenne.js.map +1 -1
- package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +27 -17
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +618 -858
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/overlay-tools/LookupResolver.js +0 -4
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +0 -2
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/esm/src/primitives/AESGCM.js +112 -137
- package/dist/esm/src/primitives/AESGCM.js.map +1 -1
- package/dist/esm/src/primitives/BigNumber.js +1011 -3969
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/K256.js +53 -37
- package/dist/esm/src/primitives/K256.js.map +1 -1
- package/dist/esm/src/primitives/Mersenne.js +16 -21
- package/dist/esm/src/primitives/Mersenne.js.map +1 -1
- package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -1
- package/dist/esm/src/primitives/utils.js +29 -17
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/script/Spend.js +618 -857
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/overlay-tools/LookupResolver.d.ts +1 -3
- package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +1 -0
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
- package/dist/types/src/primitives/AESGCM.d.ts.map +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts +238 -1705
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/K256.d.ts.map +1 -1
- package/dist/types/src/primitives/Mersenne.d.ts +2 -2
- package/dist/types/src/primitives/Mersenne.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +2 -0
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts +11 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/performance.md +70 -0
- package/docs/primitives.md +262 -3049
- package/package.json +1 -1
- package/src/auth/__tests/Peer.test.ts +38 -23
- package/src/auth/certificates/__tests/MasterCertificate.test.ts +27 -20
- package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +24 -24
- package/src/overlay-tools/LookupResolver.ts +1 -9
- package/src/overlay-tools/SHIPBroadcaster.ts +1 -2
- package/src/overlay-tools/__tests/LookupResolver.test.ts +0 -112
- package/src/primitives/AESGCM.ts +118 -164
- package/src/primitives/BigNumber.ts +867 -4180
- package/src/primitives/K256.ts +57 -37
- package/src/primitives/Mersenne.ts +16 -20
- package/src/primitives/MontgomoryMethod.ts +2 -2
- package/src/primitives/__tests/ReductionContext.test.ts +6 -1
- package/src/primitives/utils.ts +28 -17
- package/src/script/Spend.ts +634 -1309
- package/src/transaction/__tests/Transaction.test.ts +14 -16
- package/src/transaction/__tests/Transaction.benchmarks.test.ts +0 -237
|
@@ -28,1726 +28,276 @@ export default class BigNumber {
|
|
|
28
28
|
* console.log(BigNumber.wordSize); // output: 26
|
|
29
29
|
*/
|
|
30
30
|
static readonly wordSize: number;
|
|
31
|
+
private static readonly WORD_SIZE_BIGINT;
|
|
32
|
+
private static readonly WORD_MASK;
|
|
33
|
+
private static readonly MAX_SAFE_INTEGER_BIGINT;
|
|
34
|
+
private static readonly MIN_SAFE_INTEGER_BIGINT;
|
|
35
|
+
private static readonly MAX_IMULN_ARG;
|
|
36
|
+
private static readonly MAX_NUMBER_CONSTRUCTOR_MAG_BIGINT;
|
|
37
|
+
private _magnitude;
|
|
38
|
+
private _sign;
|
|
39
|
+
private _nominalWordLength;
|
|
31
40
|
/**
|
|
32
|
-
*
|
|
33
|
-
* - If 0, the number is positive.
|
|
34
|
-
* - If 1, the number is negative.
|
|
35
|
-
*
|
|
36
|
-
* @property negative
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* let num = new BigNumber("-10");
|
|
40
|
-
* console.log(num.negative); // output: 1
|
|
41
|
-
*/
|
|
42
|
-
negative: number;
|
|
43
|
-
/**
|
|
44
|
-
* Array of numbers, where each number represents a part of the value of the big number.
|
|
45
|
-
*
|
|
46
|
-
* @property words
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* let num = new BigNumber(50000);
|
|
50
|
-
* console.log(num.words); // output: [ 50000 ]
|
|
51
|
-
*/
|
|
52
|
-
words: number[];
|
|
53
|
-
/**
|
|
54
|
-
* Length of the words array.
|
|
55
|
-
*
|
|
56
|
-
* @property length
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* let num = new BigNumber(50000);
|
|
60
|
-
* console.log(num.length); // output: 1
|
|
61
|
-
*/
|
|
62
|
-
length: number;
|
|
63
|
-
/**
|
|
64
|
-
* Reduction context of the big number.
|
|
65
|
-
*
|
|
66
|
-
* @property red
|
|
67
|
-
*/
|
|
68
|
-
red: ReductionContext | null;
|
|
69
|
-
/**
|
|
70
|
-
* Checks whether a value is an instance of BigNumber. If not, then checks the features of the input to determine potential compatibility. Regular JS numbers fail this check.
|
|
71
|
-
*
|
|
72
|
-
* @method isBN
|
|
73
|
-
* @param num - The value to be checked.
|
|
74
|
-
* @returns - Returns a boolean value determining whether or not the checked num parameter is a BigNumber.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* const validNum = new BigNumber(5);
|
|
78
|
-
* BigNumber.isBN(validNum); // returns true
|
|
79
|
-
*
|
|
80
|
-
* const invalidNum = 5;
|
|
81
|
-
* BigNumber.isBN(invalidNum); // returns false
|
|
82
|
-
*/
|
|
83
|
-
static isBN(num: any): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Returns the bigger value between two BigNumbers
|
|
86
|
-
*
|
|
87
|
-
* @method max
|
|
88
|
-
* @param left - The first BigNumber to be compared.
|
|
89
|
-
* @param right - The second BigNumber to be compared.
|
|
90
|
-
* @returns - Returns the bigger BigNumber between left and right.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* const bn1 = new BigNumber(5);
|
|
94
|
-
* const bn2 = new BigNumber(10);
|
|
95
|
-
* BigNumber.max(bn1, bn2); // returns bn2
|
|
96
|
-
*/
|
|
97
|
-
static max(left: BigNumber, right: BigNumber): BigNumber;
|
|
98
|
-
/**
|
|
99
|
-
* Returns the smaller value between two BigNumbers
|
|
100
|
-
*
|
|
101
|
-
* @method min
|
|
102
|
-
* @param left - The first BigNumber to be compared.
|
|
103
|
-
* @param right - The second BigNumber to be compared.
|
|
104
|
-
* @returns - Returns the smaller value between left and right.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* const bn1 = new BigNumber(5);
|
|
108
|
-
* const bn2 = new BigNumber(10);
|
|
109
|
-
* BigNumber.min(bn1, bn2); // returns bn1
|
|
110
|
-
*/
|
|
111
|
-
static min(left: BigNumber, right: BigNumber): BigNumber;
|
|
112
|
-
/**
|
|
113
|
-
* @constructor
|
|
114
|
-
*
|
|
115
|
-
* @param number - The number (various types accepted) to construct a BigNumber from. Default is 0.
|
|
116
|
-
*
|
|
117
|
-
* @param base - The base of number provided. By default is 10.
|
|
118
|
-
*
|
|
119
|
-
* @param endian - The endianness provided. By default is 'big endian'.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* import BigNumber from './BigNumber';
|
|
123
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
124
|
-
*/
|
|
125
|
-
constructor(number?: number | string | number[], base?: number | 'be' | 'le' | 'hex', endian?: 'be' | 'le');
|
|
126
|
-
/**
|
|
127
|
-
* Asserts that a certain condition is true. If it is not, throws an error with the provided message.
|
|
128
|
-
*
|
|
129
|
-
* @method assert
|
|
130
|
-
* @private
|
|
131
|
-
* @param val - The condition to be checked.
|
|
132
|
-
* @param msg - The error message to throw if the condition is not satisfied. Default is 'Assertion failed'.
|
|
133
|
-
*/
|
|
134
|
-
private assert;
|
|
135
|
-
/**
|
|
136
|
-
* Function to initialize a BigNumber from a regular number. It also determines if the number is negative and sets the negative property accordingly.
|
|
137
|
-
* If the endianness provided is little endian ('le'), it reverses the bytes.
|
|
138
|
-
*
|
|
139
|
-
* @method initNumber
|
|
140
|
-
* @private
|
|
141
|
-
* @param number - The number to initialize the BigNumber from.
|
|
142
|
-
* @param base - The base of the number provided.
|
|
143
|
-
* @param endian - The endianness ('be' for big-endian, 'le' for little-endian).
|
|
144
|
-
* @returns The current BigNumber instance.
|
|
145
|
-
*/
|
|
146
|
-
private initNumber;
|
|
147
|
-
/**
|
|
148
|
-
* Creates a new BigNumber from the provided number array and initializes it based on the base and endian provided.
|
|
149
|
-
*
|
|
150
|
-
* @method initArray
|
|
151
|
-
* @private
|
|
152
|
-
* @param number - The array of numbers to initialize the BigNumber from. Each number represents a part of the value of the big number.
|
|
153
|
-
* @param endian - The endianness ('be' for big-endian, 'le' for little-endian).
|
|
154
|
-
* @return The current BigNumber instance.
|
|
155
|
-
*/
|
|
156
|
-
private initArray;
|
|
157
|
-
/**
|
|
158
|
-
* Function to extract the 4-bit number from a hexadecimal character
|
|
159
|
-
*
|
|
160
|
-
* @method parseHex4Bits
|
|
161
|
-
* @private
|
|
162
|
-
* @param string - The string containing the hexadecimal character.
|
|
163
|
-
* @param index - The index of the hexadecimal character in the string.
|
|
164
|
-
* @return The decimal value corresponding to the hexadecimal character.
|
|
165
|
-
*/
|
|
166
|
-
private parseHex4Bits;
|
|
167
|
-
/**
|
|
168
|
-
* Function to extract the 8-bit number from two hexadecimal characters
|
|
169
|
-
*
|
|
170
|
-
* @method parseHexByte
|
|
171
|
-
* @private
|
|
172
|
-
* @param string - The string containing the hexadecimal characters.
|
|
173
|
-
* @param lowerBound - The lower bound of the index to start parsing from.
|
|
174
|
-
* @param index - The index of the second hexadecimal character in the string.
|
|
175
|
-
* @return The decimal value corresponding to the two hexadecimal characters.
|
|
176
|
-
*/
|
|
177
|
-
private parseHexByte;
|
|
178
|
-
/**
|
|
179
|
-
* Function to parse and convert a specific string portion into a big number in hexadecimal base.
|
|
180
|
-
*
|
|
181
|
-
* @method parseHex
|
|
182
|
-
* @private
|
|
183
|
-
* @param number - The string to parse.
|
|
184
|
-
* @param start - The index to start parsing from.
|
|
185
|
-
* @param endian - The endianness ('be', 'le').
|
|
186
|
-
* @return The current BigNumber instance.
|
|
187
|
-
*/
|
|
188
|
-
private parseHex;
|
|
189
|
-
/**
|
|
190
|
-
* Function to convert a particular string portion into a base word.
|
|
191
|
-
*
|
|
192
|
-
* @method parseBaseWord
|
|
193
|
-
* @private
|
|
194
|
-
* @param str - The string to parse.
|
|
195
|
-
* @param start - The index to start parsing from.
|
|
196
|
-
* @param end - The index to stop parsing at.
|
|
197
|
-
* @param mul - The base to be used for the conversion.
|
|
198
|
-
* @return The decimal value of the parsed base word.
|
|
199
|
-
*/
|
|
200
|
-
private parseBaseWord;
|
|
201
|
-
/**
|
|
202
|
-
* Function to convert a string into a big number in a specific base.
|
|
203
|
-
*
|
|
204
|
-
* @method parseBase
|
|
205
|
-
* @private
|
|
206
|
-
* @param number - The string to be converted into a big number.
|
|
207
|
-
* @param base - The base to be used for conversion.
|
|
208
|
-
* @param start - The index to start conversion from.
|
|
209
|
-
* @return The current BigNumber instance.
|
|
210
|
-
*/
|
|
211
|
-
private parseBase;
|
|
212
|
-
/**
|
|
213
|
-
* The copy method copies the state of this BigNumber into an exsiting `dest` BigNumber.
|
|
214
|
-
*
|
|
215
|
-
* @method copy
|
|
216
|
-
* @param dest - The BigNumber instance that will be updated to become a copy.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* const bn1 = new BigNumber('123456', 10, 'be');
|
|
220
|
-
* const bn2 = new BigNumber();
|
|
221
|
-
* bn1.copy(bn2);
|
|
222
|
-
* // bn2 is now a BigNumber representing 123456
|
|
223
|
-
*/
|
|
224
|
-
copy(dest: BigNumber): void;
|
|
225
|
-
/**
|
|
226
|
-
*
|
|
227
|
-
* Directly transfers the attributes of the source BigNumber to the destination BigNumber.
|
|
228
|
-
*
|
|
229
|
-
* @method move
|
|
230
|
-
* @param dest - The BigNumber that attributes will be moved into.
|
|
231
|
-
* @param src - The BigNumber that attributes will be moved from.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* const src = new BigNumber('123456', 10, 'be');
|
|
235
|
-
* const dest = new BigNumber();
|
|
236
|
-
* BigNumber.move(dest, src);
|
|
237
|
-
* // dest is now a BigNumber representing 123456
|
|
238
|
-
*/
|
|
239
|
-
static move(dest: BigNumber, src: BigNumber): void;
|
|
240
|
-
/**
|
|
241
|
-
* Creates a copy of the current BigNumber instance.
|
|
242
|
-
*
|
|
243
|
-
* @method clone
|
|
244
|
-
* @returns A new BigNumber instance, identical to the original.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
248
|
-
* const bnClone = bn.clone();
|
|
249
|
-
*/
|
|
250
|
-
clone(): BigNumber;
|
|
251
|
-
/**
|
|
252
|
-
* Increases the BigNumber length up to a certain size and initializes new elements with 0.
|
|
253
|
-
*
|
|
254
|
-
* @method expand
|
|
255
|
-
* @param {number} size - The desired size to grow the BigNumber length.
|
|
256
|
-
* @returns The BigNumber instance after expansion.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
260
|
-
* bn.expand(10);
|
|
261
|
-
*/
|
|
262
|
-
expand(size: number): this;
|
|
263
|
-
/**
|
|
264
|
-
* Removes leading zeros.
|
|
265
|
-
*
|
|
266
|
-
* @method strip
|
|
267
|
-
* @returns - Returns the BigNumber after stripping leading zeros.
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* const bn = new BigNumber("000000", 2, "be");
|
|
271
|
-
* bn.strip();
|
|
272
|
-
* // bn now represents 0
|
|
273
|
-
*/
|
|
274
|
-
strip(): this;
|
|
275
|
-
/**
|
|
276
|
-
* Normalizes the sign of the BigNumber. Changes -0 to 0.
|
|
277
|
-
*
|
|
278
|
-
* @method normSign
|
|
279
|
-
* @returns The normalized BigNumber instance.
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* const bn = new BigNumber('-0', 10, 'be');
|
|
283
|
-
* bn.normSign();
|
|
284
|
-
*/
|
|
285
|
-
normSign(): this;
|
|
286
|
-
/**
|
|
287
|
-
* Utility for inspecting the current BigNumber instance. Accompanied with a prefix '<BN: ' or '<BN-R: '.
|
|
288
|
-
*
|
|
289
|
-
* @method inspect
|
|
290
|
-
* @returns A string representation to inspect the BigNumber instance.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
294
|
-
* bn.inspect();
|
|
295
|
-
*/
|
|
296
|
-
inspect(): string;
|
|
297
|
-
/**
|
|
298
|
-
* Converts the BigNumber instance to a string representation.
|
|
299
|
-
*
|
|
300
|
-
* @method toString
|
|
301
|
-
* @param base - The base for representing number. Default is 10. Other accepted values are 16 and 'hex'.
|
|
302
|
-
* @param padding - Represents the minimum number of digits to represent the BigNumber as a string. Default is 1.
|
|
303
|
-
* @throws If base is not between 2 and 36.
|
|
304
|
-
* @returns The string representation of the BigNumber instance
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
308
|
-
* bn.toString(16); // Converts the BigNumber to a hexadecimal string.
|
|
309
|
-
*/
|
|
310
|
-
toString(base?: number | 'hex', padding?: number): string;
|
|
311
|
-
private toHexString;
|
|
312
|
-
private toBaseString;
|
|
313
|
-
/**
|
|
314
|
-
* Converts the BigNumber instance to a JavaScript number.
|
|
315
|
-
* Please note that JavaScript numbers are only precise up to 53 bits.
|
|
316
|
-
*
|
|
317
|
-
* @method toNumber
|
|
318
|
-
* @throws If the BigNumber instance cannot be safely stored in a JavaScript number
|
|
319
|
-
* @returns The JavaScript number representation of the BigNumber instance.
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
323
|
-
* bn.toNumber();
|
|
324
|
-
*/
|
|
325
|
-
toNumber(): number;
|
|
326
|
-
/**
|
|
327
|
-
* Converts the BigNumber instance to a JSON-formatted string.
|
|
328
|
-
*
|
|
329
|
-
* @method toJSON
|
|
330
|
-
* @returns The JSON string representation of the BigNumber instance.
|
|
331
|
-
*
|
|
332
|
-
* @example
|
|
333
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
334
|
-
* bn.toJSON();
|
|
335
|
-
*/
|
|
336
|
-
toJSON(): string;
|
|
337
|
-
/**
|
|
338
|
-
* An internal method to format the BigNumber instance into ArrayTypes of Little Endian Type.
|
|
339
|
-
* This is a private method.
|
|
340
|
-
*
|
|
341
|
-
* @method toArrayLikeLE
|
|
342
|
-
* @private
|
|
343
|
-
* @param res - The resultant ArrayType instance
|
|
344
|
-
* @param byteLength - The byte length to define the size of ArrayType
|
|
345
|
-
*/
|
|
346
|
-
private toArrayLikeLE;
|
|
347
|
-
/**
|
|
348
|
-
* An internal method to format the BigNumber instance into ArrayTypes of Big Endian Type.
|
|
349
|
-
* This is a private method.
|
|
350
|
-
*
|
|
351
|
-
* @method toArrayLikeBE
|
|
352
|
-
* @private
|
|
353
|
-
* @param res - The resultant ArrayType instance
|
|
354
|
-
* @param byteLength - The byte length to define the size of ArrayType
|
|
355
|
-
*/
|
|
356
|
-
private toArrayLikeBE;
|
|
357
|
-
/**
|
|
358
|
-
* Converts the BigNumber instance to a JavaScript number array.
|
|
359
|
-
*
|
|
360
|
-
* @method toArray
|
|
361
|
-
* @param endian - The endian for converting BigNumber to array. Default value is 'be'.
|
|
362
|
-
* @param length - The length for the resultant array. Default value is undefined.
|
|
363
|
-
* @returns The JavaScript array representation of the BigNumber instance.
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* const bn = new BigNumber('123456', 10, 'be');
|
|
367
|
-
* bn.toArray('be', 8);
|
|
368
|
-
*/
|
|
369
|
-
toArray(endian?: 'le' | 'be', length?: number): number[];
|
|
370
|
-
/**
|
|
371
|
-
* A utility method to count the word bits.
|
|
372
|
-
* This is a private method.
|
|
373
|
-
*
|
|
374
|
-
* @method countWordBits
|
|
375
|
-
* @private
|
|
376
|
-
* @param w - The input number to count the word bits.
|
|
377
|
-
* @returns The number of word bits
|
|
378
|
-
*/
|
|
379
|
-
private countWordBits;
|
|
380
|
-
/**
|
|
381
|
-
* A utility method to compute the number of zero bits.
|
|
382
|
-
* This is a private method.
|
|
383
|
-
*
|
|
384
|
-
* @method zeroWordBits
|
|
385
|
-
* @private
|
|
386
|
-
* @param w - The input number to count the zero bits.
|
|
387
|
-
* @returns The number of zero bits
|
|
388
|
-
*/
|
|
389
|
-
private zeroWordBits;
|
|
390
|
-
/**
|
|
391
|
-
* Returns the number of used bits in this big number.
|
|
392
|
-
*
|
|
393
|
-
* @method bitLength
|
|
394
|
-
* @returns The number of used bits
|
|
395
|
-
*/
|
|
396
|
-
bitLength(): number;
|
|
397
|
-
/**
|
|
398
|
-
* Convert a big number to a boolean array representing
|
|
399
|
-
* a binary number, where each array index is a bit.
|
|
400
|
-
* @static
|
|
401
|
-
* @method toBitArray
|
|
402
|
-
* @param num - The big number to convert.
|
|
403
|
-
* @returns Returns an array of booleans representing
|
|
404
|
-
* a binary number, with each array index being a bit.
|
|
405
|
-
* @example
|
|
406
|
-
* const BigNumber = require("./BigNumber");
|
|
407
|
-
* const bn = new BigNumber('6'); // binary: 110
|
|
408
|
-
* const bits = BigNumber.toBitArray(bn); // [1,1,0]
|
|
409
|
-
*/
|
|
410
|
-
static toBitArray(num: BigNumber): Array<0 | 1>;
|
|
411
|
-
/**
|
|
412
|
-
* Convert this big number to a boolean array representing
|
|
413
|
-
* a binary number, where each array index is a bit.
|
|
414
|
-
* @method toBitArray
|
|
415
|
-
* @returns Returns an array of booleans representing a binary number.
|
|
416
|
-
*
|
|
417
|
-
* @example
|
|
418
|
-
* const BigNumber = require("./BigNumber");
|
|
419
|
-
* const bn = new BigNumber('6'); // binary: 110
|
|
420
|
-
* const bits = bn.toBitArray(); // [ 1, 1, 0 ]
|
|
421
|
-
*/
|
|
422
|
-
toBitArray(): Array<0 | 1>;
|
|
423
|
-
/**
|
|
424
|
-
* Returns the number of trailing zero bits in the big number.
|
|
425
|
-
* @method zeroBits
|
|
426
|
-
* @returns Returns the number of trailing zero bits
|
|
427
|
-
* in the binary representation of the big number.
|
|
428
|
-
* @example
|
|
429
|
-
* const BigNumber = require("./BigNumber");
|
|
430
|
-
* const bn = new BigNumber('8'); // binary: 1000
|
|
431
|
-
* const zeroBits = bn.zeroBits(); // 3
|
|
432
|
-
*/
|
|
433
|
-
zeroBits(): number;
|
|
434
|
-
/**
|
|
435
|
-
* Get the byte length of the BigNumber
|
|
436
|
-
*
|
|
437
|
-
* @method byteLength
|
|
438
|
-
* @returns Returns the byte length of the big number.
|
|
439
|
-
* @example
|
|
440
|
-
* const BigNumber = require("./BigNumber");
|
|
441
|
-
* const bn = new BigNumber('1234');
|
|
442
|
-
* const byteLen = bn.byteLength();
|
|
443
|
-
*/
|
|
444
|
-
byteLength(): number;
|
|
445
|
-
/**
|
|
446
|
-
* Converts this big number to two's complement with a specified bit width.
|
|
447
|
-
* @method toTwos
|
|
448
|
-
* @param width - The bit width.
|
|
449
|
-
* @returns Returns the two's complement of the big number.
|
|
450
|
-
*
|
|
451
|
-
* @example
|
|
452
|
-
* const BigNumber = require("./BigNumber");
|
|
453
|
-
* const bn = new BigNumber('-1234');
|
|
454
|
-
* const twosComp = bn.toTwos(16);
|
|
455
|
-
*/
|
|
456
|
-
toTwos(width: number): BigNumber;
|
|
457
|
-
/**
|
|
458
|
-
* Converts this big number from two's complement with a specified bit width.
|
|
459
|
-
* @method fromTwos
|
|
460
|
-
* @param width - The bit width.
|
|
461
|
-
* @returns Returns the big number converted from two's complement.
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* const BigNumber = require("./BigNumber");
|
|
465
|
-
* const bn = new BigNumber('-1234');
|
|
466
|
-
* const fromTwos = bn.fromTwos(16);
|
|
467
|
-
*/
|
|
468
|
-
fromTwos(width: number): BigNumber;
|
|
469
|
-
/**
|
|
470
|
-
* Checks if the big number is negative.
|
|
471
|
-
* @method isNeg
|
|
472
|
-
* @returns Returns true if the big number is negative, otherwise false.
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* const BigNumber = require("./BigNumber");
|
|
476
|
-
* const bn = new BigNumber('-1234');
|
|
477
|
-
* const isNegative = bn.isNeg(); // true
|
|
478
|
-
*/
|
|
479
|
-
isNeg(): boolean;
|
|
480
|
-
/**
|
|
481
|
-
* Negates the big number and returns a new instance.
|
|
482
|
-
* @method neg
|
|
483
|
-
* @returns Returns a new BigNumber that is the negation of this big number.
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* const BigNumber = require("./BigNumber");
|
|
487
|
-
* const bn = new BigNumber('1234');
|
|
488
|
-
* const neg = bn.neg(); // -1234
|
|
489
|
-
*/
|
|
490
|
-
neg(): BigNumber;
|
|
491
|
-
/**
|
|
492
|
-
* Negates the big number in-place.
|
|
493
|
-
* @method ineg
|
|
494
|
-
* @returns Returns this big number as the negation of itself.
|
|
495
|
-
*
|
|
496
|
-
* @example
|
|
497
|
-
* const BigNumber = require("./BigNumber");
|
|
498
|
-
* const bn = new BigNumber('1234');
|
|
499
|
-
* bn.ineg(); // bn is now -1234
|
|
500
|
-
*/
|
|
501
|
-
ineg(): BigNumber;
|
|
502
|
-
/**
|
|
503
|
-
* Performs a bitwise OR operation with another BigNumber and stores
|
|
504
|
-
* the result in this BigNumber.
|
|
505
|
-
* @method iuor
|
|
506
|
-
* @param num - The other BigNumber.
|
|
507
|
-
* @returns Returns this BigNumber after performing the bitwise OR operation.
|
|
508
|
-
*
|
|
509
|
-
* @example
|
|
510
|
-
* const BigNumber = require("./BigNumber");
|
|
511
|
-
* const bn1 = new BigNumber('10'); // binary: 1010
|
|
512
|
-
* const bn2 = new(num: BigNumber): BigNumber BigNumber('6'); // binary: 0110
|
|
513
|
-
* bn1.iuor(bn2); // now, bn1 binary: 1110
|
|
514
|
-
*/
|
|
515
|
-
iuor(num: BigNumber): BigNumber;
|
|
516
|
-
/**
|
|
517
|
-
* Performs a bitwise OR operation with another BigNumber, considering
|
|
518
|
-
* that neither of the numbers can be negative. Stores the result in this BigNumber.
|
|
519
|
-
* @method ior
|
|
520
|
-
* @param num - The other BigNumber.
|
|
521
|
-
* @returns Returns this BigNumber after performing the bitwise OR operation.
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* const BigNumber = require("./BigNumber");
|
|
525
|
-
* const bn1 = new BigNumber('10'); // binary: 1010
|
|
526
|
-
* const bn2 = new BigNumber('6'); // binary: 0110
|
|
527
|
-
* bn1.ior(bn2); // now, bn1 binary: 1110
|
|
528
|
-
*/
|
|
529
|
-
ior(num: BigNumber): BigNumber;
|
|
530
|
-
/**
|
|
531
|
-
* Performs a bitwise OR operation on the current instance and given
|
|
532
|
-
* BigNumber and returns a new BigNumber, in such a way that if either
|
|
533
|
-
* the corresponding bit in the first operand or the second operand is
|
|
534
|
-
* 1, then the output is also 1.
|
|
535
|
-
*
|
|
536
|
-
* @method or
|
|
537
|
-
* @param num - The BigNumber to perform the bitwise OR operation with.
|
|
538
|
-
* @returns Returns a new BigNumber resulting from the bitwise OR operation.
|
|
539
|
-
*
|
|
540
|
-
* @example
|
|
541
|
-
* const num1 = new BigNumber('10');
|
|
542
|
-
* const num2 = new BigNumber('20');
|
|
543
|
-
* console.log(num1.or(num2).toString());
|
|
544
|
-
*/
|
|
545
|
-
or(num: BigNumber): BigNumber;
|
|
546
|
-
/**
|
|
547
|
-
* Performs a bitwise OR operation on the current instance and given
|
|
548
|
-
* BigNumber without considering signed bit(no negative values) and returns a new BigNumber,
|
|
549
|
-
* similar to the `or` method.
|
|
550
|
-
*
|
|
551
|
-
* @method uor
|
|
552
|
-
* @param num - The BigNumber to perform the bitwise OR operation with.
|
|
553
|
-
* @returns Returns a new BigNumber resulting from the bitwise OR operation without sign consideration.
|
|
554
|
-
*
|
|
555
|
-
* @example
|
|
556
|
-
* const num1 = new BigNumber('10');
|
|
557
|
-
* const num2 = new BigNumber('20');
|
|
558
|
-
* console.log(num1.uor(num2).toString());
|
|
559
|
-
*/
|
|
560
|
-
uor(num: BigNumber): BigNumber;
|
|
561
|
-
/**
|
|
562
|
-
* Performs a bitwise AND operation in-place(this method changes the calling object)
|
|
563
|
-
* on the current instance and given BigNumber such that it modifies the current
|
|
564
|
-
* instance and keeps the bits set in the result only if the corresponding bit is set
|
|
565
|
-
* in both operands.
|
|
566
|
-
*
|
|
567
|
-
* @method iuand
|
|
568
|
-
* @param num - The BigNumber to perform the bitwise AND operation with.
|
|
569
|
-
* @returns Returns the current BigNumber instance after performing the bitwise AND operation.
|
|
570
|
-
*
|
|
571
|
-
* @example
|
|
572
|
-
* const num1 = new BigNumber('10');
|
|
573
|
-
* const num2 = new BigNumber('20');
|
|
574
|
-
* console.log(num1.iuand(num2).toString());
|
|
575
|
-
*/
|
|
576
|
-
iuand(num: BigNumber): BigNumber;
|
|
577
|
-
/**
|
|
578
|
-
* Performs an in-place operation that does a bitwise AND operation in-place,
|
|
579
|
-
* on the current instance and given BigNumber such that it modifies the current
|
|
580
|
-
* instance only if neither operand is negative. This method is similar to the iuand method but
|
|
581
|
-
* checks for negative values before operation.
|
|
582
|
-
*
|
|
583
|
-
* @method iand
|
|
584
|
-
* @param num - The BigNumber to perform the bitwise AND operation with.
|
|
585
|
-
* @returns Returns the current BigNumber instance after performing the bitwise AND operation.
|
|
586
|
-
*
|
|
587
|
-
* @example
|
|
588
|
-
* const num1 = new BigNumber('10');
|
|
589
|
-
* const num2 = new BigNumber('20');
|
|
590
|
-
* console.log(num1.iand(num2).toString());
|
|
591
|
-
*/
|
|
592
|
-
iand(num: BigNumber): BigNumber;
|
|
593
|
-
/**
|
|
594
|
-
* Performs a bitwise AND operation that returns a new BigNumber, and keeps the bits
|
|
595
|
-
* set in the result only if the corresponding bit is set in both operands.
|
|
596
|
-
*
|
|
597
|
-
* @method and
|
|
598
|
-
* @param num - The BigNumber to perform the bitwise AND operation with.
|
|
599
|
-
* @returns Returns new BigNumber resulting from the bitwise AND operation.
|
|
600
|
-
*
|
|
601
|
-
* @example
|
|
602
|
-
* const num1 = new BigNumber('10');
|
|
603
|
-
* const num2 = new BigNumber('20');
|
|
604
|
-
* console.log(num1.and(num2).toString());
|
|
605
|
-
*/
|
|
606
|
-
and(num: BigNumber): BigNumber;
|
|
607
|
-
/**
|
|
608
|
-
* Performs a bitwise AND operation without considering signed bit
|
|
609
|
-
* (no negative values) which returns a new BigNumber, similar to the `and` method.
|
|
610
|
-
*
|
|
611
|
-
* @method uand
|
|
612
|
-
* @param num - The BigNumber to perform the bitwise AND operation with.
|
|
613
|
-
* @returns Returns new BigNumber resulting from the bitwise AND operation without sign consideration.
|
|
614
|
-
*
|
|
615
|
-
* @example
|
|
616
|
-
* const num1 = new BigNumber('10');
|
|
617
|
-
* const num2 = new BigNumber('20');
|
|
618
|
-
* console.log(num1.uand(num2).toString());
|
|
619
|
-
*/
|
|
620
|
-
uand(num: BigNumber): BigNumber;
|
|
621
|
-
/**
|
|
622
|
-
* Modifies the current instance by performing a bitwise XOR operation
|
|
623
|
-
* in-place with the provided BigNumber. It keeps the bits set in the result only if the
|
|
624
|
-
* corresponding bits in the operands are different.
|
|
625
|
-
*
|
|
626
|
-
* @method iuxor
|
|
627
|
-
* @param num - The BigNumber to perform the bitwise XOR operation with.
|
|
628
|
-
* @returns Returns the current BigNumber instance after performing the bitwise XOR operation.
|
|
629
|
-
*
|
|
630
|
-
* @example
|
|
631
|
-
* const num1 = new BigNumber('10');
|
|
632
|
-
* const num2 = new BigNumber('20');
|
|
633
|
-
* console.log(num1.iuxor(num2).toString());
|
|
634
|
-
*/
|
|
635
|
-
iuxor(num: BigNumber): this;
|
|
636
|
-
/**
|
|
637
|
-
* Performs an in-place operation that does a bitwise XOR operation in-place,
|
|
638
|
-
* on the current instance and given BigNumber such that it modifies the current
|
|
639
|
-
* instance only if neither operand is negative. This method is similar to the iuxor method but
|
|
640
|
-
* checks for negative values before operation.
|
|
641
|
-
*
|
|
642
|
-
* @method ixor
|
|
643
|
-
* @param num - The BigNumber to perform the bitwise XOR operation with.
|
|
644
|
-
* @returns Returns the current BigNumber instance after performing the bitwise XOR operation.
|
|
645
|
-
*
|
|
646
|
-
* @example
|
|
647
|
-
* const num1 = new BigNumber('10');
|
|
648
|
-
* const num2 = new BigNumber('20');
|
|
649
|
-
* console.log(num1.ixor(num2).toString());
|
|
650
|
-
*/
|
|
651
|
-
ixor(num: BigNumber): this;
|
|
652
|
-
/**
|
|
653
|
-
* Performs a bitwise XOR operation which returns a new BigNumber, and keeps the bits
|
|
654
|
-
* set in the result only if the corresponding bits in the operands are different.
|
|
655
|
-
*
|
|
656
|
-
* @method xor
|
|
657
|
-
* @param num - The BigNumber to perform the bitwise XOR operation with.
|
|
658
|
-
* @returns Returns a new BigNumber resulting from the bitwise XOR operation.
|
|
659
|
-
*
|
|
660
|
-
* @example
|
|
661
|
-
* const num1 = new BigNumber('10');
|
|
662
|
-
* const num2 = new BigNumber('20');
|
|
663
|
-
* console.log(num1.xor(num2).toString());
|
|
664
|
-
*/
|
|
665
|
-
xor(num: BigNumber): BigNumber;
|
|
666
|
-
/**
|
|
667
|
-
* Performs an unsigned XOR operation on this BigNumber with the supplied BigNumber. Returns a new BigNumber.
|
|
668
|
-
*
|
|
669
|
-
* @method uxor
|
|
670
|
-
* @param num - The BigNumber with which the unsigned bitwise XOR operation is to be performed.
|
|
671
|
-
* @returns Returns a new BigNumber resulting from the unsigned bitwise XOR operation.
|
|
672
|
-
*
|
|
673
|
-
* @example
|
|
674
|
-
* const num1 = new BigNumber('30');
|
|
675
|
-
* const num2 = new BigNumber('40');
|
|
676
|
-
* console.log(num1.uxor(num2).toString()); // Output will be the result of unsigned XOR operation
|
|
677
|
-
*/
|
|
678
|
-
uxor(num: BigNumber): BigNumber;
|
|
679
|
-
/**
|
|
680
|
-
* In-place method that performs a bitwise NOT operation on a BigNumber up to a specified bit width.
|
|
681
|
-
*
|
|
682
|
-
* @method inotn
|
|
683
|
-
* @param width - The number of bits to perform the NOT operation on.
|
|
684
|
-
* @returns Returns the BigNumber after performing the bitwise NOT operation.
|
|
685
|
-
*
|
|
686
|
-
* @example
|
|
687
|
-
* const num = new BigNumber('42');
|
|
688
|
-
* num.inotn(10);
|
|
689
|
-
* console.log(num.toString());
|
|
690
|
-
*/
|
|
691
|
-
inotn(width: number): BigNumber;
|
|
692
|
-
/**
|
|
693
|
-
* Performs a bitwise NOT operation on a BigNumber up to a specified bit width. Returns a new BigNumber.
|
|
694
|
-
*
|
|
695
|
-
* @method notn
|
|
696
|
-
* @param width - The number of bits to perform the NOT operation on.
|
|
697
|
-
* @returns Returns a new BigNumber resulting from the bitwise NOT operation.
|
|
698
|
-
*
|
|
699
|
-
* @example
|
|
700
|
-
* const num = new BigNumber('42');
|
|
701
|
-
* const notnResult = num.notn(10);
|
|
702
|
-
* console.log(notnResult.toString());
|
|
703
|
-
*/
|
|
704
|
-
notn(width: number): BigNumber;
|
|
705
|
-
/**
|
|
706
|
-
* Set `bit` of `this` BigNumber. The `bit` is a position in the binary representation,
|
|
707
|
-
* and `val` is the value to be set at that position (`0` or `1`).
|
|
708
|
-
*
|
|
709
|
-
* @method setn
|
|
710
|
-
* @param bit - The bit position to set.
|
|
711
|
-
* @param val - The value to set at the bit position.
|
|
712
|
-
* @returns Returns the BigNumber after setting the value at the bit position.
|
|
713
|
-
*
|
|
714
|
-
* @example
|
|
715
|
-
* const num = new BigNumber('42');
|
|
716
|
-
* num.setn(2, 1);
|
|
717
|
-
* console.log(num.toString());
|
|
718
|
-
*/
|
|
719
|
-
setn(bit: number, val: 0 | 1 | true | false): this;
|
|
720
|
-
/**
|
|
721
|
-
* Add `num` to `this` BigNumber in-place.
|
|
722
|
-
*
|
|
723
|
-
* @method iadd
|
|
724
|
-
* @param num - The BigNumber to add to `this` BigNumber.
|
|
725
|
-
* @returns Returns the BigNumber after performing the addition.
|
|
726
|
-
*
|
|
727
|
-
* @example
|
|
728
|
-
* const num1 = new BigNumber('10');
|
|
729
|
-
* num1.iadd(new BigNumber('20'));
|
|
730
|
-
* console.log(num1.toString());
|
|
731
|
-
*/
|
|
732
|
-
iadd(num: BigNumber): this;
|
|
733
|
-
/**
|
|
734
|
-
* Add `num` to `this` BigNumber.
|
|
735
|
-
*
|
|
736
|
-
* @method add
|
|
737
|
-
* @param num - The BigNumber to add to `this` BigNumber.
|
|
738
|
-
* @returns Returns a new BigNumber which is the result of the addition.
|
|
739
|
-
*
|
|
740
|
-
* @example
|
|
741
|
-
* const num1 = new BigNumber('10');
|
|
742
|
-
* const addResult = num1.add(new BigNumber('20'));
|
|
743
|
-
* console.log(addResult.toString());
|
|
744
|
-
*/
|
|
745
|
-
add(num: BigNumber): BigNumber;
|
|
746
|
-
/**
|
|
747
|
-
* Subtract `num` from `this` BigNumber in-place.
|
|
748
|
-
*
|
|
749
|
-
* @method isub
|
|
750
|
-
* @param num - The BigNumber to be subtracted from `this` BigNumber.
|
|
751
|
-
* @returns Returns the BigNumber after performing the subtraction.
|
|
752
|
-
*
|
|
753
|
-
* @example
|
|
754
|
-
* const num1 = new BigNumber('20');
|
|
755
|
-
* num1.isub(new BigNumber('10'));
|
|
756
|
-
* console.log(num1.toString());
|
|
757
|
-
*/
|
|
758
|
-
isub(num: BigNumber): BigNumber;
|
|
759
|
-
/**
|
|
760
|
-
* Subtract `num` from `this` BigNumber.
|
|
761
|
-
*
|
|
762
|
-
* @method sub
|
|
763
|
-
* @param num - The BigNumber to be subtracted from `this` BigNumber.
|
|
764
|
-
* @returns Returns a new BigNumber which is the result of the subtraction.
|
|
765
|
-
*
|
|
766
|
-
* @example
|
|
767
|
-
* const num1 = new BigNumber('20');
|
|
768
|
-
* const subResult = num1.sub(new BigNumber('10'));
|
|
769
|
-
* console.log(subResult.toString());
|
|
770
|
-
*/
|
|
771
|
-
sub(num: BigNumber): BigNumber;
|
|
772
|
-
private smallMulTo;
|
|
773
|
-
comb10MulTo(self: BigNumber, num: BigNumber, out: BigNumber): BigNumber;
|
|
774
|
-
private bigMulTo;
|
|
775
|
-
/**
|
|
776
|
-
* Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
777
|
-
* It chooses the multiplication method based on the lengths of the numbers to optimize execution time.
|
|
778
|
-
*
|
|
779
|
-
* @method mulTo
|
|
780
|
-
* @param num - The BigNumber multiply with.
|
|
781
|
-
* @param out - The BigNumber where to store the result.
|
|
782
|
-
* @returns The BigNumber resulting from the multiplication operation.
|
|
783
|
-
*
|
|
784
|
-
* @example
|
|
785
|
-
* const bn1 = new BigNumber('12345');
|
|
786
|
-
* const bn2 = new BigNumber('23456');
|
|
787
|
-
* const output = new BigNumber();
|
|
788
|
-
* bn1.mulTo(bn2, output);
|
|
789
|
-
*/
|
|
790
|
-
mulTo(num: BigNumber, out: BigNumber): BigNumber;
|
|
791
|
-
/**
|
|
792
|
-
* Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
793
|
-
* It creates a new BigNumber to store the result.
|
|
794
|
-
*
|
|
795
|
-
* @method mul
|
|
796
|
-
* @param num - The BigNumber to multiply with.
|
|
797
|
-
* @returns The BigNumber resulting from the multiplication operation.
|
|
798
|
-
*
|
|
799
|
-
* @example
|
|
800
|
-
* const bn1 = new BigNumber('12345');
|
|
801
|
-
* const bn2 = new BigNumber('23456');
|
|
802
|
-
* const result = bn1.mul(bn2);
|
|
803
|
-
*/
|
|
804
|
-
mul(num: BigNumber): BigNumber;
|
|
805
|
-
/**
|
|
806
|
-
* Performs an in-place multiplication of the BigNumber instance by a given BigNumber.
|
|
807
|
-
*
|
|
808
|
-
* @method imul
|
|
809
|
-
* @param num - The BigNumber to multiply with.
|
|
810
|
-
* @returns The BigNumber itself after the multiplication.
|
|
811
|
-
*
|
|
812
|
-
* @example
|
|
813
|
-
* const bn1 = new BigNumber('12345');
|
|
814
|
-
* const bn2 = new BigNumber('23456');
|
|
815
|
-
* bn1.imul(bn2);
|
|
816
|
-
*/
|
|
817
|
-
imul(num: BigNumber): BigNumber;
|
|
818
|
-
/**
|
|
819
|
-
* Performs an in-place multiplication of the BigNumber instance by a number.
|
|
820
|
-
* This method asserts the input to be a number less than 0x4000000 to prevent overflowing.
|
|
821
|
-
* If negavtive number is provided, the resulting BigNumber will be inversely negative.
|
|
822
|
-
*
|
|
823
|
-
* @method imuln
|
|
824
|
-
* @param num - The number to multiply with.
|
|
825
|
-
* @returns The BigNumber itself after the multiplication.
|
|
826
|
-
*
|
|
827
|
-
* @example
|
|
828
|
-
* const bn = new BigNumber('12345');
|
|
829
|
-
* bn.imuln(23456);
|
|
830
|
-
*/
|
|
831
|
-
imuln(num: number): BigNumber;
|
|
832
|
-
/**
|
|
833
|
-
* Performs multiplication between the BigNumber instance and a number.
|
|
834
|
-
* It performs the multiplication operation in-place to a cloned BigNumber.
|
|
835
|
-
*
|
|
836
|
-
* @method muln
|
|
837
|
-
* @param num - The number to multiply with.
|
|
838
|
-
* @returns The resulting BigNumber from the multiplication operation.
|
|
839
|
-
*
|
|
840
|
-
* @example
|
|
841
|
-
* const bn = new BigNumber('12345');
|
|
842
|
-
* const result = bn.muln(23456);
|
|
843
|
-
*/
|
|
844
|
-
muln(num: number): BigNumber;
|
|
845
|
-
/**
|
|
846
|
-
* Squares the BigNumber instance.
|
|
847
|
-
*
|
|
848
|
-
* @method sqr
|
|
849
|
-
* @returns The BigNumber squared.
|
|
850
|
-
*
|
|
851
|
-
* @example
|
|
852
|
-
* const bn = new BigNumber('12345');
|
|
853
|
-
* const result = bn.sqr();
|
|
854
|
-
*/
|
|
855
|
-
sqr(): BigNumber;
|
|
856
|
-
/**
|
|
857
|
-
* Performs in-place multiplication of the BigNumber instance by itself.
|
|
858
|
-
*
|
|
859
|
-
* @method isqr
|
|
860
|
-
* @returns The result of multiplying the BigNumber instance by itself.
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* let myNumber = new BigNumber(4);
|
|
864
|
-
* myNumber.isqr(); // Returns BigNumber of value 16
|
|
865
|
-
*/
|
|
866
|
-
isqr(): BigNumber;
|
|
867
|
-
/**
|
|
868
|
-
* Raises the BigNumber instance to the power of the specified BigNumber.
|
|
869
|
-
*
|
|
870
|
-
* @method pow
|
|
871
|
-
* @param num - The exponent to raise the BigNumber instance to.
|
|
872
|
-
* @returns The result of raising the BigNumber instance to the power of num.
|
|
873
|
-
*
|
|
874
|
-
* @example
|
|
875
|
-
* let base = new BigNumber(2);
|
|
876
|
-
* let exponent = new BigNumber(3);
|
|
877
|
-
* base.pow(exponent); // Returns BigNumber of value 8
|
|
878
|
-
*/
|
|
879
|
-
pow(num: BigNumber): BigNumber;
|
|
880
|
-
/**
|
|
881
|
-
* Performs in-place bitwise left shift operation on the BigNumber instance.
|
|
882
|
-
*
|
|
883
|
-
* @method iushln
|
|
884
|
-
* @param bits - The number of positions to shift.
|
|
885
|
-
* @returns The BigNumber instance after performing the shift operation.
|
|
886
|
-
*
|
|
887
|
-
* @example
|
|
888
|
-
* let myNumber = new BigNumber(4);
|
|
889
|
-
* myNumber.iushln(2); // Returns BigNumber of value 16
|
|
890
|
-
*/
|
|
891
|
-
iushln(bits: number): this;
|
|
892
|
-
/**
|
|
893
|
-
* Performs an in-place left shift operation on the BigNumber instance only if it is non-negative.
|
|
894
|
-
*
|
|
895
|
-
* @method ishln
|
|
896
|
-
* @param bits - The number of positions to shift.
|
|
897
|
-
* @returns The BigNumber instance after performing the shift operation.
|
|
898
|
-
*
|
|
899
|
-
* @example
|
|
900
|
-
* let myNumber = new BigNumber(4);
|
|
901
|
-
* myNumber.ishln(2); // Returns BigNumber of value 16
|
|
902
|
-
*/
|
|
903
|
-
ishln(bits: number): this;
|
|
904
|
-
/**
|
|
905
|
-
* Performs an in-place unsigned bitwise right shift operation on the BigNumber instance.
|
|
906
|
-
*
|
|
907
|
-
* @method iushrn
|
|
908
|
-
* @param bits - The number of positions to shift.
|
|
909
|
-
* @param hint - Lowest bit before trailing zeroes.
|
|
910
|
-
* @param extended - To be filled with the bits that are shifted out.
|
|
911
|
-
* @returns The BigNumber instance after performing the shift operation.
|
|
912
|
-
*
|
|
913
|
-
* @example
|
|
914
|
-
* let myNumber = new BigNumber(16);
|
|
915
|
-
* myNumber.iushrn(2); // Returns BigNumber of value 4
|
|
916
|
-
*/
|
|
917
|
-
iushrn(bits: number, hint?: number, extended?: BigNumber): this;
|
|
918
|
-
/**
|
|
919
|
-
* Performs an in-place right shift operation on the BigNumber instance only if it is non-negative.
|
|
920
|
-
*
|
|
921
|
-
* @method ishrn
|
|
922
|
-
* @param bits - The number of positions to shift.
|
|
923
|
-
* @param hint - Lowest bit before trailing zeroes.
|
|
924
|
-
* @param extended - To be filled with the bits that are shifted out.
|
|
925
|
-
* @returns The BigNumber instance after performing the shift operation.
|
|
926
|
-
*
|
|
927
|
-
* @example
|
|
928
|
-
* let myNumber = new BigNumber(16);
|
|
929
|
-
* myNumber.ishrn(2); // Returns BigNumber of value 4
|
|
930
|
-
*/
|
|
931
|
-
ishrn(bits: any, hint?: any, extended?: any): this;
|
|
932
|
-
/**
|
|
933
|
-
* Performs a bitwise left shift operation on a clone of the BigNumber instance.
|
|
934
|
-
*
|
|
935
|
-
* @method shln
|
|
936
|
-
* @param bits - The number of positions to shift.
|
|
937
|
-
* @returns A new BigNumber, which is the result of the shift operation.
|
|
938
|
-
*
|
|
939
|
-
* @example
|
|
940
|
-
* let myNumber = new BigNumber(4);
|
|
941
|
-
* let shiftedNumber = myNumber.shln(2);
|
|
942
|
-
* console.log(shiftedNumber.toString()); // Outputs "16"
|
|
943
|
-
*/
|
|
944
|
-
shln(bits: any): BigNumber;
|
|
945
|
-
/**
|
|
946
|
-
* Performs an unsigned bitwise shift left operation on a clone of the BigNumber instance.
|
|
947
|
-
*
|
|
948
|
-
* @method ushln
|
|
949
|
-
* @param bits - The number of bits to shift.
|
|
950
|
-
* @returns A new BigNumber resulting from the shift operation.
|
|
951
|
-
*
|
|
952
|
-
* @example
|
|
953
|
-
* let myNumber = new BigNumber(4);
|
|
954
|
-
* let shiftedNumber = myNumber.ushln(2);
|
|
955
|
-
* console.log(shiftedNumber.toString()); // Outputs "16"
|
|
956
|
-
*/
|
|
957
|
-
ushln(bits: any): BigNumber;
|
|
958
|
-
/**
|
|
959
|
-
* Performs a bitwise right shift operation on a clone of the BigNumber instance.
|
|
960
|
-
*
|
|
961
|
-
* @method shrn
|
|
962
|
-
* @param bits - The number of bits to shift.
|
|
963
|
-
* @returns A new BigNumber resulting from the shift operation.
|
|
964
|
-
*
|
|
965
|
-
* @example
|
|
966
|
-
* let myNumber = new BigNumber(16);
|
|
967
|
-
* let shiftedNumber = myNumber.shrn(3);
|
|
968
|
-
* console.log(shiftedNumber.toString()); // Outputs "2"
|
|
969
|
-
*/
|
|
970
|
-
shrn(bits: any): BigNumber;
|
|
971
|
-
/**
|
|
972
|
-
* Performs an unsigned bitwise shift right operation on a clone of the BigNumber instance.
|
|
973
|
-
*
|
|
974
|
-
* @method ushrn
|
|
975
|
-
* @param bits - The number of bits to shift.
|
|
976
|
-
* @returns A new BigNumber resulting from the shift operation.
|
|
977
|
-
*
|
|
978
|
-
* @example
|
|
979
|
-
* let myNumber = new BigNumber(20);
|
|
980
|
-
* let shiftedNumber = myNumber.ushrn(2);
|
|
981
|
-
* console.log(shiftedNumber.toString()); // Outputs "5"
|
|
982
|
-
*/
|
|
983
|
-
ushrn(bits: any): BigNumber;
|
|
984
|
-
/**
|
|
985
|
-
* Tests if the nth bit of the BigNumber is set.
|
|
986
|
-
*
|
|
987
|
-
* @method testn
|
|
988
|
-
* @param bit - The position of the bit to test.
|
|
989
|
-
* @returns A boolean indicating whether the nth bit is set.
|
|
990
|
-
*
|
|
991
|
-
* @example
|
|
992
|
-
* let myNumber = new BigNumber(10); // 1010 in binary
|
|
993
|
-
* myNumber.testn(1); // Returns true (indicating that the second bit from right is set)
|
|
994
|
-
*/
|
|
995
|
-
testn(bit: number): boolean;
|
|
996
|
-
/**
|
|
997
|
-
* Performs an in-place operation to keep only the lower bits of the number.
|
|
998
|
-
* @method imaskn
|
|
999
|
-
* @param bits - The number of lower bits to keep.
|
|
1000
|
-
* @returns Returns the BigNumber with only the specified lower bits.
|
|
1001
|
-
* @throws Will throw an error if bits is not a positive number.
|
|
1002
|
-
* @throws Will throw an error if initial BigNumber is negative as imaskn only works with positive numbers.
|
|
1003
|
-
* @example
|
|
1004
|
-
* const myNumber = new BigNumber(52);
|
|
1005
|
-
* myNumber.imaskn(2); // myNumber becomes 0 because lower 2 bits of 52 (110100) are 00.
|
|
1006
|
-
*/
|
|
1007
|
-
imaskn(bits: any): this;
|
|
1008
|
-
/**
|
|
1009
|
-
* Returns a new BigNumber that keeps only the lower bits of the original number.
|
|
1010
|
-
* @method maskn
|
|
1011
|
-
* @param bits - The number of lower bits to keep.
|
|
1012
|
-
* @returns Returns a new BigNumber with only the specified lower bits of the original number.
|
|
1013
|
-
* @example
|
|
1014
|
-
* const myNumber = new BigNumber(52);
|
|
1015
|
-
* const newNumber = myNumber.maskn(2); // newNumber becomes 0, myNumber doesn't change.
|
|
1016
|
-
*/
|
|
1017
|
-
maskn(bits: any): BigNumber;
|
|
1018
|
-
/**
|
|
1019
|
-
* Performs an in-place addition of a plain number to the BigNumber.
|
|
1020
|
-
* @method iaddn
|
|
1021
|
-
* @param num - The plain number to add.
|
|
1022
|
-
* @returns Returns the BigNumber after the addition.
|
|
1023
|
-
* @throws Will throw an error if num is not a number or is larger than 0x4000000.
|
|
1024
|
-
* @example
|
|
1025
|
-
* const myNumber = new BigNumber(50);
|
|
1026
|
-
* myNumber.iaddn(2); // myNumber becomes 52.
|
|
1027
|
-
*/
|
|
1028
|
-
iaddn(num: number): BigNumber;
|
|
1029
|
-
/**
|
|
1030
|
-
* A helper method for in-place addition, used when there are no sign changes or size checks needed.
|
|
1031
|
-
* @private
|
|
1032
|
-
* @method _iaddn
|
|
1033
|
-
* @param num - The plain number to add.
|
|
1034
|
-
* @returns Returns the BigNumber after the addition.
|
|
1035
|
-
*/
|
|
1036
|
-
_iaddn(num: number): this;
|
|
1037
|
-
/**
|
|
1038
|
-
* Performs an in-place subtraction of a plain number from the BigNumber.
|
|
1039
|
-
* @method isubn
|
|
1040
|
-
* @param num - The plain number to subtract.
|
|
1041
|
-
* @returns Returns the BigNumber after the subtraction.
|
|
1042
|
-
* @throws Will throw an error if num is not a number or is larger than 0x4000000.
|
|
1043
|
-
* @example
|
|
1044
|
-
* const myNumber = new BigNumber(52);
|
|
1045
|
-
* myNumber.isubn(2); // myNumber becomes 50.
|
|
1046
|
-
*/
|
|
1047
|
-
isubn(num: number): BigNumber;
|
|
1048
|
-
/**
|
|
1049
|
-
* Returns a new BigNumber that is the result of adding a plain number to the original BigNumber.
|
|
1050
|
-
* @method addn
|
|
1051
|
-
* @param num - The plain number to add.
|
|
1052
|
-
* @returns Returns a new BigNumber which is the sum of the original BigNumber and the plain number.
|
|
1053
|
-
* @example
|
|
1054
|
-
* const myNumber = new BigNumber(50);
|
|
1055
|
-
* const newNumber = myNumber.addn(2); // newNumber becomes 52, myNumber doesn't change.
|
|
1056
|
-
*/
|
|
1057
|
-
addn(num: number): BigNumber;
|
|
1058
|
-
/**
|
|
1059
|
-
* Returns a new BigNumber that is the result of subtracting a plain number from the original BigNumber.
|
|
1060
|
-
* @method subn
|
|
1061
|
-
* @param num - The plain number to subtract.
|
|
1062
|
-
* @returns Returns a new BigNumber which is the difference of the original BigNumber and the plain number.
|
|
1063
|
-
* @example
|
|
1064
|
-
* const myNumber = new BigNumber(52);
|
|
1065
|
-
* const newNumber = myNumber.subn(2); // newNumber becomes 50, myNumber doesn't change.
|
|
1066
|
-
*/
|
|
1067
|
-
subn(num: number): BigNumber;
|
|
1068
|
-
/**
|
|
1069
|
-
* Performs an in-place operation to make the BigNumber an absolute value.
|
|
1070
|
-
* @method iabs
|
|
1071
|
-
* @returns Returns the BigNumber as an absolute value.
|
|
1072
|
-
* @example
|
|
1073
|
-
* const myNumber = new BigNumber(-50);
|
|
1074
|
-
* myNumber.iabs(); // myNumber becomes 50.
|
|
1075
|
-
*/
|
|
1076
|
-
iabs(): this;
|
|
1077
|
-
/**
|
|
1078
|
-
* Obtains the absolute value of a BigNumber instance.
|
|
1079
|
-
* This operation does not affect the actual object but instead returns a new instance of BigNumber.
|
|
1080
|
-
*
|
|
1081
|
-
* @method abs
|
|
1082
|
-
* @returns a new BigNumber instance with the absolute value of the current instance.
|
|
1083
|
-
*
|
|
1084
|
-
* @example
|
|
1085
|
-
* let negativeNumber = new BigNumber(-10);
|
|
1086
|
-
* let absolute = negativeNumber.abs();
|
|
1087
|
-
* console.log(absolute.toString()); // Outputs: "10"
|
|
1088
|
-
*/
|
|
1089
|
-
abs(): BigNumber;
|
|
1090
|
-
/**
|
|
1091
|
-
* Perform an in-place shift left, subtract, and multiply operation on a BigNumber instance.
|
|
1092
|
-
* This method modifies the existing BigNumber instance.
|
|
1093
|
-
*
|
|
1094
|
-
* @method _ishlnsubmul
|
|
1095
|
-
* @param num - The BigNumber to be operated on.
|
|
1096
|
-
* @param mul - The multiplication factor.
|
|
1097
|
-
* @param shift - The number of places to shift left.
|
|
1098
|
-
* @returns the updated BigNumber instance after performing the in-place shift, subtract, and multiply operations.
|
|
1099
|
-
*
|
|
1100
|
-
* @example
|
|
1101
|
-
* let number = new BigNumber(10);
|
|
1102
|
-
* number._ishlnsubmul(new BigNumber(2), 3, 1);
|
|
1103
|
-
* console.log(number.toString()); // Outputs result after performing operations
|
|
1104
|
-
*/
|
|
1105
|
-
_ishlnsubmul(num: BigNumber, mul: any, shift: number): this;
|
|
1106
|
-
/**
|
|
1107
|
-
* Performs a division on a BigNumber instance word-wise.
|
|
1108
|
-
*
|
|
1109
|
-
* This is a private method and should not be directly accessed.
|
|
1110
|
-
*
|
|
1111
|
-
* @method wordDiv
|
|
1112
|
-
* @private
|
|
1113
|
-
* @param num - The BigNumber to divide by.
|
|
1114
|
-
* @param mode - Specifies the operation mode as 'mod' for modulus or 'div' for division.
|
|
1115
|
-
* @returns Object with division (div) and modulo (mod) results, subject to the 'mode' specified.
|
|
1116
|
-
*/
|
|
1117
|
-
private wordDiv;
|
|
1118
|
-
/**
|
|
1119
|
-
* Performs division and/or modulus operation on a BigNumber instance depending on the 'mode' parameter.
|
|
1120
|
-
* If the mode parameter is not provided, both division and modulus results are returned.
|
|
1121
|
-
*
|
|
1122
|
-
* @method divmod
|
|
1123
|
-
* @param num - The BigNumber to divide by.
|
|
1124
|
-
* @param mode - Specifies operation as 'mod' for modulus, 'div' for division, or both if not specified.
|
|
1125
|
-
* @param positive - Specifies if unsigned modulus is requested.
|
|
1126
|
-
* @returns Object with properties for division (div) and modulo (mod) results.
|
|
1127
|
-
*
|
|
1128
|
-
* @example
|
|
1129
|
-
* let number = new BigNumber(10);
|
|
1130
|
-
* let result = number.divmod(new BigNumber(3));
|
|
1131
|
-
* console.log(result.div.toString()); // Outputs: "3"
|
|
1132
|
-
* console.log(result.mod.toString()); // Outputs: "1"
|
|
1133
|
-
*/
|
|
1134
|
-
divmod(num: BigNumber, mode?: 'div' | 'mod', positive?: boolean): any;
|
|
1135
|
-
/**
|
|
1136
|
-
* Divides a BigNumber instance by another BigNumber and returns result. This does not modify the actual object.
|
|
1137
|
-
*
|
|
1138
|
-
* @method div
|
|
1139
|
-
* @param num - The BigNumber to divide by.
|
|
1140
|
-
* @returns A new BigNumber instance of the division result.
|
|
1141
|
-
*
|
|
1142
|
-
* @example
|
|
1143
|
-
* let number = new BigNumber(10);
|
|
1144
|
-
* let result = number.div(new BigNumber(2));
|
|
1145
|
-
* console.log(result.toString()); // Outputs: "5"
|
|
1146
|
-
*/
|
|
1147
|
-
div(num: BigNumber): BigNumber;
|
|
1148
|
-
/**
|
|
1149
|
-
* Returns the remainder after division of one `BigNumber` by another `BigNumber`.
|
|
1150
|
-
*
|
|
1151
|
-
* @method mod
|
|
1152
|
-
* @param num - The divisor `BigNumber`.
|
|
1153
|
-
* @returns The remainder `BigNumber` after division.
|
|
1154
|
-
*
|
|
1155
|
-
* @example
|
|
1156
|
-
* const bigNum1 = new BigNumber('100');
|
|
1157
|
-
* const bigNum2 = new BigNumber('45');
|
|
1158
|
-
* const remainder = bigNum1.mod(bigNum2); // remainder here would be '10'
|
|
1159
|
-
*/
|
|
1160
|
-
mod(num: BigNumber): BigNumber;
|
|
1161
|
-
/**
|
|
1162
|
-
* Returns the remainder after unsigned division of one `BigNumber` by another `BigNumber`.
|
|
1163
|
-
*
|
|
1164
|
-
* @method umod
|
|
1165
|
-
* @param num - The divisor `BigNumber`.
|
|
1166
|
-
* @returns The remainder `BigNumber` after unsigned division.
|
|
1167
|
-
* Note: Here 'unsigned division' means that signs of the numbers are ignored.
|
|
1168
|
-
*
|
|
1169
|
-
* @example
|
|
1170
|
-
* const bigNum1 = new BigNumber('-100');
|
|
1171
|
-
* const bigNum2 = new BigNumber('45');
|
|
1172
|
-
* const remainder = bigNum1.umod(bigNum2); // remainder here would be '10' as signs are ignored.
|
|
1173
|
-
*/
|
|
1174
|
-
umod(num: BigNumber): BigNumber;
|
|
1175
|
-
/**
|
|
1176
|
-
* Returns the rounded quotient after division of one `BigNumber` by another `BigNumber`.
|
|
1177
|
-
*
|
|
1178
|
-
* @method divRound
|
|
1179
|
-
* @param num - The divisor `BigNumber`.
|
|
1180
|
-
* @returns The rounded quotient `BigNumber` after division.
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* const bigNum1 = new BigNumber('100');
|
|
1184
|
-
* const bigNum2 = new BigNumber('45');
|
|
1185
|
-
* const quotient = bigNum1.divRound(bigNum2); // quotient here would be '2'
|
|
1186
|
-
*/
|
|
1187
|
-
divRound(num: BigNumber): BigNumber;
|
|
1188
|
-
/**
|
|
1189
|
-
* Returns the remainder after division of a `BigNumber` by a primitive number.
|
|
1190
|
-
*
|
|
1191
|
-
* @method modrn
|
|
1192
|
-
* @param num - The divisor primitive number.
|
|
1193
|
-
* @returns The remainder number after division.
|
|
1194
|
-
*
|
|
1195
|
-
* @example
|
|
1196
|
-
* const bigNum = new BigNumber('100');
|
|
1197
|
-
* const num = 45;
|
|
1198
|
-
* const remainder = bigNum.modrn(num); // remainder here would be '10'
|
|
1199
|
-
*/
|
|
1200
|
-
modrn(num: number): number;
|
|
1201
|
-
/**
|
|
1202
|
-
* Performs an in-place division of a `BigNumber` by a primitive number.
|
|
1203
|
-
*
|
|
1204
|
-
* @method idivn
|
|
1205
|
-
* @param num - The divisor primitive number.
|
|
1206
|
-
* @returns The `BigNumber` itself after being divided.
|
|
1207
|
-
* Note: 'in-place' means that this operation modifies the original `BigNumber`.
|
|
1208
|
-
*
|
|
1209
|
-
* @example
|
|
1210
|
-
* const bigNum = new BigNumber('100');
|
|
1211
|
-
* const num = 45;
|
|
1212
|
-
* bigNum.idivn(num); // the bigNum here directly becomes '2'
|
|
1213
|
-
*/
|
|
1214
|
-
idivn(num: number): BigNumber;
|
|
1215
|
-
/**
|
|
1216
|
-
* Returns the quotient `BigNumber` after division of one `BigNumber` by a primitive number.
|
|
1217
|
-
*
|
|
1218
|
-
* @method divn
|
|
1219
|
-
* @param num - The divisor primitive number.
|
|
1220
|
-
* @returns A new quotient `BigNumber` after division.
|
|
1221
|
-
*
|
|
1222
|
-
* @example
|
|
1223
|
-
* const bigNum = new BigNumber('100');
|
|
1224
|
-
* const num = 45;
|
|
1225
|
-
* const quotient = bigNum.divn(num); // quotient here would be '2'
|
|
1226
|
-
*/
|
|
1227
|
-
divn(num: number): BigNumber;
|
|
1228
|
-
/**
|
|
1229
|
-
* Computes the Extended Euclidean Algorithm for this BigNumber and provided BigNumber `p`.
|
|
1230
|
-
* The Extended Euclidean Algorithm is a method to find the GCD (Greatest Common Divisor) and the multiplicative inverse in a modulus field.
|
|
1231
|
-
*
|
|
1232
|
-
* @method egcd
|
|
1233
|
-
* @param p - The `BigNumber` with which the Extended Euclidean Algorithm will be computed.
|
|
1234
|
-
* @returns An object `{a: BigNumber, b: BigNumber, gcd: BigNumber}` where `gcd` is the GCD of the numbers, `a` is the coefficient of `this`, and `b` is the coefficient of `p` in Bézout's identity.
|
|
1235
|
-
*
|
|
1236
|
-
* @example
|
|
1237
|
-
* const bigNum1 = new BigNumber('100');
|
|
1238
|
-
* const bigNum2 = new BigNumber('45');
|
|
1239
|
-
* const result = bigNum1.egcd(bigNum2);
|
|
1240
|
-
*/
|
|
1241
|
-
egcd(p: BigNumber): {
|
|
1242
|
-
a: BigNumber;
|
|
1243
|
-
b: BigNumber;
|
|
1244
|
-
gcd: BigNumber;
|
|
1245
|
-
};
|
|
1246
|
-
/**
|
|
1247
|
-
* Compute the multiplicative inverse of the current BigNumber in the modulus field specified by `p`.
|
|
1248
|
-
* The multiplicative inverse is a number which when multiplied with the current BigNumber gives '1' in the modulus field.
|
|
1249
|
-
*
|
|
1250
|
-
* @method _invmp
|
|
1251
|
-
* @param p - The `BigNumber` specifying the modulus field.
|
|
1252
|
-
* @returns The multiplicative inverse `BigNumber` in the modulus field specified by `p`.
|
|
1253
|
-
*
|
|
1254
|
-
* @example
|
|
1255
|
-
* const bigNum = new BigNumber('45');
|
|
1256
|
-
* const p = new BigNumber('100');
|
|
1257
|
-
* const inverse = bigNum._invmp(p); // inverse here would be a BigNumber such that (inverse*bigNum) % p = '1'
|
|
1258
|
-
*/
|
|
1259
|
-
_invmp(p: BigNumber): BigNumber;
|
|
1260
|
-
/**
|
|
1261
|
-
* Computes and returns the greatest common divisor (GCD) of this BigNumber and the provided BigNumber.
|
|
1262
|
-
*
|
|
1263
|
-
* @method gcd
|
|
1264
|
-
* @param num - The BigNumber with which to compute the GCD.
|
|
1265
|
-
* @returns The GCD of this BigNumber and the provided BigNumber.
|
|
1266
|
-
*
|
|
1267
|
-
* @example
|
|
1268
|
-
* let a = new BigNumber(48);
|
|
1269
|
-
* let b = new BigNumber(18);
|
|
1270
|
-
* let gcd = a.gcd(b);
|
|
1271
|
-
*/
|
|
1272
|
-
gcd(num: BigNumber): BigNumber;
|
|
1273
|
-
/**
|
|
1274
|
-
* Computes and returns the modular multiplicative inverse of this BigNumber in the field defined by the provided BigNumber.
|
|
1275
|
-
*
|
|
1276
|
-
* @method invm
|
|
1277
|
-
* @param num - The BigNumber that defines the field.
|
|
1278
|
-
* @returns The modular multiplicative inverse of this BigNumber.
|
|
1279
|
-
*
|
|
1280
|
-
* @example
|
|
1281
|
-
* let a = new BigNumber(3);
|
|
1282
|
-
* let field = new BigNumber(7);
|
|
1283
|
-
* let inverse = a.invm(field);
|
|
1284
|
-
*/
|
|
1285
|
-
invm(num: BigNumber): BigNumber;
|
|
1286
|
-
/**
|
|
1287
|
-
* Checks if this BigNumber is even.
|
|
1288
|
-
* An even number is an integer which is evenly divisible by two.
|
|
1289
|
-
*
|
|
1290
|
-
* @method isEven
|
|
1291
|
-
* @returns true if this BigNumber is even, else false.
|
|
1292
|
-
*
|
|
1293
|
-
* @example
|
|
1294
|
-
* let a = new BigNumber(4);
|
|
1295
|
-
* let isEven = a.isEven(); // true
|
|
1296
|
-
*/
|
|
1297
|
-
isEven(): boolean;
|
|
1298
|
-
/**
|
|
1299
|
-
* Checks if this BigNumber is Odd.
|
|
1300
|
-
* An odd number is an integer which is not evenly divisible by two.
|
|
1301
|
-
*
|
|
1302
|
-
* @method isOdd
|
|
1303
|
-
* @returns true if this BigNumber is Odd, else false.
|
|
1304
|
-
*
|
|
1305
|
-
* @example
|
|
1306
|
-
* let a = new BigNumber(3);
|
|
1307
|
-
* let isOdd = a.isOdd(); // true
|
|
1308
|
-
*/
|
|
1309
|
-
isOdd(): boolean;
|
|
1310
|
-
/**
|
|
1311
|
-
* Returns the result of bitwise AND operation between the least significant 26 bits of
|
|
1312
|
-
* this BigNumber and the provided number.
|
|
1313
|
-
* This method is mostly used to mask-off less significant bits.
|
|
1314
|
-
*
|
|
1315
|
-
* @method andln
|
|
1316
|
-
* @param num - The number to AND with.
|
|
1317
|
-
* @returns The result of the AND operation.
|
|
1318
|
-
*
|
|
1319
|
-
* @example
|
|
1320
|
-
* let a = new BigNumber(60);
|
|
1321
|
-
* let result = a.andln(13); // 12
|
|
1322
|
-
*/
|
|
1323
|
-
andln(num: number): number;
|
|
1324
|
-
/**
|
|
1325
|
-
* Increments the value at the bit position specified by the input parameter.
|
|
1326
|
-
*
|
|
1327
|
-
* @method bincn
|
|
1328
|
-
* @param bit - The bit position to increment at.
|
|
1329
|
-
* @returns This BigNumber after incrementing at the specific bit position.
|
|
1330
|
-
*
|
|
1331
|
-
* @example
|
|
1332
|
-
* let a = new BigNumber(5);
|
|
1333
|
-
* a.bincn(2); // a = 7
|
|
1334
|
-
*/
|
|
1335
|
-
bincn(bit: number): this;
|
|
1336
|
-
/**
|
|
1337
|
-
* Checks if this BigNumber is Zero.
|
|
1338
|
-
* A BigNumber is zero if it only contains one word and that word is 0.
|
|
1339
|
-
*
|
|
1340
|
-
* @method isZero
|
|
1341
|
-
* @returns true if this BigNumber is Zero, else false.
|
|
1342
|
-
*
|
|
1343
|
-
* @example
|
|
1344
|
-
* let a = new BigNumber(0);
|
|
1345
|
-
* let isZero = a.isZero(); // true
|
|
1346
|
-
*/
|
|
1347
|
-
isZero(): boolean;
|
|
1348
|
-
/**
|
|
1349
|
-
* Compares this BigNumber with the given number.
|
|
1350
|
-
* It returns -1 if this BigNumber is less than the number, 0 if they're equal, and 1 if the BigNumber is greater than the number.
|
|
1351
|
-
*
|
|
1352
|
-
* @method cmpn
|
|
1353
|
-
* @param num - The number to compare with.
|
|
1354
|
-
* @returns -1, 0, or 1 based on the comparison result.
|
|
1355
|
-
*
|
|
1356
|
-
* @example
|
|
1357
|
-
* let a = new BigNumber(15);
|
|
1358
|
-
* let result = a.cmpn(10); // 1
|
|
1359
|
-
*/
|
|
1360
|
-
cmpn(num: number): 1 | 0 | -1;
|
|
1361
|
-
/**
|
|
1362
|
-
* Compare this big number with another big number.
|
|
1363
|
-
* @method cmp
|
|
1364
|
-
* @param num - The big number to compare with.
|
|
1365
|
-
* @returns Returns:
|
|
1366
|
-
* 1 if this big number is greater,
|
|
1367
|
-
* -1 if it's less,
|
|
1368
|
-
* 0 if they are equal.
|
|
1369
|
-
*
|
|
1370
|
-
* @example
|
|
1371
|
-
* import BigNumber from './BigNumber';
|
|
1372
|
-
* const bn1 = new BigNumber('10');
|
|
1373
|
-
* const bn2 = new BigNumber('6');
|
|
1374
|
-
* const comparisonResult = bn1.cmp(bn2); // 1 - because 10 is greater than 6
|
|
1375
|
-
*/
|
|
1376
|
-
cmp(num: BigNumber): 1 | 0 | -1;
|
|
1377
|
-
/**
|
|
1378
|
-
* Performs an unsigned comparison between this BigNumber instance and another.
|
|
1379
|
-
*
|
|
1380
|
-
* @method ucmp
|
|
1381
|
-
* @param num - The BigNumber instance to compare with.
|
|
1382
|
-
* @returns Returns 1 if this BigNumber is bigger, -1 if it is smaller, and 0 if they are equal.
|
|
1383
|
-
*
|
|
1384
|
-
* @example
|
|
1385
|
-
* let bigNumber1 = new BigNumber('1234');
|
|
1386
|
-
* let bigNumber2 = new BigNumber('2345');
|
|
1387
|
-
* let comparisonResult = bigNumber1.ucmp(bigNumber2); // Returns -1
|
|
1388
|
-
*/
|
|
1389
|
-
ucmp(num: BigNumber): 1 | 0 | -1;
|
|
1390
|
-
/**
|
|
1391
|
-
* Checks if this BigNumber instance is greater than a number.
|
|
1392
|
-
*
|
|
1393
|
-
* @method gtn
|
|
1394
|
-
* @param num - The number to compare with.
|
|
1395
|
-
* @returns Returns true if this BigNumber is greater than the number, false otherwise.
|
|
1396
|
-
*
|
|
1397
|
-
* @example
|
|
1398
|
-
* let bigNumber = new BigNumber('2345');
|
|
1399
|
-
* let isGreater = bigNumber.gtn(1234); // Returns true
|
|
1400
|
-
*/
|
|
1401
|
-
gtn(num: number): boolean;
|
|
1402
|
-
/**
|
|
1403
|
-
* Checks if this BigNumber instance is greater than another BigNumber.
|
|
1404
|
-
*
|
|
1405
|
-
* @method gt
|
|
1406
|
-
* @param num - The BigNumber to compare with.
|
|
1407
|
-
* @returns Returns true if this BigNumber is greater than the other BigNumber, false otherwise.
|
|
1408
|
-
*
|
|
1409
|
-
* @example
|
|
1410
|
-
* let bigNumber1 = new BigNumber('2345');
|
|
1411
|
-
* let bigNumber2 = new BigNumber('1234');
|
|
1412
|
-
* let isGreater = bigNumber1.gt(bigNumber2); // Returns true
|
|
1413
|
-
*/
|
|
1414
|
-
gt(num: BigNumber): boolean;
|
|
1415
|
-
/**
|
|
1416
|
-
* Checks if this BigNumber instance is greater than or equal to a number.
|
|
1417
|
-
*
|
|
1418
|
-
* @method gten
|
|
1419
|
-
* @param num - The number to compare with.
|
|
1420
|
-
* @returns Returns true if this BigNumber is greater than or equal to the number, false otherwise.
|
|
1421
|
-
*
|
|
1422
|
-
* @example
|
|
1423
|
-
* let bigNumber = new BigNumber('1234');
|
|
1424
|
-
* let isGreaterOrEqual = bigNumber.gten(1234); // Returns true
|
|
1425
|
-
*/
|
|
1426
|
-
gten(num: number): boolean;
|
|
1427
|
-
/**
|
|
1428
|
-
* Checks if this BigNumber instance is greater than or equal to another BigNumber.
|
|
1429
|
-
*
|
|
1430
|
-
* @method gte
|
|
1431
|
-
* @param num - The BigNumber to compare with.
|
|
1432
|
-
* @returns Returns true if this BigNumber is greater than or equal to the other BigNumber, false otherwise.
|
|
1433
|
-
*
|
|
1434
|
-
* @example
|
|
1435
|
-
* let bigNumber1 = new BigNumber('1234');
|
|
1436
|
-
* let bigNumber2 = new BigNumber('1234');
|
|
1437
|
-
* let isGreaterOrEqual = bigNumber1.gte(bigNumber2); // Returns true
|
|
1438
|
-
*/
|
|
1439
|
-
gte(num: BigNumber): boolean;
|
|
1440
|
-
/**
|
|
1441
|
-
* Checks if this BigNumber instance is less than a number.
|
|
1442
|
-
*
|
|
1443
|
-
* @method ltn
|
|
1444
|
-
* @param num - The number to compare with.
|
|
1445
|
-
* @returns Returns true if this BigNumber is less than the number, false otherwise.
|
|
41
|
+
* Reduction context of the big number.
|
|
1446
42
|
*
|
|
1447
|
-
* @
|
|
1448
|
-
* let bigNumber = new BigNumber('1234');
|
|
1449
|
-
* let isLess = bigNumber.ltn(2345); // Returns true
|
|
43
|
+
* @property red
|
|
1450
44
|
*/
|
|
1451
|
-
|
|
45
|
+
red: ReductionContext | null;
|
|
1452
46
|
/**
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1456
|
-
* @param num - The BigNumber to compare with.
|
|
1457
|
-
* @returns Returns true if this BigNumber is less than the other BigNumber, false otherwise.
|
|
47
|
+
* Negative flag. Indicates whether the big number is a negative number.
|
|
48
|
+
* - If 0, the number is positive.
|
|
49
|
+
* - If 1, the number is negative.
|
|
1458
50
|
*
|
|
1459
|
-
* @
|
|
1460
|
-
* let bigNumber1 = new BigNumber('1234');
|
|
1461
|
-
* let bigNumber2 = new BigNumber('2345');
|
|
1462
|
-
* let isLess = bigNumber1.lt(bigNumber2); // Returns true
|
|
51
|
+
* @property negative
|
|
1463
52
|
*/
|
|
1464
|
-
|
|
53
|
+
get negative(): number;
|
|
1465
54
|
/**
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1468
|
-
* @method lten
|
|
1469
|
-
* @param num - The number to compare with.
|
|
1470
|
-
* @returns Returns true if this BigNumber is less than or equal to the number, false otherwise.
|
|
1471
|
-
*
|
|
1472
|
-
* @example
|
|
1473
|
-
* let bigNumber = new BigNumber('2345');
|
|
1474
|
-
* let isLessOrEqual = bigNumber.lten(2345); // Returns true
|
|
55
|
+
* Sets the negative flag. Only 0 (positive) or 1 (negative) are allowed.
|
|
1475
56
|
*/
|
|
1476
|
-
|
|
57
|
+
set negative(val: number);
|
|
58
|
+
private get _computedWordsArray();
|
|
1477
59
|
/**
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
* @method lte
|
|
1481
|
-
* @param num - The BigNumber to compare with.
|
|
1482
|
-
* @returns Returns true if this BigNumber is less than or equal to the other BigNumber, false otherwise.
|
|
60
|
+
* Array of numbers, where each number represents a part of the value of the big number.
|
|
1483
61
|
*
|
|
1484
|
-
* @
|
|
1485
|
-
* let bigNumber1 = new BigNumber('2345');
|
|
1486
|
-
* let bigNumber2 = new BigNumber('2345');
|
|
1487
|
-
* let isLessOrEqual = bigNumber1.lte(bigNumber2); // Returns true
|
|
62
|
+
* @property words
|
|
1488
63
|
*/
|
|
1489
|
-
|
|
64
|
+
get words(): number[];
|
|
1490
65
|
/**
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
* @method eqn
|
|
1494
|
-
* @param num - The number to compare with.
|
|
1495
|
-
* @returns Returns true if this BigNumber is equal to the number, false otherwise.
|
|
1496
|
-
*
|
|
1497
|
-
* @example
|
|
1498
|
-
* let bigNumber = new BigNumber('1234');
|
|
1499
|
-
* let isEqual = bigNumber.eqn(1234); // Returns true
|
|
66
|
+
* Sets the words array representing the value of the big number.
|
|
1500
67
|
*/
|
|
1501
|
-
|
|
68
|
+
set words(newWords: number[]);
|
|
1502
69
|
/**
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
* @method eq
|
|
1506
|
-
* @param num - The number to compare equality with.
|
|
1507
|
-
* @returns Returns true if the current BigNumber is equal to the provided number, otherwise false.
|
|
70
|
+
* Length of the words array.
|
|
1508
71
|
*
|
|
1509
|
-
* @
|
|
1510
|
-
* let bigNum = new BigNumber(10);
|
|
1511
|
-
* bigNum.eq(new BigNumber(10)); // true
|
|
72
|
+
* @property length
|
|
1512
73
|
*/
|
|
1513
|
-
|
|
74
|
+
get length(): number;
|
|
1514
75
|
/**
|
|
1515
|
-
*
|
|
1516
|
-
* Throws an error in case the number is either negative or already in a reduction context.
|
|
76
|
+
* Checks whether a value is an instance of BigNumber. Regular JS numbers fail this check.
|
|
1517
77
|
*
|
|
1518
|
-
* @method
|
|
1519
|
-
* @param
|
|
1520
|
-
* @returns Returns
|
|
1521
|
-
*
|
|
1522
|
-
* @example
|
|
1523
|
-
* let bigNum = new BigNumber(10);
|
|
1524
|
-
* let redCtx = new ReductionContext();
|
|
1525
|
-
* bigNum.toRed(redCtx);
|
|
78
|
+
* @method isBN
|
|
79
|
+
* @param num - The value to be checked.
|
|
80
|
+
* @returns - Returns a boolean value determining whether or not the checked num parameter is a BigNumber.
|
|
1526
81
|
*/
|
|
1527
|
-
|
|
82
|
+
static isBN(num: any): boolean;
|
|
1528
83
|
/**
|
|
1529
|
-
*
|
|
1530
|
-
* Throws an error in case the number is not in a reduction context.
|
|
1531
|
-
*
|
|
1532
|
-
* @method fromRed
|
|
1533
|
-
* @returns Returns the BigNumber out of the ReductionContext.
|
|
84
|
+
* Returns the bigger value between two BigNumbers
|
|
1534
85
|
*
|
|
1535
|
-
* @
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
*
|
|
1539
|
-
* bigNum.fromRed();
|
|
86
|
+
* @method max
|
|
87
|
+
* @param left - The first BigNumber to be compared.
|
|
88
|
+
* @param right - The second BigNumber to be compared.
|
|
89
|
+
* @returns - Returns the bigger BigNumber between left and right.
|
|
1540
90
|
*/
|
|
1541
|
-
|
|
91
|
+
static max(left: BigNumber, right: BigNumber): BigNumber;
|
|
1542
92
|
/**
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
* @method forceRed
|
|
1546
|
-
* @param ctx - The ReductionContext to forcefully convert the BigNumber to.
|
|
1547
|
-
* @returns Returns the BigNumber in the given ReductionContext.
|
|
93
|
+
* Returns the smaller value between two BigNumbers
|
|
1548
94
|
*
|
|
1549
|
-
* @
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
95
|
+
* @method min
|
|
96
|
+
* @param left - The first BigNumber to be compared.
|
|
97
|
+
* @param right - The second BigNumber to be compared.
|
|
98
|
+
* @returns - Returns the smaller value between left and right.
|
|
1553
99
|
*/
|
|
1554
|
-
|
|
100
|
+
static min(left: BigNumber, right: BigNumber): BigNumber;
|
|
1555
101
|
/**
|
|
1556
|
-
*
|
|
1557
|
-
* Throws an error in case the number is not in a reduction context.
|
|
1558
|
-
*
|
|
1559
|
-
* @method redAdd
|
|
1560
|
-
* @param num - The number to add to the current BigNumber.
|
|
1561
|
-
* @returns Returns a new BigNumber that's the sum of the current BigNumber and the provided number in the reduction context.
|
|
102
|
+
* @constructor
|
|
1562
103
|
*
|
|
1563
|
-
* @
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
* bigNum.toRed(redCtx);
|
|
1567
|
-
* bigNum.redAdd(new BigNumber(20)); // returns a BigNumber of 30 in reduction context
|
|
104
|
+
* @param number - The number (various types accepted) to construct a BigNumber from. Default is 0.
|
|
105
|
+
* @param base - The base of number provided. By default is 10.
|
|
106
|
+
* @param endian - The endianness provided. By default is 'big endian'.
|
|
1568
107
|
*/
|
|
1569
|
-
|
|
108
|
+
constructor(number?: number | string | number[] | bigint | undefined, base?: number | 'be' | 'le' | 'hex', endian?: 'be' | 'le');
|
|
109
|
+
private _bigIntToStringInBase;
|
|
110
|
+
private _parseBaseString;
|
|
111
|
+
private _parseBaseWord;
|
|
112
|
+
private _initializeState;
|
|
113
|
+
private _finishInitialization;
|
|
114
|
+
private assert;
|
|
115
|
+
private initNumber;
|
|
116
|
+
private initArray;
|
|
117
|
+
copy(dest: BigNumber): void;
|
|
118
|
+
static move(dest: BigNumber, src: BigNumber): void;
|
|
119
|
+
clone(): BigNumber;
|
|
120
|
+
expand(size: number): this;
|
|
121
|
+
strip(): this;
|
|
122
|
+
normSign(): this;
|
|
123
|
+
inspect(): string;
|
|
124
|
+
private _getMinimalHex;
|
|
1570
125
|
/**
|
|
1571
|
-
*
|
|
1572
|
-
* Throws an error in case the number is not in a reduction context.
|
|
1573
|
-
*
|
|
1574
|
-
* @method redIAdd
|
|
1575
|
-
* @param num - The number to add to the current BigNumber.
|
|
1576
|
-
* @returns Returns the modified current BigNumber after adding the provided number in the reduction context.
|
|
126
|
+
* Converts the BigNumber instance to a string representation.
|
|
1577
127
|
*
|
|
1578
|
-
* @
|
|
1579
|
-
*
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
* bigNum.redIAdd(new BigNumber(20)); // modifies the bigNum to 30 in reduction context
|
|
128
|
+
* @method toString
|
|
129
|
+
* @param base - The base for representing number. Default is 10. Other accepted values are 16 and 'hex'.
|
|
130
|
+
* @param padding - Represents the minimum number of digits to represent the BigNumber as a string. Default is 1.
|
|
131
|
+
* @returns The string representation of the BigNumber instance
|
|
1583
132
|
*/
|
|
1584
|
-
|
|
133
|
+
toString(base?: number | 'hex', padding?: number): string;
|
|
134
|
+
private toBaseString;
|
|
1585
135
|
/**
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
* @method redSub
|
|
1590
|
-
* @param num - The number to subtract from the current BigNumber.
|
|
1591
|
-
* @returns Returns a new BigNumber that's the subtraction result of the current BigNumber and the provided number in the reduction context.
|
|
136
|
+
* Converts the BigNumber instance to a JavaScript number.
|
|
137
|
+
* Please note that JavaScript numbers are only precise up to 53 bits.
|
|
1592
138
|
*
|
|
1593
|
-
* @
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1596
|
-
* bigNum.toRed(redCtx);
|
|
1597
|
-
* bigNum.redSub(new BigNumber(20)); // returns a BigNumber of 10 in reduction context
|
|
139
|
+
* @method toNumber
|
|
140
|
+
* @throws If the BigNumber instance cannot be safely stored in a JavaScript number
|
|
141
|
+
* @returns The JavaScript number representation of the BigNumber instance.
|
|
1598
142
|
*/
|
|
1599
|
-
|
|
143
|
+
toNumber(): number;
|
|
1600
144
|
/**
|
|
1601
|
-
*
|
|
1602
|
-
* Throws an error in case the number is not in a reduction context.
|
|
1603
|
-
*
|
|
1604
|
-
* @method redISub
|
|
1605
|
-
* @param num - The number to subtract from the current BigNumber.
|
|
1606
|
-
* @returns Returns the modified current BigNumber after subtracting the provided number in the reduction context.
|
|
145
|
+
* Converts the BigNumber instance to a JSON-formatted string.
|
|
1607
146
|
*
|
|
1608
|
-
* @
|
|
1609
|
-
*
|
|
1610
|
-
* let redCtx = new ReductionContext();
|
|
1611
|
-
* bigNum.toRed(redCtx);
|
|
1612
|
-
* bigNum.redISub(new BigNumber(20)); // modifies the bigNum to 10 in reduction context
|
|
147
|
+
* @method toJSON
|
|
148
|
+
* @returns The JSON string representation of the BigNumber instance.
|
|
1613
149
|
*/
|
|
1614
|
-
|
|
150
|
+
toJSON(): string;
|
|
151
|
+
private toArrayLikeGeneric;
|
|
1615
152
|
/**
|
|
1616
|
-
*
|
|
1617
|
-
* Throws an error in case the number is not in a reduction context.
|
|
153
|
+
* Converts the BigNumber instance to an array of bytes.
|
|
1618
154
|
*
|
|
1619
|
-
* @method
|
|
1620
|
-
* @param
|
|
1621
|
-
* @
|
|
1622
|
-
*
|
|
1623
|
-
* @example
|
|
1624
|
-
* let bigNum = new BigNumber(1);
|
|
1625
|
-
* let redCtx = new ReductionContext();
|
|
1626
|
-
* bigNum.toRed(redCtx);
|
|
1627
|
-
* bigNum.redShl(2); // returns a BigNumber of 4 in reduction context
|
|
155
|
+
* @method toArray
|
|
156
|
+
* @param endian - Endianness of the output array, defaults to 'be'.
|
|
157
|
+
* @param length - Optional length of the output array.
|
|
158
|
+
* @returns Array of bytes representing the BigNumber.
|
|
1628
159
|
*/
|
|
1629
|
-
|
|
160
|
+
toArray(endian?: 'le' | 'be', length?: number): number[];
|
|
1630
161
|
/**
|
|
1631
|
-
*
|
|
1632
|
-
* Throws an error in case the number is not in a reduction context.
|
|
1633
|
-
*
|
|
1634
|
-
* @method redMul
|
|
1635
|
-
* @param num - The number to multiply with the current BigNumber.
|
|
1636
|
-
* @returns Returns a new BigNumber that's the product of the current BigNumber and the provided number in the reduction context.
|
|
162
|
+
* Calculates the number of bits required to represent the BigNumber.
|
|
1637
163
|
*
|
|
1638
|
-
* @
|
|
1639
|
-
*
|
|
1640
|
-
* let redCtx = new ReductionContext();
|
|
1641
|
-
* bigNum.toRed(redCtx);
|
|
1642
|
-
* bigNum.redMul(new BigNumber(20)); // returns a BigNumber of 200 in reduction context
|
|
164
|
+
* @method bitLength
|
|
165
|
+
* @returns The bit length of the BigNumber.
|
|
1643
166
|
*/
|
|
1644
|
-
|
|
167
|
+
bitLength(): number;
|
|
1645
168
|
/**
|
|
1646
|
-
*
|
|
1647
|
-
* Expects that this BigNumber is within the reduction context i.e., it has been reduced.
|
|
169
|
+
* Converts a BigNumber to an array of bits.
|
|
1648
170
|
*
|
|
1649
|
-
* @method
|
|
1650
|
-
* @param num - The BigNumber to
|
|
1651
|
-
* @returns
|
|
1652
|
-
*
|
|
1653
|
-
* @example
|
|
1654
|
-
* let bigNum1 = new BigNumber('10').toRed(someRed);
|
|
1655
|
-
* let bigNum2 = new BigNumber('5');
|
|
1656
|
-
* bigNum1.redIMul(bigNum2);
|
|
171
|
+
* @method toBitArray
|
|
172
|
+
* @param num - The BigNumber to convert.
|
|
173
|
+
* @returns An array of bits.
|
|
1657
174
|
*/
|
|
1658
|
-
|
|
175
|
+
static toBitArray(num: BigNumber): Array<0 | 1>;
|
|
1659
176
|
/**
|
|
1660
|
-
*
|
|
1661
|
-
* This function squares the calling BigNumber and returns the result.
|
|
1662
|
-
* It only works if the number is "reduced". A number is considered reduced
|
|
1663
|
-
* if it has a `red` field that points to a reduction context object.
|
|
1664
|
-
*
|
|
1665
|
-
* @method redSqr
|
|
1666
|
-
* @throws If the BigNumber is not reduced
|
|
1667
|
-
* @returns The square of the BigNumber
|
|
1668
|
-
*
|
|
1669
|
-
* @example
|
|
1670
|
-
* const num = new BigNumber('25').toRed(someRed);
|
|
1671
|
-
* const result = num.redSqr();
|
|
1672
|
-
* console.log(result.toString()); // Outputs: '625' mod the red value
|
|
177
|
+
* Instance version of {@link toBitArray}.
|
|
1673
178
|
*/
|
|
1674
|
-
|
|
179
|
+
toBitArray(): Array<0 | 1>;
|
|
1675
180
|
/**
|
|
1676
|
-
*
|
|
1677
|
-
* This function squares the calling BigNumber and overwrites it with the result.
|
|
1678
|
-
* It only works if the number is "reduced". A number is considered reduced
|
|
1679
|
-
* if it has a `red` field that points to a reduction context object.
|
|
181
|
+
* Returns the number of trailing zero bits in the big number.
|
|
1680
182
|
*
|
|
1681
|
-
* @method
|
|
1682
|
-
* @
|
|
1683
|
-
*
|
|
183
|
+
* @method zeroBits
|
|
184
|
+
* @returns Returns the number of trailing zero bits
|
|
185
|
+
* in the binary representation of the big number.
|
|
1684
186
|
*
|
|
1685
187
|
* @example
|
|
1686
|
-
* const
|
|
1687
|
-
*
|
|
1688
|
-
* console.log(num.toString()); // Outputs: '625' mod the red value
|
|
188
|
+
* const bn = new BigNumber('8'); // binary: 1000
|
|
189
|
+
* const zeroBits = bn.zeroBits(); // 3
|
|
1689
190
|
*/
|
|
1690
|
-
|
|
191
|
+
zeroBits(): number;
|
|
1691
192
|
/**
|
|
1692
|
-
*
|
|
1693
|
-
* This function calculates the square root of the calling BigNumber
|
|
1694
|
-
* and returns the result. It only works if the number is "reduced".
|
|
1695
|
-
* A number is considered reduced if it has a `red`
|
|
1696
|
-
* field that points to a reduction context object.
|
|
193
|
+
* Calculates the number of bytes required to represent the BigNumber.
|
|
1697
194
|
*
|
|
1698
|
-
* @method
|
|
1699
|
-
* @
|
|
1700
|
-
* @returns The square root of the BigNumber
|
|
1701
|
-
*
|
|
1702
|
-
* @example
|
|
1703
|
-
* const num = new BigNumber('4').toRed(someRed);
|
|
1704
|
-
* const result = num.redSqrt();
|
|
1705
|
-
* console.log(result.toString()); // Outputs: '2' mod the red value
|
|
195
|
+
* @method byteLength
|
|
196
|
+
* @returns The byte length of the BigNumber.
|
|
1706
197
|
*/
|
|
198
|
+
byteLength(): number;
|
|
199
|
+
private _getSignedValue;
|
|
200
|
+
private _setValueFromSigned;
|
|
201
|
+
toTwos(width: number): BigNumber;
|
|
202
|
+
fromTwos(width: number): BigNumber;
|
|
203
|
+
isNeg(): boolean;
|
|
204
|
+
neg(): BigNumber;
|
|
205
|
+
ineg(): this;
|
|
206
|
+
private _iuop;
|
|
207
|
+
iuor(num: BigNumber): this;
|
|
208
|
+
iuand(num: BigNumber): this;
|
|
209
|
+
iuxor(num: BigNumber): this;
|
|
210
|
+
private _iop;
|
|
211
|
+
ior(num: BigNumber): this;
|
|
212
|
+
iand(num: BigNumber): this;
|
|
213
|
+
ixor(num: BigNumber): this;
|
|
214
|
+
private _uop_new;
|
|
215
|
+
or(num: BigNumber): BigNumber;
|
|
216
|
+
uor(num: BigNumber): BigNumber;
|
|
217
|
+
and(num: BigNumber): BigNumber;
|
|
218
|
+
uand(num: BigNumber): BigNumber;
|
|
219
|
+
xor(num: BigNumber): BigNumber;
|
|
220
|
+
uxor(num: BigNumber): BigNumber;
|
|
221
|
+
inotn(width: number): this;
|
|
222
|
+
notn(width: number): BigNumber;
|
|
223
|
+
setn(bit: number, val: any): this;
|
|
224
|
+
iadd(num: BigNumber): this;
|
|
225
|
+
add(num: BigNumber): BigNumber;
|
|
226
|
+
isub(num: BigNumber): this;
|
|
227
|
+
sub(num: BigNumber): BigNumber;
|
|
228
|
+
mul(num: BigNumber): BigNumber;
|
|
229
|
+
imul(num: BigNumber): this;
|
|
230
|
+
imuln(num: number): this;
|
|
231
|
+
muln(num: number): BigNumber;
|
|
232
|
+
sqr(): BigNumber;
|
|
233
|
+
isqr(): this;
|
|
234
|
+
pow(num: BigNumber): BigNumber;
|
|
235
|
+
iushln(bits: number): this;
|
|
236
|
+
ishln(bits: number): this;
|
|
237
|
+
iushrn(bits: number, hint?: number, extended?: BigNumber): this;
|
|
238
|
+
ishrn(bits: number, hint?: number, extended?: BigNumber): this;
|
|
239
|
+
shln(bits: number): BigNumber;
|
|
240
|
+
ushln(bits: number): BigNumber;
|
|
241
|
+
shrn(bits: number): BigNumber;
|
|
242
|
+
ushrn(bits: number): BigNumber;
|
|
243
|
+
testn(bit: number): boolean;
|
|
244
|
+
imaskn(bits: number): this;
|
|
245
|
+
maskn(bits: number): BigNumber;
|
|
246
|
+
iaddn(num: number): this;
|
|
247
|
+
_iaddn(num: number): this;
|
|
248
|
+
isubn(num: number): this;
|
|
249
|
+
addn(num: number): BigNumber;
|
|
250
|
+
subn(num: number): BigNumber;
|
|
251
|
+
iabs(): this;
|
|
252
|
+
abs(): BigNumber;
|
|
253
|
+
divmod(num: BigNumber, mode?: 'div' | 'mod', positive?: boolean): any;
|
|
254
|
+
div(num: BigNumber): BigNumber;
|
|
255
|
+
mod(num: BigNumber): BigNumber;
|
|
256
|
+
umod(num: BigNumber): BigNumber;
|
|
257
|
+
divRound(num: BigNumber): BigNumber;
|
|
258
|
+
modrn(numArg: number): number;
|
|
259
|
+
idivn(num: number): this;
|
|
260
|
+
divn(num: number): BigNumber;
|
|
261
|
+
egcd(p: BigNumber): {
|
|
262
|
+
a: BigNumber;
|
|
263
|
+
b: BigNumber;
|
|
264
|
+
gcd: BigNumber;
|
|
265
|
+
};
|
|
266
|
+
gcd(num: BigNumber): BigNumber;
|
|
267
|
+
invm(num: BigNumber): BigNumber;
|
|
268
|
+
isEven(): boolean;
|
|
269
|
+
isOdd(): boolean;
|
|
270
|
+
andln(num: number): number;
|
|
271
|
+
bincn(bit: number): this;
|
|
272
|
+
isZero(): boolean;
|
|
273
|
+
cmpn(num: number): 1 | 0 | -1;
|
|
274
|
+
cmp(num: BigNumber): 1 | 0 | -1;
|
|
275
|
+
ucmp(num: BigNumber): 1 | 0 | -1;
|
|
276
|
+
gtn(num: number): boolean;
|
|
277
|
+
gt(num: BigNumber): boolean;
|
|
278
|
+
gten(num: number): boolean;
|
|
279
|
+
gte(num: BigNumber): boolean;
|
|
280
|
+
ltn(num: number): boolean;
|
|
281
|
+
lt(num: BigNumber): boolean;
|
|
282
|
+
lten(num: number): boolean;
|
|
283
|
+
lte(num: BigNumber): boolean;
|
|
284
|
+
eqn(num: number): boolean;
|
|
285
|
+
eq(num: BigNumber): boolean;
|
|
286
|
+
toRed(ctx: ReductionContext): BigNumber;
|
|
287
|
+
fromRed(): BigNumber;
|
|
288
|
+
forceRed(ctx: ReductionContext): this;
|
|
289
|
+
redAdd(num: BigNumber): BigNumber;
|
|
290
|
+
redIAdd(num: BigNumber): BigNumber;
|
|
291
|
+
redSub(num: BigNumber): BigNumber;
|
|
292
|
+
redISub(num: BigNumber): BigNumber;
|
|
293
|
+
redShl(num: number): BigNumber;
|
|
294
|
+
redMul(num: BigNumber): BigNumber;
|
|
295
|
+
redIMul(num: BigNumber): BigNumber;
|
|
296
|
+
redSqr(): BigNumber;
|
|
297
|
+
redISqr(): BigNumber;
|
|
1707
298
|
redSqrt(): BigNumber;
|
|
1708
|
-
/**
|
|
1709
|
-
* Find multiplicative inverse (reciprocal) in respect to reduction context.
|
|
1710
|
-
* The method works only on numbers that have a reduction context set.
|
|
1711
|
-
*
|
|
1712
|
-
* @method redInvm
|
|
1713
|
-
* @returns Returns a BigNumber that is multiplicative inverse in respect to the reduction context.
|
|
1714
|
-
* @throws Will throw an error if this number does not have a reduction context.
|
|
1715
|
-
*
|
|
1716
|
-
* @example
|
|
1717
|
-
* let a = new BigNumber('2345', 16);
|
|
1718
|
-
* a.red = someReductionContext;
|
|
1719
|
-
* let aInverse = a.redInvm();
|
|
1720
|
-
*/
|
|
1721
299
|
redInvm(): BigNumber;
|
|
1722
|
-
/**
|
|
1723
|
-
* Find negative version of this number in respect to reduction context.
|
|
1724
|
-
* The method works only on numbers that have a reduction context set.
|
|
1725
|
-
*
|
|
1726
|
-
* @method redNeg
|
|
1727
|
-
* @returns Returns a BigNumber that is the negative version of this number in respect to the reduction context.
|
|
1728
|
-
* @throws Will throw an error if this number does not have a reduction context.
|
|
1729
|
-
*
|
|
1730
|
-
* @example
|
|
1731
|
-
* let a = new BigNumber('2345', 16);
|
|
1732
|
-
* a.red = someReductionContext;
|
|
1733
|
-
* let aNeg = a.redNeg();
|
|
1734
|
-
*/
|
|
1735
300
|
redNeg(): BigNumber;
|
|
1736
|
-
/**
|
|
1737
|
-
* Raises this number to the power of 'num', in respect to reduction context.
|
|
1738
|
-
* Note that 'num' must not have a reduction context set.
|
|
1739
|
-
*
|
|
1740
|
-
* @method redPow
|
|
1741
|
-
* @param num - The exponent to raise this number to.
|
|
1742
|
-
* @returns Returns a BigNumber that is this number raised to the power of 'num', in respect to the reduction context.
|
|
1743
|
-
* @throws Will throw an error if this number does not have a reduction context or 'num' has a reduction context.
|
|
1744
|
-
*
|
|
1745
|
-
* @example
|
|
1746
|
-
* let a = new BigNumber(3);
|
|
1747
|
-
* a.red = someReductionContext;
|
|
1748
|
-
* let b = new BigNumber(3);
|
|
1749
|
-
* let result = a.redPow(b); // equivalent to (a^b) mod red
|
|
1750
|
-
*/
|
|
1751
301
|
redPow(num: BigNumber): BigNumber;
|
|
1752
302
|
/**
|
|
1753
303
|
* Creates a BigNumber from a hexadecimal string.
|
|
@@ -1755,13 +305,14 @@ export default class BigNumber {
|
|
|
1755
305
|
* @static
|
|
1756
306
|
* @method fromHex
|
|
1757
307
|
* @param hex - The hexadecimal string to create a BigNumber from.
|
|
308
|
+
* @param endian - Optional endianness for parsing the hex string.
|
|
1758
309
|
* @returns Returns a BigNumber created from the hexadecimal input string.
|
|
1759
310
|
*
|
|
1760
311
|
* @example
|
|
1761
312
|
* const exampleHex = 'a1b2c3';
|
|
1762
313
|
* const bigNumber = BigNumber.fromHex(exampleHex);
|
|
1763
314
|
*/
|
|
1764
|
-
static fromHex(hex: string, endian?: 'little' | 'big'): BigNumber;
|
|
315
|
+
static fromHex(hex: string, endian?: 'le' | 'be' | 'little' | 'big'): BigNumber;
|
|
1765
316
|
/**
|
|
1766
317
|
* Converts this BigNumber to a hexadecimal string.
|
|
1767
318
|
*
|
|
@@ -1770,10 +321,10 @@ export default class BigNumber {
|
|
|
1770
321
|
* @returns Returns a string representing the hexadecimal value of this BigNumber.
|
|
1771
322
|
*
|
|
1772
323
|
* @example
|
|
1773
|
-
* const bigNumber = new BigNumber(255)
|
|
1774
|
-
* const hex = bigNumber.toHex()
|
|
324
|
+
* const bigNumber = new BigNumber(255)
|
|
325
|
+
* const hex = bigNumber.toHex()
|
|
1775
326
|
*/
|
|
1776
|
-
toHex(
|
|
327
|
+
toHex(byteLength?: number): string;
|
|
1777
328
|
/**
|
|
1778
329
|
* Creates a BigNumber from a JSON-serialized string.
|
|
1779
330
|
*
|
|
@@ -1781,10 +332,6 @@ export default class BigNumber {
|
|
|
1781
332
|
* @method fromJSON
|
|
1782
333
|
* @param str - The JSON-serialized string to create a BigNumber from.
|
|
1783
334
|
* @returns Returns a BigNumber created from the JSON input string.
|
|
1784
|
-
*
|
|
1785
|
-
* @example
|
|
1786
|
-
* const serialized = '{"type":"BigNumber","hex":"a1b2c3"}';
|
|
1787
|
-
* const bigNumber = BigNumber.fromJSON(serialized);
|
|
1788
335
|
*/
|
|
1789
336
|
static fromJSON(str: string): BigNumber;
|
|
1790
337
|
/**
|
|
@@ -1794,10 +341,6 @@ export default class BigNumber {
|
|
|
1794
341
|
* @method fromNumber
|
|
1795
342
|
* @param n - The number to create a BigNumber from.
|
|
1796
343
|
* @returns Returns a BigNumber equivalent to the input number.
|
|
1797
|
-
*
|
|
1798
|
-
* @example
|
|
1799
|
-
* const number = 1234;
|
|
1800
|
-
* const bigNumber = BigNumber.fromNumber(number);
|
|
1801
344
|
*/
|
|
1802
345
|
static fromNumber(n: number): BigNumber;
|
|
1803
346
|
/**
|
|
@@ -1808,10 +351,6 @@ export default class BigNumber {
|
|
|
1808
351
|
* @param str - The string to create a BigNumber from.
|
|
1809
352
|
* @param base - The base used for conversion. If not provided, base 10 is assumed.
|
|
1810
353
|
* @returns Returns a BigNumber equivalent to the string after conversion from the specified base.
|
|
1811
|
-
*
|
|
1812
|
-
* @example
|
|
1813
|
-
* const str = '1234';
|
|
1814
|
-
* const bigNumber = BigNumber.fromString(str, 16);
|
|
1815
354
|
*/
|
|
1816
355
|
static fromString(str: string, base?: number | 'hex'): BigNumber;
|
|
1817
356
|
/**
|
|
@@ -1819,25 +358,17 @@ export default class BigNumber {
|
|
|
1819
358
|
*
|
|
1820
359
|
* @static
|
|
1821
360
|
* @method fromSm
|
|
1822
|
-
* @param
|
|
361
|
+
* @param bytes - The signed magnitude number to convert to a BigNumber.
|
|
1823
362
|
* @param endian - Defines endianess. If not provided, big endian is assumed.
|
|
1824
363
|
* @returns Returns a BigNumber equivalent to the signed magnitude number interpreted with specified endianess.
|
|
1825
|
-
*
|
|
1826
|
-
* @example
|
|
1827
|
-
* const num = [0x81]
|
|
1828
|
-
* const bigNumber = BigNumber.fromSm(num, { endian: 'little' }); // equivalent to BigNumber from '-1'
|
|
1829
364
|
*/
|
|
1830
|
-
static fromSm(
|
|
365
|
+
static fromSm(bytes: number[], endian?: 'big' | 'little'): BigNumber;
|
|
1831
366
|
/**
|
|
1832
367
|
* Converts this BigNumber to a signed magnitude number.
|
|
1833
368
|
*
|
|
1834
369
|
* @method toSm
|
|
1835
370
|
* @param endian - Defines endianess. If not provided, big endian is assumed.
|
|
1836
371
|
* @returns Returns an array equivalent to this BigNumber interpreted as a signed magnitude with specified endianess.
|
|
1837
|
-
*
|
|
1838
|
-
* @example
|
|
1839
|
-
* const bigNumber = new BigNumber(-1);
|
|
1840
|
-
* const num = bigNumber.toSm('little'); // [0x81]
|
|
1841
372
|
*/
|
|
1842
373
|
toSm(endian?: 'big' | 'little'): number[];
|
|
1843
374
|
/**
|
|
@@ -1849,10 +380,6 @@ export default class BigNumber {
|
|
|
1849
380
|
* @param strict - If true, an error is thrown if the number has negative bit set.
|
|
1850
381
|
* @returns Returns a BigNumber equivalent to the "bits" value in a block header.
|
|
1851
382
|
* @throws Will throw an error if `strict` is `true` and the number has negative bit set.
|
|
1852
|
-
*
|
|
1853
|
-
* @example
|
|
1854
|
-
* const bits = 0x1d00ffff;
|
|
1855
|
-
* const bigNumber = BigNumber.fromBits(bits);
|
|
1856
383
|
*/
|
|
1857
384
|
static fromBits(bits: number, strict?: boolean): BigNumber;
|
|
1858
385
|
/**
|
|
@@ -1860,10 +387,6 @@ export default class BigNumber {
|
|
|
1860
387
|
*
|
|
1861
388
|
* @method toBits
|
|
1862
389
|
* @returns Returns a number equivalent to the "bits" value in a block header.
|
|
1863
|
-
*
|
|
1864
|
-
* @example
|
|
1865
|
-
* const bigNumber = new BigNumber(1);
|
|
1866
|
-
* const bits = bigNumber.toBits();
|
|
1867
390
|
*/
|
|
1868
391
|
toBits(): number;
|
|
1869
392
|
/**
|
|
@@ -1873,13 +396,8 @@ export default class BigNumber {
|
|
|
1873
396
|
* @method fromScriptNum
|
|
1874
397
|
* @param num - The number in the format used in Bitcoin scripts.
|
|
1875
398
|
* @param requireMinimal - If true, non-minimally encoded values will throw an error.
|
|
1876
|
-
* @param maxNumSize - The maximum allowed size for the number.
|
|
399
|
+
* @param maxNumSize - The maximum allowed size for the number.
|
|
1877
400
|
* @returns Returns a BigNumber equivalent to the number used in a Bitcoin script.
|
|
1878
|
-
* @throws Will throw an error if `requireMinimal` is `true` and the value is non-minimally encoded. Will throw an error if number length is greater than `maxNumSize`.
|
|
1879
|
-
*
|
|
1880
|
-
* @example
|
|
1881
|
-
* const num = [0x02, 0x01]
|
|
1882
|
-
* const bigNumber = BigNumber.fromScriptNum(num, true, 5)
|
|
1883
401
|
*/
|
|
1884
402
|
static fromScriptNum(num: number[], requireMinimal?: boolean, maxNumSize?: number): BigNumber;
|
|
1885
403
|
/**
|
|
@@ -1887,11 +405,26 @@ export default class BigNumber {
|
|
|
1887
405
|
*
|
|
1888
406
|
* @method toScriptNum
|
|
1889
407
|
* @returns Returns the equivalent to this BigNumber as a Bitcoin script number.
|
|
1890
|
-
*
|
|
1891
|
-
* @example
|
|
1892
|
-
* const bigNumber = new BigNumber(258)
|
|
1893
|
-
* const num = bigNumber.toScriptNum() // equivalent to bigNumber.toSm('little')
|
|
1894
408
|
*/
|
|
1895
409
|
toScriptNum(): number[];
|
|
410
|
+
/**
|
|
411
|
+
* Compute the multiplicative inverse of the current BigNumber in the modulus field specified by `p`.
|
|
412
|
+
* The multiplicative inverse is a number which when multiplied with the current BigNumber gives '1' in the modulus field.
|
|
413
|
+
*
|
|
414
|
+
* @method _invmp
|
|
415
|
+
* @param p - The `BigNumber` specifying the modulus field.
|
|
416
|
+
* @returns The multiplicative inverse `BigNumber` in the modulus field specified by `p`.
|
|
417
|
+
*/
|
|
418
|
+
_invmp(p: BigNumber): BigNumber;
|
|
419
|
+
/**
|
|
420
|
+
* Performs multiplication between the BigNumber instance and a given BigNumber.
|
|
421
|
+
* It chooses the multiplication method based on the lengths of the numbers to optimize execution time.
|
|
422
|
+
*
|
|
423
|
+
* @method mulTo
|
|
424
|
+
* @param num - The BigNumber multiply with.
|
|
425
|
+
* @param out - The BigNumber where to store the result.
|
|
426
|
+
* @returns The BigNumber resulting from the multiplication operation.
|
|
427
|
+
*/
|
|
428
|
+
mulTo(num: BigNumber, out: BigNumber): BigNumber;
|
|
1896
429
|
}
|
|
1897
430
|
//# sourceMappingURL=BigNumber.d.ts.map
|