@injectivelabs/wallet-ledger 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 +2364 -0
- package/dist/cjs/index.d.cts +115 -0
- package/dist/cjs/package.json +2 -2
- package/dist/esm/chunk-BIPRnmEv.js +23 -0
- package/dist/esm/index.d.ts +115 -4
- package/dist/esm/index.js +2073 -4
- package/dist/esm/package.json +2 -2
- package/package.json +17 -17
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/strategy/Ledger/Base.d.ts +0 -45
- package/dist/cjs/strategy/Ledger/Base.js +0 -283
- package/dist/cjs/strategy/Ledger/Eip1193Provider.d.ts +0 -4500
- package/dist/cjs/strategy/Ledger/Eip1193Provider.js +0 -192
- package/dist/cjs/strategy/Ledger/LedgerLegacy.d.ts +0 -5
- package/dist/cjs/strategy/Ledger/LedgerLegacy.js +0 -17
- package/dist/cjs/strategy/Ledger/LedgerLive.d.ts +0 -5
- package/dist/cjs/strategy/Ledger/LedgerLive.js +0 -17
- package/dist/cjs/strategy/Ledger/hw/AccountManager.d.ts +0 -22
- package/dist/cjs/strategy/Ledger/hw/AccountManager.js +0 -88
- package/dist/cjs/strategy/Ledger/hw/index.d.ts +0 -11
- package/dist/cjs/strategy/Ledger/hw/index.js +0 -66
- package/dist/cjs/strategy/Ledger/utils.d.ts +0 -16
- package/dist/cjs/strategy/Ledger/utils.js +0 -19
- package/dist/cjs/strategy/LedgerCosmos/hw/AccountManager.d.ts +0 -20
- package/dist/cjs/strategy/LedgerCosmos/hw/AccountManager.js +0 -69
- package/dist/cjs/strategy/LedgerCosmos/hw/index.d.ts +0 -11
- package/dist/cjs/strategy/LedgerCosmos/hw/index.js +0 -49
- package/dist/cjs/strategy/LedgerCosmos/index.d.ts +0 -37
- package/dist/cjs/strategy/LedgerCosmos/index.js +0 -159
- package/dist/cjs/strategy/lib.d.ts +0 -14
- package/dist/cjs/strategy/lib.js +0 -86
- package/dist/cjs/types.d.ts +0 -22
- package/dist/cjs/types.js +0 -12
- package/dist/esm/strategy/Ledger/Base.d.ts +0 -45
- package/dist/esm/strategy/Ledger/Base.js +0 -277
- package/dist/esm/strategy/Ledger/Eip1193Provider.d.ts +0 -4500
- package/dist/esm/strategy/Ledger/Eip1193Provider.js +0 -155
- package/dist/esm/strategy/Ledger/LedgerLegacy.d.ts +0 -5
- package/dist/esm/strategy/Ledger/LedgerLegacy.js +0 -10
- package/dist/esm/strategy/Ledger/LedgerLive.d.ts +0 -5
- package/dist/esm/strategy/Ledger/LedgerLive.js +0 -10
- package/dist/esm/strategy/Ledger/hw/AccountManager.d.ts +0 -22
- package/dist/esm/strategy/Ledger/hw/AccountManager.js +0 -85
- package/dist/esm/strategy/Ledger/hw/index.d.ts +0 -11
- package/dist/esm/strategy/Ledger/hw/index.js +0 -60
- package/dist/esm/strategy/Ledger/utils.d.ts +0 -16
- package/dist/esm/strategy/Ledger/utils.js +0 -14
- package/dist/esm/strategy/LedgerCosmos/hw/AccountManager.d.ts +0 -20
- package/dist/esm/strategy/LedgerCosmos/hw/AccountManager.js +0 -66
- package/dist/esm/strategy/LedgerCosmos/hw/index.d.ts +0 -11
- package/dist/esm/strategy/LedgerCosmos/hw/index.js +0 -43
- package/dist/esm/strategy/LedgerCosmos/index.d.ts +0 -37
- package/dist/esm/strategy/LedgerCosmos/index.js +0 -152
- package/dist/esm/strategy/lib.d.ts +0 -14
- package/dist/esm/strategy/lib.js +0 -46
- package/dist/esm/types.d.ts +0 -22
- package/dist/esm/types.js +0 -9
|
@@ -0,0 +1,2364 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
let viem = require("viem");
|
|
28
|
+
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
29
|
+
let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
|
|
30
|
+
let alchemy_sdk = require("alchemy-sdk");
|
|
31
|
+
let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
|
|
32
|
+
let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
|
|
33
|
+
let viem_chains = require("viem/chains");
|
|
34
|
+
viem_chains = __toESM(viem_chains);
|
|
35
|
+
|
|
36
|
+
//#region src/types.ts
|
|
37
|
+
const LedgerDerivationPathType = {
|
|
38
|
+
LedgerLive: "ledger-live",
|
|
39
|
+
LedgerMew: "ledger-mew"
|
|
40
|
+
};
|
|
41
|
+
const WalletLedger = {
|
|
42
|
+
Ledger: "ledger",
|
|
43
|
+
LedgerCosmos: "ledger-cosmos",
|
|
44
|
+
LedgerLegacy: "ledger-legacy"
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region ../../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
|
|
49
|
+
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 = [
|
|
50
|
+
1,
|
|
51
|
+
10,
|
|
52
|
+
100,
|
|
53
|
+
1e3,
|
|
54
|
+
1e4,
|
|
55
|
+
1e5,
|
|
56
|
+
1e6,
|
|
57
|
+
1e7,
|
|
58
|
+
1e8,
|
|
59
|
+
1e9,
|
|
60
|
+
1e10,
|
|
61
|
+
1e11,
|
|
62
|
+
0xe8d4a51000,
|
|
63
|
+
0x9184e72a000
|
|
64
|
+
], SQRT_BASE = 1e7, MAX = 1e9;
|
|
65
|
+
function clone(configObject) {
|
|
66
|
+
var div, convertBase, parseNumeric, P = BigNumber$1.prototype = {
|
|
67
|
+
constructor: BigNumber$1,
|
|
68
|
+
toString: null,
|
|
69
|
+
valueOf: null
|
|
70
|
+
}, 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 = {
|
|
71
|
+
prefix: "",
|
|
72
|
+
groupSize: 3,
|
|
73
|
+
secondaryGroupSize: 0,
|
|
74
|
+
groupSeparator: ",",
|
|
75
|
+
decimalSeparator: ".",
|
|
76
|
+
fractionGroupSize: 0,
|
|
77
|
+
fractionGroupSeparator: "\xA0",
|
|
78
|
+
suffix: ""
|
|
79
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
80
|
+
function BigNumber$1(v, b) {
|
|
81
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
82
|
+
if (!(x instanceof BigNumber$1)) return new BigNumber$1(v, b);
|
|
83
|
+
if (b == null) {
|
|
84
|
+
if (v && v._isBigNumber === true) {
|
|
85
|
+
x.s = v.s;
|
|
86
|
+
if (!v.c || v.e > MAX_EXP) x.c = x.e = null;
|
|
87
|
+
else if (v.e < MIN_EXP) x.c = [x.e = 0];
|
|
88
|
+
else {
|
|
89
|
+
x.e = v.e;
|
|
90
|
+
x.c = v.c.slice();
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
95
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
96
|
+
if (v === ~~v) {
|
|
97
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++);
|
|
98
|
+
if (e > MAX_EXP) x.c = x.e = null;
|
|
99
|
+
else {
|
|
100
|
+
x.e = e;
|
|
101
|
+
x.c = [v];
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
str = String(v);
|
|
106
|
+
} else {
|
|
107
|
+
if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
|
|
108
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
109
|
+
}
|
|
110
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
111
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
112
|
+
if (e < 0) e = i;
|
|
113
|
+
e += +str.slice(i + 1);
|
|
114
|
+
str = str.substring(0, i);
|
|
115
|
+
} else if (e < 0) e = str.length;
|
|
116
|
+
} else {
|
|
117
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
118
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
119
|
+
x = new BigNumber$1(v);
|
|
120
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
121
|
+
}
|
|
122
|
+
str = String(v);
|
|
123
|
+
if (isNum = typeof v == "number") {
|
|
124
|
+
if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
|
|
125
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
126
|
+
if (BigNumber$1.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) throw Error(tooManyDigits + v);
|
|
127
|
+
} else x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
128
|
+
alphabet = ALPHABET.slice(0, b);
|
|
129
|
+
e = i = 0;
|
|
130
|
+
for (len = str.length; i < len; i++) if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
131
|
+
if (c == ".") {
|
|
132
|
+
if (i > e) {
|
|
133
|
+
e = len;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
} else if (!caseChanged) {
|
|
137
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
138
|
+
caseChanged = true;
|
|
139
|
+
i = -1;
|
|
140
|
+
e = 0;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return parseNumeric(x, String(v), isNum, b);
|
|
145
|
+
}
|
|
146
|
+
isNum = false;
|
|
147
|
+
str = convertBase(str, b, 10, x.s);
|
|
148
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
149
|
+
else e = str.length;
|
|
150
|
+
}
|
|
151
|
+
for (i = 0; str.charCodeAt(i) === 48; i++);
|
|
152
|
+
for (len = str.length; str.charCodeAt(--len) === 48;);
|
|
153
|
+
if (str = str.slice(i, ++len)) {
|
|
154
|
+
len -= i;
|
|
155
|
+
if (isNum && BigNumber$1.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) throw Error(tooManyDigits + x.s * v);
|
|
156
|
+
if ((e = e - i - 1) > MAX_EXP) x.c = x.e = null;
|
|
157
|
+
else if (e < MIN_EXP) x.c = [x.e = 0];
|
|
158
|
+
else {
|
|
159
|
+
x.e = e;
|
|
160
|
+
x.c = [];
|
|
161
|
+
i = (e + 1) % LOG_BASE;
|
|
162
|
+
if (e < 0) i += LOG_BASE;
|
|
163
|
+
if (i < len) {
|
|
164
|
+
if (i) x.c.push(+str.slice(0, i));
|
|
165
|
+
for (len -= LOG_BASE; i < len;) x.c.push(+str.slice(i, i += LOG_BASE));
|
|
166
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
167
|
+
} else i -= len;
|
|
168
|
+
for (; i--; str += "0");
|
|
169
|
+
x.c.push(+str);
|
|
170
|
+
}
|
|
171
|
+
} else x.c = [x.e = 0];
|
|
172
|
+
}
|
|
173
|
+
BigNumber$1.clone = clone;
|
|
174
|
+
BigNumber$1.ROUND_UP = 0;
|
|
175
|
+
BigNumber$1.ROUND_DOWN = 1;
|
|
176
|
+
BigNumber$1.ROUND_CEIL = 2;
|
|
177
|
+
BigNumber$1.ROUND_FLOOR = 3;
|
|
178
|
+
BigNumber$1.ROUND_HALF_UP = 4;
|
|
179
|
+
BigNumber$1.ROUND_HALF_DOWN = 5;
|
|
180
|
+
BigNumber$1.ROUND_HALF_EVEN = 6;
|
|
181
|
+
BigNumber$1.ROUND_HALF_CEIL = 7;
|
|
182
|
+
BigNumber$1.ROUND_HALF_FLOOR = 8;
|
|
183
|
+
BigNumber$1.EUCLID = 9;
|
|
184
|
+
BigNumber$1.config = BigNumber$1.set = function(obj) {
|
|
185
|
+
var p, v;
|
|
186
|
+
if (obj != null) if (typeof obj == "object") {
|
|
187
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
188
|
+
v = obj[p];
|
|
189
|
+
intCheck(v, 0, MAX, p);
|
|
190
|
+
DECIMAL_PLACES = v;
|
|
191
|
+
}
|
|
192
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
193
|
+
v = obj[p];
|
|
194
|
+
intCheck(v, 0, 8, p);
|
|
195
|
+
ROUNDING_MODE = v;
|
|
196
|
+
}
|
|
197
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
198
|
+
v = obj[p];
|
|
199
|
+
if (v && v.pop) {
|
|
200
|
+
intCheck(v[0], -MAX, 0, p);
|
|
201
|
+
intCheck(v[1], 0, MAX, p);
|
|
202
|
+
TO_EXP_NEG = v[0];
|
|
203
|
+
TO_EXP_POS = v[1];
|
|
204
|
+
} else {
|
|
205
|
+
intCheck(v, -MAX, MAX, p);
|
|
206
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
210
|
+
v = obj[p];
|
|
211
|
+
if (v && v.pop) {
|
|
212
|
+
intCheck(v[0], -MAX, -1, p);
|
|
213
|
+
intCheck(v[1], 1, MAX, p);
|
|
214
|
+
MIN_EXP = v[0];
|
|
215
|
+
MAX_EXP = v[1];
|
|
216
|
+
} else {
|
|
217
|
+
intCheck(v, -MAX, MAX, p);
|
|
218
|
+
if (v) MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
219
|
+
else throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
223
|
+
v = obj[p];
|
|
224
|
+
if (v === !!v) if (v) if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) CRYPTO = v;
|
|
225
|
+
else {
|
|
226
|
+
CRYPTO = !v;
|
|
227
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
228
|
+
}
|
|
229
|
+
else CRYPTO = v;
|
|
230
|
+
else throw Error(bignumberError + p + " not true or false: " + v);
|
|
231
|
+
}
|
|
232
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
233
|
+
v = obj[p];
|
|
234
|
+
intCheck(v, 0, 9, p);
|
|
235
|
+
MODULO_MODE = v;
|
|
236
|
+
}
|
|
237
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
238
|
+
v = obj[p];
|
|
239
|
+
intCheck(v, 0, MAX, p);
|
|
240
|
+
POW_PRECISION = v;
|
|
241
|
+
}
|
|
242
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
243
|
+
v = obj[p];
|
|
244
|
+
if (typeof v == "object") FORMAT = v;
|
|
245
|
+
else throw Error(bignumberError + p + " not an object: " + v);
|
|
246
|
+
}
|
|
247
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
248
|
+
v = obj[p];
|
|
249
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
250
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
251
|
+
ALPHABET = v;
|
|
252
|
+
} else throw Error(bignumberError + p + " invalid: " + v);
|
|
253
|
+
}
|
|
254
|
+
} else throw Error(bignumberError + "Object expected: " + obj);
|
|
255
|
+
return {
|
|
256
|
+
DECIMAL_PLACES,
|
|
257
|
+
ROUNDING_MODE,
|
|
258
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
259
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
260
|
+
CRYPTO,
|
|
261
|
+
MODULO_MODE,
|
|
262
|
+
POW_PRECISION,
|
|
263
|
+
FORMAT,
|
|
264
|
+
ALPHABET
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
BigNumber$1.isBigNumber = function(v) {
|
|
268
|
+
if (!v || v._isBigNumber !== true) return false;
|
|
269
|
+
if (!BigNumber$1.DEBUG) return true;
|
|
270
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
271
|
+
out: if ({}.toString.call(c) == "[object Array]") {
|
|
272
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
273
|
+
if (c[0] === 0) {
|
|
274
|
+
if (e === 0 && c.length === 1) return true;
|
|
275
|
+
break out;
|
|
276
|
+
}
|
|
277
|
+
i = (e + 1) % LOG_BASE;
|
|
278
|
+
if (i < 1) i += LOG_BASE;
|
|
279
|
+
if (String(c[0]).length == i) {
|
|
280
|
+
for (i = 0; i < c.length; i++) {
|
|
281
|
+
n = c[i];
|
|
282
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
|
|
283
|
+
}
|
|
284
|
+
if (n !== 0) return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) return true;
|
|
288
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
289
|
+
};
|
|
290
|
+
BigNumber$1.maximum = BigNumber$1.max = function() {
|
|
291
|
+
return maxOrMin(arguments, -1);
|
|
292
|
+
};
|
|
293
|
+
BigNumber$1.minimum = BigNumber$1.min = function() {
|
|
294
|
+
return maxOrMin(arguments, 1);
|
|
295
|
+
};
|
|
296
|
+
BigNumber$1.random = (function() {
|
|
297
|
+
var pow2_53 = 9007199254740992;
|
|
298
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
299
|
+
return mathfloor(Math.random() * pow2_53);
|
|
300
|
+
} : function() {
|
|
301
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
302
|
+
};
|
|
303
|
+
return function(dp) {
|
|
304
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber$1(ONE);
|
|
305
|
+
if (dp == null) dp = DECIMAL_PLACES;
|
|
306
|
+
else intCheck(dp, 0, MAX);
|
|
307
|
+
k = mathceil(dp / LOG_BASE);
|
|
308
|
+
if (CRYPTO) if (crypto.getRandomValues) {
|
|
309
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
310
|
+
for (; i < k;) {
|
|
311
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
312
|
+
if (v >= 9e15) {
|
|
313
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
314
|
+
a[i] = b[0];
|
|
315
|
+
a[i + 1] = b[1];
|
|
316
|
+
} else {
|
|
317
|
+
c.push(v % 0x5af3107a4000);
|
|
318
|
+
i += 2;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
i = k / 2;
|
|
322
|
+
} else if (crypto.randomBytes) {
|
|
323
|
+
a = crypto.randomBytes(k *= 7);
|
|
324
|
+
for (; i < k;) {
|
|
325
|
+
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];
|
|
326
|
+
if (v >= 9e15) crypto.randomBytes(7).copy(a, i);
|
|
327
|
+
else {
|
|
328
|
+
c.push(v % 0x5af3107a4000);
|
|
329
|
+
i += 7;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
i = k / 7;
|
|
333
|
+
} else {
|
|
334
|
+
CRYPTO = false;
|
|
335
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
336
|
+
}
|
|
337
|
+
if (!CRYPTO) for (; i < k;) {
|
|
338
|
+
v = random53bitInt();
|
|
339
|
+
if (v < 9e15) c[i++] = v % 0x5af3107a4000;
|
|
340
|
+
}
|
|
341
|
+
k = c[--i];
|
|
342
|
+
dp %= LOG_BASE;
|
|
343
|
+
if (k && dp) {
|
|
344
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
345
|
+
c[i] = mathfloor(k / v) * v;
|
|
346
|
+
}
|
|
347
|
+
for (; c[i] === 0; c.pop(), i--);
|
|
348
|
+
if (i < 0) c = [e = 0];
|
|
349
|
+
else {
|
|
350
|
+
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
|
|
351
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
|
|
352
|
+
if (i < LOG_BASE) e -= LOG_BASE - i;
|
|
353
|
+
}
|
|
354
|
+
rand.e = e;
|
|
355
|
+
rand.c = c;
|
|
356
|
+
return rand;
|
|
357
|
+
};
|
|
358
|
+
})();
|
|
359
|
+
BigNumber$1.sum = function() {
|
|
360
|
+
var i = 1, args = arguments, sum = new BigNumber$1(args[0]);
|
|
361
|
+
for (; i < args.length;) sum = sum.plus(args[i++]);
|
|
362
|
+
return sum;
|
|
363
|
+
};
|
|
364
|
+
convertBase = (function() {
|
|
365
|
+
var decimal = "0123456789";
|
|
366
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
367
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
368
|
+
for (; i < len;) {
|
|
369
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
|
|
370
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
371
|
+
for (j = 0; j < arr.length; j++) if (arr[j] > baseOut - 1) {
|
|
372
|
+
if (arr[j + 1] == null) arr[j + 1] = 0;
|
|
373
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
374
|
+
arr[j] %= baseOut;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return arr.reverse();
|
|
378
|
+
}
|
|
379
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
380
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
381
|
+
if (i >= 0) {
|
|
382
|
+
k = POW_PRECISION;
|
|
383
|
+
POW_PRECISION = 0;
|
|
384
|
+
str = str.replace(".", "");
|
|
385
|
+
y = new BigNumber$1(baseIn);
|
|
386
|
+
x = y.pow(str.length - i);
|
|
387
|
+
POW_PRECISION = k;
|
|
388
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
|
|
389
|
+
y.e = y.c.length;
|
|
390
|
+
}
|
|
391
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
392
|
+
e = k = xc.length;
|
|
393
|
+
for (; xc[--k] == 0; xc.pop());
|
|
394
|
+
if (!xc[0]) return alphabet.charAt(0);
|
|
395
|
+
if (i < 0) --e;
|
|
396
|
+
else {
|
|
397
|
+
x.c = xc;
|
|
398
|
+
x.e = e;
|
|
399
|
+
x.s = sign;
|
|
400
|
+
x = div(x, y, dp, rm, baseOut);
|
|
401
|
+
xc = x.c;
|
|
402
|
+
r = x.r;
|
|
403
|
+
e = x.e;
|
|
404
|
+
}
|
|
405
|
+
d = e + dp + 1;
|
|
406
|
+
i = xc[d];
|
|
407
|
+
k = baseOut / 2;
|
|
408
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
409
|
+
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));
|
|
410
|
+
if (d < 1 || !xc[0]) str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
411
|
+
else {
|
|
412
|
+
xc.length = d;
|
|
413
|
+
if (r) for (--baseOut; ++xc[--d] > baseOut;) {
|
|
414
|
+
xc[d] = 0;
|
|
415
|
+
if (!d) {
|
|
416
|
+
++e;
|
|
417
|
+
xc = [1].concat(xc);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
for (k = xc.length; !xc[--k];);
|
|
421
|
+
for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]));
|
|
422
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
423
|
+
}
|
|
424
|
+
return str;
|
|
425
|
+
};
|
|
426
|
+
})();
|
|
427
|
+
div = (function() {
|
|
428
|
+
function multiply(x, k, base) {
|
|
429
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
430
|
+
for (x = x.slice(); i--;) {
|
|
431
|
+
xlo = x[i] % SQRT_BASE;
|
|
432
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
433
|
+
m = khi * xlo + xhi * klo;
|
|
434
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
435
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
436
|
+
x[i] = temp % base;
|
|
437
|
+
}
|
|
438
|
+
if (carry) x = [carry].concat(x);
|
|
439
|
+
return x;
|
|
440
|
+
}
|
|
441
|
+
function compare$1(a, b, aL, bL) {
|
|
442
|
+
var i, cmp;
|
|
443
|
+
if (aL != bL) cmp = aL > bL ? 1 : -1;
|
|
444
|
+
else for (i = cmp = 0; i < aL; i++) if (a[i] != b[i]) {
|
|
445
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
return cmp;
|
|
449
|
+
}
|
|
450
|
+
function subtract(a, b, aL, base) {
|
|
451
|
+
var i = 0;
|
|
452
|
+
for (; aL--;) {
|
|
453
|
+
a[aL] -= i;
|
|
454
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
455
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
456
|
+
}
|
|
457
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1));
|
|
458
|
+
}
|
|
459
|
+
return function(x, y, dp, rm, base) {
|
|
460
|
+
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;
|
|
461
|
+
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);
|
|
462
|
+
q = new BigNumber$1(s);
|
|
463
|
+
qc = q.c = [];
|
|
464
|
+
e = x.e - y.e;
|
|
465
|
+
s = dp + e + 1;
|
|
466
|
+
if (!base) {
|
|
467
|
+
base = BASE;
|
|
468
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
469
|
+
s = s / LOG_BASE | 0;
|
|
470
|
+
}
|
|
471
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++);
|
|
472
|
+
if (yc[i] > (xc[i] || 0)) e--;
|
|
473
|
+
if (s < 0) {
|
|
474
|
+
qc.push(1);
|
|
475
|
+
more = true;
|
|
476
|
+
} else {
|
|
477
|
+
xL = xc.length;
|
|
478
|
+
yL = yc.length;
|
|
479
|
+
i = 0;
|
|
480
|
+
s += 2;
|
|
481
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
482
|
+
if (n > 1) {
|
|
483
|
+
yc = multiply(yc, n, base);
|
|
484
|
+
xc = multiply(xc, n, base);
|
|
485
|
+
yL = yc.length;
|
|
486
|
+
xL = xc.length;
|
|
487
|
+
}
|
|
488
|
+
xi = yL;
|
|
489
|
+
rem = xc.slice(0, yL);
|
|
490
|
+
remL = rem.length;
|
|
491
|
+
for (; remL < yL; rem[remL++] = 0);
|
|
492
|
+
yz = yc.slice();
|
|
493
|
+
yz = [0].concat(yz);
|
|
494
|
+
yc0 = yc[0];
|
|
495
|
+
if (yc[1] >= base / 2) yc0++;
|
|
496
|
+
do {
|
|
497
|
+
n = 0;
|
|
498
|
+
cmp = compare$1(yc, rem, yL, remL);
|
|
499
|
+
if (cmp < 0) {
|
|
500
|
+
rem0 = rem[0];
|
|
501
|
+
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
502
|
+
n = mathfloor(rem0 / yc0);
|
|
503
|
+
if (n > 1) {
|
|
504
|
+
if (n >= base) n = base - 1;
|
|
505
|
+
prod = multiply(yc, n, base);
|
|
506
|
+
prodL = prod.length;
|
|
507
|
+
remL = rem.length;
|
|
508
|
+
while (compare$1(prod, rem, prodL, remL) == 1) {
|
|
509
|
+
n--;
|
|
510
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
511
|
+
prodL = prod.length;
|
|
512
|
+
cmp = 1;
|
|
513
|
+
}
|
|
514
|
+
} else {
|
|
515
|
+
if (n == 0) cmp = n = 1;
|
|
516
|
+
prod = yc.slice();
|
|
517
|
+
prodL = prod.length;
|
|
518
|
+
}
|
|
519
|
+
if (prodL < remL) prod = [0].concat(prod);
|
|
520
|
+
subtract(rem, prod, remL, base);
|
|
521
|
+
remL = rem.length;
|
|
522
|
+
if (cmp == -1) while (compare$1(yc, rem, yL, remL) < 1) {
|
|
523
|
+
n++;
|
|
524
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
525
|
+
remL = rem.length;
|
|
526
|
+
}
|
|
527
|
+
} else if (cmp === 0) {
|
|
528
|
+
n++;
|
|
529
|
+
rem = [0];
|
|
530
|
+
}
|
|
531
|
+
qc[i++] = n;
|
|
532
|
+
if (rem[0]) rem[remL++] = xc[xi] || 0;
|
|
533
|
+
else {
|
|
534
|
+
rem = [xc[xi]];
|
|
535
|
+
remL = 1;
|
|
536
|
+
}
|
|
537
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
538
|
+
more = rem[0] != null;
|
|
539
|
+
if (!qc[0]) qc.splice(0, 1);
|
|
540
|
+
}
|
|
541
|
+
if (base == BASE) {
|
|
542
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
|
|
543
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
544
|
+
} else {
|
|
545
|
+
q.e = e;
|
|
546
|
+
q.r = +more;
|
|
547
|
+
}
|
|
548
|
+
return q;
|
|
549
|
+
};
|
|
550
|
+
})();
|
|
551
|
+
function format(n, i, rm, id) {
|
|
552
|
+
var c0, e, ne, len, str;
|
|
553
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
554
|
+
else intCheck(rm, 0, 8);
|
|
555
|
+
if (!n.c) return n.toString();
|
|
556
|
+
c0 = n.c[0];
|
|
557
|
+
ne = n.e;
|
|
558
|
+
if (i == null) {
|
|
559
|
+
str = coeffToString(n.c);
|
|
560
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
561
|
+
} else {
|
|
562
|
+
n = round(new BigNumber$1(n), i, rm);
|
|
563
|
+
e = n.e;
|
|
564
|
+
str = coeffToString(n.c);
|
|
565
|
+
len = str.length;
|
|
566
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
567
|
+
for (; len < i; str += "0", len++);
|
|
568
|
+
str = toExponential(str, e);
|
|
569
|
+
} else {
|
|
570
|
+
i -= ne;
|
|
571
|
+
str = toFixedPoint(str, e, "0");
|
|
572
|
+
if (e + 1 > len) {
|
|
573
|
+
if (--i > 0) for (str += "."; i--; str += "0");
|
|
574
|
+
} else {
|
|
575
|
+
i += e - len;
|
|
576
|
+
if (i > 0) {
|
|
577
|
+
if (e + 1 == len) str += ".";
|
|
578
|
+
for (; i--; str += "0");
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
584
|
+
}
|
|
585
|
+
function maxOrMin(args, n) {
|
|
586
|
+
var k, y, i = 1, x = new BigNumber$1(args[0]);
|
|
587
|
+
for (; i < args.length; i++) {
|
|
588
|
+
y = new BigNumber$1(args[i]);
|
|
589
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) x = y;
|
|
590
|
+
}
|
|
591
|
+
return x;
|
|
592
|
+
}
|
|
593
|
+
function normalise(n, c, e) {
|
|
594
|
+
var i = 1, j = c.length;
|
|
595
|
+
for (; !c[--j]; c.pop());
|
|
596
|
+
for (j = c[0]; j >= 10; j /= 10, i++);
|
|
597
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) n.c = n.e = null;
|
|
598
|
+
else if (e < MIN_EXP) n.c = [n.e = 0];
|
|
599
|
+
else {
|
|
600
|
+
n.e = e;
|
|
601
|
+
n.c = c;
|
|
602
|
+
}
|
|
603
|
+
return n;
|
|
604
|
+
}
|
|
605
|
+
parseNumeric = (function() {
|
|
606
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
607
|
+
return function(x, str, isNum, b) {
|
|
608
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
609
|
+
if (isInfinityOrNaN.test(s)) x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
610
|
+
else {
|
|
611
|
+
if (!isNum) {
|
|
612
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
613
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
614
|
+
return !b || b == base ? p1 : m;
|
|
615
|
+
});
|
|
616
|
+
if (b) {
|
|
617
|
+
base = b;
|
|
618
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
619
|
+
}
|
|
620
|
+
if (str != s) return new BigNumber$1(s, base);
|
|
621
|
+
}
|
|
622
|
+
if (BigNumber$1.DEBUG) throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
623
|
+
x.s = null;
|
|
624
|
+
}
|
|
625
|
+
x.c = x.e = null;
|
|
626
|
+
};
|
|
627
|
+
})();
|
|
628
|
+
function round(x, sd, rm, r) {
|
|
629
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
630
|
+
if (xc) {
|
|
631
|
+
out: {
|
|
632
|
+
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
|
|
633
|
+
i = sd - d;
|
|
634
|
+
if (i < 0) {
|
|
635
|
+
i += LOG_BASE;
|
|
636
|
+
j = sd;
|
|
637
|
+
n = xc[ni = 0];
|
|
638
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
639
|
+
} else {
|
|
640
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
641
|
+
if (ni >= xc.length) if (r) {
|
|
642
|
+
for (; xc.length <= ni; xc.push(0));
|
|
643
|
+
n = rd = 0;
|
|
644
|
+
d = 1;
|
|
645
|
+
i %= LOG_BASE;
|
|
646
|
+
j = i - LOG_BASE + 1;
|
|
647
|
+
} else break out;
|
|
648
|
+
else {
|
|
649
|
+
n = k = xc[ni];
|
|
650
|
+
for (d = 1; k >= 10; k /= 10, d++);
|
|
651
|
+
i %= LOG_BASE;
|
|
652
|
+
j = i - LOG_BASE + d;
|
|
653
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
657
|
+
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));
|
|
658
|
+
if (sd < 1 || !xc[0]) {
|
|
659
|
+
xc.length = 0;
|
|
660
|
+
if (r) {
|
|
661
|
+
sd -= x.e + 1;
|
|
662
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
663
|
+
x.e = -sd || 0;
|
|
664
|
+
} else xc[0] = x.e = 0;
|
|
665
|
+
return x;
|
|
666
|
+
}
|
|
667
|
+
if (i == 0) {
|
|
668
|
+
xc.length = ni;
|
|
669
|
+
k = 1;
|
|
670
|
+
ni--;
|
|
671
|
+
} else {
|
|
672
|
+
xc.length = ni + 1;
|
|
673
|
+
k = pows10[LOG_BASE - i];
|
|
674
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
675
|
+
}
|
|
676
|
+
if (r) for (;;) if (ni == 0) {
|
|
677
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
|
|
678
|
+
j = xc[0] += k;
|
|
679
|
+
for (k = 1; j >= 10; j /= 10, k++);
|
|
680
|
+
if (i != k) {
|
|
681
|
+
x.e++;
|
|
682
|
+
if (xc[0] == BASE) xc[0] = 1;
|
|
683
|
+
}
|
|
684
|
+
break;
|
|
685
|
+
} else {
|
|
686
|
+
xc[ni] += k;
|
|
687
|
+
if (xc[ni] != BASE) break;
|
|
688
|
+
xc[ni--] = 0;
|
|
689
|
+
k = 1;
|
|
690
|
+
}
|
|
691
|
+
for (i = xc.length; xc[--i] === 0; xc.pop());
|
|
692
|
+
}
|
|
693
|
+
if (x.e > MAX_EXP) x.c = x.e = null;
|
|
694
|
+
else if (x.e < MIN_EXP) x.c = [x.e = 0];
|
|
695
|
+
}
|
|
696
|
+
return x;
|
|
697
|
+
}
|
|
698
|
+
function valueOf(n) {
|
|
699
|
+
var str, e = n.e;
|
|
700
|
+
if (e === null) return n.toString();
|
|
701
|
+
str = coeffToString(n.c);
|
|
702
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
703
|
+
return n.s < 0 ? "-" + str : str;
|
|
704
|
+
}
|
|
705
|
+
P.absoluteValue = P.abs = function() {
|
|
706
|
+
var x = new BigNumber$1(this);
|
|
707
|
+
if (x.s < 0) x.s = 1;
|
|
708
|
+
return x;
|
|
709
|
+
};
|
|
710
|
+
P.comparedTo = function(y, b) {
|
|
711
|
+
return compare(this, new BigNumber$1(y, b));
|
|
712
|
+
};
|
|
713
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
714
|
+
var c, n, v, x = this;
|
|
715
|
+
if (dp != null) {
|
|
716
|
+
intCheck(dp, 0, MAX);
|
|
717
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
718
|
+
else intCheck(rm, 0, 8);
|
|
719
|
+
return round(new BigNumber$1(x), dp + x.e + 1, rm);
|
|
720
|
+
}
|
|
721
|
+
if (!(c = x.c)) return null;
|
|
722
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
723
|
+
if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
|
|
724
|
+
if (n < 0) n = 0;
|
|
725
|
+
return n;
|
|
726
|
+
};
|
|
727
|
+
P.dividedBy = P.div = function(y, b) {
|
|
728
|
+
return div(this, new BigNumber$1(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
729
|
+
};
|
|
730
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
731
|
+
return div(this, new BigNumber$1(y, b), 0, 1);
|
|
732
|
+
};
|
|
733
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
734
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
735
|
+
n = new BigNumber$1(n);
|
|
736
|
+
if (n.c && !n.isInteger()) throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
737
|
+
if (m != null) m = new BigNumber$1(m);
|
|
738
|
+
nIsBig = n.e > 14;
|
|
739
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
740
|
+
y = new BigNumber$1(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
741
|
+
return m ? y.mod(m) : y;
|
|
742
|
+
}
|
|
743
|
+
nIsNeg = n.s < 0;
|
|
744
|
+
if (m) {
|
|
745
|
+
if (m.c ? !m.c[0] : !m.s) return new BigNumber$1(NaN);
|
|
746
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
747
|
+
if (isModExp) x = x.mod(m);
|
|
748
|
+
} 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))) {
|
|
749
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
750
|
+
if (x.e > -1) k = 1 / k;
|
|
751
|
+
return new BigNumber$1(nIsNeg ? 1 / k : k);
|
|
752
|
+
} else if (POW_PRECISION) k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
753
|
+
if (nIsBig) {
|
|
754
|
+
half = new BigNumber$1(.5);
|
|
755
|
+
if (nIsNeg) n.s = 1;
|
|
756
|
+
nIsOdd = isOdd(n);
|
|
757
|
+
} else {
|
|
758
|
+
i = Math.abs(+valueOf(n));
|
|
759
|
+
nIsOdd = i % 2;
|
|
760
|
+
}
|
|
761
|
+
y = new BigNumber$1(ONE);
|
|
762
|
+
for (;;) {
|
|
763
|
+
if (nIsOdd) {
|
|
764
|
+
y = y.times(x);
|
|
765
|
+
if (!y.c) break;
|
|
766
|
+
if (k) {
|
|
767
|
+
if (y.c.length > k) y.c.length = k;
|
|
768
|
+
} else if (isModExp) y = y.mod(m);
|
|
769
|
+
}
|
|
770
|
+
if (i) {
|
|
771
|
+
i = mathfloor(i / 2);
|
|
772
|
+
if (i === 0) break;
|
|
773
|
+
nIsOdd = i % 2;
|
|
774
|
+
} else {
|
|
775
|
+
n = n.times(half);
|
|
776
|
+
round(n, n.e + 1, 1);
|
|
777
|
+
if (n.e > 14) nIsOdd = isOdd(n);
|
|
778
|
+
else {
|
|
779
|
+
i = +valueOf(n);
|
|
780
|
+
if (i === 0) break;
|
|
781
|
+
nIsOdd = i % 2;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
x = x.times(x);
|
|
785
|
+
if (k) {
|
|
786
|
+
if (x.c && x.c.length > k) x.c.length = k;
|
|
787
|
+
} else if (isModExp) x = x.mod(m);
|
|
788
|
+
}
|
|
789
|
+
if (isModExp) return y;
|
|
790
|
+
if (nIsNeg) y = ONE.div(y);
|
|
791
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
792
|
+
};
|
|
793
|
+
P.integerValue = function(rm) {
|
|
794
|
+
var n = new BigNumber$1(this);
|
|
795
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
796
|
+
else intCheck(rm, 0, 8);
|
|
797
|
+
return round(n, n.e + 1, rm);
|
|
798
|
+
};
|
|
799
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
800
|
+
return compare(this, new BigNumber$1(y, b)) === 0;
|
|
801
|
+
};
|
|
802
|
+
P.isFinite = function() {
|
|
803
|
+
return !!this.c;
|
|
804
|
+
};
|
|
805
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
806
|
+
return compare(this, new BigNumber$1(y, b)) > 0;
|
|
807
|
+
};
|
|
808
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
809
|
+
return (b = compare(this, new BigNumber$1(y, b))) === 1 || b === 0;
|
|
810
|
+
};
|
|
811
|
+
P.isInteger = function() {
|
|
812
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
813
|
+
};
|
|
814
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
815
|
+
return compare(this, new BigNumber$1(y, b)) < 0;
|
|
816
|
+
};
|
|
817
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
818
|
+
return (b = compare(this, new BigNumber$1(y, b))) === -1 || b === 0;
|
|
819
|
+
};
|
|
820
|
+
P.isNaN = function() {
|
|
821
|
+
return !this.s;
|
|
822
|
+
};
|
|
823
|
+
P.isNegative = function() {
|
|
824
|
+
return this.s < 0;
|
|
825
|
+
};
|
|
826
|
+
P.isPositive = function() {
|
|
827
|
+
return this.s > 0;
|
|
828
|
+
};
|
|
829
|
+
P.isZero = function() {
|
|
830
|
+
return !!this.c && this.c[0] == 0;
|
|
831
|
+
};
|
|
832
|
+
P.minus = function(y, b) {
|
|
833
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
834
|
+
y = new BigNumber$1(y, b);
|
|
835
|
+
b = y.s;
|
|
836
|
+
if (!a || !b) return new BigNumber$1(NaN);
|
|
837
|
+
if (a != b) {
|
|
838
|
+
y.s = -b;
|
|
839
|
+
return x.plus(y);
|
|
840
|
+
}
|
|
841
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
842
|
+
if (!xe || !ye) {
|
|
843
|
+
if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber$1(yc ? x : NaN);
|
|
844
|
+
if (!xc[0] || !yc[0]) return yc[0] ? (y.s = -b, y) : new BigNumber$1(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
845
|
+
}
|
|
846
|
+
xe = bitFloor(xe);
|
|
847
|
+
ye = bitFloor(ye);
|
|
848
|
+
xc = xc.slice();
|
|
849
|
+
if (a = xe - ye) {
|
|
850
|
+
if (xLTy = a < 0) {
|
|
851
|
+
a = -a;
|
|
852
|
+
t = xc;
|
|
853
|
+
} else {
|
|
854
|
+
ye = xe;
|
|
855
|
+
t = yc;
|
|
856
|
+
}
|
|
857
|
+
t.reverse();
|
|
858
|
+
for (b = a; b--; t.push(0));
|
|
859
|
+
t.reverse();
|
|
860
|
+
} else {
|
|
861
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
862
|
+
for (a = b = 0; b < j; b++) if (xc[b] != yc[b]) {
|
|
863
|
+
xLTy = xc[b] < yc[b];
|
|
864
|
+
break;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if (xLTy) {
|
|
868
|
+
t = xc;
|
|
869
|
+
xc = yc;
|
|
870
|
+
yc = t;
|
|
871
|
+
y.s = -y.s;
|
|
872
|
+
}
|
|
873
|
+
b = (j = yc.length) - (i = xc.length);
|
|
874
|
+
if (b > 0) for (; b--; xc[i++] = 0);
|
|
875
|
+
b = BASE - 1;
|
|
876
|
+
for (; j > a;) {
|
|
877
|
+
if (xc[--j] < yc[j]) {
|
|
878
|
+
for (i = j; i && !xc[--i]; xc[i] = b);
|
|
879
|
+
--xc[i];
|
|
880
|
+
xc[j] += BASE;
|
|
881
|
+
}
|
|
882
|
+
xc[j] -= yc[j];
|
|
883
|
+
}
|
|
884
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye);
|
|
885
|
+
if (!xc[0]) {
|
|
886
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
887
|
+
y.c = [y.e = 0];
|
|
888
|
+
return y;
|
|
889
|
+
}
|
|
890
|
+
return normalise(y, xc, ye);
|
|
891
|
+
};
|
|
892
|
+
P.modulo = P.mod = function(y, b) {
|
|
893
|
+
var q, s, x = this;
|
|
894
|
+
y = new BigNumber$1(y, b);
|
|
895
|
+
if (!x.c || !y.s || y.c && !y.c[0]) return new BigNumber$1(NaN);
|
|
896
|
+
else if (!y.c || x.c && !x.c[0]) return new BigNumber$1(x);
|
|
897
|
+
if (MODULO_MODE == 9) {
|
|
898
|
+
s = y.s;
|
|
899
|
+
y.s = 1;
|
|
900
|
+
q = div(x, y, 0, 3);
|
|
901
|
+
y.s = s;
|
|
902
|
+
q.s *= s;
|
|
903
|
+
} else q = div(x, y, 0, MODULO_MODE);
|
|
904
|
+
y = x.minus(q.times(y));
|
|
905
|
+
if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
|
|
906
|
+
return y;
|
|
907
|
+
};
|
|
908
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
909
|
+
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;
|
|
910
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
911
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) y.c = y.e = y.s = null;
|
|
912
|
+
else {
|
|
913
|
+
y.s *= x.s;
|
|
914
|
+
if (!xc || !yc) y.c = y.e = null;
|
|
915
|
+
else {
|
|
916
|
+
y.c = [0];
|
|
917
|
+
y.e = 0;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return y;
|
|
921
|
+
}
|
|
922
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
923
|
+
y.s *= x.s;
|
|
924
|
+
xcL = xc.length;
|
|
925
|
+
ycL = yc.length;
|
|
926
|
+
if (xcL < ycL) {
|
|
927
|
+
zc = xc;
|
|
928
|
+
xc = yc;
|
|
929
|
+
yc = zc;
|
|
930
|
+
i = xcL;
|
|
931
|
+
xcL = ycL;
|
|
932
|
+
ycL = i;
|
|
933
|
+
}
|
|
934
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0));
|
|
935
|
+
base = BASE;
|
|
936
|
+
sqrtBase = SQRT_BASE;
|
|
937
|
+
for (i = ycL; --i >= 0;) {
|
|
938
|
+
c = 0;
|
|
939
|
+
ylo = yc[i] % sqrtBase;
|
|
940
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
941
|
+
for (k = xcL, j = i + k; j > i;) {
|
|
942
|
+
xlo = xc[--k] % sqrtBase;
|
|
943
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
944
|
+
m = yhi * xlo + xhi * ylo;
|
|
945
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
946
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
947
|
+
zc[j--] = xlo % base;
|
|
948
|
+
}
|
|
949
|
+
zc[j] = c;
|
|
950
|
+
}
|
|
951
|
+
if (c) ++e;
|
|
952
|
+
else zc.splice(0, 1);
|
|
953
|
+
return normalise(y, zc, e);
|
|
954
|
+
};
|
|
955
|
+
P.negated = function() {
|
|
956
|
+
var x = new BigNumber$1(this);
|
|
957
|
+
x.s = -x.s || null;
|
|
958
|
+
return x;
|
|
959
|
+
};
|
|
960
|
+
P.plus = function(y, b) {
|
|
961
|
+
var t, x = this, a = x.s;
|
|
962
|
+
y = new BigNumber$1(y, b);
|
|
963
|
+
b = y.s;
|
|
964
|
+
if (!a || !b) return new BigNumber$1(NaN);
|
|
965
|
+
if (a != b) {
|
|
966
|
+
y.s = -b;
|
|
967
|
+
return x.minus(y);
|
|
968
|
+
}
|
|
969
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
970
|
+
if (!xe || !ye) {
|
|
971
|
+
if (!xc || !yc) return new BigNumber$1(a / 0);
|
|
972
|
+
if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber$1(xc[0] ? x : a * 0);
|
|
973
|
+
}
|
|
974
|
+
xe = bitFloor(xe);
|
|
975
|
+
ye = bitFloor(ye);
|
|
976
|
+
xc = xc.slice();
|
|
977
|
+
if (a = xe - ye) {
|
|
978
|
+
if (a > 0) {
|
|
979
|
+
ye = xe;
|
|
980
|
+
t = yc;
|
|
981
|
+
} else {
|
|
982
|
+
a = -a;
|
|
983
|
+
t = xc;
|
|
984
|
+
}
|
|
985
|
+
t.reverse();
|
|
986
|
+
for (; a--; t.push(0));
|
|
987
|
+
t.reverse();
|
|
988
|
+
}
|
|
989
|
+
a = xc.length;
|
|
990
|
+
b = yc.length;
|
|
991
|
+
if (a - b < 0) {
|
|
992
|
+
t = yc;
|
|
993
|
+
yc = xc;
|
|
994
|
+
xc = t;
|
|
995
|
+
b = a;
|
|
996
|
+
}
|
|
997
|
+
for (a = 0; b;) {
|
|
998
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
999
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
1000
|
+
}
|
|
1001
|
+
if (a) {
|
|
1002
|
+
xc = [a].concat(xc);
|
|
1003
|
+
++ye;
|
|
1004
|
+
}
|
|
1005
|
+
return normalise(y, xc, ye);
|
|
1006
|
+
};
|
|
1007
|
+
P.precision = P.sd = function(sd, rm) {
|
|
1008
|
+
var c, n, v, x = this;
|
|
1009
|
+
if (sd != null && sd !== !!sd) {
|
|
1010
|
+
intCheck(sd, 1, MAX);
|
|
1011
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
1012
|
+
else intCheck(rm, 0, 8);
|
|
1013
|
+
return round(new BigNumber$1(x), sd, rm);
|
|
1014
|
+
}
|
|
1015
|
+
if (!(c = x.c)) return null;
|
|
1016
|
+
v = c.length - 1;
|
|
1017
|
+
n = v * LOG_BASE + 1;
|
|
1018
|
+
if (v = c[v]) {
|
|
1019
|
+
for (; v % 10 == 0; v /= 10, n--);
|
|
1020
|
+
for (v = c[0]; v >= 10; v /= 10, n++);
|
|
1021
|
+
}
|
|
1022
|
+
if (sd && x.e + 1 > n) n = x.e + 1;
|
|
1023
|
+
return n;
|
|
1024
|
+
};
|
|
1025
|
+
P.shiftedBy = function(k) {
|
|
1026
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
1027
|
+
return this.times("1e" + k);
|
|
1028
|
+
};
|
|
1029
|
+
P.squareRoot = P.sqrt = function() {
|
|
1030
|
+
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");
|
|
1031
|
+
if (s !== 1 || !c || !c[0]) return new BigNumber$1(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : Infinity);
|
|
1032
|
+
s = Math.sqrt(+valueOf(x));
|
|
1033
|
+
if (s == 0 || s == Infinity) {
|
|
1034
|
+
n = coeffToString(c);
|
|
1035
|
+
if ((n.length + e) % 2 == 0) n += "0";
|
|
1036
|
+
s = Math.sqrt(+n);
|
|
1037
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
1038
|
+
if (s == Infinity) n = "5e" + e;
|
|
1039
|
+
else {
|
|
1040
|
+
n = s.toExponential();
|
|
1041
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
1042
|
+
}
|
|
1043
|
+
r = new BigNumber$1(n);
|
|
1044
|
+
} else r = new BigNumber$1(s + "");
|
|
1045
|
+
if (r.c[0]) {
|
|
1046
|
+
e = r.e;
|
|
1047
|
+
s = e + dp;
|
|
1048
|
+
if (s < 3) s = 0;
|
|
1049
|
+
for (;;) {
|
|
1050
|
+
t = r;
|
|
1051
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
1052
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
1053
|
+
if (r.e < e) --s;
|
|
1054
|
+
n = n.slice(s - 3, s + 1);
|
|
1055
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
1056
|
+
if (!rep) {
|
|
1057
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
1058
|
+
if (t.times(t).eq(x)) {
|
|
1059
|
+
r = t;
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
dp += 4;
|
|
1064
|
+
s += 4;
|
|
1065
|
+
rep = 1;
|
|
1066
|
+
} else {
|
|
1067
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
1068
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
1069
|
+
m = !r.times(r).eq(x);
|
|
1070
|
+
}
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
1077
|
+
};
|
|
1078
|
+
P.toExponential = function(dp, rm) {
|
|
1079
|
+
if (dp != null) {
|
|
1080
|
+
intCheck(dp, 0, MAX);
|
|
1081
|
+
dp++;
|
|
1082
|
+
}
|
|
1083
|
+
return format(this, dp, rm, 1);
|
|
1084
|
+
};
|
|
1085
|
+
P.toFixed = function(dp, rm) {
|
|
1086
|
+
if (dp != null) {
|
|
1087
|
+
intCheck(dp, 0, MAX);
|
|
1088
|
+
dp = dp + this.e + 1;
|
|
1089
|
+
}
|
|
1090
|
+
return format(this, dp, rm);
|
|
1091
|
+
};
|
|
1092
|
+
P.toFormat = function(dp, rm, format$1) {
|
|
1093
|
+
var str, x = this;
|
|
1094
|
+
if (format$1 == null) if (dp != null && rm && typeof rm == "object") {
|
|
1095
|
+
format$1 = rm;
|
|
1096
|
+
rm = null;
|
|
1097
|
+
} else if (dp && typeof dp == "object") {
|
|
1098
|
+
format$1 = dp;
|
|
1099
|
+
dp = rm = null;
|
|
1100
|
+
} else format$1 = FORMAT;
|
|
1101
|
+
else if (typeof format$1 != "object") throw Error(bignumberError + "Argument not an object: " + format$1);
|
|
1102
|
+
str = x.toFixed(dp, rm);
|
|
1103
|
+
if (x.c) {
|
|
1104
|
+
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;
|
|
1105
|
+
if (g2) {
|
|
1106
|
+
i = g1;
|
|
1107
|
+
g1 = g2;
|
|
1108
|
+
g2 = i;
|
|
1109
|
+
len -= i;
|
|
1110
|
+
}
|
|
1111
|
+
if (g1 > 0 && len > 0) {
|
|
1112
|
+
i = len % g1 || g1;
|
|
1113
|
+
intPart = intDigits.substr(0, i);
|
|
1114
|
+
for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
|
|
1115
|
+
if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
|
|
1116
|
+
if (isNeg) intPart = "-" + intPart;
|
|
1117
|
+
}
|
|
1118
|
+
str = fractionPart ? intPart + (format$1.decimalSeparator || "") + ((g2 = +format$1.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format$1.fractionGroupSeparator || "")) : fractionPart) : intPart;
|
|
1119
|
+
}
|
|
1120
|
+
return (format$1.prefix || "") + str + (format$1.suffix || "");
|
|
1121
|
+
};
|
|
1122
|
+
P.toFraction = function(md) {
|
|
1123
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
1124
|
+
if (md != null) {
|
|
1125
|
+
n = new BigNumber$1(md);
|
|
1126
|
+
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));
|
|
1127
|
+
}
|
|
1128
|
+
if (!xc) return new BigNumber$1(x);
|
|
1129
|
+
d = new BigNumber$1(ONE);
|
|
1130
|
+
n1 = d0 = new BigNumber$1(ONE);
|
|
1131
|
+
d1 = n0 = new BigNumber$1(ONE);
|
|
1132
|
+
s = coeffToString(xc);
|
|
1133
|
+
e = d.e = s.length - x.e - 1;
|
|
1134
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
1135
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
1136
|
+
exp = MAX_EXP;
|
|
1137
|
+
MAX_EXP = Infinity;
|
|
1138
|
+
n = new BigNumber$1(s);
|
|
1139
|
+
n0.c[0] = 0;
|
|
1140
|
+
for (;;) {
|
|
1141
|
+
q = div(n, d, 0, 1);
|
|
1142
|
+
d2 = d0.plus(q.times(d1));
|
|
1143
|
+
if (d2.comparedTo(md) == 1) break;
|
|
1144
|
+
d0 = d1;
|
|
1145
|
+
d1 = d2;
|
|
1146
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
1147
|
+
n0 = d2;
|
|
1148
|
+
d = n.minus(q.times(d2 = d));
|
|
1149
|
+
n = d2;
|
|
1150
|
+
}
|
|
1151
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
1152
|
+
n0 = n0.plus(d2.times(n1));
|
|
1153
|
+
d0 = d0.plus(d2.times(d1));
|
|
1154
|
+
n0.s = n1.s = x.s;
|
|
1155
|
+
e = e * 2;
|
|
1156
|
+
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];
|
|
1157
|
+
MAX_EXP = exp;
|
|
1158
|
+
return r;
|
|
1159
|
+
};
|
|
1160
|
+
P.toNumber = function() {
|
|
1161
|
+
return +valueOf(this);
|
|
1162
|
+
};
|
|
1163
|
+
P.toPrecision = function(sd, rm) {
|
|
1164
|
+
if (sd != null) intCheck(sd, 1, MAX);
|
|
1165
|
+
return format(this, sd, rm, 2);
|
|
1166
|
+
};
|
|
1167
|
+
P.toString = function(b) {
|
|
1168
|
+
var str, n = this, s = n.s, e = n.e;
|
|
1169
|
+
if (e === null) if (s) {
|
|
1170
|
+
str = "Infinity";
|
|
1171
|
+
if (s < 0) str = "-" + str;
|
|
1172
|
+
} else str = "NaN";
|
|
1173
|
+
else {
|
|
1174
|
+
if (b == null) str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
1175
|
+
else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
1176
|
+
n = round(new BigNumber$1(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
1177
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
1178
|
+
} else {
|
|
1179
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
1180
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
1181
|
+
}
|
|
1182
|
+
if (s < 0 && n.c[0]) str = "-" + str;
|
|
1183
|
+
}
|
|
1184
|
+
return str;
|
|
1185
|
+
};
|
|
1186
|
+
P.valueOf = P.toJSON = function() {
|
|
1187
|
+
return valueOf(this);
|
|
1188
|
+
};
|
|
1189
|
+
P._isBigNumber = true;
|
|
1190
|
+
P[Symbol.toStringTag] = "BigNumber";
|
|
1191
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
|
|
1192
|
+
if (configObject != null) BigNumber$1.set(configObject);
|
|
1193
|
+
return BigNumber$1;
|
|
1194
|
+
}
|
|
1195
|
+
function bitFloor(n) {
|
|
1196
|
+
var i = n | 0;
|
|
1197
|
+
return n > 0 || n === i ? i : i - 1;
|
|
1198
|
+
}
|
|
1199
|
+
function coeffToString(a) {
|
|
1200
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
1201
|
+
for (; i < j;) {
|
|
1202
|
+
s = a[i++] + "";
|
|
1203
|
+
z = LOG_BASE - s.length;
|
|
1204
|
+
for (; z--; s = "0" + s);
|
|
1205
|
+
r += s;
|
|
1206
|
+
}
|
|
1207
|
+
for (j = r.length; r.charCodeAt(--j) === 48;);
|
|
1208
|
+
return r.slice(0, j + 1 || 1);
|
|
1209
|
+
}
|
|
1210
|
+
function compare(x, y) {
|
|
1211
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
1212
|
+
if (!i || !j) return null;
|
|
1213
|
+
a = xc && !xc[0];
|
|
1214
|
+
b = yc && !yc[0];
|
|
1215
|
+
if (a || b) return a ? b ? 0 : -j : i;
|
|
1216
|
+
if (i != j) return i;
|
|
1217
|
+
a = i < 0;
|
|
1218
|
+
b = k == l;
|
|
1219
|
+
if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
|
|
1220
|
+
if (!b) return k > l ^ a ? 1 : -1;
|
|
1221
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
1222
|
+
for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
1223
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
1224
|
+
}
|
|
1225
|
+
function intCheck(n, min, max, name) {
|
|
1226
|
+
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));
|
|
1227
|
+
}
|
|
1228
|
+
function isOdd(n) {
|
|
1229
|
+
var k = n.c.length - 1;
|
|
1230
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
1231
|
+
}
|
|
1232
|
+
function toExponential(str, e) {
|
|
1233
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
1234
|
+
}
|
|
1235
|
+
function toFixedPoint(str, e, z) {
|
|
1236
|
+
var len, zs;
|
|
1237
|
+
if (e < 0) {
|
|
1238
|
+
for (zs = z + "."; ++e; zs += z);
|
|
1239
|
+
str = zs + str;
|
|
1240
|
+
} else {
|
|
1241
|
+
len = str.length;
|
|
1242
|
+
if (++e > len) {
|
|
1243
|
+
for (zs = z, e -= len; --e; zs += z);
|
|
1244
|
+
str += zs;
|
|
1245
|
+
} else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
|
|
1246
|
+
}
|
|
1247
|
+
return str;
|
|
1248
|
+
}
|
|
1249
|
+
var BigNumber = clone();
|
|
1250
|
+
|
|
1251
|
+
//#endregion
|
|
1252
|
+
//#region ../../utils/dist/esm/constants-BxcSsKjm.js
|
|
1253
|
+
const DEFAULT_BLOCK_TIMEOUT_HEIGHT = 120;
|
|
1254
|
+
const DEFAULT_BLOCK_TIME_IN_SECONDS = .7;
|
|
1255
|
+
/**
|
|
1256
|
+
* Default timeout for transaction block inclusion polling.
|
|
1257
|
+
*
|
|
1258
|
+
* Calculation: 120 blocks × 0.7 seconds/block = 84 seconds = 84,000ms
|
|
1259
|
+
*/
|
|
1260
|
+
const DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = Math.floor(DEFAULT_BLOCK_TIMEOUT_HEIGHT * DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3);
|
|
1261
|
+
const DEFAULT_TIMESTAMP_TIMEOUT_MS = 60 * 1e3 * 3;
|
|
1262
|
+
|
|
1263
|
+
//#endregion
|
|
1264
|
+
//#region ../../../node_modules/.pnpm/@bangjelkoski+store2@2.14.3/node_modules/@bangjelkoski/store2/dist/store2.js
|
|
1265
|
+
var require_store2 = /* @__PURE__ */ __commonJS({ "../../../node_modules/.pnpm/@bangjelkoski+store2@2.14.3/node_modules/@bangjelkoski/store2/dist/store2.js": ((exports, module) => {
|
|
1266
|
+
(function(window, define) {
|
|
1267
|
+
var _ = {
|
|
1268
|
+
version: "2.14.3",
|
|
1269
|
+
areas: {},
|
|
1270
|
+
apis: {},
|
|
1271
|
+
nsdelim: ".",
|
|
1272
|
+
inherit: function(api, o) {
|
|
1273
|
+
for (var p in api) if (!o.hasOwnProperty(p)) Object.defineProperty(o, p, Object.getOwnPropertyDescriptor(api, p));
|
|
1274
|
+
return o;
|
|
1275
|
+
},
|
|
1276
|
+
stringify: function(d, fn) {
|
|
1277
|
+
return d === void 0 || typeof d === "function" ? d + "" : JSON.stringify(d, fn || _.replace);
|
|
1278
|
+
},
|
|
1279
|
+
parse: function(s, fn) {
|
|
1280
|
+
try {
|
|
1281
|
+
return JSON.parse(s, fn || _.revive);
|
|
1282
|
+
} catch (e) {
|
|
1283
|
+
return s;
|
|
1284
|
+
}
|
|
1285
|
+
},
|
|
1286
|
+
fn: function(name, fn) {
|
|
1287
|
+
_.storeAPI[name] = fn;
|
|
1288
|
+
for (var api in _.apis) _.apis[api][name] = fn;
|
|
1289
|
+
},
|
|
1290
|
+
get: function(area, key) {
|
|
1291
|
+
return area.getItem(key);
|
|
1292
|
+
},
|
|
1293
|
+
set: function(area, key, string) {
|
|
1294
|
+
area.setItem(key, string);
|
|
1295
|
+
},
|
|
1296
|
+
remove: function(area, key) {
|
|
1297
|
+
area.removeItem(key);
|
|
1298
|
+
},
|
|
1299
|
+
key: function(area, i) {
|
|
1300
|
+
return area.key(i);
|
|
1301
|
+
},
|
|
1302
|
+
length: function(area) {
|
|
1303
|
+
return area.length;
|
|
1304
|
+
},
|
|
1305
|
+
clear: function(area) {
|
|
1306
|
+
area.clear();
|
|
1307
|
+
},
|
|
1308
|
+
Store: function(id, area, namespace) {
|
|
1309
|
+
var store$2 = _.inherit(_.storeAPI, function(key, data, overwrite) {
|
|
1310
|
+
if (arguments.length === 0) return store$2.getAll();
|
|
1311
|
+
if (typeof data === "function") return store$2.transact(key, data, overwrite);
|
|
1312
|
+
if (data !== void 0) return store$2.set(key, data, overwrite);
|
|
1313
|
+
if (typeof key === "string" || typeof key === "number") return store$2.get(key);
|
|
1314
|
+
if (typeof key === "function") return store$2.each(key);
|
|
1315
|
+
if (!key) return store$2.clear();
|
|
1316
|
+
return store$2.setAll(key, data);
|
|
1317
|
+
});
|
|
1318
|
+
store$2._id = id;
|
|
1319
|
+
try {
|
|
1320
|
+
var testKey = "__store2_test";
|
|
1321
|
+
area.setItem(testKey, "ok");
|
|
1322
|
+
store$2._area = area;
|
|
1323
|
+
area.removeItem(testKey);
|
|
1324
|
+
} catch (e) {
|
|
1325
|
+
store$2._area = _.storage("fake");
|
|
1326
|
+
}
|
|
1327
|
+
store$2._ns = namespace || "";
|
|
1328
|
+
if (!_.areas[id]) _.areas[id] = store$2._area;
|
|
1329
|
+
if (!_.apis[store$2._ns + store$2._id]) _.apis[store$2._ns + store$2._id] = store$2;
|
|
1330
|
+
return store$2;
|
|
1331
|
+
},
|
|
1332
|
+
storeAPI: {
|
|
1333
|
+
area: function(id, area) {
|
|
1334
|
+
var store$2 = this[id];
|
|
1335
|
+
if (!store$2 || !store$2.area) {
|
|
1336
|
+
store$2 = _.Store(id, area, this._ns);
|
|
1337
|
+
if (!this[id]) this[id] = store$2;
|
|
1338
|
+
}
|
|
1339
|
+
return store$2;
|
|
1340
|
+
},
|
|
1341
|
+
namespace: function(namespace, singleArea, delim) {
|
|
1342
|
+
delim = delim || this._delim || _.nsdelim;
|
|
1343
|
+
if (!namespace) return this._ns ? this._ns.substring(0, this._ns.length - delim.length) : "";
|
|
1344
|
+
var ns = namespace, store$2 = this[ns];
|
|
1345
|
+
if (!store$2 || !store$2.namespace) {
|
|
1346
|
+
store$2 = _.Store(this._id, this._area, this._ns + ns + delim);
|
|
1347
|
+
store$2._delim = delim;
|
|
1348
|
+
if (!this[ns]) this[ns] = store$2;
|
|
1349
|
+
if (!singleArea) for (var name in _.areas) store$2.area(name, _.areas[name]);
|
|
1350
|
+
}
|
|
1351
|
+
return store$2;
|
|
1352
|
+
},
|
|
1353
|
+
isFake: function(force) {
|
|
1354
|
+
if (force) {
|
|
1355
|
+
this._real = this._area;
|
|
1356
|
+
this._area = _.storage("fake");
|
|
1357
|
+
} else if (force === false) this._area = this._real || this._area;
|
|
1358
|
+
return this._area.name === "fake";
|
|
1359
|
+
},
|
|
1360
|
+
toString: function() {
|
|
1361
|
+
return "store" + (this._ns ? "." + this.namespace() : "") + "[" + this._id + "]";
|
|
1362
|
+
},
|
|
1363
|
+
has: function(key) {
|
|
1364
|
+
if (this._area.has) return this._area.has(this._in(key));
|
|
1365
|
+
return !!(this._in(key) in this._area);
|
|
1366
|
+
},
|
|
1367
|
+
size: function() {
|
|
1368
|
+
return this.keys().length;
|
|
1369
|
+
},
|
|
1370
|
+
each: function(fn, fill) {
|
|
1371
|
+
for (var i = 0, m = _.length(this._area); i < m; i++) {
|
|
1372
|
+
var key = this._out(_.key(this._area, i));
|
|
1373
|
+
if (key !== void 0) {
|
|
1374
|
+
if (fn.call(this, key, this.get(key), fill) === false) break;
|
|
1375
|
+
}
|
|
1376
|
+
if (m > _.length(this._area)) {
|
|
1377
|
+
m--;
|
|
1378
|
+
i--;
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
return fill || this;
|
|
1382
|
+
},
|
|
1383
|
+
keys: function(fillList) {
|
|
1384
|
+
return this.each(function(k, v, list) {
|
|
1385
|
+
list.push(k);
|
|
1386
|
+
}, fillList || []);
|
|
1387
|
+
},
|
|
1388
|
+
get: function(key, alt) {
|
|
1389
|
+
var s = _.get(this._area, this._in(key)), fn;
|
|
1390
|
+
if (typeof alt === "function") {
|
|
1391
|
+
fn = alt;
|
|
1392
|
+
alt = null;
|
|
1393
|
+
}
|
|
1394
|
+
return s !== null ? _.parse(s, fn) : alt != null ? alt : s;
|
|
1395
|
+
},
|
|
1396
|
+
getAll: function(fillObj) {
|
|
1397
|
+
return this.each(function(k, v, all) {
|
|
1398
|
+
all[k] = v;
|
|
1399
|
+
}, fillObj || {});
|
|
1400
|
+
},
|
|
1401
|
+
transact: function(key, fn, alt) {
|
|
1402
|
+
var val = this.get(key, alt), ret = fn(val);
|
|
1403
|
+
this.set(key, ret === void 0 ? val : ret);
|
|
1404
|
+
return this;
|
|
1405
|
+
},
|
|
1406
|
+
set: function(key, data, overwrite) {
|
|
1407
|
+
var d = this.get(key), replacer;
|
|
1408
|
+
if (d != null && overwrite === false) return data;
|
|
1409
|
+
if (typeof overwrite === "function") {
|
|
1410
|
+
replacer = overwrite;
|
|
1411
|
+
overwrite = void 0;
|
|
1412
|
+
}
|
|
1413
|
+
return _.set(this._area, this._in(key), _.stringify(data, replacer), overwrite) || d;
|
|
1414
|
+
},
|
|
1415
|
+
setAll: function(data, overwrite) {
|
|
1416
|
+
var changed, val;
|
|
1417
|
+
for (var key in data) {
|
|
1418
|
+
val = data[key];
|
|
1419
|
+
if (this.set(key, val, overwrite) !== val) changed = true;
|
|
1420
|
+
}
|
|
1421
|
+
return changed;
|
|
1422
|
+
},
|
|
1423
|
+
add: function(key, data, replacer) {
|
|
1424
|
+
var d = this.get(key);
|
|
1425
|
+
if (d instanceof Array) data = d.concat(data);
|
|
1426
|
+
else if (d !== null) {
|
|
1427
|
+
var type = typeof d;
|
|
1428
|
+
if (type === typeof data && type === "object") {
|
|
1429
|
+
for (var k in data) d[k] = data[k];
|
|
1430
|
+
data = d;
|
|
1431
|
+
} else data = d + data;
|
|
1432
|
+
}
|
|
1433
|
+
_.set(this._area, this._in(key), _.stringify(data, replacer));
|
|
1434
|
+
return data;
|
|
1435
|
+
},
|
|
1436
|
+
remove: function(key, alt) {
|
|
1437
|
+
var d = this.get(key, alt);
|
|
1438
|
+
_.remove(this._area, this._in(key));
|
|
1439
|
+
return d;
|
|
1440
|
+
},
|
|
1441
|
+
clear: function() {
|
|
1442
|
+
if (!this._ns) _.clear(this._area);
|
|
1443
|
+
else this.each(function(k) {
|
|
1444
|
+
_.remove(this._area, this._in(k));
|
|
1445
|
+
}, 1);
|
|
1446
|
+
return this;
|
|
1447
|
+
},
|
|
1448
|
+
clearAll: function() {
|
|
1449
|
+
var area = this._area;
|
|
1450
|
+
for (var id in _.areas) if (_.areas.hasOwnProperty(id)) {
|
|
1451
|
+
this._area = _.areas[id];
|
|
1452
|
+
this.clear();
|
|
1453
|
+
}
|
|
1454
|
+
this._area = area;
|
|
1455
|
+
return this;
|
|
1456
|
+
},
|
|
1457
|
+
_in: function(k) {
|
|
1458
|
+
if (typeof k !== "string") k = _.stringify(k);
|
|
1459
|
+
return this._ns ? this._ns + k : k;
|
|
1460
|
+
},
|
|
1461
|
+
_out: function(k) {
|
|
1462
|
+
return this._ns ? k && k.indexOf(this._ns) === 0 ? k.substring(this._ns.length) : void 0 : k;
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
storage: function(name) {
|
|
1466
|
+
return _.inherit(_.storageAPI, {
|
|
1467
|
+
items: {},
|
|
1468
|
+
name
|
|
1469
|
+
});
|
|
1470
|
+
},
|
|
1471
|
+
storageAPI: {
|
|
1472
|
+
length: 0,
|
|
1473
|
+
has: function(k) {
|
|
1474
|
+
return this.items.hasOwnProperty(k);
|
|
1475
|
+
},
|
|
1476
|
+
key: function(i) {
|
|
1477
|
+
var c = 0;
|
|
1478
|
+
for (var k in this.items) if (this.has(k) && i === c++) return k;
|
|
1479
|
+
},
|
|
1480
|
+
setItem: function(k, v) {
|
|
1481
|
+
if (!this.has(k)) this.length++;
|
|
1482
|
+
this.items[k] = v;
|
|
1483
|
+
},
|
|
1484
|
+
removeItem: function(k) {
|
|
1485
|
+
if (this.has(k)) {
|
|
1486
|
+
delete this.items[k];
|
|
1487
|
+
this.length--;
|
|
1488
|
+
}
|
|
1489
|
+
},
|
|
1490
|
+
getItem: function(k) {
|
|
1491
|
+
return this.has(k) ? this.items[k] : null;
|
|
1492
|
+
},
|
|
1493
|
+
clear: function() {
|
|
1494
|
+
for (var k in this.items) this.removeItem(k);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
var store$1 = _.Store("local", (function() {
|
|
1499
|
+
try {
|
|
1500
|
+
return localStorage;
|
|
1501
|
+
} catch (e) {}
|
|
1502
|
+
})());
|
|
1503
|
+
store$1.local = store$1;
|
|
1504
|
+
store$1._ = _;
|
|
1505
|
+
store$1.area("session", (function() {
|
|
1506
|
+
try {
|
|
1507
|
+
return sessionStorage;
|
|
1508
|
+
} catch (e) {}
|
|
1509
|
+
})());
|
|
1510
|
+
store$1.area("page", _.storage("page"));
|
|
1511
|
+
if (typeof define === "function" && define.amd !== void 0) define("store2", [], function() {
|
|
1512
|
+
return store$1;
|
|
1513
|
+
});
|
|
1514
|
+
else if (typeof module !== "undefined" && module.exports) {
|
|
1515
|
+
module.exports = store$1;
|
|
1516
|
+
module.exports.store = store$1;
|
|
1517
|
+
} else {
|
|
1518
|
+
if (window.store) _.conflict = window.store;
|
|
1519
|
+
window.store = store$1;
|
|
1520
|
+
}
|
|
1521
|
+
})(exports, exports && exports.define);
|
|
1522
|
+
}) });
|
|
1523
|
+
|
|
1524
|
+
//#endregion
|
|
1525
|
+
//#region ../../utils/dist/esm/index.js
|
|
1526
|
+
var import_store2 = require_store2();
|
|
1527
|
+
const sleep = (timeout) => new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1528
|
+
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
|
|
1531
|
+
function _typeof(o) {
|
|
1532
|
+
"@babel/helpers - typeof";
|
|
1533
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
1534
|
+
return typeof o$1;
|
|
1535
|
+
} : function(o$1) {
|
|
1536
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
1537
|
+
}, _typeof(o);
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
//#endregion
|
|
1541
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
|
|
1542
|
+
function toPrimitive(t, r) {
|
|
1543
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1544
|
+
var e = t[Symbol.toPrimitive];
|
|
1545
|
+
if (void 0 !== e) {
|
|
1546
|
+
var i = e.call(t, r || "default");
|
|
1547
|
+
if ("object" != _typeof(i)) return i;
|
|
1548
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1549
|
+
}
|
|
1550
|
+
return ("string" === r ? String : Number)(t);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
//#endregion
|
|
1554
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
|
|
1555
|
+
function toPropertyKey(t) {
|
|
1556
|
+
var i = toPrimitive(t, "string");
|
|
1557
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
//#endregion
|
|
1561
|
+
//#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
|
|
1562
|
+
function _defineProperty(e, r, t) {
|
|
1563
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1564
|
+
value: t,
|
|
1565
|
+
enumerable: !0,
|
|
1566
|
+
configurable: !0,
|
|
1567
|
+
writable: !0
|
|
1568
|
+
}) : e[r] = t, e;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
//#endregion
|
|
1572
|
+
//#region src/strategy/Ledger/hw/AccountManager.ts
|
|
1573
|
+
const addressOfHDKey = (hdKey) => {
|
|
1574
|
+
const shouldSanitizePublicKey = true;
|
|
1575
|
+
const derivedPublicKey = hdKey.publicKey;
|
|
1576
|
+
return (0, __injectivelabs_sdk_ts.addHexPrefix)((0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.publicKeyToAddress)(derivedPublicKey, shouldSanitizePublicKey)));
|
|
1577
|
+
};
|
|
1578
|
+
var AccountManager$1 = class {
|
|
1579
|
+
constructor(ledger) {
|
|
1580
|
+
_defineProperty(this, "wallets", []);
|
|
1581
|
+
_defineProperty(this, "ledger", void 0);
|
|
1582
|
+
_defineProperty(this, "getLedgerDerivationPathBasedOnType", ({ fullBaseDerivationPath, derivationPathType, index }) => {
|
|
1583
|
+
if (derivationPathType === LedgerDerivationPathType.LedgerLive) return `${fullBaseDerivationPath}/${index}'/0/0`;
|
|
1584
|
+
return `${fullBaseDerivationPath}/0'/${index}`;
|
|
1585
|
+
});
|
|
1586
|
+
this.ledger = ledger;
|
|
1587
|
+
this.wallets = [];
|
|
1588
|
+
}
|
|
1589
|
+
async getWallets(baseDerivationPath, derivationPathType) {
|
|
1590
|
+
const { start, end } = this.getOffset();
|
|
1591
|
+
/**
|
|
1592
|
+
* 1. Wallets are not yet fetched at all,
|
|
1593
|
+
* 2. Wallets are not yet fetched for that offset
|
|
1594
|
+
*/
|
|
1595
|
+
if (!this.hasWallets() || !this.hasWalletsInOffset(start)) await this.getWalletsBasedOnIndex({
|
|
1596
|
+
start,
|
|
1597
|
+
end,
|
|
1598
|
+
baseDerivationPath,
|
|
1599
|
+
derivationPathType
|
|
1600
|
+
});
|
|
1601
|
+
return this.wallets.slice(start, end);
|
|
1602
|
+
}
|
|
1603
|
+
async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType }) {
|
|
1604
|
+
for (let index = start; index < end; index += 1) {
|
|
1605
|
+
const path = this.getLedgerDerivationPathBasedOnType({
|
|
1606
|
+
fullBaseDerivationPath: baseDerivationPath,
|
|
1607
|
+
derivationPathType,
|
|
1608
|
+
index
|
|
1609
|
+
});
|
|
1610
|
+
const result = await this.ledger.getAddress(path);
|
|
1611
|
+
const hdKey = {
|
|
1612
|
+
publicKey: (0, __injectivelabs_sdk_ts.hexToUint8Array)(result.publicKey),
|
|
1613
|
+
chainCode: (0, __injectivelabs_sdk_ts.hexToUint8Array)(result.chainCode || "")
|
|
1614
|
+
};
|
|
1615
|
+
const address = result.address || addressOfHDKey(hdKey);
|
|
1616
|
+
this.wallets.push({
|
|
1617
|
+
hdKey,
|
|
1618
|
+
baseDerivationPath,
|
|
1619
|
+
address: address.toLowerCase(),
|
|
1620
|
+
derivationPath: path
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
hasWallets() {
|
|
1625
|
+
return this.wallets.length > 0;
|
|
1626
|
+
}
|
|
1627
|
+
hasWalletsInOffset(offset) {
|
|
1628
|
+
return this.wallets.length > offset;
|
|
1629
|
+
}
|
|
1630
|
+
getOffset() {
|
|
1631
|
+
const totalWallets = this.wallets.length;
|
|
1632
|
+
return {
|
|
1633
|
+
start: totalWallets,
|
|
1634
|
+
end: totalWallets + __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
hasWalletForAddress(address) {
|
|
1638
|
+
return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase()) !== void 0;
|
|
1639
|
+
}
|
|
1640
|
+
async getWalletForAddress(address) {
|
|
1641
|
+
return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase());
|
|
1642
|
+
}
|
|
1643
|
+
reset() {
|
|
1644
|
+
this.wallets = [];
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
//#endregion
|
|
1649
|
+
//#region src/strategy/lib.ts
|
|
1650
|
+
let EthType;
|
|
1651
|
+
let CosmosType;
|
|
1652
|
+
let ledgerServiceType;
|
|
1653
|
+
let TransportWebUSB;
|
|
1654
|
+
let TransportWebHID;
|
|
1655
|
+
async function loadEthType() {
|
|
1656
|
+
if (!EthType) {
|
|
1657
|
+
const module$1 = await import("@bangjelkoski/ledgerhq-hw-app-eth");
|
|
1658
|
+
EthType = module$1.Eth ? module$1.Eth : module$1.default.Eth;
|
|
1659
|
+
}
|
|
1660
|
+
return EthType;
|
|
1661
|
+
}
|
|
1662
|
+
async function loadCosmosType() {
|
|
1663
|
+
if (!CosmosType) {
|
|
1664
|
+
const module$1 = await import("@bangjelkoski/ledgerhq-hw-app-cosmos");
|
|
1665
|
+
CosmosType = module$1.Cosmos ? module$1.Cosmos : module$1.default.Cosmos;
|
|
1666
|
+
}
|
|
1667
|
+
return CosmosType;
|
|
1668
|
+
}
|
|
1669
|
+
async function loadLedgerServiceType() {
|
|
1670
|
+
if (!ledgerServiceType) {
|
|
1671
|
+
const module$1 = await import("@bangjelkoski/ledgerhq-hw-app-eth");
|
|
1672
|
+
ledgerServiceType = module$1.ledgerService || module$1.default.ledgerService;
|
|
1673
|
+
}
|
|
1674
|
+
return ledgerServiceType;
|
|
1675
|
+
}
|
|
1676
|
+
async function loadTransportWebUSB() {
|
|
1677
|
+
if (!TransportWebUSB) {
|
|
1678
|
+
const module$1 = await import("@bangjelkoski/ledgerhq-hw-transport-webusb");
|
|
1679
|
+
TransportWebUSB = module$1.TransportWebUSB || module$1.default.TransportWebUSB;
|
|
1680
|
+
}
|
|
1681
|
+
return TransportWebUSB;
|
|
1682
|
+
}
|
|
1683
|
+
async function loadTransportWebHIDType() {
|
|
1684
|
+
if (!TransportWebHID) {
|
|
1685
|
+
const module$1 = await import("@bangjelkoski/ledgerhq-hw-transport-webhid");
|
|
1686
|
+
TransportWebHID = module$1.TransportWebHID || module$1.default.TransportWebHID;
|
|
1687
|
+
}
|
|
1688
|
+
return TransportWebHID;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
//#endregion
|
|
1692
|
+
//#region src/strategy/Ledger/hw/index.ts
|
|
1693
|
+
var LedgerTransport$1 = class LedgerTransport$1 {
|
|
1694
|
+
constructor() {
|
|
1695
|
+
_defineProperty(this, "ledger", null);
|
|
1696
|
+
_defineProperty(this, "accountManager", null);
|
|
1697
|
+
}
|
|
1698
|
+
static async getTransport() {
|
|
1699
|
+
const TransportWebUSB$1 = await loadTransportWebUSB();
|
|
1700
|
+
const TransportWebHID$1 = await loadTransportWebHIDType();
|
|
1701
|
+
try {
|
|
1702
|
+
if (await TransportWebHID$1.isSupported()) {
|
|
1703
|
+
const list = await TransportWebHID$1.list();
|
|
1704
|
+
if (list.length > 0 && list[0].opened) return new TransportWebHID$1(list[0]);
|
|
1705
|
+
const existing = await TransportWebHID$1.openConnected().catch(() => null);
|
|
1706
|
+
if (existing) return existing;
|
|
1707
|
+
return await TransportWebHID$1.request();
|
|
1708
|
+
}
|
|
1709
|
+
if (await TransportWebUSB$1.isSupported()) {
|
|
1710
|
+
const existing = await TransportWebUSB$1.openConnected().catch(() => null);
|
|
1711
|
+
if (existing) return existing;
|
|
1712
|
+
return await TransportWebUSB$1.request();
|
|
1713
|
+
}
|
|
1714
|
+
} catch (e) {
|
|
1715
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message));
|
|
1716
|
+
}
|
|
1717
|
+
return TransportWebUSB$1.request();
|
|
1718
|
+
}
|
|
1719
|
+
async getInstance() {
|
|
1720
|
+
const EthereumApp = await loadEthType();
|
|
1721
|
+
if (!this.ledger) {
|
|
1722
|
+
const transport = await LedgerTransport$1.getTransport();
|
|
1723
|
+
this.ledger = new EthereumApp(transport);
|
|
1724
|
+
transport.on("disconnect", () => {
|
|
1725
|
+
this.ledger = null;
|
|
1726
|
+
this.accountManager = null;
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
return this.ledger;
|
|
1730
|
+
}
|
|
1731
|
+
async getAccountManager() {
|
|
1732
|
+
if (!this.accountManager) this.accountManager = new AccountManager$1(await this.getInstance());
|
|
1733
|
+
return this.accountManager;
|
|
1734
|
+
}
|
|
1735
|
+
async refresh() {
|
|
1736
|
+
if (!this.ledger) return new LedgerTransport$1();
|
|
1737
|
+
this.ledger.transport.close();
|
|
1738
|
+
return new LedgerTransport$1();
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
|
|
1742
|
+
//#endregion
|
|
1743
|
+
//#region src/strategy/Ledger/utils.ts
|
|
1744
|
+
/**
|
|
1745
|
+
* Used mainly for Ledger Nano S
|
|
1746
|
+
*/
|
|
1747
|
+
const domainHash = (message) => {
|
|
1748
|
+
return (0, viem.hashDomain)({
|
|
1749
|
+
domain: message.domain,
|
|
1750
|
+
types: message.types
|
|
1751
|
+
});
|
|
1752
|
+
};
|
|
1753
|
+
const messageHash = (message) => {
|
|
1754
|
+
return (0, viem.hashStruct)({
|
|
1755
|
+
data: message.message,
|
|
1756
|
+
types: message.types,
|
|
1757
|
+
primaryType: message.primaryType
|
|
1758
|
+
});
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
//#endregion
|
|
1762
|
+
//#region src/strategy/Ledger/Eip1193Provider.ts
|
|
1763
|
+
var LedgerEip1193Provider = class {
|
|
1764
|
+
constructor(ledger, params) {
|
|
1765
|
+
_defineProperty(this, "ledger", void 0);
|
|
1766
|
+
_defineProperty(this, "derivationPath", void 0);
|
|
1767
|
+
_defineProperty(this, "address", void 0);
|
|
1768
|
+
_defineProperty(this, "chainId", void 0);
|
|
1769
|
+
this.ledger = ledger;
|
|
1770
|
+
this.derivationPath = "m/44'/60'/0'/0/0";
|
|
1771
|
+
this.chainId = parseInt(params.chainId || "1");
|
|
1772
|
+
}
|
|
1773
|
+
async getClient() {
|
|
1774
|
+
const chain = (0, viem.extractChain)({
|
|
1775
|
+
id: this.chainId,
|
|
1776
|
+
chains: Object.values(viem_chains)
|
|
1777
|
+
});
|
|
1778
|
+
return (0, viem.createWalletClient)({
|
|
1779
|
+
transport: (0, viem.http)(),
|
|
1780
|
+
chain,
|
|
1781
|
+
account: await this.getAddress()
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
async setChainId(chainId) {
|
|
1785
|
+
this.chainId = parseInt(chainId.replace("0x", ""), 16);
|
|
1786
|
+
}
|
|
1787
|
+
async getAddress() {
|
|
1788
|
+
if (!this.address) {
|
|
1789
|
+
const { address } = await (await this.ledger.getInstance()).getAddress(this.derivationPath);
|
|
1790
|
+
this.address = address;
|
|
1791
|
+
}
|
|
1792
|
+
return this.address;
|
|
1793
|
+
}
|
|
1794
|
+
async signTypedData(data) {
|
|
1795
|
+
const result = await (await this.ledger.getInstance()).signEIP712Message(this.derivationPath, JSON.parse(data));
|
|
1796
|
+
const combined = `${result.r}${result.s}${result.v.toString(16)}`;
|
|
1797
|
+
return combined.startsWith("0x") ? combined : `0x${combined}`;
|
|
1798
|
+
}
|
|
1799
|
+
async signTransaction(txData) {
|
|
1800
|
+
const ledgerInstance = await this.ledger.getInstance();
|
|
1801
|
+
const serializedTransaction = (0, viem.serializeTransaction)(txData);
|
|
1802
|
+
const resolution = await (await loadLedgerServiceType()).resolveTransaction(serializedTransaction.substring(2), {}, {});
|
|
1803
|
+
const signature = await ledgerInstance.signTransaction(this.derivationPath, serializedTransaction.substring(2), resolution);
|
|
1804
|
+
return (0, viem.serializeTransaction)(txData, {
|
|
1805
|
+
r: signature.r,
|
|
1806
|
+
s: signature.s,
|
|
1807
|
+
v: BigInt(signature.v)
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
async signMessage(messageHex) {
|
|
1811
|
+
const result = await (await this.ledger.getInstance()).signPersonalMessage(this.derivationPath, messageHex);
|
|
1812
|
+
const combined = `${result.r}${result.s}${result.v.toString(16)}`;
|
|
1813
|
+
return combined.startsWith("0x") ? combined : `0x${combined}`;
|
|
1814
|
+
}
|
|
1815
|
+
getChain() {
|
|
1816
|
+
return (0, viem.extractChain)({
|
|
1817
|
+
id: this.chainId,
|
|
1818
|
+
chains: Object.values(viem_chains)
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
async request(args) {
|
|
1822
|
+
if (args.method === "eth_requestAccounts") return [await this.getAddress()];
|
|
1823
|
+
if (args.method === "eth_sign") {
|
|
1824
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
|
|
1825
|
+
return this.signMessage(args.params[0]);
|
|
1826
|
+
}
|
|
1827
|
+
if (args.method === "eth_signTransaction") {
|
|
1828
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
|
|
1829
|
+
return this.signTransaction(args.params[0]);
|
|
1830
|
+
}
|
|
1831
|
+
if (args.method === "eth_signTypedData") {
|
|
1832
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
|
|
1833
|
+
return this.signTypedData(args.params[0]);
|
|
1834
|
+
}
|
|
1835
|
+
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
1836
|
+
if (args.method === "wallet_switchEthereumChain") {
|
|
1837
|
+
var _args$params$;
|
|
1838
|
+
return this.setChainId(((_args$params$ = args.params[0]) === null || _args$params$ === void 0 ? void 0 : _args$params$.chainId) || "0x1");
|
|
1839
|
+
}
|
|
1840
|
+
if (args.method === "eth_estimateGas") {
|
|
1841
|
+
const client = (0, viem.createPublicClient)({
|
|
1842
|
+
chain: this.getChain(),
|
|
1843
|
+
transport: (0, viem.http)()
|
|
1844
|
+
});
|
|
1845
|
+
const data = {
|
|
1846
|
+
to: args.params[0].to,
|
|
1847
|
+
value: args.params[0].value,
|
|
1848
|
+
data: args.params[0].data,
|
|
1849
|
+
account: await this.getAddress()
|
|
1850
|
+
};
|
|
1851
|
+
return `0x${(await client.estimateGas(data)).toString(16)}`;
|
|
1852
|
+
}
|
|
1853
|
+
if (args.method === "eth_getTransactionCount") {
|
|
1854
|
+
if (!args.params) throw new Error("params is required");
|
|
1855
|
+
return `0x${(await (0, viem.createPublicClient)({
|
|
1856
|
+
chain: this.getChain(),
|
|
1857
|
+
transport: (0, viem.http)()
|
|
1858
|
+
}).getTransactionCount({
|
|
1859
|
+
address: await this.getAddress(),
|
|
1860
|
+
blockTag: "pending"
|
|
1861
|
+
})).toString(16)}`;
|
|
1862
|
+
}
|
|
1863
|
+
if (args.method === "eth_sendTransaction") {
|
|
1864
|
+
const address = await this.getAddress();
|
|
1865
|
+
const walletClient = (0, viem.createWalletClient)({
|
|
1866
|
+
transport: (0, viem.http)(),
|
|
1867
|
+
chain: this.getChain(),
|
|
1868
|
+
account: address
|
|
1869
|
+
});
|
|
1870
|
+
const preparedTransaction = await walletClient.prepareTransactionRequest({ ...args.params[0] });
|
|
1871
|
+
const signedTransaction = await this.signTransaction(preparedTransaction);
|
|
1872
|
+
return await walletClient.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
1873
|
+
}
|
|
1874
|
+
return (await this.getClient()).request({
|
|
1875
|
+
method: args.method,
|
|
1876
|
+
params: args.params
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
on(_event, _listener) {
|
|
1880
|
+
throw new Error("Method not implemented.");
|
|
1881
|
+
}
|
|
1882
|
+
once(_event, _listener) {
|
|
1883
|
+
throw new Error("Method not implemented.");
|
|
1884
|
+
}
|
|
1885
|
+
removeListener(_event, _listener) {
|
|
1886
|
+
throw new Error("Method not implemented.");
|
|
1887
|
+
}
|
|
1888
|
+
off(_event, _listener) {
|
|
1889
|
+
throw new Error("Method not implemented.");
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1893
|
+
//#endregion
|
|
1894
|
+
//#region src/strategy/Ledger/Base.ts
|
|
1895
|
+
var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
1896
|
+
constructor(args) {
|
|
1897
|
+
super(args);
|
|
1898
|
+
_defineProperty(this, "baseDerivationPath", void 0);
|
|
1899
|
+
_defineProperty(this, "derivationPathType", void 0);
|
|
1900
|
+
_defineProperty(this, "ledger", void 0);
|
|
1901
|
+
_defineProperty(this, "evmOptions", void 0);
|
|
1902
|
+
_defineProperty(this, "alchemy", void 0);
|
|
1903
|
+
this.baseDerivationPath = __injectivelabs_wallet_base.DEFAULT_BASE_DERIVATION_PATH;
|
|
1904
|
+
this.derivationPathType = args.derivationPathType;
|
|
1905
|
+
this.ledger = new LedgerTransport$1();
|
|
1906
|
+
this.evmOptions = args.evmOptions;
|
|
1907
|
+
}
|
|
1908
|
+
async getWalletDeviceType() {
|
|
1909
|
+
return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Hardware);
|
|
1910
|
+
}
|
|
1911
|
+
async enable() {
|
|
1912
|
+
return Promise.resolve(true);
|
|
1913
|
+
}
|
|
1914
|
+
async disconnect() {
|
|
1915
|
+
this.ledger = await this.ledger.refresh();
|
|
1916
|
+
}
|
|
1917
|
+
async getAddresses() {
|
|
1918
|
+
const { baseDerivationPath, derivationPathType } = this;
|
|
1919
|
+
try {
|
|
1920
|
+
return (await (await this.ledger.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => k.address);
|
|
1921
|
+
} catch (e) {
|
|
1922
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message), {
|
|
1923
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1924
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1925
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
async getSessionOrConfirm(address) {
|
|
1930
|
+
return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
1931
|
+
}
|
|
1932
|
+
async sendEvmTransaction(txData, args) {
|
|
1933
|
+
const signedTransaction = await this.signEvmTransaction(txData, args);
|
|
1934
|
+
try {
|
|
1935
|
+
return await (await (await this.getAlchemy(args.evmChainId)).config.getProvider()).send("eth_sendRawTransaction", [signedTransaction]);
|
|
1936
|
+
} catch (e) {
|
|
1937
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message), {
|
|
1938
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1939
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1940
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
async sendTransaction(transaction, options) {
|
|
1945
|
+
const { endpoints, txTimeout } = options;
|
|
1946
|
+
if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using Ethereum native wallets"));
|
|
1947
|
+
const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
|
|
1948
|
+
if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
|
|
1949
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1950
|
+
contextCode: response.code,
|
|
1951
|
+
contextModule: response.codespace
|
|
1952
|
+
});
|
|
1953
|
+
return response;
|
|
1954
|
+
}
|
|
1955
|
+
async signEip712TypedData(eip712json, address) {
|
|
1956
|
+
const { derivationPath } = await this.getWalletForAddress(address);
|
|
1957
|
+
const object = JSON.parse(eip712json);
|
|
1958
|
+
try {
|
|
1959
|
+
const result = await (await this.ledger.getInstance()).signEIP712Message(derivationPath, object);
|
|
1960
|
+
const combined = `${result.r}${result.s}${result.v.toString(16)}`;
|
|
1961
|
+
return combined.startsWith("0x") ? combined : `0x${combined}`;
|
|
1962
|
+
} catch (e) {
|
|
1963
|
+
const errorMessage = e.message;
|
|
1964
|
+
if (!(errorMessage.includes("instruction not supported") || errorMessage.includes("invalid status") || errorMessage.includes("not supported") || errorMessage.includes("INS_NOT_SUPPORTED"))) throw new __injectivelabs_exceptions.LedgerException(new Error(errorMessage), {
|
|
1965
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1966
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1967
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
1968
|
+
});
|
|
1969
|
+
try {
|
|
1970
|
+
const result = await (await this.ledger.getInstance()).signEIP712HashedMessage(derivationPath, domainHash(object), messageHash(object));
|
|
1971
|
+
const combined = `${result.r}${result.s}${result.v.toString(16)}`;
|
|
1972
|
+
return combined.startsWith("0x") ? combined : `0x${combined}`;
|
|
1973
|
+
} catch (e$1) {
|
|
1974
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e$1.message), {
|
|
1975
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1976
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1977
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
async signAminoCosmosTransaction(_transaction) {
|
|
1983
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
|
|
1984
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1985
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1986
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SendTransaction
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
async signCosmosTransaction(_transaction) {
|
|
1990
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
|
|
1991
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
1992
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
1993
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SendTransaction
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
async signArbitrary(signer, data) {
|
|
1997
|
+
try {
|
|
1998
|
+
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
1999
|
+
const result = await (await this.ledger.getInstance()).signPersonalMessage(derivationPath, (0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)((0, __injectivelabs_sdk_ts.toUtf8)(data))));
|
|
2000
|
+
const combined = `${result.r}${result.s}${result.v.toString(16)}`;
|
|
2001
|
+
return combined.startsWith("0x") ? combined : `0x${combined}`;
|
|
2002
|
+
} catch (e) {
|
|
2003
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message), {
|
|
2004
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2005
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2006
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
async getEthereumChainId() {
|
|
2011
|
+
return (await (await this.getAlchemy()).config.getProvider()).network.chainId.toString();
|
|
2012
|
+
}
|
|
2013
|
+
async getEvmTransactionReceipt(txHash, evmChainId) {
|
|
2014
|
+
const provider = await (await this.getAlchemy(evmChainId)).config.getProvider();
|
|
2015
|
+
const interval = 3e3;
|
|
2016
|
+
const maxAttempts = 10;
|
|
2017
|
+
let attempts = 0;
|
|
2018
|
+
while (attempts < maxAttempts) {
|
|
2019
|
+
attempts++;
|
|
2020
|
+
await sleep(interval);
|
|
2021
|
+
try {
|
|
2022
|
+
if (await provider.send("eth_getTransactionReceipt", [txHash])) return txHash;
|
|
2023
|
+
} catch (_unused) {}
|
|
2024
|
+
}
|
|
2025
|
+
throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
|
|
2026
|
+
}
|
|
2027
|
+
async getPubKey() {
|
|
2028
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You can only fetch PubKey from Cosmos native wallets"));
|
|
2029
|
+
}
|
|
2030
|
+
async signEvmTransaction(txData, args) {
|
|
2031
|
+
const ledgerService = await loadLedgerServiceType();
|
|
2032
|
+
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
2033
|
+
const chainId = parseInt(args.evmChainId.toString(), 10);
|
|
2034
|
+
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
2035
|
+
const parseHexValue = (value) => {
|
|
2036
|
+
if (typeof value === "string") {
|
|
2037
|
+
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
2038
|
+
return BigInt(hexValue);
|
|
2039
|
+
}
|
|
2040
|
+
return BigInt(value);
|
|
2041
|
+
};
|
|
2042
|
+
const eip1559TxData = {
|
|
2043
|
+
type: "eip1559",
|
|
2044
|
+
chainId,
|
|
2045
|
+
nonce,
|
|
2046
|
+
to: txData.to,
|
|
2047
|
+
value: parseHexValue(txData.value || "0x0"),
|
|
2048
|
+
data: txData.data,
|
|
2049
|
+
gas: parseHexValue(txData.gas),
|
|
2050
|
+
maxFeePerGas: parseHexValue(txData.maxFeePerGas),
|
|
2051
|
+
maxPriorityFeePerGas: parseHexValue(txData.maxPriorityFeePerGas)
|
|
2052
|
+
};
|
|
2053
|
+
const serializedTxHex = (0, viem.serializeTransaction)(eip1559TxData).slice(2);
|
|
2054
|
+
try {
|
|
2055
|
+
const ledger = await this.ledger.getInstance();
|
|
2056
|
+
const { derivationPath } = await this.getWalletForAddress(args.address);
|
|
2057
|
+
const resolution = await ledgerService.resolveTransaction(serializedTxHex, {}, {});
|
|
2058
|
+
const txSig = await ledger.signTransaction(derivationPath, serializedTxHex, resolution);
|
|
2059
|
+
return (0, viem.serializeTransaction)({
|
|
2060
|
+
...eip1559TxData,
|
|
2061
|
+
v: BigInt(`0x${txSig.v}`),
|
|
2062
|
+
r: `0x${txSig.r}`,
|
|
2063
|
+
s: `0x${txSig.s}`
|
|
2064
|
+
});
|
|
2065
|
+
} catch (e) {
|
|
2066
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message), {
|
|
2067
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2068
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2069
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignEvmTransaction
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
async getWalletForAddress(address) {
|
|
2074
|
+
try {
|
|
2075
|
+
const { baseDerivationPath, derivationPathType } = this;
|
|
2076
|
+
const accountManager = await this.ledger.getAccountManager();
|
|
2077
|
+
if (!accountManager.hasWalletForAddress(address)) for (let i = 0; i < __injectivelabs_wallet_base.DEFAULT_ADDRESS_SEARCH_LIMIT / __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH; i += 1) {
|
|
2078
|
+
await accountManager.getWallets(baseDerivationPath, derivationPathType);
|
|
2079
|
+
if (accountManager.hasWalletForAddress(address)) return await accountManager.getWalletForAddress(address);
|
|
2080
|
+
}
|
|
2081
|
+
return await accountManager.getWalletForAddress(address);
|
|
2082
|
+
} catch (e) {
|
|
2083
|
+
throw new __injectivelabs_exceptions.LedgerException(new Error(e.message), {
|
|
2084
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2085
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2086
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
async getEip1193Provider() {
|
|
2091
|
+
return new LedgerEip1193Provider(this.ledger, {
|
|
2092
|
+
chainId: this.evmOptions.evmChainId.toString(),
|
|
2093
|
+
derivationPath: this.baseDerivationPath
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
async getAlchemy(evmChainId) {
|
|
2097
|
+
var _options$rpcUrls;
|
|
2098
|
+
if (this.alchemy) return this.alchemy;
|
|
2099
|
+
const options = this.evmOptions;
|
|
2100
|
+
const chainId = evmChainId || options.evmChainId;
|
|
2101
|
+
const url = options.rpcUrl || ((_options$rpcUrls = options.rpcUrls) === null || _options$rpcUrls === void 0 ? void 0 : _options$rpcUrls[chainId]);
|
|
2102
|
+
if (!url) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("Please pass rpcUrl within the evmOptions"));
|
|
2103
|
+
this.alchemy = new alchemy_sdk.Alchemy({
|
|
2104
|
+
apiKey: (0, __injectivelabs_wallet_base.getKeyFromRpcUrl)(url),
|
|
2105
|
+
network: chainId === __injectivelabs_ts_types.EvmChainId.Mainnet ? alchemy_sdk.Network.ETH_MAINNET : alchemy_sdk.Network.ETH_SEPOLIA
|
|
2106
|
+
});
|
|
2107
|
+
return this.alchemy;
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
|
|
2111
|
+
//#endregion
|
|
2112
|
+
//#region src/strategy/Ledger/LedgerLive.ts
|
|
2113
|
+
var LedgerLive = class extends LedgerBase {
|
|
2114
|
+
constructor(args) {
|
|
2115
|
+
super({
|
|
2116
|
+
...args,
|
|
2117
|
+
derivationPathType: LedgerDerivationPathType.LedgerLive
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
|
|
2122
|
+
//#endregion
|
|
2123
|
+
//#region src/strategy/LedgerCosmos/hw/AccountManager.ts
|
|
2124
|
+
var AccountManager = class {
|
|
2125
|
+
constructor(ledger) {
|
|
2126
|
+
_defineProperty(this, "wallets", []);
|
|
2127
|
+
_defineProperty(this, "ledger", void 0);
|
|
2128
|
+
_defineProperty(this, "getLedgerDerivationPathBasedOnType", ({ fullBaseDerivationPath, index }) => {
|
|
2129
|
+
return `${fullBaseDerivationPath}/${index}'/0/0`;
|
|
2130
|
+
});
|
|
2131
|
+
this.ledger = ledger;
|
|
2132
|
+
this.wallets = [];
|
|
2133
|
+
}
|
|
2134
|
+
async getWallets(baseDerivationPath) {
|
|
2135
|
+
const { start, end } = this.getOffset();
|
|
2136
|
+
/**
|
|
2137
|
+
* 1. Wallets are not yet fetched at all,
|
|
2138
|
+
* 2. Wallets are not yet fetched for that offset
|
|
2139
|
+
*/
|
|
2140
|
+
if (!this.hasWallets() || !this.hasWalletsInOffset(start)) await this.getWalletsBasedOnIndex({
|
|
2141
|
+
start,
|
|
2142
|
+
end,
|
|
2143
|
+
baseDerivationPath
|
|
2144
|
+
});
|
|
2145
|
+
return this.wallets.slice(start, end);
|
|
2146
|
+
}
|
|
2147
|
+
async getWalletsBasedOnIndex({ start, end, baseDerivationPath }) {
|
|
2148
|
+
for (let index = start; index < end; index += 1) {
|
|
2149
|
+
const path = this.getLedgerDerivationPathBasedOnType({
|
|
2150
|
+
fullBaseDerivationPath: baseDerivationPath,
|
|
2151
|
+
index
|
|
2152
|
+
});
|
|
2153
|
+
const { address, publicKey } = await this.ledger.getAddress(path, "inj");
|
|
2154
|
+
this.wallets.push({
|
|
2155
|
+
publicKey,
|
|
2156
|
+
baseDerivationPath,
|
|
2157
|
+
address: address.toLowerCase(),
|
|
2158
|
+
derivationPath: path
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
hasWallets() {
|
|
2163
|
+
return this.wallets.length > 0;
|
|
2164
|
+
}
|
|
2165
|
+
hasWalletsInOffset(offset) {
|
|
2166
|
+
return this.wallets.length > offset;
|
|
2167
|
+
}
|
|
2168
|
+
getOffset() {
|
|
2169
|
+
const totalWallets = this.wallets.length;
|
|
2170
|
+
return {
|
|
2171
|
+
start: totalWallets,
|
|
2172
|
+
end: totalWallets + __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
hasWalletForAddress(address) {
|
|
2176
|
+
return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase()) !== void 0;
|
|
2177
|
+
}
|
|
2178
|
+
async getWalletForAddress(address) {
|
|
2179
|
+
return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase());
|
|
2180
|
+
}
|
|
2181
|
+
reset() {
|
|
2182
|
+
this.wallets = [];
|
|
2183
|
+
}
|
|
2184
|
+
};
|
|
2185
|
+
|
|
2186
|
+
//#endregion
|
|
2187
|
+
//#region src/strategy/LedgerCosmos/hw/index.ts
|
|
2188
|
+
var LedgerTransport = class LedgerTransport {
|
|
2189
|
+
constructor() {
|
|
2190
|
+
_defineProperty(this, "ledger", null);
|
|
2191
|
+
_defineProperty(this, "accountManager", null);
|
|
2192
|
+
}
|
|
2193
|
+
static async getTransport() {
|
|
2194
|
+
const TransportWebUSB$1 = await loadTransportWebUSB();
|
|
2195
|
+
const TransportWebHID$1 = await loadTransportWebHIDType();
|
|
2196
|
+
try {
|
|
2197
|
+
if (await TransportWebHID$1.isSupported()) return await TransportWebHID$1.create();
|
|
2198
|
+
if (await TransportWebUSB$1.isSupported()) return await TransportWebHID$1.create();
|
|
2199
|
+
} catch (e) {
|
|
2200
|
+
throw new __injectivelabs_exceptions.LedgerCosmosException(new Error(e.message));
|
|
2201
|
+
}
|
|
2202
|
+
return await TransportWebHID$1.create();
|
|
2203
|
+
}
|
|
2204
|
+
async getInstance() {
|
|
2205
|
+
const CosmosApp = await loadCosmosType();
|
|
2206
|
+
if (!this.ledger) this.ledger = new CosmosApp(await LedgerTransport.getTransport());
|
|
2207
|
+
return this.ledger;
|
|
2208
|
+
}
|
|
2209
|
+
async getAccountManager() {
|
|
2210
|
+
if (!this.accountManager) this.accountManager = new AccountManager(await this.getInstance());
|
|
2211
|
+
return this.accountManager;
|
|
2212
|
+
}
|
|
2213
|
+
async refresh() {
|
|
2214
|
+
if (!this.ledger) return new LedgerTransport();
|
|
2215
|
+
this.ledger.transport.close();
|
|
2216
|
+
return new LedgerTransport();
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
//#endregion
|
|
2221
|
+
//#region src/strategy/LedgerCosmos/index.ts
|
|
2222
|
+
var LedgerCosmos = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
2223
|
+
constructor(args) {
|
|
2224
|
+
super(args);
|
|
2225
|
+
_defineProperty(this, "baseDerivationPath", void 0);
|
|
2226
|
+
_defineProperty(this, "ledger", void 0);
|
|
2227
|
+
this.baseDerivationPath = __injectivelabs_wallet_base.DEFAULT_BASE_DERIVATION_PATH;
|
|
2228
|
+
this.ledger = new LedgerTransport();
|
|
2229
|
+
}
|
|
2230
|
+
async getWalletDeviceType() {
|
|
2231
|
+
return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Hardware);
|
|
2232
|
+
}
|
|
2233
|
+
async enable() {
|
|
2234
|
+
return Promise.resolve(true);
|
|
2235
|
+
}
|
|
2236
|
+
async disconnect() {
|
|
2237
|
+
this.ledger = await this.ledger.refresh();
|
|
2238
|
+
}
|
|
2239
|
+
async getAddresses() {
|
|
2240
|
+
const { baseDerivationPath } = this;
|
|
2241
|
+
try {
|
|
2242
|
+
return (await (await this.ledger.getAccountManager()).getWallets(baseDerivationPath)).map((k) => k.address);
|
|
2243
|
+
} catch (e) {
|
|
2244
|
+
throw new __injectivelabs_exceptions.LedgerCosmosException(new Error(e.message), {
|
|
2245
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2246
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2247
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
async getSessionOrConfirm(address) {
|
|
2252
|
+
return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
2253
|
+
}
|
|
2254
|
+
async sendEvmTransaction(_txData, _options) {
|
|
2255
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("sendEvmTransaction is not supported. LedgerCosmos only supports sending cosmos transactions"), {
|
|
2256
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2257
|
+
context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
async sendTransaction(transaction, options) {
|
|
2261
|
+
const { endpoints, txTimeout } = options;
|
|
2262
|
+
if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using LedgerCosmos wallet"));
|
|
2263
|
+
const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
|
|
2264
|
+
if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
|
|
2265
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2266
|
+
contextCode: response.code,
|
|
2267
|
+
contextModule: response.codespace
|
|
2268
|
+
});
|
|
2269
|
+
return response;
|
|
2270
|
+
}
|
|
2271
|
+
async signAminoCosmosTransaction(transaction) {
|
|
2272
|
+
try {
|
|
2273
|
+
const { derivationPath } = await this.getWalletForAddress(transaction.address);
|
|
2274
|
+
return {
|
|
2275
|
+
signed: void 0,
|
|
2276
|
+
signature: {
|
|
2277
|
+
signature: (0, __injectivelabs_sdk_ts.uint8ArrayToBase64)((await (await this.ledger.getInstance()).sign(derivationPath, JSON.stringify((0, __injectivelabs_sdk_ts.sortObjectByKeys)(transaction.signDoc)))).signature),
|
|
2278
|
+
pub_key: void 0
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
} catch (e) {
|
|
2282
|
+
throw new __injectivelabs_exceptions.LedgerCosmosException(new Error(e.message), {
|
|
2283
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2284
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2285
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
async signCosmosTransaction(_transaction) {
|
|
2290
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing using direct sign"), {
|
|
2291
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2292
|
+
context: __injectivelabs_wallet_base.WalletAction.SendTransaction
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
async signEip712TypedData(_eip712Json, _address) {
|
|
2296
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("This wallet does not support signing Evm transactions"), {
|
|
2297
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2298
|
+
context: __injectivelabs_wallet_base.WalletAction.SendTransaction
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
async signArbitrary(signer, data) {
|
|
2302
|
+
try {
|
|
2303
|
+
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
2304
|
+
return (0, __injectivelabs_sdk_ts.uint8ArrayToBase64)((await (await this.ledger.getInstance()).sign(derivationPath, (0, __injectivelabs_sdk_ts.toUtf8)(data))).signature);
|
|
2305
|
+
} catch (e) {
|
|
2306
|
+
throw new __injectivelabs_exceptions.LedgerCosmosException(new Error(e.message), {
|
|
2307
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2308
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2309
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
async getEthereumChainId() {
|
|
2314
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEthereumChainId is not supported on Keplr"), {
|
|
2315
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2316
|
+
context: __injectivelabs_wallet_base.WalletAction.GetChainId
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
async getEvmTransactionReceipt(_txHash) {
|
|
2320
|
+
throw new __injectivelabs_exceptions.CosmosWalletException(/* @__PURE__ */ new Error("getEvmTransactionReceipt is not supported on Keplr"), {
|
|
2321
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2322
|
+
context: __injectivelabs_wallet_base.WalletAction.GetEvmTransactionReceipt
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
async getPubKey(address) {
|
|
2326
|
+
if (!address) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You can only fetch PubKey corresponding to an address"));
|
|
2327
|
+
return (0, __injectivelabs_sdk_ts.uint8ArrayToBase64)((0, __injectivelabs_sdk_ts.hexToUint8Array)((await this.getWalletForAddress(address)).publicKey || ""));
|
|
2328
|
+
}
|
|
2329
|
+
async getWalletForAddress(address) {
|
|
2330
|
+
try {
|
|
2331
|
+
const { baseDerivationPath } = this;
|
|
2332
|
+
const accountManager = await this.ledger.getAccountManager();
|
|
2333
|
+
if (!accountManager.hasWalletForAddress(address)) for (let i = 0; i < __injectivelabs_wallet_base.DEFAULT_ADDRESS_SEARCH_LIMIT / __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH; i += 1) {
|
|
2334
|
+
await accountManager.getWallets(baseDerivationPath);
|
|
2335
|
+
if (accountManager.hasWalletForAddress(address)) return await accountManager.getWalletForAddress(address);
|
|
2336
|
+
}
|
|
2337
|
+
return await accountManager.getWalletForAddress(address);
|
|
2338
|
+
} catch (e) {
|
|
2339
|
+
throw new __injectivelabs_exceptions.LedgerCosmosException(new Error(e.message), {
|
|
2340
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
2341
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
2342
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2348
|
+
//#endregion
|
|
2349
|
+
//#region src/strategy/Ledger/LedgerLegacy.ts
|
|
2350
|
+
var LedgerLegacy = class extends LedgerBase {
|
|
2351
|
+
constructor(args) {
|
|
2352
|
+
super({
|
|
2353
|
+
...args,
|
|
2354
|
+
derivationPathType: LedgerDerivationPathType.LedgerMew
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2359
|
+
//#endregion
|
|
2360
|
+
exports.LedgerCosmosStrategy = LedgerCosmos;
|
|
2361
|
+
exports.LedgerDerivationPathType = LedgerDerivationPathType;
|
|
2362
|
+
exports.LedgerLegacyStrategy = LedgerLegacy;
|
|
2363
|
+
exports.LedgerLiveStrategy = LedgerLive;
|
|
2364
|
+
exports.WalletLedger = WalletLedger;
|