@injectivelabs/wallet-base 1.16.24 → 1.16.25-alpha.0
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/index.cjs +1805 -0
- package/dist/cjs/index.d.cts +436 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/chunk-BIPRnmEv.js +23 -0
- package/dist/esm/index.d.ts +436 -3
- package/dist/esm/index.js +1496 -3
- package/dist/esm/package.json +2 -2
- package/package.json +17 -17
- package/dist/cjs/base.d.ts +0 -9
- package/dist/cjs/base.js +0 -17
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/types/enums.d.ts +0 -64
- package/dist/cjs/types/enums.js +0 -53
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/index.js +0 -18
- package/dist/cjs/types/provider.d.ts +0 -38
- package/dist/cjs/types/provider.js +0 -2
- package/dist/cjs/types/strategy.d.ts +0 -256
- package/dist/cjs/types/strategy.js +0 -8
- package/dist/cjs/utils/address.d.ts +0 -2
- package/dist/cjs/utils/address.js +0 -30
- package/dist/cjs/utils/alchemy.d.ts +0 -1
- package/dist/cjs/utils/alchemy.js +0 -11
- package/dist/cjs/utils/constants.d.ts +0 -6
- package/dist/cjs/utils/constants.js +0 -9
- package/dist/cjs/utils/cosmos.d.ts +0 -2
- package/dist/cjs/utils/cosmos.js +0 -13
- package/dist/cjs/utils/index.d.ts +0 -6
- package/dist/cjs/utils/index.js +0 -22
- package/dist/cjs/utils/tx.d.ts +0 -31
- package/dist/cjs/utils/tx.js +0 -14
- package/dist/cjs/utils/wallet.d.ts +0 -7
- package/dist/cjs/utils/wallet.js +0 -52
- package/dist/esm/base.d.ts +0 -9
- package/dist/esm/base.js +0 -14
- package/dist/esm/types/enums.d.ts +0 -64
- package/dist/esm/types/enums.js +0 -50
- package/dist/esm/types/index.d.ts +0 -3
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/provider.d.ts +0 -38
- package/dist/esm/types/provider.js +0 -1
- package/dist/esm/types/strategy.d.ts +0 -256
- package/dist/esm/types/strategy.js +0 -5
- package/dist/esm/utils/address.d.ts +0 -2
- package/dist/esm/utils/address.js +0 -25
- package/dist/esm/utils/alchemy.d.ts +0 -1
- package/dist/esm/utils/alchemy.js +0 -7
- package/dist/esm/utils/constants.d.ts +0 -6
- package/dist/esm/utils/constants.js +0 -6
- package/dist/esm/utils/cosmos.d.ts +0 -2
- package/dist/esm/utils/cosmos.js +0 -9
- package/dist/esm/utils/index.d.ts +0 -6
- package/dist/esm/utils/index.js +0 -6
- package/dist/esm/utils/tx.d.ts +0 -31
- package/dist/esm/utils/tx.js +0 -10
- package/dist/esm/utils/wallet.d.ts +0 -7
- package/dist/esm/utils/wallet.js +0 -43
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,1496 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { WalletErrorActionModule } from "@injectivelabs/exceptions";
|
|
2
|
+
import "@bangjelkoski/store2";
|
|
3
|
+
import "http-status-codes";
|
|
4
|
+
import { CosmosTxV1Beta1TxPb, getEthereumAddress, getInjectiveAddress } from "@injectivelabs/sdk-ts";
|
|
5
|
+
|
|
6
|
+
//#region src/types/enums.ts
|
|
7
|
+
const BroadcastMode = {
|
|
8
|
+
Block: "block",
|
|
9
|
+
Sync: "sync",
|
|
10
|
+
Async: "async"
|
|
11
|
+
};
|
|
12
|
+
const Wallet = {
|
|
13
|
+
Leap: "leap",
|
|
14
|
+
Keplr: "keplr",
|
|
15
|
+
Ninji: "ninji",
|
|
16
|
+
Magic: "magic",
|
|
17
|
+
Rabby: "rabby",
|
|
18
|
+
Ledger: "ledger",
|
|
19
|
+
BitGet: "BitGet",
|
|
20
|
+
OWallet: "owallet",
|
|
21
|
+
Phantom: "phantom",
|
|
22
|
+
Rainbow: "rainbow",
|
|
23
|
+
Turnkey: "turnkey",
|
|
24
|
+
Metamask: "metamask",
|
|
25
|
+
OkxWallet: "okx-wallet",
|
|
26
|
+
PrivateKey: "private-key",
|
|
27
|
+
TrustWallet: "trust-wallet",
|
|
28
|
+
TrezorBip32: "trezor-bip32",
|
|
29
|
+
TrezorBip44: "trezor-bip44",
|
|
30
|
+
Cosmostation: "cosmostation",
|
|
31
|
+
LedgerCosmos: "ledger-cosmos",
|
|
32
|
+
LedgerLegacy: "ledger-legacy",
|
|
33
|
+
WalletConnect: "wallet-connect",
|
|
34
|
+
CosmostationEth: "cosmostation-eth"
|
|
35
|
+
};
|
|
36
|
+
const MagicProvider = {
|
|
37
|
+
Email: "email",
|
|
38
|
+
Apple: "apple",
|
|
39
|
+
Github: "github",
|
|
40
|
+
Google: "google",
|
|
41
|
+
Discord: "discord",
|
|
42
|
+
Twitter: "twitter",
|
|
43
|
+
Facebook: "facebook"
|
|
44
|
+
};
|
|
45
|
+
const WalletDeviceType = {
|
|
46
|
+
Mobile: "mobile",
|
|
47
|
+
Other: "other",
|
|
48
|
+
Browser: "browser",
|
|
49
|
+
Hardware: "hardware"
|
|
50
|
+
};
|
|
51
|
+
const WalletEventListener = {
|
|
52
|
+
AccountChange: "account-change",
|
|
53
|
+
ChainIdChange: "chain-id-change"
|
|
54
|
+
};
|
|
55
|
+
const WalletAction = { ...WalletErrorActionModule };
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/types/strategy.ts
|
|
59
|
+
const TurnkeyProvider = {
|
|
60
|
+
Email: "email",
|
|
61
|
+
Google: "google",
|
|
62
|
+
Apple: "apple"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region ../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
|
|
67
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, mathceil = Math.ceil, mathfloor = Math.floor, bignumberError = "[BigNumber Error] ", tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ", BASE = 0x5af3107a4000, LOG_BASE = 14, MAX_SAFE_INTEGER = 9007199254740991, POWS_TEN = [
|
|
68
|
+
1,
|
|
69
|
+
10,
|
|
70
|
+
100,
|
|
71
|
+
1e3,
|
|
72
|
+
1e4,
|
|
73
|
+
1e5,
|
|
74
|
+
1e6,
|
|
75
|
+
1e7,
|
|
76
|
+
1e8,
|
|
77
|
+
1e9,
|
|
78
|
+
1e10,
|
|
79
|
+
1e11,
|
|
80
|
+
0xe8d4a51000,
|
|
81
|
+
0x9184e72a000
|
|
82
|
+
], SQRT_BASE = 1e7, MAX = 1e9;
|
|
83
|
+
function clone(configObject) {
|
|
84
|
+
var div, convertBase, parseNumeric, P = BigNumber$1.prototype = {
|
|
85
|
+
constructor: BigNumber$1,
|
|
86
|
+
toString: null,
|
|
87
|
+
valueOf: null
|
|
88
|
+
}, ONE = new BigNumber$1(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
89
|
+
prefix: "",
|
|
90
|
+
groupSize: 3,
|
|
91
|
+
secondaryGroupSize: 0,
|
|
92
|
+
groupSeparator: ",",
|
|
93
|
+
decimalSeparator: ".",
|
|
94
|
+
fractionGroupSize: 0,
|
|
95
|
+
fractionGroupSeparator: "\xA0",
|
|
96
|
+
suffix: ""
|
|
97
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
98
|
+
function BigNumber$1(v, b) {
|
|
99
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
100
|
+
if (!(x instanceof BigNumber$1)) return new BigNumber$1(v, b);
|
|
101
|
+
if (b == null) {
|
|
102
|
+
if (v && v._isBigNumber === true) {
|
|
103
|
+
x.s = v.s;
|
|
104
|
+
if (!v.c || v.e > MAX_EXP) x.c = x.e = null;
|
|
105
|
+
else if (v.e < MIN_EXP) x.c = [x.e = 0];
|
|
106
|
+
else {
|
|
107
|
+
x.e = v.e;
|
|
108
|
+
x.c = v.c.slice();
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
113
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
114
|
+
if (v === ~~v) {
|
|
115
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++);
|
|
116
|
+
if (e > MAX_EXP) x.c = x.e = null;
|
|
117
|
+
else {
|
|
118
|
+
x.e = e;
|
|
119
|
+
x.c = [v];
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
str = String(v);
|
|
124
|
+
} else {
|
|
125
|
+
if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
|
|
126
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
127
|
+
}
|
|
128
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
129
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
130
|
+
if (e < 0) e = i;
|
|
131
|
+
e += +str.slice(i + 1);
|
|
132
|
+
str = str.substring(0, i);
|
|
133
|
+
} else if (e < 0) e = str.length;
|
|
134
|
+
} else {
|
|
135
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
136
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
137
|
+
x = new BigNumber$1(v);
|
|
138
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
139
|
+
}
|
|
140
|
+
str = String(v);
|
|
141
|
+
if (isNum = typeof v == "number") {
|
|
142
|
+
if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
|
|
143
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
144
|
+
if (BigNumber$1.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) throw Error(tooManyDigits + v);
|
|
145
|
+
} else x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
146
|
+
alphabet = ALPHABET.slice(0, b);
|
|
147
|
+
e = i = 0;
|
|
148
|
+
for (len = str.length; i < len; i++) if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
149
|
+
if (c == ".") {
|
|
150
|
+
if (i > e) {
|
|
151
|
+
e = len;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
} else if (!caseChanged) {
|
|
155
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
156
|
+
caseChanged = true;
|
|
157
|
+
i = -1;
|
|
158
|
+
e = 0;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return parseNumeric(x, String(v), isNum, b);
|
|
163
|
+
}
|
|
164
|
+
isNum = false;
|
|
165
|
+
str = convertBase(str, b, 10, x.s);
|
|
166
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
167
|
+
else e = str.length;
|
|
168
|
+
}
|
|
169
|
+
for (i = 0; str.charCodeAt(i) === 48; i++);
|
|
170
|
+
for (len = str.length; str.charCodeAt(--len) === 48;);
|
|
171
|
+
if (str = str.slice(i, ++len)) {
|
|
172
|
+
len -= i;
|
|
173
|
+
if (isNum && BigNumber$1.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) throw Error(tooManyDigits + x.s * v);
|
|
174
|
+
if ((e = e - i - 1) > MAX_EXP) x.c = x.e = null;
|
|
175
|
+
else if (e < MIN_EXP) x.c = [x.e = 0];
|
|
176
|
+
else {
|
|
177
|
+
x.e = e;
|
|
178
|
+
x.c = [];
|
|
179
|
+
i = (e + 1) % LOG_BASE;
|
|
180
|
+
if (e < 0) i += LOG_BASE;
|
|
181
|
+
if (i < len) {
|
|
182
|
+
if (i) x.c.push(+str.slice(0, i));
|
|
183
|
+
for (len -= LOG_BASE; i < len;) x.c.push(+str.slice(i, i += LOG_BASE));
|
|
184
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
185
|
+
} else i -= len;
|
|
186
|
+
for (; i--; str += "0");
|
|
187
|
+
x.c.push(+str);
|
|
188
|
+
}
|
|
189
|
+
} else x.c = [x.e = 0];
|
|
190
|
+
}
|
|
191
|
+
BigNumber$1.clone = clone;
|
|
192
|
+
BigNumber$1.ROUND_UP = 0;
|
|
193
|
+
BigNumber$1.ROUND_DOWN = 1;
|
|
194
|
+
BigNumber$1.ROUND_CEIL = 2;
|
|
195
|
+
BigNumber$1.ROUND_FLOOR = 3;
|
|
196
|
+
BigNumber$1.ROUND_HALF_UP = 4;
|
|
197
|
+
BigNumber$1.ROUND_HALF_DOWN = 5;
|
|
198
|
+
BigNumber$1.ROUND_HALF_EVEN = 6;
|
|
199
|
+
BigNumber$1.ROUND_HALF_CEIL = 7;
|
|
200
|
+
BigNumber$1.ROUND_HALF_FLOOR = 8;
|
|
201
|
+
BigNumber$1.EUCLID = 9;
|
|
202
|
+
BigNumber$1.config = BigNumber$1.set = function(obj) {
|
|
203
|
+
var p, v;
|
|
204
|
+
if (obj != null) if (typeof obj == "object") {
|
|
205
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
206
|
+
v = obj[p];
|
|
207
|
+
intCheck(v, 0, MAX, p);
|
|
208
|
+
DECIMAL_PLACES = v;
|
|
209
|
+
}
|
|
210
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
211
|
+
v = obj[p];
|
|
212
|
+
intCheck(v, 0, 8, p);
|
|
213
|
+
ROUNDING_MODE = v;
|
|
214
|
+
}
|
|
215
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
216
|
+
v = obj[p];
|
|
217
|
+
if (v && v.pop) {
|
|
218
|
+
intCheck(v[0], -MAX, 0, p);
|
|
219
|
+
intCheck(v[1], 0, MAX, p);
|
|
220
|
+
TO_EXP_NEG = v[0];
|
|
221
|
+
TO_EXP_POS = v[1];
|
|
222
|
+
} else {
|
|
223
|
+
intCheck(v, -MAX, MAX, p);
|
|
224
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
228
|
+
v = obj[p];
|
|
229
|
+
if (v && v.pop) {
|
|
230
|
+
intCheck(v[0], -MAX, -1, p);
|
|
231
|
+
intCheck(v[1], 1, MAX, p);
|
|
232
|
+
MIN_EXP = v[0];
|
|
233
|
+
MAX_EXP = v[1];
|
|
234
|
+
} else {
|
|
235
|
+
intCheck(v, -MAX, MAX, p);
|
|
236
|
+
if (v) MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
237
|
+
else throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
241
|
+
v = obj[p];
|
|
242
|
+
if (v === !!v) if (v) if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) CRYPTO = v;
|
|
243
|
+
else {
|
|
244
|
+
CRYPTO = !v;
|
|
245
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
246
|
+
}
|
|
247
|
+
else CRYPTO = v;
|
|
248
|
+
else throw Error(bignumberError + p + " not true or false: " + v);
|
|
249
|
+
}
|
|
250
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
251
|
+
v = obj[p];
|
|
252
|
+
intCheck(v, 0, 9, p);
|
|
253
|
+
MODULO_MODE = v;
|
|
254
|
+
}
|
|
255
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
256
|
+
v = obj[p];
|
|
257
|
+
intCheck(v, 0, MAX, p);
|
|
258
|
+
POW_PRECISION = v;
|
|
259
|
+
}
|
|
260
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
261
|
+
v = obj[p];
|
|
262
|
+
if (typeof v == "object") FORMAT = v;
|
|
263
|
+
else throw Error(bignumberError + p + " not an object: " + v);
|
|
264
|
+
}
|
|
265
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
266
|
+
v = obj[p];
|
|
267
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
268
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
269
|
+
ALPHABET = v;
|
|
270
|
+
} else throw Error(bignumberError + p + " invalid: " + v);
|
|
271
|
+
}
|
|
272
|
+
} else throw Error(bignumberError + "Object expected: " + obj);
|
|
273
|
+
return {
|
|
274
|
+
DECIMAL_PLACES,
|
|
275
|
+
ROUNDING_MODE,
|
|
276
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
277
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
278
|
+
CRYPTO,
|
|
279
|
+
MODULO_MODE,
|
|
280
|
+
POW_PRECISION,
|
|
281
|
+
FORMAT,
|
|
282
|
+
ALPHABET
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
BigNumber$1.isBigNumber = function(v) {
|
|
286
|
+
if (!v || v._isBigNumber !== true) return false;
|
|
287
|
+
if (!BigNumber$1.DEBUG) return true;
|
|
288
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
289
|
+
out: if ({}.toString.call(c) == "[object Array]") {
|
|
290
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
291
|
+
if (c[0] === 0) {
|
|
292
|
+
if (e === 0 && c.length === 1) return true;
|
|
293
|
+
break out;
|
|
294
|
+
}
|
|
295
|
+
i = (e + 1) % LOG_BASE;
|
|
296
|
+
if (i < 1) i += LOG_BASE;
|
|
297
|
+
if (String(c[0]).length == i) {
|
|
298
|
+
for (i = 0; i < c.length; i++) {
|
|
299
|
+
n = c[i];
|
|
300
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
|
|
301
|
+
}
|
|
302
|
+
if (n !== 0) return true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) return true;
|
|
306
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
307
|
+
};
|
|
308
|
+
BigNumber$1.maximum = BigNumber$1.max = function() {
|
|
309
|
+
return maxOrMin(arguments, -1);
|
|
310
|
+
};
|
|
311
|
+
BigNumber$1.minimum = BigNumber$1.min = function() {
|
|
312
|
+
return maxOrMin(arguments, 1);
|
|
313
|
+
};
|
|
314
|
+
BigNumber$1.random = (function() {
|
|
315
|
+
var pow2_53 = 9007199254740992;
|
|
316
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
317
|
+
return mathfloor(Math.random() * pow2_53);
|
|
318
|
+
} : function() {
|
|
319
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
320
|
+
};
|
|
321
|
+
return function(dp) {
|
|
322
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber$1(ONE);
|
|
323
|
+
if (dp == null) dp = DECIMAL_PLACES;
|
|
324
|
+
else intCheck(dp, 0, MAX);
|
|
325
|
+
k = mathceil(dp / LOG_BASE);
|
|
326
|
+
if (CRYPTO) if (crypto.getRandomValues) {
|
|
327
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
328
|
+
for (; i < k;) {
|
|
329
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
330
|
+
if (v >= 9e15) {
|
|
331
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
332
|
+
a[i] = b[0];
|
|
333
|
+
a[i + 1] = b[1];
|
|
334
|
+
} else {
|
|
335
|
+
c.push(v % 0x5af3107a4000);
|
|
336
|
+
i += 2;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
i = k / 2;
|
|
340
|
+
} else if (crypto.randomBytes) {
|
|
341
|
+
a = crypto.randomBytes(k *= 7);
|
|
342
|
+
for (; i < k;) {
|
|
343
|
+
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
344
|
+
if (v >= 9e15) crypto.randomBytes(7).copy(a, i);
|
|
345
|
+
else {
|
|
346
|
+
c.push(v % 0x5af3107a4000);
|
|
347
|
+
i += 7;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
i = k / 7;
|
|
351
|
+
} else {
|
|
352
|
+
CRYPTO = false;
|
|
353
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
354
|
+
}
|
|
355
|
+
if (!CRYPTO) for (; i < k;) {
|
|
356
|
+
v = random53bitInt();
|
|
357
|
+
if (v < 9e15) c[i++] = v % 0x5af3107a4000;
|
|
358
|
+
}
|
|
359
|
+
k = c[--i];
|
|
360
|
+
dp %= LOG_BASE;
|
|
361
|
+
if (k && dp) {
|
|
362
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
363
|
+
c[i] = mathfloor(k / v) * v;
|
|
364
|
+
}
|
|
365
|
+
for (; c[i] === 0; c.pop(), i--);
|
|
366
|
+
if (i < 0) c = [e = 0];
|
|
367
|
+
else {
|
|
368
|
+
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
|
|
369
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
|
|
370
|
+
if (i < LOG_BASE) e -= LOG_BASE - i;
|
|
371
|
+
}
|
|
372
|
+
rand.e = e;
|
|
373
|
+
rand.c = c;
|
|
374
|
+
return rand;
|
|
375
|
+
};
|
|
376
|
+
})();
|
|
377
|
+
BigNumber$1.sum = function() {
|
|
378
|
+
var i = 1, args = arguments, sum = new BigNumber$1(args[0]);
|
|
379
|
+
for (; i < args.length;) sum = sum.plus(args[i++]);
|
|
380
|
+
return sum;
|
|
381
|
+
};
|
|
382
|
+
convertBase = (function() {
|
|
383
|
+
var decimal = "0123456789";
|
|
384
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
385
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
386
|
+
for (; i < len;) {
|
|
387
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
|
|
388
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
389
|
+
for (j = 0; j < arr.length; j++) if (arr[j] > baseOut - 1) {
|
|
390
|
+
if (arr[j + 1] == null) arr[j + 1] = 0;
|
|
391
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
392
|
+
arr[j] %= baseOut;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return arr.reverse();
|
|
396
|
+
}
|
|
397
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
398
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
399
|
+
if (i >= 0) {
|
|
400
|
+
k = POW_PRECISION;
|
|
401
|
+
POW_PRECISION = 0;
|
|
402
|
+
str = str.replace(".", "");
|
|
403
|
+
y = new BigNumber$1(baseIn);
|
|
404
|
+
x = y.pow(str.length - i);
|
|
405
|
+
POW_PRECISION = k;
|
|
406
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
|
|
407
|
+
y.e = y.c.length;
|
|
408
|
+
}
|
|
409
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
410
|
+
e = k = xc.length;
|
|
411
|
+
for (; xc[--k] == 0; xc.pop());
|
|
412
|
+
if (!xc[0]) return alphabet.charAt(0);
|
|
413
|
+
if (i < 0) --e;
|
|
414
|
+
else {
|
|
415
|
+
x.c = xc;
|
|
416
|
+
x.e = e;
|
|
417
|
+
x.s = sign;
|
|
418
|
+
x = div(x, y, dp, rm, baseOut);
|
|
419
|
+
xc = x.c;
|
|
420
|
+
r = x.r;
|
|
421
|
+
e = x.e;
|
|
422
|
+
}
|
|
423
|
+
d = e + dp + 1;
|
|
424
|
+
i = xc[d];
|
|
425
|
+
k = baseOut / 2;
|
|
426
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
427
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
428
|
+
if (d < 1 || !xc[0]) str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
429
|
+
else {
|
|
430
|
+
xc.length = d;
|
|
431
|
+
if (r) for (--baseOut; ++xc[--d] > baseOut;) {
|
|
432
|
+
xc[d] = 0;
|
|
433
|
+
if (!d) {
|
|
434
|
+
++e;
|
|
435
|
+
xc = [1].concat(xc);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (k = xc.length; !xc[--k];);
|
|
439
|
+
for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]));
|
|
440
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
441
|
+
}
|
|
442
|
+
return str;
|
|
443
|
+
};
|
|
444
|
+
})();
|
|
445
|
+
div = (function() {
|
|
446
|
+
function multiply(x, k, base) {
|
|
447
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
448
|
+
for (x = x.slice(); i--;) {
|
|
449
|
+
xlo = x[i] % SQRT_BASE;
|
|
450
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
451
|
+
m = khi * xlo + xhi * klo;
|
|
452
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
453
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
454
|
+
x[i] = temp % base;
|
|
455
|
+
}
|
|
456
|
+
if (carry) x = [carry].concat(x);
|
|
457
|
+
return x;
|
|
458
|
+
}
|
|
459
|
+
function compare$1(a, b, aL, bL) {
|
|
460
|
+
var i, cmp;
|
|
461
|
+
if (aL != bL) cmp = aL > bL ? 1 : -1;
|
|
462
|
+
else for (i = cmp = 0; i < aL; i++) if (a[i] != b[i]) {
|
|
463
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
return cmp;
|
|
467
|
+
}
|
|
468
|
+
function subtract(a, b, aL, base) {
|
|
469
|
+
var i = 0;
|
|
470
|
+
for (; aL--;) {
|
|
471
|
+
a[aL] -= i;
|
|
472
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
473
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
474
|
+
}
|
|
475
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1));
|
|
476
|
+
}
|
|
477
|
+
return function(x, y, dp, rm, base) {
|
|
478
|
+
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
|
|
479
|
+
if (!xc || !xc[0] || !yc || !yc[0]) return new BigNumber$1(!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0);
|
|
480
|
+
q = new BigNumber$1(s);
|
|
481
|
+
qc = q.c = [];
|
|
482
|
+
e = x.e - y.e;
|
|
483
|
+
s = dp + e + 1;
|
|
484
|
+
if (!base) {
|
|
485
|
+
base = BASE;
|
|
486
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
487
|
+
s = s / LOG_BASE | 0;
|
|
488
|
+
}
|
|
489
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++);
|
|
490
|
+
if (yc[i] > (xc[i] || 0)) e--;
|
|
491
|
+
if (s < 0) {
|
|
492
|
+
qc.push(1);
|
|
493
|
+
more = true;
|
|
494
|
+
} else {
|
|
495
|
+
xL = xc.length;
|
|
496
|
+
yL = yc.length;
|
|
497
|
+
i = 0;
|
|
498
|
+
s += 2;
|
|
499
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
500
|
+
if (n > 1) {
|
|
501
|
+
yc = multiply(yc, n, base);
|
|
502
|
+
xc = multiply(xc, n, base);
|
|
503
|
+
yL = yc.length;
|
|
504
|
+
xL = xc.length;
|
|
505
|
+
}
|
|
506
|
+
xi = yL;
|
|
507
|
+
rem = xc.slice(0, yL);
|
|
508
|
+
remL = rem.length;
|
|
509
|
+
for (; remL < yL; rem[remL++] = 0);
|
|
510
|
+
yz = yc.slice();
|
|
511
|
+
yz = [0].concat(yz);
|
|
512
|
+
yc0 = yc[0];
|
|
513
|
+
if (yc[1] >= base / 2) yc0++;
|
|
514
|
+
do {
|
|
515
|
+
n = 0;
|
|
516
|
+
cmp = compare$1(yc, rem, yL, remL);
|
|
517
|
+
if (cmp < 0) {
|
|
518
|
+
rem0 = rem[0];
|
|
519
|
+
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
520
|
+
n = mathfloor(rem0 / yc0);
|
|
521
|
+
if (n > 1) {
|
|
522
|
+
if (n >= base) n = base - 1;
|
|
523
|
+
prod = multiply(yc, n, base);
|
|
524
|
+
prodL = prod.length;
|
|
525
|
+
remL = rem.length;
|
|
526
|
+
while (compare$1(prod, rem, prodL, remL) == 1) {
|
|
527
|
+
n--;
|
|
528
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
529
|
+
prodL = prod.length;
|
|
530
|
+
cmp = 1;
|
|
531
|
+
}
|
|
532
|
+
} else {
|
|
533
|
+
if (n == 0) cmp = n = 1;
|
|
534
|
+
prod = yc.slice();
|
|
535
|
+
prodL = prod.length;
|
|
536
|
+
}
|
|
537
|
+
if (prodL < remL) prod = [0].concat(prod);
|
|
538
|
+
subtract(rem, prod, remL, base);
|
|
539
|
+
remL = rem.length;
|
|
540
|
+
if (cmp == -1) while (compare$1(yc, rem, yL, remL) < 1) {
|
|
541
|
+
n++;
|
|
542
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
543
|
+
remL = rem.length;
|
|
544
|
+
}
|
|
545
|
+
} else if (cmp === 0) {
|
|
546
|
+
n++;
|
|
547
|
+
rem = [0];
|
|
548
|
+
}
|
|
549
|
+
qc[i++] = n;
|
|
550
|
+
if (rem[0]) rem[remL++] = xc[xi] || 0;
|
|
551
|
+
else {
|
|
552
|
+
rem = [xc[xi]];
|
|
553
|
+
remL = 1;
|
|
554
|
+
}
|
|
555
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
556
|
+
more = rem[0] != null;
|
|
557
|
+
if (!qc[0]) qc.splice(0, 1);
|
|
558
|
+
}
|
|
559
|
+
if (base == BASE) {
|
|
560
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
|
|
561
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
562
|
+
} else {
|
|
563
|
+
q.e = e;
|
|
564
|
+
q.r = +more;
|
|
565
|
+
}
|
|
566
|
+
return q;
|
|
567
|
+
};
|
|
568
|
+
})();
|
|
569
|
+
function format(n, i, rm, id) {
|
|
570
|
+
var c0, e, ne, len, str;
|
|
571
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
572
|
+
else intCheck(rm, 0, 8);
|
|
573
|
+
if (!n.c) return n.toString();
|
|
574
|
+
c0 = n.c[0];
|
|
575
|
+
ne = n.e;
|
|
576
|
+
if (i == null) {
|
|
577
|
+
str = coeffToString(n.c);
|
|
578
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
579
|
+
} else {
|
|
580
|
+
n = round(new BigNumber$1(n), i, rm);
|
|
581
|
+
e = n.e;
|
|
582
|
+
str = coeffToString(n.c);
|
|
583
|
+
len = str.length;
|
|
584
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
585
|
+
for (; len < i; str += "0", len++);
|
|
586
|
+
str = toExponential(str, e);
|
|
587
|
+
} else {
|
|
588
|
+
i -= ne;
|
|
589
|
+
str = toFixedPoint(str, e, "0");
|
|
590
|
+
if (e + 1 > len) {
|
|
591
|
+
if (--i > 0) for (str += "."; i--; str += "0");
|
|
592
|
+
} else {
|
|
593
|
+
i += e - len;
|
|
594
|
+
if (i > 0) {
|
|
595
|
+
if (e + 1 == len) str += ".";
|
|
596
|
+
for (; i--; str += "0");
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
602
|
+
}
|
|
603
|
+
function maxOrMin(args, n) {
|
|
604
|
+
var k, y, i = 1, x = new BigNumber$1(args[0]);
|
|
605
|
+
for (; i < args.length; i++) {
|
|
606
|
+
y = new BigNumber$1(args[i]);
|
|
607
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) x = y;
|
|
608
|
+
}
|
|
609
|
+
return x;
|
|
610
|
+
}
|
|
611
|
+
function normalise(n, c, e) {
|
|
612
|
+
var i = 1, j = c.length;
|
|
613
|
+
for (; !c[--j]; c.pop());
|
|
614
|
+
for (j = c[0]; j >= 10; j /= 10, i++);
|
|
615
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) n.c = n.e = null;
|
|
616
|
+
else if (e < MIN_EXP) n.c = [n.e = 0];
|
|
617
|
+
else {
|
|
618
|
+
n.e = e;
|
|
619
|
+
n.c = c;
|
|
620
|
+
}
|
|
621
|
+
return n;
|
|
622
|
+
}
|
|
623
|
+
parseNumeric = (function() {
|
|
624
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
625
|
+
return function(x, str, isNum, b) {
|
|
626
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
627
|
+
if (isInfinityOrNaN.test(s)) x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
628
|
+
else {
|
|
629
|
+
if (!isNum) {
|
|
630
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
631
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
632
|
+
return !b || b == base ? p1 : m;
|
|
633
|
+
});
|
|
634
|
+
if (b) {
|
|
635
|
+
base = b;
|
|
636
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
637
|
+
}
|
|
638
|
+
if (str != s) return new BigNumber$1(s, base);
|
|
639
|
+
}
|
|
640
|
+
if (BigNumber$1.DEBUG) throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
641
|
+
x.s = null;
|
|
642
|
+
}
|
|
643
|
+
x.c = x.e = null;
|
|
644
|
+
};
|
|
645
|
+
})();
|
|
646
|
+
function round(x, sd, rm, r) {
|
|
647
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
648
|
+
if (xc) {
|
|
649
|
+
out: {
|
|
650
|
+
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
|
|
651
|
+
i = sd - d;
|
|
652
|
+
if (i < 0) {
|
|
653
|
+
i += LOG_BASE;
|
|
654
|
+
j = sd;
|
|
655
|
+
n = xc[ni = 0];
|
|
656
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
657
|
+
} else {
|
|
658
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
659
|
+
if (ni >= xc.length) if (r) {
|
|
660
|
+
for (; xc.length <= ni; xc.push(0));
|
|
661
|
+
n = rd = 0;
|
|
662
|
+
d = 1;
|
|
663
|
+
i %= LOG_BASE;
|
|
664
|
+
j = i - LOG_BASE + 1;
|
|
665
|
+
} else break out;
|
|
666
|
+
else {
|
|
667
|
+
n = k = xc[ni];
|
|
668
|
+
for (d = 1; k >= 10; k /= 10, d++);
|
|
669
|
+
i %= LOG_BASE;
|
|
670
|
+
j = i - LOG_BASE + d;
|
|
671
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
675
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
676
|
+
if (sd < 1 || !xc[0]) {
|
|
677
|
+
xc.length = 0;
|
|
678
|
+
if (r) {
|
|
679
|
+
sd -= x.e + 1;
|
|
680
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
681
|
+
x.e = -sd || 0;
|
|
682
|
+
} else xc[0] = x.e = 0;
|
|
683
|
+
return x;
|
|
684
|
+
}
|
|
685
|
+
if (i == 0) {
|
|
686
|
+
xc.length = ni;
|
|
687
|
+
k = 1;
|
|
688
|
+
ni--;
|
|
689
|
+
} else {
|
|
690
|
+
xc.length = ni + 1;
|
|
691
|
+
k = pows10[LOG_BASE - i];
|
|
692
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
693
|
+
}
|
|
694
|
+
if (r) for (;;) if (ni == 0) {
|
|
695
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
|
|
696
|
+
j = xc[0] += k;
|
|
697
|
+
for (k = 1; j >= 10; j /= 10, k++);
|
|
698
|
+
if (i != k) {
|
|
699
|
+
x.e++;
|
|
700
|
+
if (xc[0] == BASE) xc[0] = 1;
|
|
701
|
+
}
|
|
702
|
+
break;
|
|
703
|
+
} else {
|
|
704
|
+
xc[ni] += k;
|
|
705
|
+
if (xc[ni] != BASE) break;
|
|
706
|
+
xc[ni--] = 0;
|
|
707
|
+
k = 1;
|
|
708
|
+
}
|
|
709
|
+
for (i = xc.length; xc[--i] === 0; xc.pop());
|
|
710
|
+
}
|
|
711
|
+
if (x.e > MAX_EXP) x.c = x.e = null;
|
|
712
|
+
else if (x.e < MIN_EXP) x.c = [x.e = 0];
|
|
713
|
+
}
|
|
714
|
+
return x;
|
|
715
|
+
}
|
|
716
|
+
function valueOf(n) {
|
|
717
|
+
var str, e = n.e;
|
|
718
|
+
if (e === null) return n.toString();
|
|
719
|
+
str = coeffToString(n.c);
|
|
720
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
721
|
+
return n.s < 0 ? "-" + str : str;
|
|
722
|
+
}
|
|
723
|
+
P.absoluteValue = P.abs = function() {
|
|
724
|
+
var x = new BigNumber$1(this);
|
|
725
|
+
if (x.s < 0) x.s = 1;
|
|
726
|
+
return x;
|
|
727
|
+
};
|
|
728
|
+
P.comparedTo = function(y, b) {
|
|
729
|
+
return compare(this, new BigNumber$1(y, b));
|
|
730
|
+
};
|
|
731
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
732
|
+
var c, n, v, x = this;
|
|
733
|
+
if (dp != null) {
|
|
734
|
+
intCheck(dp, 0, MAX);
|
|
735
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
736
|
+
else intCheck(rm, 0, 8);
|
|
737
|
+
return round(new BigNumber$1(x), dp + x.e + 1, rm);
|
|
738
|
+
}
|
|
739
|
+
if (!(c = x.c)) return null;
|
|
740
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
741
|
+
if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
|
|
742
|
+
if (n < 0) n = 0;
|
|
743
|
+
return n;
|
|
744
|
+
};
|
|
745
|
+
P.dividedBy = P.div = function(y, b) {
|
|
746
|
+
return div(this, new BigNumber$1(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
747
|
+
};
|
|
748
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
749
|
+
return div(this, new BigNumber$1(y, b), 0, 1);
|
|
750
|
+
};
|
|
751
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
752
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
753
|
+
n = new BigNumber$1(n);
|
|
754
|
+
if (n.c && !n.isInteger()) throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
755
|
+
if (m != null) m = new BigNumber$1(m);
|
|
756
|
+
nIsBig = n.e > 14;
|
|
757
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
758
|
+
y = new BigNumber$1(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
759
|
+
return m ? y.mod(m) : y;
|
|
760
|
+
}
|
|
761
|
+
nIsNeg = n.s < 0;
|
|
762
|
+
if (m) {
|
|
763
|
+
if (m.c ? !m.c[0] : !m.s) return new BigNumber$1(NaN);
|
|
764
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
765
|
+
if (isModExp) x = x.mod(m);
|
|
766
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
|
767
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
768
|
+
if (x.e > -1) k = 1 / k;
|
|
769
|
+
return new BigNumber$1(nIsNeg ? 1 / k : k);
|
|
770
|
+
} else if (POW_PRECISION) k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
771
|
+
if (nIsBig) {
|
|
772
|
+
half = new BigNumber$1(.5);
|
|
773
|
+
if (nIsNeg) n.s = 1;
|
|
774
|
+
nIsOdd = isOdd(n);
|
|
775
|
+
} else {
|
|
776
|
+
i = Math.abs(+valueOf(n));
|
|
777
|
+
nIsOdd = i % 2;
|
|
778
|
+
}
|
|
779
|
+
y = new BigNumber$1(ONE);
|
|
780
|
+
for (;;) {
|
|
781
|
+
if (nIsOdd) {
|
|
782
|
+
y = y.times(x);
|
|
783
|
+
if (!y.c) break;
|
|
784
|
+
if (k) {
|
|
785
|
+
if (y.c.length > k) y.c.length = k;
|
|
786
|
+
} else if (isModExp) y = y.mod(m);
|
|
787
|
+
}
|
|
788
|
+
if (i) {
|
|
789
|
+
i = mathfloor(i / 2);
|
|
790
|
+
if (i === 0) break;
|
|
791
|
+
nIsOdd = i % 2;
|
|
792
|
+
} else {
|
|
793
|
+
n = n.times(half);
|
|
794
|
+
round(n, n.e + 1, 1);
|
|
795
|
+
if (n.e > 14) nIsOdd = isOdd(n);
|
|
796
|
+
else {
|
|
797
|
+
i = +valueOf(n);
|
|
798
|
+
if (i === 0) break;
|
|
799
|
+
nIsOdd = i % 2;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
x = x.times(x);
|
|
803
|
+
if (k) {
|
|
804
|
+
if (x.c && x.c.length > k) x.c.length = k;
|
|
805
|
+
} else if (isModExp) x = x.mod(m);
|
|
806
|
+
}
|
|
807
|
+
if (isModExp) return y;
|
|
808
|
+
if (nIsNeg) y = ONE.div(y);
|
|
809
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
810
|
+
};
|
|
811
|
+
P.integerValue = function(rm) {
|
|
812
|
+
var n = new BigNumber$1(this);
|
|
813
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
814
|
+
else intCheck(rm, 0, 8);
|
|
815
|
+
return round(n, n.e + 1, rm);
|
|
816
|
+
};
|
|
817
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
818
|
+
return compare(this, new BigNumber$1(y, b)) === 0;
|
|
819
|
+
};
|
|
820
|
+
P.isFinite = function() {
|
|
821
|
+
return !!this.c;
|
|
822
|
+
};
|
|
823
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
824
|
+
return compare(this, new BigNumber$1(y, b)) > 0;
|
|
825
|
+
};
|
|
826
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
827
|
+
return (b = compare(this, new BigNumber$1(y, b))) === 1 || b === 0;
|
|
828
|
+
};
|
|
829
|
+
P.isInteger = function() {
|
|
830
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
831
|
+
};
|
|
832
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
833
|
+
return compare(this, new BigNumber$1(y, b)) < 0;
|
|
834
|
+
};
|
|
835
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
836
|
+
return (b = compare(this, new BigNumber$1(y, b))) === -1 || b === 0;
|
|
837
|
+
};
|
|
838
|
+
P.isNaN = function() {
|
|
839
|
+
return !this.s;
|
|
840
|
+
};
|
|
841
|
+
P.isNegative = function() {
|
|
842
|
+
return this.s < 0;
|
|
843
|
+
};
|
|
844
|
+
P.isPositive = function() {
|
|
845
|
+
return this.s > 0;
|
|
846
|
+
};
|
|
847
|
+
P.isZero = function() {
|
|
848
|
+
return !!this.c && this.c[0] == 0;
|
|
849
|
+
};
|
|
850
|
+
P.minus = function(y, b) {
|
|
851
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
852
|
+
y = new BigNumber$1(y, b);
|
|
853
|
+
b = y.s;
|
|
854
|
+
if (!a || !b) return new BigNumber$1(NaN);
|
|
855
|
+
if (a != b) {
|
|
856
|
+
y.s = -b;
|
|
857
|
+
return x.plus(y);
|
|
858
|
+
}
|
|
859
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
860
|
+
if (!xe || !ye) {
|
|
861
|
+
if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber$1(yc ? x : NaN);
|
|
862
|
+
if (!xc[0] || !yc[0]) return yc[0] ? (y.s = -b, y) : new BigNumber$1(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
863
|
+
}
|
|
864
|
+
xe = bitFloor(xe);
|
|
865
|
+
ye = bitFloor(ye);
|
|
866
|
+
xc = xc.slice();
|
|
867
|
+
if (a = xe - ye) {
|
|
868
|
+
if (xLTy = a < 0) {
|
|
869
|
+
a = -a;
|
|
870
|
+
t = xc;
|
|
871
|
+
} else {
|
|
872
|
+
ye = xe;
|
|
873
|
+
t = yc;
|
|
874
|
+
}
|
|
875
|
+
t.reverse();
|
|
876
|
+
for (b = a; b--; t.push(0));
|
|
877
|
+
t.reverse();
|
|
878
|
+
} else {
|
|
879
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
880
|
+
for (a = b = 0; b < j; b++) if (xc[b] != yc[b]) {
|
|
881
|
+
xLTy = xc[b] < yc[b];
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (xLTy) {
|
|
886
|
+
t = xc;
|
|
887
|
+
xc = yc;
|
|
888
|
+
yc = t;
|
|
889
|
+
y.s = -y.s;
|
|
890
|
+
}
|
|
891
|
+
b = (j = yc.length) - (i = xc.length);
|
|
892
|
+
if (b > 0) for (; b--; xc[i++] = 0);
|
|
893
|
+
b = BASE - 1;
|
|
894
|
+
for (; j > a;) {
|
|
895
|
+
if (xc[--j] < yc[j]) {
|
|
896
|
+
for (i = j; i && !xc[--i]; xc[i] = b);
|
|
897
|
+
--xc[i];
|
|
898
|
+
xc[j] += BASE;
|
|
899
|
+
}
|
|
900
|
+
xc[j] -= yc[j];
|
|
901
|
+
}
|
|
902
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye);
|
|
903
|
+
if (!xc[0]) {
|
|
904
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
905
|
+
y.c = [y.e = 0];
|
|
906
|
+
return y;
|
|
907
|
+
}
|
|
908
|
+
return normalise(y, xc, ye);
|
|
909
|
+
};
|
|
910
|
+
P.modulo = P.mod = function(y, b) {
|
|
911
|
+
var q, s, x = this;
|
|
912
|
+
y = new BigNumber$1(y, b);
|
|
913
|
+
if (!x.c || !y.s || y.c && !y.c[0]) return new BigNumber$1(NaN);
|
|
914
|
+
else if (!y.c || x.c && !x.c[0]) return new BigNumber$1(x);
|
|
915
|
+
if (MODULO_MODE == 9) {
|
|
916
|
+
s = y.s;
|
|
917
|
+
y.s = 1;
|
|
918
|
+
q = div(x, y, 0, 3);
|
|
919
|
+
y.s = s;
|
|
920
|
+
q.s *= s;
|
|
921
|
+
} else q = div(x, y, 0, MODULO_MODE);
|
|
922
|
+
y = x.minus(q.times(y));
|
|
923
|
+
if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
|
|
924
|
+
return y;
|
|
925
|
+
};
|
|
926
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
927
|
+
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber$1(y, b)).c;
|
|
928
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
929
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) y.c = y.e = y.s = null;
|
|
930
|
+
else {
|
|
931
|
+
y.s *= x.s;
|
|
932
|
+
if (!xc || !yc) y.c = y.e = null;
|
|
933
|
+
else {
|
|
934
|
+
y.c = [0];
|
|
935
|
+
y.e = 0;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return y;
|
|
939
|
+
}
|
|
940
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
941
|
+
y.s *= x.s;
|
|
942
|
+
xcL = xc.length;
|
|
943
|
+
ycL = yc.length;
|
|
944
|
+
if (xcL < ycL) {
|
|
945
|
+
zc = xc;
|
|
946
|
+
xc = yc;
|
|
947
|
+
yc = zc;
|
|
948
|
+
i = xcL;
|
|
949
|
+
xcL = ycL;
|
|
950
|
+
ycL = i;
|
|
951
|
+
}
|
|
952
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0));
|
|
953
|
+
base = BASE;
|
|
954
|
+
sqrtBase = SQRT_BASE;
|
|
955
|
+
for (i = ycL; --i >= 0;) {
|
|
956
|
+
c = 0;
|
|
957
|
+
ylo = yc[i] % sqrtBase;
|
|
958
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
959
|
+
for (k = xcL, j = i + k; j > i;) {
|
|
960
|
+
xlo = xc[--k] % sqrtBase;
|
|
961
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
962
|
+
m = yhi * xlo + xhi * ylo;
|
|
963
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
964
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
965
|
+
zc[j--] = xlo % base;
|
|
966
|
+
}
|
|
967
|
+
zc[j] = c;
|
|
968
|
+
}
|
|
969
|
+
if (c) ++e;
|
|
970
|
+
else zc.splice(0, 1);
|
|
971
|
+
return normalise(y, zc, e);
|
|
972
|
+
};
|
|
973
|
+
P.negated = function() {
|
|
974
|
+
var x = new BigNumber$1(this);
|
|
975
|
+
x.s = -x.s || null;
|
|
976
|
+
return x;
|
|
977
|
+
};
|
|
978
|
+
P.plus = function(y, b) {
|
|
979
|
+
var t, x = this, a = x.s;
|
|
980
|
+
y = new BigNumber$1(y, b);
|
|
981
|
+
b = y.s;
|
|
982
|
+
if (!a || !b) return new BigNumber$1(NaN);
|
|
983
|
+
if (a != b) {
|
|
984
|
+
y.s = -b;
|
|
985
|
+
return x.minus(y);
|
|
986
|
+
}
|
|
987
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
988
|
+
if (!xe || !ye) {
|
|
989
|
+
if (!xc || !yc) return new BigNumber$1(a / 0);
|
|
990
|
+
if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber$1(xc[0] ? x : a * 0);
|
|
991
|
+
}
|
|
992
|
+
xe = bitFloor(xe);
|
|
993
|
+
ye = bitFloor(ye);
|
|
994
|
+
xc = xc.slice();
|
|
995
|
+
if (a = xe - ye) {
|
|
996
|
+
if (a > 0) {
|
|
997
|
+
ye = xe;
|
|
998
|
+
t = yc;
|
|
999
|
+
} else {
|
|
1000
|
+
a = -a;
|
|
1001
|
+
t = xc;
|
|
1002
|
+
}
|
|
1003
|
+
t.reverse();
|
|
1004
|
+
for (; a--; t.push(0));
|
|
1005
|
+
t.reverse();
|
|
1006
|
+
}
|
|
1007
|
+
a = xc.length;
|
|
1008
|
+
b = yc.length;
|
|
1009
|
+
if (a - b < 0) {
|
|
1010
|
+
t = yc;
|
|
1011
|
+
yc = xc;
|
|
1012
|
+
xc = t;
|
|
1013
|
+
b = a;
|
|
1014
|
+
}
|
|
1015
|
+
for (a = 0; b;) {
|
|
1016
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
1017
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
1018
|
+
}
|
|
1019
|
+
if (a) {
|
|
1020
|
+
xc = [a].concat(xc);
|
|
1021
|
+
++ye;
|
|
1022
|
+
}
|
|
1023
|
+
return normalise(y, xc, ye);
|
|
1024
|
+
};
|
|
1025
|
+
P.precision = P.sd = function(sd, rm) {
|
|
1026
|
+
var c, n, v, x = this;
|
|
1027
|
+
if (sd != null && sd !== !!sd) {
|
|
1028
|
+
intCheck(sd, 1, MAX);
|
|
1029
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
1030
|
+
else intCheck(rm, 0, 8);
|
|
1031
|
+
return round(new BigNumber$1(x), sd, rm);
|
|
1032
|
+
}
|
|
1033
|
+
if (!(c = x.c)) return null;
|
|
1034
|
+
v = c.length - 1;
|
|
1035
|
+
n = v * LOG_BASE + 1;
|
|
1036
|
+
if (v = c[v]) {
|
|
1037
|
+
for (; v % 10 == 0; v /= 10, n--);
|
|
1038
|
+
for (v = c[0]; v >= 10; v /= 10, n++);
|
|
1039
|
+
}
|
|
1040
|
+
if (sd && x.e + 1 > n) n = x.e + 1;
|
|
1041
|
+
return n;
|
|
1042
|
+
};
|
|
1043
|
+
P.shiftedBy = function(k) {
|
|
1044
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
1045
|
+
return this.times("1e" + k);
|
|
1046
|
+
};
|
|
1047
|
+
P.squareRoot = P.sqrt = function() {
|
|
1048
|
+
var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber$1("0.5");
|
|
1049
|
+
if (s !== 1 || !c || !c[0]) return new BigNumber$1(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : Infinity);
|
|
1050
|
+
s = Math.sqrt(+valueOf(x));
|
|
1051
|
+
if (s == 0 || s == Infinity) {
|
|
1052
|
+
n = coeffToString(c);
|
|
1053
|
+
if ((n.length + e) % 2 == 0) n += "0";
|
|
1054
|
+
s = Math.sqrt(+n);
|
|
1055
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
1056
|
+
if (s == Infinity) n = "5e" + e;
|
|
1057
|
+
else {
|
|
1058
|
+
n = s.toExponential();
|
|
1059
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
1060
|
+
}
|
|
1061
|
+
r = new BigNumber$1(n);
|
|
1062
|
+
} else r = new BigNumber$1(s + "");
|
|
1063
|
+
if (r.c[0]) {
|
|
1064
|
+
e = r.e;
|
|
1065
|
+
s = e + dp;
|
|
1066
|
+
if (s < 3) s = 0;
|
|
1067
|
+
for (;;) {
|
|
1068
|
+
t = r;
|
|
1069
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
1070
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
1071
|
+
if (r.e < e) --s;
|
|
1072
|
+
n = n.slice(s - 3, s + 1);
|
|
1073
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
1074
|
+
if (!rep) {
|
|
1075
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
1076
|
+
if (t.times(t).eq(x)) {
|
|
1077
|
+
r = t;
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
dp += 4;
|
|
1082
|
+
s += 4;
|
|
1083
|
+
rep = 1;
|
|
1084
|
+
} else {
|
|
1085
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
1086
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
1087
|
+
m = !r.times(r).eq(x);
|
|
1088
|
+
}
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
1095
|
+
};
|
|
1096
|
+
P.toExponential = function(dp, rm) {
|
|
1097
|
+
if (dp != null) {
|
|
1098
|
+
intCheck(dp, 0, MAX);
|
|
1099
|
+
dp++;
|
|
1100
|
+
}
|
|
1101
|
+
return format(this, dp, rm, 1);
|
|
1102
|
+
};
|
|
1103
|
+
P.toFixed = function(dp, rm) {
|
|
1104
|
+
if (dp != null) {
|
|
1105
|
+
intCheck(dp, 0, MAX);
|
|
1106
|
+
dp = dp + this.e + 1;
|
|
1107
|
+
}
|
|
1108
|
+
return format(this, dp, rm);
|
|
1109
|
+
};
|
|
1110
|
+
P.toFormat = function(dp, rm, format$1) {
|
|
1111
|
+
var str, x = this;
|
|
1112
|
+
if (format$1 == null) if (dp != null && rm && typeof rm == "object") {
|
|
1113
|
+
format$1 = rm;
|
|
1114
|
+
rm = null;
|
|
1115
|
+
} else if (dp && typeof dp == "object") {
|
|
1116
|
+
format$1 = dp;
|
|
1117
|
+
dp = rm = null;
|
|
1118
|
+
} else format$1 = FORMAT;
|
|
1119
|
+
else if (typeof format$1 != "object") throw Error(bignumberError + "Argument not an object: " + format$1);
|
|
1120
|
+
str = x.toFixed(dp, rm);
|
|
1121
|
+
if (x.c) {
|
|
1122
|
+
var i, arr = str.split("."), g1 = +format$1.groupSize, g2 = +format$1.secondaryGroupSize, groupSeparator = format$1.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
1123
|
+
if (g2) {
|
|
1124
|
+
i = g1;
|
|
1125
|
+
g1 = g2;
|
|
1126
|
+
g2 = i;
|
|
1127
|
+
len -= i;
|
|
1128
|
+
}
|
|
1129
|
+
if (g1 > 0 && len > 0) {
|
|
1130
|
+
i = len % g1 || g1;
|
|
1131
|
+
intPart = intDigits.substr(0, i);
|
|
1132
|
+
for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
|
|
1133
|
+
if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
|
|
1134
|
+
if (isNeg) intPart = "-" + intPart;
|
|
1135
|
+
}
|
|
1136
|
+
str = fractionPart ? intPart + (format$1.decimalSeparator || "") + ((g2 = +format$1.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format$1.fractionGroupSeparator || "")) : fractionPart) : intPart;
|
|
1137
|
+
}
|
|
1138
|
+
return (format$1.prefix || "") + str + (format$1.suffix || "");
|
|
1139
|
+
};
|
|
1140
|
+
P.toFraction = function(md) {
|
|
1141
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
1142
|
+
if (md != null) {
|
|
1143
|
+
n = new BigNumber$1(md);
|
|
1144
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
1145
|
+
}
|
|
1146
|
+
if (!xc) return new BigNumber$1(x);
|
|
1147
|
+
d = new BigNumber$1(ONE);
|
|
1148
|
+
n1 = d0 = new BigNumber$1(ONE);
|
|
1149
|
+
d1 = n0 = new BigNumber$1(ONE);
|
|
1150
|
+
s = coeffToString(xc);
|
|
1151
|
+
e = d.e = s.length - x.e - 1;
|
|
1152
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
1153
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
1154
|
+
exp = MAX_EXP;
|
|
1155
|
+
MAX_EXP = Infinity;
|
|
1156
|
+
n = new BigNumber$1(s);
|
|
1157
|
+
n0.c[0] = 0;
|
|
1158
|
+
for (;;) {
|
|
1159
|
+
q = div(n, d, 0, 1);
|
|
1160
|
+
d2 = d0.plus(q.times(d1));
|
|
1161
|
+
if (d2.comparedTo(md) == 1) break;
|
|
1162
|
+
d0 = d1;
|
|
1163
|
+
d1 = d2;
|
|
1164
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
1165
|
+
n0 = d2;
|
|
1166
|
+
d = n.minus(q.times(d2 = d));
|
|
1167
|
+
n = d2;
|
|
1168
|
+
}
|
|
1169
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
1170
|
+
n0 = n0.plus(d2.times(n1));
|
|
1171
|
+
d0 = d0.plus(d2.times(d1));
|
|
1172
|
+
n0.s = n1.s = x.s;
|
|
1173
|
+
e = e * 2;
|
|
1174
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
1175
|
+
MAX_EXP = exp;
|
|
1176
|
+
return r;
|
|
1177
|
+
};
|
|
1178
|
+
P.toNumber = function() {
|
|
1179
|
+
return +valueOf(this);
|
|
1180
|
+
};
|
|
1181
|
+
P.toPrecision = function(sd, rm) {
|
|
1182
|
+
if (sd != null) intCheck(sd, 1, MAX);
|
|
1183
|
+
return format(this, sd, rm, 2);
|
|
1184
|
+
};
|
|
1185
|
+
P.toString = function(b) {
|
|
1186
|
+
var str, n = this, s = n.s, e = n.e;
|
|
1187
|
+
if (e === null) if (s) {
|
|
1188
|
+
str = "Infinity";
|
|
1189
|
+
if (s < 0) str = "-" + str;
|
|
1190
|
+
} else str = "NaN";
|
|
1191
|
+
else {
|
|
1192
|
+
if (b == null) str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
1193
|
+
else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
1194
|
+
n = round(new BigNumber$1(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
1195
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
1196
|
+
} else {
|
|
1197
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
1198
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
1199
|
+
}
|
|
1200
|
+
if (s < 0 && n.c[0]) str = "-" + str;
|
|
1201
|
+
}
|
|
1202
|
+
return str;
|
|
1203
|
+
};
|
|
1204
|
+
P.valueOf = P.toJSON = function() {
|
|
1205
|
+
return valueOf(this);
|
|
1206
|
+
};
|
|
1207
|
+
P._isBigNumber = true;
|
|
1208
|
+
P[Symbol.toStringTag] = "BigNumber";
|
|
1209
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
|
|
1210
|
+
if (configObject != null) BigNumber$1.set(configObject);
|
|
1211
|
+
return BigNumber$1;
|
|
1212
|
+
}
|
|
1213
|
+
function bitFloor(n) {
|
|
1214
|
+
var i = n | 0;
|
|
1215
|
+
return n > 0 || n === i ? i : i - 1;
|
|
1216
|
+
}
|
|
1217
|
+
function coeffToString(a) {
|
|
1218
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
1219
|
+
for (; i < j;) {
|
|
1220
|
+
s = a[i++] + "";
|
|
1221
|
+
z = LOG_BASE - s.length;
|
|
1222
|
+
for (; z--; s = "0" + s);
|
|
1223
|
+
r += s;
|
|
1224
|
+
}
|
|
1225
|
+
for (j = r.length; r.charCodeAt(--j) === 48;);
|
|
1226
|
+
return r.slice(0, j + 1 || 1);
|
|
1227
|
+
}
|
|
1228
|
+
function compare(x, y) {
|
|
1229
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
1230
|
+
if (!i || !j) return null;
|
|
1231
|
+
a = xc && !xc[0];
|
|
1232
|
+
b = yc && !yc[0];
|
|
1233
|
+
if (a || b) return a ? b ? 0 : -j : i;
|
|
1234
|
+
if (i != j) return i;
|
|
1235
|
+
a = i < 0;
|
|
1236
|
+
b = k == l;
|
|
1237
|
+
if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
|
|
1238
|
+
if (!b) return k > l ^ a ? 1 : -1;
|
|
1239
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
1240
|
+
for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
1241
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
1242
|
+
}
|
|
1243
|
+
function intCheck(n, min, max, name) {
|
|
1244
|
+
if (n < min || n > max || n !== mathfloor(n)) throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
1245
|
+
}
|
|
1246
|
+
function isOdd(n) {
|
|
1247
|
+
var k = n.c.length - 1;
|
|
1248
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
1249
|
+
}
|
|
1250
|
+
function toExponential(str, e) {
|
|
1251
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
1252
|
+
}
|
|
1253
|
+
function toFixedPoint(str, e, z) {
|
|
1254
|
+
var len, zs;
|
|
1255
|
+
if (e < 0) {
|
|
1256
|
+
for (zs = z + "."; ++e; zs += z);
|
|
1257
|
+
str = zs + str;
|
|
1258
|
+
} else {
|
|
1259
|
+
len = str.length;
|
|
1260
|
+
if (++e > len) {
|
|
1261
|
+
for (zs = z, e -= len; --e; zs += z);
|
|
1262
|
+
str += zs;
|
|
1263
|
+
} else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
|
|
1264
|
+
}
|
|
1265
|
+
return str;
|
|
1266
|
+
}
|
|
1267
|
+
var BigNumber = clone();
|
|
1268
|
+
|
|
1269
|
+
//#endregion
|
|
1270
|
+
//#region ../../utils/dist/esm/constants-BxcSsKjm.js
|
|
1271
|
+
var BigNumber_default = BigNumber;
|
|
1272
|
+
/**
|
|
1273
|
+
* Converts a value to BigNumber if it isn't already
|
|
1274
|
+
*/
|
|
1275
|
+
const toBigNumber = (value) => {
|
|
1276
|
+
if (value instanceof BigNumber) return value;
|
|
1277
|
+
return new BigNumber(value);
|
|
1278
|
+
};
|
|
1279
|
+
/**
|
|
1280
|
+
* Converts a value to Wei (multiplies by 10^decimals) default to 18 decimals
|
|
1281
|
+
*/
|
|
1282
|
+
const toChainFormat = (value, decimals = 18) => {
|
|
1283
|
+
return toBigNumber(value).multipliedBy(new BigNumber(10).pow(decimals));
|
|
1284
|
+
};
|
|
1285
|
+
const DEFAULT_GAS_LIMIT = 4e5;
|
|
1286
|
+
const DEFAULT_GAS_PRICE = 16e7;
|
|
1287
|
+
const DEFAULT_BLOCK_TIMEOUT_HEIGHT = 120;
|
|
1288
|
+
const DEFAULT_BLOCK_TIME_IN_SECONDS = .7;
|
|
1289
|
+
/**
|
|
1290
|
+
* Default timeout for transaction block inclusion polling.
|
|
1291
|
+
*
|
|
1292
|
+
* Calculation: 120 blocks × 0.7 seconds/block = 84 seconds = 84,000ms
|
|
1293
|
+
*/
|
|
1294
|
+
const DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = Math.floor(DEFAULT_BLOCK_TIMEOUT_HEIGHT * DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3);
|
|
1295
|
+
const DEFAULT_TIMESTAMP_TIMEOUT_MS = 60 * 1e3 * 3;
|
|
1296
|
+
const getDefaultStdFee = () => ({
|
|
1297
|
+
amount: [{
|
|
1298
|
+
amount: new BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString(),
|
|
1299
|
+
denom: "inj"
|
|
1300
|
+
}],
|
|
1301
|
+
gas: DEFAULT_GAS_LIMIT.toString(),
|
|
1302
|
+
payer: "",
|
|
1303
|
+
granter: "",
|
|
1304
|
+
feePayer: ""
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region ../../utils/dist/esm/index.js
|
|
1309
|
+
const getStdFeeFromObject = (args) => {
|
|
1310
|
+
if (!args) return getDefaultStdFee();
|
|
1311
|
+
const { payer, granter, feePayer, gasPrice = DEFAULT_GAS_PRICE, gas = DEFAULT_GAS_LIMIT.toString() } = args;
|
|
1312
|
+
const gasNormalized = toBigNumber(gas).toFixed(0);
|
|
1313
|
+
const gasPriceNormalized = toBigNumber(gasPrice).toFixed(0);
|
|
1314
|
+
return {
|
|
1315
|
+
amount: [{
|
|
1316
|
+
denom: "inj",
|
|
1317
|
+
amount: toBigNumber(gasNormalized).times(gasPriceNormalized).toFixed()
|
|
1318
|
+
}],
|
|
1319
|
+
gas: toBigNumber(gasNormalized).toFixed(),
|
|
1320
|
+
payer,
|
|
1321
|
+
granter,
|
|
1322
|
+
feePayer
|
|
1323
|
+
};
|
|
1324
|
+
};
|
|
1325
|
+
const getStdFeeFromString = (gasPrice) => {
|
|
1326
|
+
const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
|
|
1327
|
+
if (!matchResult) throw new Error("Invalid gas price string");
|
|
1328
|
+
const [_, amount] = matchResult;
|
|
1329
|
+
return getStdFeeFromObject({
|
|
1330
|
+
gas: toChainFormat(amount, 18).dividedBy(DEFAULT_GAS_PRICE).toFixed(0),
|
|
1331
|
+
gasPrice: DEFAULT_GAS_PRICE
|
|
1332
|
+
});
|
|
1333
|
+
};
|
|
1334
|
+
const getStdFee = (args) => {
|
|
1335
|
+
if (!args) return getDefaultStdFee();
|
|
1336
|
+
if (typeof args === "string") return getStdFeeFromString(args);
|
|
1337
|
+
return getStdFeeFromObject({ ...args });
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
//#endregion
|
|
1341
|
+
//#region src/utils/tx.ts
|
|
1342
|
+
const createEip712StdSignDoc = ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs }) => ({
|
|
1343
|
+
chain_id: chainId,
|
|
1344
|
+
timeout_height: timeoutHeight || "",
|
|
1345
|
+
account_number: accountNumber.toString(),
|
|
1346
|
+
sequence: sequence.toString(),
|
|
1347
|
+
fee: getStdFee({ gas }),
|
|
1348
|
+
msgs: msgs.map((m) => m.toEip712()),
|
|
1349
|
+
memo: memo || ""
|
|
1350
|
+
});
|
|
1351
|
+
|
|
1352
|
+
//#endregion
|
|
1353
|
+
//#region src/utils/wallet.ts
|
|
1354
|
+
const isEvmWallet = (wallet) => [
|
|
1355
|
+
Wallet.Magic,
|
|
1356
|
+
Wallet.Rabby,
|
|
1357
|
+
Wallet.BitGet,
|
|
1358
|
+
Wallet.Ledger,
|
|
1359
|
+
Wallet.Phantom,
|
|
1360
|
+
Wallet.Rainbow,
|
|
1361
|
+
Wallet.Turnkey,
|
|
1362
|
+
Wallet.Metamask,
|
|
1363
|
+
Wallet.OkxWallet,
|
|
1364
|
+
Wallet.PrivateKey,
|
|
1365
|
+
Wallet.TrezorBip32,
|
|
1366
|
+
Wallet.TrezorBip44,
|
|
1367
|
+
Wallet.TrustWallet,
|
|
1368
|
+
Wallet.LedgerLegacy,
|
|
1369
|
+
Wallet.WalletConnect,
|
|
1370
|
+
Wallet.CosmostationEth
|
|
1371
|
+
].includes(wallet);
|
|
1372
|
+
const isCosmosWallet = (wallet) => !isEvmWallet(wallet);
|
|
1373
|
+
const isEvmBrowserWallet = (wallet) => [
|
|
1374
|
+
Wallet.Rabby,
|
|
1375
|
+
Wallet.BitGet,
|
|
1376
|
+
Wallet.Phantom,
|
|
1377
|
+
Wallet.Rainbow,
|
|
1378
|
+
Wallet.Metamask,
|
|
1379
|
+
Wallet.OkxWallet,
|
|
1380
|
+
Wallet.TrustWallet
|
|
1381
|
+
].includes(wallet);
|
|
1382
|
+
const isCosmosBrowserWallet = (wallet) => [
|
|
1383
|
+
Wallet.Leap,
|
|
1384
|
+
Wallet.Keplr,
|
|
1385
|
+
Wallet.Ninji,
|
|
1386
|
+
Wallet.OWallet,
|
|
1387
|
+
Wallet.Cosmostation
|
|
1388
|
+
].includes(wallet);
|
|
1389
|
+
const isEip712V2OnlyWallet = (wallet) => [
|
|
1390
|
+
Wallet.Magic,
|
|
1391
|
+
Wallet.Phantom,
|
|
1392
|
+
Wallet.Metamask,
|
|
1393
|
+
Wallet.WalletConnect
|
|
1394
|
+
].includes(wallet);
|
|
1395
|
+
const isCosmosAminoOnlyWallet = (wallet) => [Wallet.LedgerCosmos].includes(wallet);
|
|
1396
|
+
|
|
1397
|
+
//#endregion
|
|
1398
|
+
//#region src/utils/cosmos.ts
|
|
1399
|
+
const createCosmosSignDocFromSignDoc = (signDoc) => {
|
|
1400
|
+
return CosmosTxV1Beta1TxPb.SignDoc.create({
|
|
1401
|
+
bodyBytes: signDoc.bodyBytes,
|
|
1402
|
+
authInfoBytes: signDoc.authInfoBytes,
|
|
1403
|
+
accountNumber: BigInt(signDoc.accountNumber),
|
|
1404
|
+
chainId: signDoc.chainId
|
|
1405
|
+
});
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region src/utils/address.ts
|
|
1410
|
+
const getInjectiveSignerAddress = (address) => {
|
|
1411
|
+
if (!address) return "";
|
|
1412
|
+
if (address.startsWith("inj")) return address;
|
|
1413
|
+
if (address.startsWith("0x")) return getInjectiveAddress(address);
|
|
1414
|
+
return "";
|
|
1415
|
+
};
|
|
1416
|
+
const getEthereumSignerAddress = (address) => {
|
|
1417
|
+
if (!address) return "";
|
|
1418
|
+
if (address.startsWith("0x")) return address;
|
|
1419
|
+
if (address.startsWith("inj")) return getEthereumAddress(address);
|
|
1420
|
+
return "";
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
//#endregion
|
|
1424
|
+
//#region src/utils/alchemy.ts
|
|
1425
|
+
const getKeyFromRpcUrl = (rpcUrl) => {
|
|
1426
|
+
if (!rpcUrl.includes("alchemyapi.io") && !rpcUrl.includes("alchemy.com")) return rpcUrl;
|
|
1427
|
+
const [key] = rpcUrl.split("/").reverse();
|
|
1428
|
+
return key;
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
//#endregion
|
|
1432
|
+
//#region src/utils/constants.ts
|
|
1433
|
+
const GWEI_IN_WEI = toBigNumber(1e9);
|
|
1434
|
+
const TIP_IN_GWEI = toBigNumber(2).times(GWEI_IN_WEI);
|
|
1435
|
+
const DEFAULT_BASE_DERIVATION_PATH = "m/44'/60'";
|
|
1436
|
+
const DEFAULT_NUM_ADDRESSES_TO_FETCH = 5;
|
|
1437
|
+
const DEFAULT_ADDRESS_SEARCH_LIMIT = 100;
|
|
1438
|
+
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
|
|
1441
|
+
function _typeof(o) {
|
|
1442
|
+
"@babel/helpers - typeof";
|
|
1443
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
1444
|
+
return typeof o$1;
|
|
1445
|
+
} : function(o$1) {
|
|
1446
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
1447
|
+
}, _typeof(o);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
//#endregion
|
|
1451
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
|
|
1452
|
+
function toPrimitive(t, r) {
|
|
1453
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1454
|
+
var e = t[Symbol.toPrimitive];
|
|
1455
|
+
if (void 0 !== e) {
|
|
1456
|
+
var i = e.call(t, r || "default");
|
|
1457
|
+
if ("object" != _typeof(i)) return i;
|
|
1458
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1459
|
+
}
|
|
1460
|
+
return ("string" === r ? String : Number)(t);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
//#endregion
|
|
1464
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
|
|
1465
|
+
function toPropertyKey(t) {
|
|
1466
|
+
var i = toPrimitive(t, "string");
|
|
1467
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
//#endregion
|
|
1471
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
|
|
1472
|
+
function _defineProperty(e, r, t) {
|
|
1473
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1474
|
+
value: t,
|
|
1475
|
+
enumerable: !0,
|
|
1476
|
+
configurable: !0,
|
|
1477
|
+
writable: !0
|
|
1478
|
+
}) : e[r] = t, e;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
//#endregion
|
|
1482
|
+
//#region src/base.ts
|
|
1483
|
+
var BaseConcreteStrategy = class {
|
|
1484
|
+
constructor(args) {
|
|
1485
|
+
_defineProperty(this, "chainId", void 0);
|
|
1486
|
+
_defineProperty(this, "evmChainId", void 0);
|
|
1487
|
+
_defineProperty(this, "listeners", {});
|
|
1488
|
+
_defineProperty(this, "metadata", void 0);
|
|
1489
|
+
this.evmChainId = "evmOptions" in args && args.evmOptions ? args.evmOptions.evmChainId : void 0;
|
|
1490
|
+
this.chainId = args.chainId;
|
|
1491
|
+
this.metadata = args.metadata;
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
//#endregion
|
|
1496
|
+
export { BaseConcreteStrategy, BroadcastMode, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, GWEI_IN_WEI, MagicProvider, TIP_IN_GWEI, TurnkeyProvider, Wallet, WalletAction, WalletDeviceType, WalletEventListener, createCosmosSignDocFromSignDoc, createEip712StdSignDoc, getEthereumSignerAddress, getInjectiveSignerAddress, getKeyFromRpcUrl, isCosmosAminoOnlyWallet, isCosmosBrowserWallet, isCosmosWallet, isEip712V2OnlyWallet, isEvmBrowserWallet, isEvmWallet };
|