@orderly.network/core 0.0.52 → 0.0.54

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/index.mjs CHANGED
@@ -1,4722 +1,4 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod2) => function __require() {
11
- return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
27
- mod2
28
- ));
29
-
30
- // ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js
31
- var init_dirname = __esm({
32
- "../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js"() {
33
- "use strict";
34
- }
35
- });
36
-
37
- // ../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/process.js
38
- function Item(fun, array) {
39
- this.fun = fun;
40
- this.array = array;
41
- }
42
- function hrtime(previousTimestamp) {
43
- var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3);
44
- var clocktime = _performance.now() * 1e-3;
45
- var seconds = Math.floor(clocktime) + baseNow;
46
- var nanoseconds = Math.floor(clocktime % 1 * 1e9);
47
- if (previousTimestamp) {
48
- seconds = seconds - previousTimestamp[0];
49
- nanoseconds = nanoseconds - previousTimestamp[1];
50
- if (nanoseconds < 0) {
51
- seconds--;
52
- nanoseconds += nanoPerSec;
53
- }
54
- }
55
- return [seconds, nanoseconds];
56
- }
57
- var env, _performance, nowOffset, nanoPerSec;
58
- var init_process = __esm({
59
- "../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/process.js"() {
60
- "use strict";
61
- init_dirname();
62
- init_buffer2();
63
- init_process2();
64
- Item.prototype.run = function() {
65
- this.fun.apply(null, this.array);
66
- };
67
- env = {
68
- PATH: "/usr/bin",
69
- LANG: navigator.language + ".UTF-8",
70
- PWD: "/",
71
- HOME: "/home",
72
- TMP: "/tmp"
73
- };
74
- _performance = {
75
- now: typeof performance !== "undefined" ? performance.now.bind(performance) : void 0,
76
- timing: typeof performance !== "undefined" ? performance.timing : void 0
77
- };
78
- if (_performance.now === void 0) {
79
- nowOffset = Date.now();
80
- if (_performance.timing && _performance.timing.navigationStart) {
81
- nowOffset = _performance.timing.navigationStart;
82
- }
83
- _performance.now = () => Date.now() - nowOffset;
84
- }
85
- nanoPerSec = 1e9;
86
- hrtime.bigint = function(time) {
87
- var diff = hrtime(time);
88
- if (typeof BigInt === "undefined") {
89
- return diff[0] * nanoPerSec + diff[1];
90
- }
91
- return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]);
92
- };
93
- }
94
- });
95
-
96
- // ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/process.js
97
- var init_process2 = __esm({
98
- "../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/process.js"() {
99
- "use strict";
100
- init_process();
101
- }
102
- });
103
-
104
- // ../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/buffer.js
105
- function dew$2() {
106
- if (_dewExec$2)
107
- return exports$3;
108
- _dewExec$2 = true;
109
- exports$3.byteLength = byteLength;
110
- exports$3.toByteArray = toByteArray;
111
- exports$3.fromByteArray = fromByteArray;
112
- var lookup = [];
113
- var revLookup = [];
114
- var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
115
- var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
116
- for (var i = 0, len = code.length; i < len; ++i) {
117
- lookup[i] = code[i];
118
- revLookup[code.charCodeAt(i)] = i;
119
- }
120
- revLookup["-".charCodeAt(0)] = 62;
121
- revLookup["_".charCodeAt(0)] = 63;
122
- function getLens(b64) {
123
- var len2 = b64.length;
124
- if (len2 % 4 > 0) {
125
- throw new Error("Invalid string. Length must be a multiple of 4");
126
- }
127
- var validLen = b64.indexOf("=");
128
- if (validLen === -1)
129
- validLen = len2;
130
- var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
131
- return [validLen, placeHoldersLen];
132
- }
133
- function byteLength(b64) {
134
- var lens = getLens(b64);
135
- var validLen = lens[0];
136
- var placeHoldersLen = lens[1];
137
- return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
138
- }
139
- function _byteLength(b64, validLen, placeHoldersLen) {
140
- return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
141
- }
142
- function toByteArray(b64) {
143
- var tmp;
144
- var lens = getLens(b64);
145
- var validLen = lens[0];
146
- var placeHoldersLen = lens[1];
147
- var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
148
- var curByte = 0;
149
- var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
150
- var i2;
151
- for (i2 = 0; i2 < len2; i2 += 4) {
152
- tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
153
- arr[curByte++] = tmp >> 16 & 255;
154
- arr[curByte++] = tmp >> 8 & 255;
155
- arr[curByte++] = tmp & 255;
156
- }
157
- if (placeHoldersLen === 2) {
158
- tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
159
- arr[curByte++] = tmp & 255;
160
- }
161
- if (placeHoldersLen === 1) {
162
- tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
163
- arr[curByte++] = tmp >> 8 & 255;
164
- arr[curByte++] = tmp & 255;
165
- }
166
- return arr;
167
- }
168
- function tripletToBase64(num) {
169
- return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
170
- }
171
- function encodeChunk(uint8, start, end) {
172
- var tmp;
173
- var output = [];
174
- for (var i2 = start; i2 < end; i2 += 3) {
175
- tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
176
- output.push(tripletToBase64(tmp));
177
- }
178
- return output.join("");
179
- }
180
- function fromByteArray(uint8) {
181
- var tmp;
182
- var len2 = uint8.length;
183
- var extraBytes = len2 % 3;
184
- var parts = [];
185
- var maxChunkLength = 16383;
186
- for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
187
- parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
188
- }
189
- if (extraBytes === 1) {
190
- tmp = uint8[len2 - 1];
191
- parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
192
- } else if (extraBytes === 2) {
193
- tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
194
- parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
195
- }
196
- return parts.join("");
197
- }
198
- return exports$3;
199
- }
200
- function dew$1() {
201
- if (_dewExec$1)
202
- return exports$2;
203
- _dewExec$1 = true;
204
- exports$2.read = function(buffer, offset, isLE, mLen, nBytes) {
205
- var e, m;
206
- var eLen = nBytes * 8 - mLen - 1;
207
- var eMax = (1 << eLen) - 1;
208
- var eBias = eMax >> 1;
209
- var nBits = -7;
210
- var i = isLE ? nBytes - 1 : 0;
211
- var d = isLE ? -1 : 1;
212
- var s = buffer[offset + i];
213
- i += d;
214
- e = s & (1 << -nBits) - 1;
215
- s >>= -nBits;
216
- nBits += eLen;
217
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
218
- }
219
- m = e & (1 << -nBits) - 1;
220
- e >>= -nBits;
221
- nBits += mLen;
222
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
223
- }
224
- if (e === 0) {
225
- e = 1 - eBias;
226
- } else if (e === eMax) {
227
- return m ? NaN : (s ? -1 : 1) * Infinity;
228
- } else {
229
- m = m + Math.pow(2, mLen);
230
- e = e - eBias;
231
- }
232
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
233
- };
234
- exports$2.write = function(buffer, value, offset, isLE, mLen, nBytes) {
235
- var e, m, c;
236
- var eLen = nBytes * 8 - mLen - 1;
237
- var eMax = (1 << eLen) - 1;
238
- var eBias = eMax >> 1;
239
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
240
- var i = isLE ? 0 : nBytes - 1;
241
- var d = isLE ? 1 : -1;
242
- var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
243
- value = Math.abs(value);
244
- if (isNaN(value) || value === Infinity) {
245
- m = isNaN(value) ? 1 : 0;
246
- e = eMax;
247
- } else {
248
- e = Math.floor(Math.log(value) / Math.LN2);
249
- if (value * (c = Math.pow(2, -e)) < 1) {
250
- e--;
251
- c *= 2;
252
- }
253
- if (e + eBias >= 1) {
254
- value += rt / c;
255
- } else {
256
- value += rt * Math.pow(2, 1 - eBias);
257
- }
258
- if (value * c >= 2) {
259
- e++;
260
- c /= 2;
261
- }
262
- if (e + eBias >= eMax) {
263
- m = 0;
264
- e = eMax;
265
- } else if (e + eBias >= 1) {
266
- m = (value * c - 1) * Math.pow(2, mLen);
267
- e = e + eBias;
268
- } else {
269
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
270
- e = 0;
271
- }
272
- }
273
- for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
274
- }
275
- e = e << mLen | m;
276
- eLen += mLen;
277
- for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
278
- }
279
- buffer[offset + i - d] |= s * 128;
280
- };
281
- return exports$2;
282
- }
283
- function dew() {
284
- if (_dewExec)
285
- return exports$1;
286
- _dewExec = true;
287
- const base64 = dew$2();
288
- const ieee754 = dew$1();
289
- const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
290
- exports$1.Buffer = Buffer3;
291
- exports$1.SlowBuffer = SlowBuffer;
292
- exports$1.INSPECT_MAX_BYTES = 50;
293
- const K_MAX_LENGTH = 2147483647;
294
- exports$1.kMaxLength = K_MAX_LENGTH;
295
- Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
296
- if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
297
- console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
298
- }
299
- function typedArraySupport() {
300
- try {
301
- const arr = new Uint8Array(1);
302
- const proto = {
303
- foo: function() {
304
- return 42;
305
- }
306
- };
307
- Object.setPrototypeOf(proto, Uint8Array.prototype);
308
- Object.setPrototypeOf(arr, proto);
309
- return arr.foo() === 42;
310
- } catch (e) {
311
- return false;
312
- }
313
- }
314
- Object.defineProperty(Buffer3.prototype, "parent", {
315
- enumerable: true,
316
- get: function() {
317
- if (!Buffer3.isBuffer(this))
318
- return void 0;
319
- return this.buffer;
320
- }
321
- });
322
- Object.defineProperty(Buffer3.prototype, "offset", {
323
- enumerable: true,
324
- get: function() {
325
- if (!Buffer3.isBuffer(this))
326
- return void 0;
327
- return this.byteOffset;
328
- }
329
- });
330
- function createBuffer(length) {
331
- if (length > K_MAX_LENGTH) {
332
- throw new RangeError('The value "' + length + '" is invalid for option "size"');
333
- }
334
- const buf = new Uint8Array(length);
335
- Object.setPrototypeOf(buf, Buffer3.prototype);
336
- return buf;
337
- }
338
- function Buffer3(arg, encodingOrOffset, length) {
339
- if (typeof arg === "number") {
340
- if (typeof encodingOrOffset === "string") {
341
- throw new TypeError('The "string" argument must be of type string. Received type number');
342
- }
343
- return allocUnsafe(arg);
344
- }
345
- return from(arg, encodingOrOffset, length);
346
- }
347
- Buffer3.poolSize = 8192;
348
- function from(value, encodingOrOffset, length) {
349
- if (typeof value === "string") {
350
- return fromString(value, encodingOrOffset);
351
- }
352
- if (ArrayBuffer.isView(value)) {
353
- return fromArrayView(value);
354
- }
355
- if (value == null) {
356
- throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
357
- }
358
- if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
359
- return fromArrayBuffer(value, encodingOrOffset, length);
360
- }
361
- if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
362
- return fromArrayBuffer(value, encodingOrOffset, length);
363
- }
364
- if (typeof value === "number") {
365
- throw new TypeError('The "value" argument must not be of type number. Received type number');
366
- }
367
- const valueOf = value.valueOf && value.valueOf();
368
- if (valueOf != null && valueOf !== value) {
369
- return Buffer3.from(valueOf, encodingOrOffset, length);
370
- }
371
- const b = fromObject(value);
372
- if (b)
373
- return b;
374
- if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
375
- return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
376
- }
377
- throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
378
- }
379
- Buffer3.from = function(value, encodingOrOffset, length) {
380
- return from(value, encodingOrOffset, length);
381
- };
382
- Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
383
- Object.setPrototypeOf(Buffer3, Uint8Array);
384
- function assertSize(size) {
385
- if (typeof size !== "number") {
386
- throw new TypeError('"size" argument must be of type number');
387
- } else if (size < 0) {
388
- throw new RangeError('The value "' + size + '" is invalid for option "size"');
389
- }
390
- }
391
- function alloc(size, fill, encoding) {
392
- assertSize(size);
393
- if (size <= 0) {
394
- return createBuffer(size);
395
- }
396
- if (fill !== void 0) {
397
- return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
398
- }
399
- return createBuffer(size);
400
- }
401
- Buffer3.alloc = function(size, fill, encoding) {
402
- return alloc(size, fill, encoding);
403
- };
404
- function allocUnsafe(size) {
405
- assertSize(size);
406
- return createBuffer(size < 0 ? 0 : checked(size) | 0);
407
- }
408
- Buffer3.allocUnsafe = function(size) {
409
- return allocUnsafe(size);
410
- };
411
- Buffer3.allocUnsafeSlow = function(size) {
412
- return allocUnsafe(size);
413
- };
414
- function fromString(string, encoding) {
415
- if (typeof encoding !== "string" || encoding === "") {
416
- encoding = "utf8";
417
- }
418
- if (!Buffer3.isEncoding(encoding)) {
419
- throw new TypeError("Unknown encoding: " + encoding);
420
- }
421
- const length = byteLength(string, encoding) | 0;
422
- let buf = createBuffer(length);
423
- const actual = buf.write(string, encoding);
424
- if (actual !== length) {
425
- buf = buf.slice(0, actual);
426
- }
427
- return buf;
428
- }
429
- function fromArrayLike(array) {
430
- const length = array.length < 0 ? 0 : checked(array.length) | 0;
431
- const buf = createBuffer(length);
432
- for (let i = 0; i < length; i += 1) {
433
- buf[i] = array[i] & 255;
434
- }
435
- return buf;
436
- }
437
- function fromArrayView(arrayView) {
438
- if (isInstance(arrayView, Uint8Array)) {
439
- const copy = new Uint8Array(arrayView);
440
- return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
441
- }
442
- return fromArrayLike(arrayView);
443
- }
444
- function fromArrayBuffer(array, byteOffset, length) {
445
- if (byteOffset < 0 || array.byteLength < byteOffset) {
446
- throw new RangeError('"offset" is outside of buffer bounds');
447
- }
448
- if (array.byteLength < byteOffset + (length || 0)) {
449
- throw new RangeError('"length" is outside of buffer bounds');
450
- }
451
- let buf;
452
- if (byteOffset === void 0 && length === void 0) {
453
- buf = new Uint8Array(array);
454
- } else if (length === void 0) {
455
- buf = new Uint8Array(array, byteOffset);
456
- } else {
457
- buf = new Uint8Array(array, byteOffset, length);
458
- }
459
- Object.setPrototypeOf(buf, Buffer3.prototype);
460
- return buf;
461
- }
462
- function fromObject(obj) {
463
- if (Buffer3.isBuffer(obj)) {
464
- const len = checked(obj.length) | 0;
465
- const buf = createBuffer(len);
466
- if (buf.length === 0) {
467
- return buf;
468
- }
469
- obj.copy(buf, 0, 0, len);
470
- return buf;
471
- }
472
- if (obj.length !== void 0) {
473
- if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
474
- return createBuffer(0);
475
- }
476
- return fromArrayLike(obj);
477
- }
478
- if (obj.type === "Buffer" && Array.isArray(obj.data)) {
479
- return fromArrayLike(obj.data);
480
- }
481
- }
482
- function checked(length) {
483
- if (length >= K_MAX_LENGTH) {
484
- throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
485
- }
486
- return length | 0;
487
- }
488
- function SlowBuffer(length) {
489
- if (+length != length) {
490
- length = 0;
491
- }
492
- return Buffer3.alloc(+length);
493
- }
494
- Buffer3.isBuffer = function isBuffer(b) {
495
- return b != null && b._isBuffer === true && b !== Buffer3.prototype;
496
- };
497
- Buffer3.compare = function compare(a, b) {
498
- if (isInstance(a, Uint8Array))
499
- a = Buffer3.from(a, a.offset, a.byteLength);
500
- if (isInstance(b, Uint8Array))
501
- b = Buffer3.from(b, b.offset, b.byteLength);
502
- if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
503
- throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
504
- }
505
- if (a === b)
506
- return 0;
507
- let x = a.length;
508
- let y = b.length;
509
- for (let i = 0, len = Math.min(x, y); i < len; ++i) {
510
- if (a[i] !== b[i]) {
511
- x = a[i];
512
- y = b[i];
513
- break;
514
- }
515
- }
516
- if (x < y)
517
- return -1;
518
- if (y < x)
519
- return 1;
520
- return 0;
521
- };
522
- Buffer3.isEncoding = function isEncoding(encoding) {
523
- switch (String(encoding).toLowerCase()) {
524
- case "hex":
525
- case "utf8":
526
- case "utf-8":
527
- case "ascii":
528
- case "latin1":
529
- case "binary":
530
- case "base64":
531
- case "ucs2":
532
- case "ucs-2":
533
- case "utf16le":
534
- case "utf-16le":
535
- return true;
536
- default:
537
- return false;
538
- }
539
- };
540
- Buffer3.concat = function concat(list, length) {
541
- if (!Array.isArray(list)) {
542
- throw new TypeError('"list" argument must be an Array of Buffers');
543
- }
544
- if (list.length === 0) {
545
- return Buffer3.alloc(0);
546
- }
547
- let i;
548
- if (length === void 0) {
549
- length = 0;
550
- for (i = 0; i < list.length; ++i) {
551
- length += list[i].length;
552
- }
553
- }
554
- const buffer = Buffer3.allocUnsafe(length);
555
- let pos = 0;
556
- for (i = 0; i < list.length; ++i) {
557
- let buf = list[i];
558
- if (isInstance(buf, Uint8Array)) {
559
- if (pos + buf.length > buffer.length) {
560
- if (!Buffer3.isBuffer(buf))
561
- buf = Buffer3.from(buf);
562
- buf.copy(buffer, pos);
563
- } else {
564
- Uint8Array.prototype.set.call(buffer, buf, pos);
565
- }
566
- } else if (!Buffer3.isBuffer(buf)) {
567
- throw new TypeError('"list" argument must be an Array of Buffers');
568
- } else {
569
- buf.copy(buffer, pos);
570
- }
571
- pos += buf.length;
572
- }
573
- return buffer;
574
- };
575
- function byteLength(string, encoding) {
576
- if (Buffer3.isBuffer(string)) {
577
- return string.length;
578
- }
579
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
580
- return string.byteLength;
581
- }
582
- if (typeof string !== "string") {
583
- throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string);
584
- }
585
- const len = string.length;
586
- const mustMatch = arguments.length > 2 && arguments[2] === true;
587
- if (!mustMatch && len === 0)
588
- return 0;
589
- let loweredCase = false;
590
- for (; ; ) {
591
- switch (encoding) {
592
- case "ascii":
593
- case "latin1":
594
- case "binary":
595
- return len;
596
- case "utf8":
597
- case "utf-8":
598
- return utf8ToBytes(string).length;
599
- case "ucs2":
600
- case "ucs-2":
601
- case "utf16le":
602
- case "utf-16le":
603
- return len * 2;
604
- case "hex":
605
- return len >>> 1;
606
- case "base64":
607
- return base64ToBytes(string).length;
608
- default:
609
- if (loweredCase) {
610
- return mustMatch ? -1 : utf8ToBytes(string).length;
611
- }
612
- encoding = ("" + encoding).toLowerCase();
613
- loweredCase = true;
614
- }
615
- }
616
- }
617
- Buffer3.byteLength = byteLength;
618
- function slowToString(encoding, start, end) {
619
- let loweredCase = false;
620
- if (start === void 0 || start < 0) {
621
- start = 0;
622
- }
623
- if (start > this.length) {
624
- return "";
625
- }
626
- if (end === void 0 || end > this.length) {
627
- end = this.length;
628
- }
629
- if (end <= 0) {
630
- return "";
631
- }
632
- end >>>= 0;
633
- start >>>= 0;
634
- if (end <= start) {
635
- return "";
636
- }
637
- if (!encoding)
638
- encoding = "utf8";
639
- while (true) {
640
- switch (encoding) {
641
- case "hex":
642
- return hexSlice(this, start, end);
643
- case "utf8":
644
- case "utf-8":
645
- return utf8Slice(this, start, end);
646
- case "ascii":
647
- return asciiSlice(this, start, end);
648
- case "latin1":
649
- case "binary":
650
- return latin1Slice(this, start, end);
651
- case "base64":
652
- return base64Slice(this, start, end);
653
- case "ucs2":
654
- case "ucs-2":
655
- case "utf16le":
656
- case "utf-16le":
657
- return utf16leSlice(this, start, end);
658
- default:
659
- if (loweredCase)
660
- throw new TypeError("Unknown encoding: " + encoding);
661
- encoding = (encoding + "").toLowerCase();
662
- loweredCase = true;
663
- }
664
- }
665
- }
666
- Buffer3.prototype._isBuffer = true;
667
- function swap(b, n, m) {
668
- const i = b[n];
669
- b[n] = b[m];
670
- b[m] = i;
671
- }
672
- Buffer3.prototype.swap16 = function swap16() {
673
- const len = this.length;
674
- if (len % 2 !== 0) {
675
- throw new RangeError("Buffer size must be a multiple of 16-bits");
676
- }
677
- for (let i = 0; i < len; i += 2) {
678
- swap(this, i, i + 1);
679
- }
680
- return this;
681
- };
682
- Buffer3.prototype.swap32 = function swap32() {
683
- const len = this.length;
684
- if (len % 4 !== 0) {
685
- throw new RangeError("Buffer size must be a multiple of 32-bits");
686
- }
687
- for (let i = 0; i < len; i += 4) {
688
- swap(this, i, i + 3);
689
- swap(this, i + 1, i + 2);
690
- }
691
- return this;
692
- };
693
- Buffer3.prototype.swap64 = function swap64() {
694
- const len = this.length;
695
- if (len % 8 !== 0) {
696
- throw new RangeError("Buffer size must be a multiple of 64-bits");
697
- }
698
- for (let i = 0; i < len; i += 8) {
699
- swap(this, i, i + 7);
700
- swap(this, i + 1, i + 6);
701
- swap(this, i + 2, i + 5);
702
- swap(this, i + 3, i + 4);
703
- }
704
- return this;
705
- };
706
- Buffer3.prototype.toString = function toString() {
707
- const length = this.length;
708
- if (length === 0)
709
- return "";
710
- if (arguments.length === 0)
711
- return utf8Slice(this, 0, length);
712
- return slowToString.apply(this, arguments);
713
- };
714
- Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
715
- Buffer3.prototype.equals = function equals(b) {
716
- if (!Buffer3.isBuffer(b))
717
- throw new TypeError("Argument must be a Buffer");
718
- if (this === b)
719
- return true;
720
- return Buffer3.compare(this, b) === 0;
721
- };
722
- Buffer3.prototype.inspect = function inspect() {
723
- let str2 = "";
724
- const max = exports$1.INSPECT_MAX_BYTES;
725
- str2 = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
726
- if (this.length > max)
727
- str2 += " ... ";
728
- return "<Buffer " + str2 + ">";
729
- };
730
- if (customInspectSymbol) {
731
- Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
732
- }
733
- Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
734
- if (isInstance(target, Uint8Array)) {
735
- target = Buffer3.from(target, target.offset, target.byteLength);
736
- }
737
- if (!Buffer3.isBuffer(target)) {
738
- throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target);
739
- }
740
- if (start === void 0) {
741
- start = 0;
742
- }
743
- if (end === void 0) {
744
- end = target ? target.length : 0;
745
- }
746
- if (thisStart === void 0) {
747
- thisStart = 0;
748
- }
749
- if (thisEnd === void 0) {
750
- thisEnd = this.length;
751
- }
752
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
753
- throw new RangeError("out of range index");
754
- }
755
- if (thisStart >= thisEnd && start >= end) {
756
- return 0;
757
- }
758
- if (thisStart >= thisEnd) {
759
- return -1;
760
- }
761
- if (start >= end) {
762
- return 1;
763
- }
764
- start >>>= 0;
765
- end >>>= 0;
766
- thisStart >>>= 0;
767
- thisEnd >>>= 0;
768
- if (this === target)
769
- return 0;
770
- let x = thisEnd - thisStart;
771
- let y = end - start;
772
- const len = Math.min(x, y);
773
- const thisCopy = this.slice(thisStart, thisEnd);
774
- const targetCopy = target.slice(start, end);
775
- for (let i = 0; i < len; ++i) {
776
- if (thisCopy[i] !== targetCopy[i]) {
777
- x = thisCopy[i];
778
- y = targetCopy[i];
779
- break;
780
- }
781
- }
782
- if (x < y)
783
- return -1;
784
- if (y < x)
785
- return 1;
786
- return 0;
787
- };
788
- function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
789
- if (buffer.length === 0)
790
- return -1;
791
- if (typeof byteOffset === "string") {
792
- encoding = byteOffset;
793
- byteOffset = 0;
794
- } else if (byteOffset > 2147483647) {
795
- byteOffset = 2147483647;
796
- } else if (byteOffset < -2147483648) {
797
- byteOffset = -2147483648;
798
- }
799
- byteOffset = +byteOffset;
800
- if (numberIsNaN(byteOffset)) {
801
- byteOffset = dir ? 0 : buffer.length - 1;
802
- }
803
- if (byteOffset < 0)
804
- byteOffset = buffer.length + byteOffset;
805
- if (byteOffset >= buffer.length) {
806
- if (dir)
807
- return -1;
808
- else
809
- byteOffset = buffer.length - 1;
810
- } else if (byteOffset < 0) {
811
- if (dir)
812
- byteOffset = 0;
813
- else
814
- return -1;
815
- }
816
- if (typeof val === "string") {
817
- val = Buffer3.from(val, encoding);
818
- }
819
- if (Buffer3.isBuffer(val)) {
820
- if (val.length === 0) {
821
- return -1;
822
- }
823
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
824
- } else if (typeof val === "number") {
825
- val = val & 255;
826
- if (typeof Uint8Array.prototype.indexOf === "function") {
827
- if (dir) {
828
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
829
- } else {
830
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
831
- }
832
- }
833
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
834
- }
835
- throw new TypeError("val must be string, number or Buffer");
836
- }
837
- function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
838
- let indexSize = 1;
839
- let arrLength = arr.length;
840
- let valLength = val.length;
841
- if (encoding !== void 0) {
842
- encoding = String(encoding).toLowerCase();
843
- if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
844
- if (arr.length < 2 || val.length < 2) {
845
- return -1;
846
- }
847
- indexSize = 2;
848
- arrLength /= 2;
849
- valLength /= 2;
850
- byteOffset /= 2;
851
- }
852
- }
853
- function read(buf, i2) {
854
- if (indexSize === 1) {
855
- return buf[i2];
856
- } else {
857
- return buf.readUInt16BE(i2 * indexSize);
858
- }
859
- }
860
- let i;
861
- if (dir) {
862
- let foundIndex = -1;
863
- for (i = byteOffset; i < arrLength; i++) {
864
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
865
- if (foundIndex === -1)
866
- foundIndex = i;
867
- if (i - foundIndex + 1 === valLength)
868
- return foundIndex * indexSize;
869
- } else {
870
- if (foundIndex !== -1)
871
- i -= i - foundIndex;
872
- foundIndex = -1;
873
- }
874
- }
875
- } else {
876
- if (byteOffset + valLength > arrLength)
877
- byteOffset = arrLength - valLength;
878
- for (i = byteOffset; i >= 0; i--) {
879
- let found = true;
880
- for (let j = 0; j < valLength; j++) {
881
- if (read(arr, i + j) !== read(val, j)) {
882
- found = false;
883
- break;
884
- }
885
- }
886
- if (found)
887
- return i;
888
- }
889
- }
890
- return -1;
891
- }
892
- Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
893
- return this.indexOf(val, byteOffset, encoding) !== -1;
894
- };
895
- Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
896
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
897
- };
898
- Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
899
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
900
- };
901
- function hexWrite(buf, string, offset, length) {
902
- offset = Number(offset) || 0;
903
- const remaining = buf.length - offset;
904
- if (!length) {
905
- length = remaining;
906
- } else {
907
- length = Number(length);
908
- if (length > remaining) {
909
- length = remaining;
910
- }
911
- }
912
- const strLen = string.length;
913
- if (length > strLen / 2) {
914
- length = strLen / 2;
915
- }
916
- let i;
917
- for (i = 0; i < length; ++i) {
918
- const parsed = parseInt(string.substr(i * 2, 2), 16);
919
- if (numberIsNaN(parsed))
920
- return i;
921
- buf[offset + i] = parsed;
922
- }
923
- return i;
924
- }
925
- function utf8Write(buf, string, offset, length) {
926
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
927
- }
928
- function asciiWrite(buf, string, offset, length) {
929
- return blitBuffer(asciiToBytes(string), buf, offset, length);
930
- }
931
- function base64Write(buf, string, offset, length) {
932
- return blitBuffer(base64ToBytes(string), buf, offset, length);
933
- }
934
- function ucs2Write(buf, string, offset, length) {
935
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
936
- }
937
- Buffer3.prototype.write = function write(string, offset, length, encoding) {
938
- if (offset === void 0) {
939
- encoding = "utf8";
940
- length = this.length;
941
- offset = 0;
942
- } else if (length === void 0 && typeof offset === "string") {
943
- encoding = offset;
944
- length = this.length;
945
- offset = 0;
946
- } else if (isFinite(offset)) {
947
- offset = offset >>> 0;
948
- if (isFinite(length)) {
949
- length = length >>> 0;
950
- if (encoding === void 0)
951
- encoding = "utf8";
952
- } else {
953
- encoding = length;
954
- length = void 0;
955
- }
956
- } else {
957
- throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
958
- }
959
- const remaining = this.length - offset;
960
- if (length === void 0 || length > remaining)
961
- length = remaining;
962
- if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
963
- throw new RangeError("Attempt to write outside buffer bounds");
964
- }
965
- if (!encoding)
966
- encoding = "utf8";
967
- let loweredCase = false;
968
- for (; ; ) {
969
- switch (encoding) {
970
- case "hex":
971
- return hexWrite(this, string, offset, length);
972
- case "utf8":
973
- case "utf-8":
974
- return utf8Write(this, string, offset, length);
975
- case "ascii":
976
- case "latin1":
977
- case "binary":
978
- return asciiWrite(this, string, offset, length);
979
- case "base64":
980
- return base64Write(this, string, offset, length);
981
- case "ucs2":
982
- case "ucs-2":
983
- case "utf16le":
984
- case "utf-16le":
985
- return ucs2Write(this, string, offset, length);
986
- default:
987
- if (loweredCase)
988
- throw new TypeError("Unknown encoding: " + encoding);
989
- encoding = ("" + encoding).toLowerCase();
990
- loweredCase = true;
991
- }
992
- }
993
- };
994
- Buffer3.prototype.toJSON = function toJSON() {
995
- return {
996
- type: "Buffer",
997
- data: Array.prototype.slice.call(this._arr || this, 0)
998
- };
999
- };
1000
- function base64Slice(buf, start, end) {
1001
- if (start === 0 && end === buf.length) {
1002
- return base64.fromByteArray(buf);
1003
- } else {
1004
- return base64.fromByteArray(buf.slice(start, end));
1005
- }
1006
- }
1007
- function utf8Slice(buf, start, end) {
1008
- end = Math.min(buf.length, end);
1009
- const res = [];
1010
- let i = start;
1011
- while (i < end) {
1012
- const firstByte = buf[i];
1013
- let codePoint = null;
1014
- let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
1015
- if (i + bytesPerSequence <= end) {
1016
- let secondByte, thirdByte, fourthByte, tempCodePoint;
1017
- switch (bytesPerSequence) {
1018
- case 1:
1019
- if (firstByte < 128) {
1020
- codePoint = firstByte;
1021
- }
1022
- break;
1023
- case 2:
1024
- secondByte = buf[i + 1];
1025
- if ((secondByte & 192) === 128) {
1026
- tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
1027
- if (tempCodePoint > 127) {
1028
- codePoint = tempCodePoint;
1029
- }
1030
- }
1031
- break;
1032
- case 3:
1033
- secondByte = buf[i + 1];
1034
- thirdByte = buf[i + 2];
1035
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
1036
- tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
1037
- if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
1038
- codePoint = tempCodePoint;
1039
- }
1040
- }
1041
- break;
1042
- case 4:
1043
- secondByte = buf[i + 1];
1044
- thirdByte = buf[i + 2];
1045
- fourthByte = buf[i + 3];
1046
- if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
1047
- tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
1048
- if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
1049
- codePoint = tempCodePoint;
1050
- }
1051
- }
1052
- }
1053
- }
1054
- if (codePoint === null) {
1055
- codePoint = 65533;
1056
- bytesPerSequence = 1;
1057
- } else if (codePoint > 65535) {
1058
- codePoint -= 65536;
1059
- res.push(codePoint >>> 10 & 1023 | 55296);
1060
- codePoint = 56320 | codePoint & 1023;
1061
- }
1062
- res.push(codePoint);
1063
- i += bytesPerSequence;
1064
- }
1065
- return decodeCodePointsArray(res);
1066
- }
1067
- const MAX_ARGUMENTS_LENGTH = 4096;
1068
- function decodeCodePointsArray(codePoints) {
1069
- const len = codePoints.length;
1070
- if (len <= MAX_ARGUMENTS_LENGTH) {
1071
- return String.fromCharCode.apply(String, codePoints);
1072
- }
1073
- let res = "";
1074
- let i = 0;
1075
- while (i < len) {
1076
- res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
1077
- }
1078
- return res;
1079
- }
1080
- function asciiSlice(buf, start, end) {
1081
- let ret = "";
1082
- end = Math.min(buf.length, end);
1083
- for (let i = start; i < end; ++i) {
1084
- ret += String.fromCharCode(buf[i] & 127);
1085
- }
1086
- return ret;
1087
- }
1088
- function latin1Slice(buf, start, end) {
1089
- let ret = "";
1090
- end = Math.min(buf.length, end);
1091
- for (let i = start; i < end; ++i) {
1092
- ret += String.fromCharCode(buf[i]);
1093
- }
1094
- return ret;
1095
- }
1096
- function hexSlice(buf, start, end) {
1097
- const len = buf.length;
1098
- if (!start || start < 0)
1099
- start = 0;
1100
- if (!end || end < 0 || end > len)
1101
- end = len;
1102
- let out = "";
1103
- for (let i = start; i < end; ++i) {
1104
- out += hexSliceLookupTable[buf[i]];
1105
- }
1106
- return out;
1107
- }
1108
- function utf16leSlice(buf, start, end) {
1109
- const bytes = buf.slice(start, end);
1110
- let res = "";
1111
- for (let i = 0; i < bytes.length - 1; i += 2) {
1112
- res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1113
- }
1114
- return res;
1115
- }
1116
- Buffer3.prototype.slice = function slice(start, end) {
1117
- const len = this.length;
1118
- start = ~~start;
1119
- end = end === void 0 ? len : ~~end;
1120
- if (start < 0) {
1121
- start += len;
1122
- if (start < 0)
1123
- start = 0;
1124
- } else if (start > len) {
1125
- start = len;
1126
- }
1127
- if (end < 0) {
1128
- end += len;
1129
- if (end < 0)
1130
- end = 0;
1131
- } else if (end > len) {
1132
- end = len;
1133
- }
1134
- if (end < start)
1135
- end = start;
1136
- const newBuf = this.subarray(start, end);
1137
- Object.setPrototypeOf(newBuf, Buffer3.prototype);
1138
- return newBuf;
1139
- };
1140
- function checkOffset(offset, ext, length) {
1141
- if (offset % 1 !== 0 || offset < 0)
1142
- throw new RangeError("offset is not uint");
1143
- if (offset + ext > length)
1144
- throw new RangeError("Trying to access beyond buffer length");
1145
- }
1146
- Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
1147
- offset = offset >>> 0;
1148
- byteLength2 = byteLength2 >>> 0;
1149
- if (!noAssert)
1150
- checkOffset(offset, byteLength2, this.length);
1151
- let val = this[offset];
1152
- let mul = 1;
1153
- let i = 0;
1154
- while (++i < byteLength2 && (mul *= 256)) {
1155
- val += this[offset + i] * mul;
1156
- }
1157
- return val;
1158
- };
1159
- Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
1160
- offset = offset >>> 0;
1161
- byteLength2 = byteLength2 >>> 0;
1162
- if (!noAssert) {
1163
- checkOffset(offset, byteLength2, this.length);
1164
- }
1165
- let val = this[offset + --byteLength2];
1166
- let mul = 1;
1167
- while (byteLength2 > 0 && (mul *= 256)) {
1168
- val += this[offset + --byteLength2] * mul;
1169
- }
1170
- return val;
1171
- };
1172
- Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
1173
- offset = offset >>> 0;
1174
- if (!noAssert)
1175
- checkOffset(offset, 1, this.length);
1176
- return this[offset];
1177
- };
1178
- Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
1179
- offset = offset >>> 0;
1180
- if (!noAssert)
1181
- checkOffset(offset, 2, this.length);
1182
- return this[offset] | this[offset + 1] << 8;
1183
- };
1184
- Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
1185
- offset = offset >>> 0;
1186
- if (!noAssert)
1187
- checkOffset(offset, 2, this.length);
1188
- return this[offset] << 8 | this[offset + 1];
1189
- };
1190
- Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
1191
- offset = offset >>> 0;
1192
- if (!noAssert)
1193
- checkOffset(offset, 4, this.length);
1194
- return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
1195
- };
1196
- Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
1197
- offset = offset >>> 0;
1198
- if (!noAssert)
1199
- checkOffset(offset, 4, this.length);
1200
- return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
1201
- };
1202
- Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
1203
- offset = offset >>> 0;
1204
- validateNumber(offset, "offset");
1205
- const first = this[offset];
1206
- const last = this[offset + 7];
1207
- if (first === void 0 || last === void 0) {
1208
- boundsError(offset, this.length - 8);
1209
- }
1210
- const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
1211
- const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
1212
- return BigInt(lo) + (BigInt(hi) << BigInt(32));
1213
- });
1214
- Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
1215
- offset = offset >>> 0;
1216
- validateNumber(offset, "offset");
1217
- const first = this[offset];
1218
- const last = this[offset + 7];
1219
- if (first === void 0 || last === void 0) {
1220
- boundsError(offset, this.length - 8);
1221
- }
1222
- const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1223
- const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
1224
- return (BigInt(hi) << BigInt(32)) + BigInt(lo);
1225
- });
1226
- Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
1227
- offset = offset >>> 0;
1228
- byteLength2 = byteLength2 >>> 0;
1229
- if (!noAssert)
1230
- checkOffset(offset, byteLength2, this.length);
1231
- let val = this[offset];
1232
- let mul = 1;
1233
- let i = 0;
1234
- while (++i < byteLength2 && (mul *= 256)) {
1235
- val += this[offset + i] * mul;
1236
- }
1237
- mul *= 128;
1238
- if (val >= mul)
1239
- val -= Math.pow(2, 8 * byteLength2);
1240
- return val;
1241
- };
1242
- Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
1243
- offset = offset >>> 0;
1244
- byteLength2 = byteLength2 >>> 0;
1245
- if (!noAssert)
1246
- checkOffset(offset, byteLength2, this.length);
1247
- let i = byteLength2;
1248
- let mul = 1;
1249
- let val = this[offset + --i];
1250
- while (i > 0 && (mul *= 256)) {
1251
- val += this[offset + --i] * mul;
1252
- }
1253
- mul *= 128;
1254
- if (val >= mul)
1255
- val -= Math.pow(2, 8 * byteLength2);
1256
- return val;
1257
- };
1258
- Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
1259
- offset = offset >>> 0;
1260
- if (!noAssert)
1261
- checkOffset(offset, 1, this.length);
1262
- if (!(this[offset] & 128))
1263
- return this[offset];
1264
- return (255 - this[offset] + 1) * -1;
1265
- };
1266
- Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
1267
- offset = offset >>> 0;
1268
- if (!noAssert)
1269
- checkOffset(offset, 2, this.length);
1270
- const val = this[offset] | this[offset + 1] << 8;
1271
- return val & 32768 ? val | 4294901760 : val;
1272
- };
1273
- Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
1274
- offset = offset >>> 0;
1275
- if (!noAssert)
1276
- checkOffset(offset, 2, this.length);
1277
- const val = this[offset + 1] | this[offset] << 8;
1278
- return val & 32768 ? val | 4294901760 : val;
1279
- };
1280
- Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
1281
- offset = offset >>> 0;
1282
- if (!noAssert)
1283
- checkOffset(offset, 4, this.length);
1284
- return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
1285
- };
1286
- Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
1287
- offset = offset >>> 0;
1288
- if (!noAssert)
1289
- checkOffset(offset, 4, this.length);
1290
- return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
1291
- };
1292
- Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
1293
- offset = offset >>> 0;
1294
- validateNumber(offset, "offset");
1295
- const first = this[offset];
1296
- const last = this[offset + 7];
1297
- if (first === void 0 || last === void 0) {
1298
- boundsError(offset, this.length - 8);
1299
- }
1300
- const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
1301
- return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
1302
- });
1303
- Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
1304
- offset = offset >>> 0;
1305
- validateNumber(offset, "offset");
1306
- const first = this[offset];
1307
- const last = this[offset + 7];
1308
- if (first === void 0 || last === void 0) {
1309
- boundsError(offset, this.length - 8);
1310
- }
1311
- const val = (first << 24) + // Overflow
1312
- this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
1313
- return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
1314
- });
1315
- Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
1316
- offset = offset >>> 0;
1317
- if (!noAssert)
1318
- checkOffset(offset, 4, this.length);
1319
- return ieee754.read(this, offset, true, 23, 4);
1320
- };
1321
- Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
1322
- offset = offset >>> 0;
1323
- if (!noAssert)
1324
- checkOffset(offset, 4, this.length);
1325
- return ieee754.read(this, offset, false, 23, 4);
1326
- };
1327
- Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
1328
- offset = offset >>> 0;
1329
- if (!noAssert)
1330
- checkOffset(offset, 8, this.length);
1331
- return ieee754.read(this, offset, true, 52, 8);
1332
- };
1333
- Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
1334
- offset = offset >>> 0;
1335
- if (!noAssert)
1336
- checkOffset(offset, 8, this.length);
1337
- return ieee754.read(this, offset, false, 52, 8);
1338
- };
1339
- function checkInt(buf, value, offset, ext, max, min) {
1340
- if (!Buffer3.isBuffer(buf))
1341
- throw new TypeError('"buffer" argument must be a Buffer instance');
1342
- if (value > max || value < min)
1343
- throw new RangeError('"value" argument is out of bounds');
1344
- if (offset + ext > buf.length)
1345
- throw new RangeError("Index out of range");
1346
- }
1347
- Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
1348
- value = +value;
1349
- offset = offset >>> 0;
1350
- byteLength2 = byteLength2 >>> 0;
1351
- if (!noAssert) {
1352
- const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1353
- checkInt(this, value, offset, byteLength2, maxBytes, 0);
1354
- }
1355
- let mul = 1;
1356
- let i = 0;
1357
- this[offset] = value & 255;
1358
- while (++i < byteLength2 && (mul *= 256)) {
1359
- this[offset + i] = value / mul & 255;
1360
- }
1361
- return offset + byteLength2;
1362
- };
1363
- Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
1364
- value = +value;
1365
- offset = offset >>> 0;
1366
- byteLength2 = byteLength2 >>> 0;
1367
- if (!noAssert) {
1368
- const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
1369
- checkInt(this, value, offset, byteLength2, maxBytes, 0);
1370
- }
1371
- let i = byteLength2 - 1;
1372
- let mul = 1;
1373
- this[offset + i] = value & 255;
1374
- while (--i >= 0 && (mul *= 256)) {
1375
- this[offset + i] = value / mul & 255;
1376
- }
1377
- return offset + byteLength2;
1378
- };
1379
- Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
1380
- value = +value;
1381
- offset = offset >>> 0;
1382
- if (!noAssert)
1383
- checkInt(this, value, offset, 1, 255, 0);
1384
- this[offset] = value & 255;
1385
- return offset + 1;
1386
- };
1387
- Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
1388
- value = +value;
1389
- offset = offset >>> 0;
1390
- if (!noAssert)
1391
- checkInt(this, value, offset, 2, 65535, 0);
1392
- this[offset] = value & 255;
1393
- this[offset + 1] = value >>> 8;
1394
- return offset + 2;
1395
- };
1396
- Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
1397
- value = +value;
1398
- offset = offset >>> 0;
1399
- if (!noAssert)
1400
- checkInt(this, value, offset, 2, 65535, 0);
1401
- this[offset] = value >>> 8;
1402
- this[offset + 1] = value & 255;
1403
- return offset + 2;
1404
- };
1405
- Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
1406
- value = +value;
1407
- offset = offset >>> 0;
1408
- if (!noAssert)
1409
- checkInt(this, value, offset, 4, 4294967295, 0);
1410
- this[offset + 3] = value >>> 24;
1411
- this[offset + 2] = value >>> 16;
1412
- this[offset + 1] = value >>> 8;
1413
- this[offset] = value & 255;
1414
- return offset + 4;
1415
- };
1416
- Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
1417
- value = +value;
1418
- offset = offset >>> 0;
1419
- if (!noAssert)
1420
- checkInt(this, value, offset, 4, 4294967295, 0);
1421
- this[offset] = value >>> 24;
1422
- this[offset + 1] = value >>> 16;
1423
- this[offset + 2] = value >>> 8;
1424
- this[offset + 3] = value & 255;
1425
- return offset + 4;
1426
- };
1427
- function wrtBigUInt64LE(buf, value, offset, min, max) {
1428
- checkIntBI(value, min, max, buf, offset, 7);
1429
- let lo = Number(value & BigInt(4294967295));
1430
- buf[offset++] = lo;
1431
- lo = lo >> 8;
1432
- buf[offset++] = lo;
1433
- lo = lo >> 8;
1434
- buf[offset++] = lo;
1435
- lo = lo >> 8;
1436
- buf[offset++] = lo;
1437
- let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1438
- buf[offset++] = hi;
1439
- hi = hi >> 8;
1440
- buf[offset++] = hi;
1441
- hi = hi >> 8;
1442
- buf[offset++] = hi;
1443
- hi = hi >> 8;
1444
- buf[offset++] = hi;
1445
- return offset;
1446
- }
1447
- function wrtBigUInt64BE(buf, value, offset, min, max) {
1448
- checkIntBI(value, min, max, buf, offset, 7);
1449
- let lo = Number(value & BigInt(4294967295));
1450
- buf[offset + 7] = lo;
1451
- lo = lo >> 8;
1452
- buf[offset + 6] = lo;
1453
- lo = lo >> 8;
1454
- buf[offset + 5] = lo;
1455
- lo = lo >> 8;
1456
- buf[offset + 4] = lo;
1457
- let hi = Number(value >> BigInt(32) & BigInt(4294967295));
1458
- buf[offset + 3] = hi;
1459
- hi = hi >> 8;
1460
- buf[offset + 2] = hi;
1461
- hi = hi >> 8;
1462
- buf[offset + 1] = hi;
1463
- hi = hi >> 8;
1464
- buf[offset] = hi;
1465
- return offset + 8;
1466
- }
1467
- Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
1468
- return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
1469
- });
1470
- Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
1471
- return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
1472
- });
1473
- Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
1474
- value = +value;
1475
- offset = offset >>> 0;
1476
- if (!noAssert) {
1477
- const limit = Math.pow(2, 8 * byteLength2 - 1);
1478
- checkInt(this, value, offset, byteLength2, limit - 1, -limit);
1479
- }
1480
- let i = 0;
1481
- let mul = 1;
1482
- let sub = 0;
1483
- this[offset] = value & 255;
1484
- while (++i < byteLength2 && (mul *= 256)) {
1485
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1486
- sub = 1;
1487
- }
1488
- this[offset + i] = (value / mul >> 0) - sub & 255;
1489
- }
1490
- return offset + byteLength2;
1491
- };
1492
- Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
1493
- value = +value;
1494
- offset = offset >>> 0;
1495
- if (!noAssert) {
1496
- const limit = Math.pow(2, 8 * byteLength2 - 1);
1497
- checkInt(this, value, offset, byteLength2, limit - 1, -limit);
1498
- }
1499
- let i = byteLength2 - 1;
1500
- let mul = 1;
1501
- let sub = 0;
1502
- this[offset + i] = value & 255;
1503
- while (--i >= 0 && (mul *= 256)) {
1504
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1505
- sub = 1;
1506
- }
1507
- this[offset + i] = (value / mul >> 0) - sub & 255;
1508
- }
1509
- return offset + byteLength2;
1510
- };
1511
- Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
1512
- value = +value;
1513
- offset = offset >>> 0;
1514
- if (!noAssert)
1515
- checkInt(this, value, offset, 1, 127, -128);
1516
- if (value < 0)
1517
- value = 255 + value + 1;
1518
- this[offset] = value & 255;
1519
- return offset + 1;
1520
- };
1521
- Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
1522
- value = +value;
1523
- offset = offset >>> 0;
1524
- if (!noAssert)
1525
- checkInt(this, value, offset, 2, 32767, -32768);
1526
- this[offset] = value & 255;
1527
- this[offset + 1] = value >>> 8;
1528
- return offset + 2;
1529
- };
1530
- Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
1531
- value = +value;
1532
- offset = offset >>> 0;
1533
- if (!noAssert)
1534
- checkInt(this, value, offset, 2, 32767, -32768);
1535
- this[offset] = value >>> 8;
1536
- this[offset + 1] = value & 255;
1537
- return offset + 2;
1538
- };
1539
- Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
1540
- value = +value;
1541
- offset = offset >>> 0;
1542
- if (!noAssert)
1543
- checkInt(this, value, offset, 4, 2147483647, -2147483648);
1544
- this[offset] = value & 255;
1545
- this[offset + 1] = value >>> 8;
1546
- this[offset + 2] = value >>> 16;
1547
- this[offset + 3] = value >>> 24;
1548
- return offset + 4;
1549
- };
1550
- Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
1551
- value = +value;
1552
- offset = offset >>> 0;
1553
- if (!noAssert)
1554
- checkInt(this, value, offset, 4, 2147483647, -2147483648);
1555
- if (value < 0)
1556
- value = 4294967295 + value + 1;
1557
- this[offset] = value >>> 24;
1558
- this[offset + 1] = value >>> 16;
1559
- this[offset + 2] = value >>> 8;
1560
- this[offset + 3] = value & 255;
1561
- return offset + 4;
1562
- };
1563
- Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
1564
- return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
1565
- });
1566
- Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
1567
- return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
1568
- });
1569
- function checkIEEE754(buf, value, offset, ext, max, min) {
1570
- if (offset + ext > buf.length)
1571
- throw new RangeError("Index out of range");
1572
- if (offset < 0)
1573
- throw new RangeError("Index out of range");
1574
- }
1575
- function writeFloat(buf, value, offset, littleEndian, noAssert) {
1576
- value = +value;
1577
- offset = offset >>> 0;
1578
- if (!noAssert) {
1579
- checkIEEE754(buf, value, offset, 4);
1580
- }
1581
- ieee754.write(buf, value, offset, littleEndian, 23, 4);
1582
- return offset + 4;
1583
- }
1584
- Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
1585
- return writeFloat(this, value, offset, true, noAssert);
1586
- };
1587
- Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
1588
- return writeFloat(this, value, offset, false, noAssert);
1589
- };
1590
- function writeDouble(buf, value, offset, littleEndian, noAssert) {
1591
- value = +value;
1592
- offset = offset >>> 0;
1593
- if (!noAssert) {
1594
- checkIEEE754(buf, value, offset, 8);
1595
- }
1596
- ieee754.write(buf, value, offset, littleEndian, 52, 8);
1597
- return offset + 8;
1598
- }
1599
- Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
1600
- return writeDouble(this, value, offset, true, noAssert);
1601
- };
1602
- Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
1603
- return writeDouble(this, value, offset, false, noAssert);
1604
- };
1605
- Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
1606
- if (!Buffer3.isBuffer(target))
1607
- throw new TypeError("argument should be a Buffer");
1608
- if (!start)
1609
- start = 0;
1610
- if (!end && end !== 0)
1611
- end = this.length;
1612
- if (targetStart >= target.length)
1613
- targetStart = target.length;
1614
- if (!targetStart)
1615
- targetStart = 0;
1616
- if (end > 0 && end < start)
1617
- end = start;
1618
- if (end === start)
1619
- return 0;
1620
- if (target.length === 0 || this.length === 0)
1621
- return 0;
1622
- if (targetStart < 0) {
1623
- throw new RangeError("targetStart out of bounds");
1624
- }
1625
- if (start < 0 || start >= this.length)
1626
- throw new RangeError("Index out of range");
1627
- if (end < 0)
1628
- throw new RangeError("sourceEnd out of bounds");
1629
- if (end > this.length)
1630
- end = this.length;
1631
- if (target.length - targetStart < end - start) {
1632
- end = target.length - targetStart + start;
1633
- }
1634
- const len = end - start;
1635
- if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
1636
- this.copyWithin(targetStart, start, end);
1637
- } else {
1638
- Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
1639
- }
1640
- return len;
1641
- };
1642
- Buffer3.prototype.fill = function fill(val, start, end, encoding) {
1643
- if (typeof val === "string") {
1644
- if (typeof start === "string") {
1645
- encoding = start;
1646
- start = 0;
1647
- end = this.length;
1648
- } else if (typeof end === "string") {
1649
- encoding = end;
1650
- end = this.length;
1651
- }
1652
- if (encoding !== void 0 && typeof encoding !== "string") {
1653
- throw new TypeError("encoding must be a string");
1654
- }
1655
- if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
1656
- throw new TypeError("Unknown encoding: " + encoding);
1657
- }
1658
- if (val.length === 1) {
1659
- const code = val.charCodeAt(0);
1660
- if (encoding === "utf8" && code < 128 || encoding === "latin1") {
1661
- val = code;
1662
- }
1663
- }
1664
- } else if (typeof val === "number") {
1665
- val = val & 255;
1666
- } else if (typeof val === "boolean") {
1667
- val = Number(val);
1668
- }
1669
- if (start < 0 || this.length < start || this.length < end) {
1670
- throw new RangeError("Out of range index");
1671
- }
1672
- if (end <= start) {
1673
- return this;
1674
- }
1675
- start = start >>> 0;
1676
- end = end === void 0 ? this.length : end >>> 0;
1677
- if (!val)
1678
- val = 0;
1679
- let i;
1680
- if (typeof val === "number") {
1681
- for (i = start; i < end; ++i) {
1682
- this[i] = val;
1683
- }
1684
- } else {
1685
- const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
1686
- const len = bytes.length;
1687
- if (len === 0) {
1688
- throw new TypeError('The value "' + val + '" is invalid for argument "value"');
1689
- }
1690
- for (i = 0; i < end - start; ++i) {
1691
- this[i + start] = bytes[i % len];
1692
- }
1693
- }
1694
- return this;
1695
- };
1696
- const errors = {};
1697
- function E(sym, getMessage, Base) {
1698
- errors[sym] = class NodeError extends Base {
1699
- constructor() {
1700
- super();
1701
- Object.defineProperty(this, "message", {
1702
- value: getMessage.apply(this, arguments),
1703
- writable: true,
1704
- configurable: true
1705
- });
1706
- this.name = `${this.name} [${sym}]`;
1707
- this.stack;
1708
- delete this.name;
1709
- }
1710
- get code() {
1711
- return sym;
1712
- }
1713
- set code(value) {
1714
- Object.defineProperty(this, "code", {
1715
- configurable: true,
1716
- enumerable: true,
1717
- value,
1718
- writable: true
1719
- });
1720
- }
1721
- toString() {
1722
- return `${this.name} [${sym}]: ${this.message}`;
1723
- }
1724
- };
1725
- }
1726
- E("ERR_BUFFER_OUT_OF_BOUNDS", function(name) {
1727
- if (name) {
1728
- return `${name} is outside of buffer bounds`;
1729
- }
1730
- return "Attempt to access memory outside buffer bounds";
1731
- }, RangeError);
1732
- E("ERR_INVALID_ARG_TYPE", function(name, actual) {
1733
- return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
1734
- }, TypeError);
1735
- E("ERR_OUT_OF_RANGE", function(str2, range, input) {
1736
- let msg = `The value of "${str2}" is out of range.`;
1737
- let received = input;
1738
- if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
1739
- received = addNumericalSeparator(String(input));
1740
- } else if (typeof input === "bigint") {
1741
- received = String(input);
1742
- if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
1743
- received = addNumericalSeparator(received);
1744
- }
1745
- received += "n";
1746
- }
1747
- msg += ` It must be ${range}. Received ${received}`;
1748
- return msg;
1749
- }, RangeError);
1750
- function addNumericalSeparator(val) {
1751
- let res = "";
1752
- let i = val.length;
1753
- const start = val[0] === "-" ? 1 : 0;
1754
- for (; i >= start + 4; i -= 3) {
1755
- res = `_${val.slice(i - 3, i)}${res}`;
1756
- }
1757
- return `${val.slice(0, i)}${res}`;
1758
- }
1759
- function checkBounds(buf, offset, byteLength2) {
1760
- validateNumber(offset, "offset");
1761
- if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
1762
- boundsError(offset, buf.length - (byteLength2 + 1));
1763
- }
1764
- }
1765
- function checkIntBI(value, min, max, buf, offset, byteLength2) {
1766
- if (value > max || value < min) {
1767
- const n = typeof min === "bigint" ? "n" : "";
1768
- let range;
1769
- if (byteLength2 > 3) {
1770
- if (min === 0 || min === BigInt(0)) {
1771
- range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
1772
- } else {
1773
- range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
1774
- }
1775
- } else {
1776
- range = `>= ${min}${n} and <= ${max}${n}`;
1777
- }
1778
- throw new errors.ERR_OUT_OF_RANGE("value", range, value);
1779
- }
1780
- checkBounds(buf, offset, byteLength2);
1781
- }
1782
- function validateNumber(value, name) {
1783
- if (typeof value !== "number") {
1784
- throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
1785
- }
1786
- }
1787
- function boundsError(value, length, type) {
1788
- if (Math.floor(value) !== value) {
1789
- validateNumber(value, type);
1790
- throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
1791
- }
1792
- if (length < 0) {
1793
- throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
1794
- }
1795
- throw new errors.ERR_OUT_OF_RANGE(type || "offset", `>= ${type ? 1 : 0} and <= ${length}`, value);
1796
- }
1797
- const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
1798
- function base64clean(str2) {
1799
- str2 = str2.split("=")[0];
1800
- str2 = str2.trim().replace(INVALID_BASE64_RE, "");
1801
- if (str2.length < 2)
1802
- return "";
1803
- while (str2.length % 4 !== 0) {
1804
- str2 = str2 + "=";
1805
- }
1806
- return str2;
1807
- }
1808
- function utf8ToBytes(string, units) {
1809
- units = units || Infinity;
1810
- let codePoint;
1811
- const length = string.length;
1812
- let leadSurrogate = null;
1813
- const bytes = [];
1814
- for (let i = 0; i < length; ++i) {
1815
- codePoint = string.charCodeAt(i);
1816
- if (codePoint > 55295 && codePoint < 57344) {
1817
- if (!leadSurrogate) {
1818
- if (codePoint > 56319) {
1819
- if ((units -= 3) > -1)
1820
- bytes.push(239, 191, 189);
1821
- continue;
1822
- } else if (i + 1 === length) {
1823
- if ((units -= 3) > -1)
1824
- bytes.push(239, 191, 189);
1825
- continue;
1826
- }
1827
- leadSurrogate = codePoint;
1828
- continue;
1829
- }
1830
- if (codePoint < 56320) {
1831
- if ((units -= 3) > -1)
1832
- bytes.push(239, 191, 189);
1833
- leadSurrogate = codePoint;
1834
- continue;
1835
- }
1836
- codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
1837
- } else if (leadSurrogate) {
1838
- if ((units -= 3) > -1)
1839
- bytes.push(239, 191, 189);
1840
- }
1841
- leadSurrogate = null;
1842
- if (codePoint < 128) {
1843
- if ((units -= 1) < 0)
1844
- break;
1845
- bytes.push(codePoint);
1846
- } else if (codePoint < 2048) {
1847
- if ((units -= 2) < 0)
1848
- break;
1849
- bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
1850
- } else if (codePoint < 65536) {
1851
- if ((units -= 3) < 0)
1852
- break;
1853
- bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
1854
- } else if (codePoint < 1114112) {
1855
- if ((units -= 4) < 0)
1856
- break;
1857
- bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
1858
- } else {
1859
- throw new Error("Invalid code point");
1860
- }
1861
- }
1862
- return bytes;
1863
- }
1864
- function asciiToBytes(str2) {
1865
- const byteArray = [];
1866
- for (let i = 0; i < str2.length; ++i) {
1867
- byteArray.push(str2.charCodeAt(i) & 255);
1868
- }
1869
- return byteArray;
1870
- }
1871
- function utf16leToBytes(str2, units) {
1872
- let c, hi, lo;
1873
- const byteArray = [];
1874
- for (let i = 0; i < str2.length; ++i) {
1875
- if ((units -= 2) < 0)
1876
- break;
1877
- c = str2.charCodeAt(i);
1878
- hi = c >> 8;
1879
- lo = c % 256;
1880
- byteArray.push(lo);
1881
- byteArray.push(hi);
1882
- }
1883
- return byteArray;
1884
- }
1885
- function base64ToBytes(str2) {
1886
- return base64.toByteArray(base64clean(str2));
1887
- }
1888
- function blitBuffer(src, dst, offset, length) {
1889
- let i;
1890
- for (i = 0; i < length; ++i) {
1891
- if (i + offset >= dst.length || i >= src.length)
1892
- break;
1893
- dst[i + offset] = src[i];
1894
- }
1895
- return i;
1896
- }
1897
- function isInstance(obj, type) {
1898
- return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
1899
- }
1900
- function numberIsNaN(obj) {
1901
- return obj !== obj;
1902
- }
1903
- const hexSliceLookupTable = function() {
1904
- const alphabet = "0123456789abcdef";
1905
- const table = new Array(256);
1906
- for (let i = 0; i < 16; ++i) {
1907
- const i16 = i * 16;
1908
- for (let j = 0; j < 16; ++j) {
1909
- table[i16 + j] = alphabet[i] + alphabet[j];
1910
- }
1911
- }
1912
- return table;
1913
- }();
1914
- function defineBigIntMethod(fn) {
1915
- return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
1916
- }
1917
- function BufferBigIntNotDefined() {
1918
- throw new Error("BigInt not supported");
1919
- }
1920
- return exports$1;
1921
- }
1922
- var exports$3, _dewExec$2, exports$2, _dewExec$1, exports$1, _dewExec, exports, Buffer2, INSPECT_MAX_BYTES, kMaxLength;
1923
- var init_buffer = __esm({
1924
- "../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/buffer.js"() {
1925
- "use strict";
1926
- init_dirname();
1927
- init_buffer2();
1928
- init_process2();
1929
- exports$3 = {};
1930
- _dewExec$2 = false;
1931
- exports$2 = {};
1932
- _dewExec$1 = false;
1933
- exports$1 = {};
1934
- _dewExec = false;
1935
- exports = dew();
1936
- exports["Buffer"];
1937
- exports["SlowBuffer"];
1938
- exports["INSPECT_MAX_BYTES"];
1939
- exports["kMaxLength"];
1940
- Buffer2 = exports.Buffer;
1941
- INSPECT_MAX_BYTES = exports.INSPECT_MAX_BYTES;
1942
- kMaxLength = exports.kMaxLength;
1943
- }
1944
- });
1945
-
1946
- // ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/buffer.js
1947
- var init_buffer2 = __esm({
1948
- "../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/buffer.js"() {
1949
- "use strict";
1950
- init_buffer();
1951
- }
1952
- });
1953
-
1954
- // ../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js
1955
- var require_src = __commonJS({
1956
- "../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js"(exports2, module) {
1957
- "use strict";
1958
- init_dirname();
1959
- init_buffer2();
1960
- init_process2();
1961
- function base(ALPHABET) {
1962
- if (ALPHABET.length >= 255) {
1963
- throw new TypeError("Alphabet too long");
1964
- }
1965
- var BASE_MAP = new Uint8Array(256);
1966
- for (var j = 0; j < BASE_MAP.length; j++) {
1967
- BASE_MAP[j] = 255;
1968
- }
1969
- for (var i = 0; i < ALPHABET.length; i++) {
1970
- var x = ALPHABET.charAt(i);
1971
- var xc = x.charCodeAt(0);
1972
- if (BASE_MAP[xc] !== 255) {
1973
- throw new TypeError(x + " is ambiguous");
1974
- }
1975
- BASE_MAP[xc] = i;
1976
- }
1977
- var BASE = ALPHABET.length;
1978
- var LEADER = ALPHABET.charAt(0);
1979
- var FACTOR = Math.log(BASE) / Math.log(256);
1980
- var iFACTOR = Math.log(256) / Math.log(BASE);
1981
- function encode(source) {
1982
- if (source instanceof Uint8Array) {
1983
- } else if (ArrayBuffer.isView(source)) {
1984
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
1985
- } else if (Array.isArray(source)) {
1986
- source = Uint8Array.from(source);
1987
- }
1988
- if (!(source instanceof Uint8Array)) {
1989
- throw new TypeError("Expected Uint8Array");
1990
- }
1991
- if (source.length === 0) {
1992
- return "";
1993
- }
1994
- var zeroes = 0;
1995
- var length = 0;
1996
- var pbegin = 0;
1997
- var pend = source.length;
1998
- while (pbegin !== pend && source[pbegin] === 0) {
1999
- pbegin++;
2000
- zeroes++;
2001
- }
2002
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
2003
- var b58 = new Uint8Array(size);
2004
- while (pbegin !== pend) {
2005
- var carry = source[pbegin];
2006
- var i2 = 0;
2007
- for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
2008
- carry += 256 * b58[it1] >>> 0;
2009
- b58[it1] = carry % BASE >>> 0;
2010
- carry = carry / BASE >>> 0;
2011
- }
2012
- if (carry !== 0) {
2013
- throw new Error("Non-zero carry");
2014
- }
2015
- length = i2;
2016
- pbegin++;
2017
- }
2018
- var it2 = size - length;
2019
- while (it2 !== size && b58[it2] === 0) {
2020
- it2++;
2021
- }
2022
- var str2 = LEADER.repeat(zeroes);
2023
- for (; it2 < size; ++it2) {
2024
- str2 += ALPHABET.charAt(b58[it2]);
2025
- }
2026
- return str2;
2027
- }
2028
- function decodeUnsafe(source) {
2029
- if (typeof source !== "string") {
2030
- throw new TypeError("Expected String");
2031
- }
2032
- if (source.length === 0) {
2033
- return new Uint8Array();
2034
- }
2035
- var psz = 0;
2036
- var zeroes = 0;
2037
- var length = 0;
2038
- while (source[psz] === LEADER) {
2039
- zeroes++;
2040
- psz++;
2041
- }
2042
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
2043
- var b256 = new Uint8Array(size);
2044
- while (source[psz]) {
2045
- var carry = BASE_MAP[source.charCodeAt(psz)];
2046
- if (carry === 255) {
2047
- return;
2048
- }
2049
- var i2 = 0;
2050
- for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
2051
- carry += BASE * b256[it3] >>> 0;
2052
- b256[it3] = carry % 256 >>> 0;
2053
- carry = carry / 256 >>> 0;
2054
- }
2055
- if (carry !== 0) {
2056
- throw new Error("Non-zero carry");
2057
- }
2058
- length = i2;
2059
- psz++;
2060
- }
2061
- var it4 = size - length;
2062
- while (it4 !== size && b256[it4] === 0) {
2063
- it4++;
2064
- }
2065
- var vch = new Uint8Array(zeroes + (size - it4));
2066
- var j2 = zeroes;
2067
- while (it4 !== size) {
2068
- vch[j2++] = b256[it4++];
2069
- }
2070
- return vch;
2071
- }
2072
- function decode(string) {
2073
- var buffer = decodeUnsafe(string);
2074
- if (buffer) {
2075
- return buffer;
2076
- }
2077
- throw new Error("Non-base" + BASE + " character");
2078
- }
2079
- return {
2080
- encode,
2081
- decodeUnsafe,
2082
- decode
2083
- };
2084
- }
2085
- module.exports = base;
2086
- }
2087
- });
2088
-
2089
- // ../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js
2090
- var require_bs58 = __commonJS({
2091
- "../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js"(exports2, module) {
2092
- "use strict";
2093
- init_dirname();
2094
- init_buffer2();
2095
- init_process2();
2096
- var basex = require_src();
2097
- var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2098
- module.exports = basex(ALPHABET);
2099
- }
2100
- });
2101
-
2102
- // src/index.ts
2103
- init_dirname();
2104
- init_buffer2();
2105
- init_process2();
2106
-
2107
- // src/keyStore.ts
2108
- init_dirname();
2109
- init_buffer2();
2110
- init_process2();
2111
-
2112
- // src/keyPair.ts
2113
- init_dirname();
2114
- init_buffer2();
2115
- init_process2();
2116
- var import_bs58 = __toESM(require_bs58());
2117
-
2118
- // ../../node_modules/.pnpm/@noble+ed25519@2.0.0/node_modules/@noble/ed25519/index.js
2119
- init_dirname();
2120
- init_buffer2();
2121
- init_process2();
2122
- var P = 2n ** 255n - 19n;
2123
- var N = 2n ** 252n + 27742317777372353535851937790883648493n;
2124
- var Gx = 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an;
2125
- var Gy = 0x6666666666666666666666666666666666666666666666666666666666666658n;
2126
- var CURVE = {
2127
- a: -1n,
2128
- d: 37095705934669439343138083508754565189542113879843219016388785533085940283555n,
2129
- p: P,
2130
- n: N,
2131
- h: 8,
2132
- Gx,
2133
- Gy
2134
- // field prime, curve (group) order, cofactor
2135
- };
2136
- var err = (m = "") => {
2137
- throw new Error(m);
2138
- };
2139
- var str = (s) => typeof s === "string";
2140
- var au8 = (a, l) => (
2141
- // is Uint8Array (of specific length)
2142
- !(a instanceof Uint8Array) || typeof l === "number" && l > 0 && a.length !== l ? err("Uint8Array expected") : a
2143
- );
2144
- var u8n = (data) => new Uint8Array(data);
2145
- var toU8 = (a, len) => au8(str(a) ? h2b(a) : u8n(a), len);
2146
- var mod = (a, b = P) => {
2147
- let r = a % b;
2148
- return r >= 0n ? r : b + r;
2149
- };
2150
- var isPoint = (p) => p instanceof Point ? p : err("Point expected");
2151
- var Gpows = void 0;
2152
- var Point = class _Point {
2153
- constructor(ex, ey, ez, et) {
2154
- this.ex = ex;
2155
- this.ey = ey;
2156
- this.ez = ez;
2157
- this.et = et;
2158
- }
2159
- static fromAffine(p) {
2160
- return new _Point(p.x, p.y, 1n, mod(p.x * p.y));
2161
- }
2162
- static fromHex(hex, strict = true) {
2163
- const { d } = CURVE;
2164
- hex = toU8(hex, 32);
2165
- const normed = hex.slice();
2166
- normed[31] = hex[31] & ~128;
2167
- const y = b2n_LE(normed);
2168
- if (y === 0n) {
2169
- } else {
2170
- if (strict && !(0n < y && y < P))
2171
- err("bad y coord 1");
2172
- if (!strict && !(0n < y && y < 2n ** 256n))
2173
- err("bad y coord 2");
2174
- }
2175
- const y2 = mod(y * y);
2176
- const u = mod(y2 - 1n);
2177
- const v = mod(d * y2 + 1n);
2178
- let { isValid, value: x } = uvRatio(u, v);
2179
- if (!isValid)
2180
- err("bad y coordinate 3");
2181
- const isXOdd = (x & 1n) === 1n;
2182
- const isHeadOdd = (hex[31] & 128) !== 0;
2183
- if (isHeadOdd !== isXOdd)
2184
- x = mod(-x);
2185
- return new _Point(x, y, 1n, mod(x * y));
2186
- }
2187
- get x() {
2188
- return this.toAffine().x;
2189
- }
2190
- // .x, .y will call expensive toAffine.
2191
- get y() {
2192
- return this.toAffine().y;
2193
- }
2194
- // Should be used with care.
2195
- equals(other) {
2196
- const { ex: X1, ey: Y1, ez: Z1 } = this;
2197
- const { ex: X2, ey: Y2, ez: Z2 } = isPoint(other);
2198
- const X1Z2 = mod(X1 * Z2), X2Z1 = mod(X2 * Z1);
2199
- const Y1Z2 = mod(Y1 * Z2), Y2Z1 = mod(Y2 * Z1);
2200
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
2201
- }
2202
- is0() {
2203
- return this.equals(I);
2204
- }
2205
- negate() {
2206
- return new _Point(mod(-this.ex), this.ey, this.ez, mod(-this.et));
2207
- }
2208
- double() {
2209
- const { ex: X1, ey: Y1, ez: Z1 } = this;
2210
- const { a } = CURVE;
2211
- const A = mod(X1 * X1);
2212
- const B = mod(Y1 * Y1);
2213
- const C = mod(2n * mod(Z1 * Z1));
2214
- const D = mod(a * A);
2215
- const x1y1 = X1 + Y1;
2216
- const E = mod(mod(x1y1 * x1y1) - A - B);
2217
- const G2 = D + B;
2218
- const F = G2 - C;
2219
- const H = D - B;
2220
- const X3 = mod(E * F);
2221
- const Y3 = mod(G2 * H);
2222
- const T3 = mod(E * H);
2223
- const Z3 = mod(F * G2);
2224
- return new _Point(X3, Y3, Z3, T3);
2225
- }
2226
- add(other) {
2227
- const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
2228
- const { ex: X2, ey: Y2, ez: Z2, et: T2 } = isPoint(other);
2229
- const { a, d } = CURVE;
2230
- const A = mod(X1 * X2);
2231
- const B = mod(Y1 * Y2);
2232
- const C = mod(T1 * d * T2);
2233
- const D = mod(Z1 * Z2);
2234
- const E = mod((X1 + Y1) * (X2 + Y2) - A - B);
2235
- const F = mod(D - C);
2236
- const G2 = mod(D + C);
2237
- const H = mod(B - a * A);
2238
- const X3 = mod(E * F);
2239
- const Y3 = mod(G2 * H);
2240
- const T3 = mod(E * H);
2241
- const Z3 = mod(F * G2);
2242
- return new _Point(X3, Y3, Z3, T3);
2243
- }
2244
- mul(n, safe = true) {
2245
- if (n === 0n)
2246
- return safe === true ? err("cannot multiply by 0") : I;
2247
- if (!(typeof n === "bigint" && 0n < n && n < N))
2248
- err("invalid scalar, must be < L");
2249
- if (!safe && this.is0() || n === 1n)
2250
- return this;
2251
- if (this.equals(G))
2252
- return wNAF(n).p;
2253
- let p = I, f = G;
2254
- for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
2255
- if (n & 1n)
2256
- p = p.add(d);
2257
- else if (safe)
2258
- f = f.add(d);
2259
- }
2260
- return p;
2261
- }
2262
- multiply(scalar) {
2263
- return this.mul(scalar);
2264
- }
2265
- // Aliases for compatibilty
2266
- clearCofactor() {
2267
- return this.mul(BigInt(CURVE.h), false);
2268
- }
2269
- // multiply by cofactor
2270
- isSmallOrder() {
2271
- return this.clearCofactor().is0();
2272
- }
2273
- // check if P is small order
2274
- isTorsionFree() {
2275
- let p = this.mul(N / 2n, false).double();
2276
- if (N % 2n)
2277
- p = p.add(this);
2278
- return p.is0();
2279
- }
2280
- toAffine() {
2281
- const { ex: x, ey: y, ez: z } = this;
2282
- if (this.is0())
2283
- return { x: 0n, y: 0n };
2284
- const iz = invert(z);
2285
- if (mod(z * iz) !== 1n)
2286
- err("invalid inverse");
2287
- return { x: mod(x * iz), y: mod(y * iz) };
2288
- }
2289
- toRawBytes() {
2290
- const { x, y } = this.toAffine();
2291
- const b = n2b_32LE(y);
2292
- b[31] |= x & 1n ? 128 : 0;
2293
- return b;
2294
- }
2295
- toHex() {
2296
- return b2h(this.toRawBytes());
2297
- }
2298
- // encode to hex string
2299
- };
2300
- Point.BASE = new Point(Gx, Gy, 1n, mod(Gx * Gy));
2301
- Point.ZERO = new Point(0n, 1n, 1n, 0n);
2302
- var { BASE: G, ZERO: I } = Point;
2303
- var padh = (num, pad) => num.toString(16).padStart(pad, "0");
2304
- var b2h = (b) => Array.from(b).map((e) => padh(e, 2)).join("");
2305
- var h2b = (hex) => {
2306
- const l = hex.length;
2307
- if (!str(hex) || l % 2)
2308
- err("hex invalid 1");
2309
- const arr = u8n(l / 2);
2310
- for (let i = 0; i < arr.length; i++) {
2311
- const j = i * 2;
2312
- const h = hex.slice(j, j + 2);
2313
- const b = Number.parseInt(h, 16);
2314
- if (Number.isNaN(b) || b < 0)
2315
- err("hex invalid 2");
2316
- arr[i] = b;
2317
- }
2318
- return arr;
2319
- };
2320
- var n2b_32LE = (num) => h2b(padh(num, 32 * 2)).reverse();
2321
- var b2n_LE = (b) => BigInt("0x" + b2h(u8n(au8(b)).reverse()));
2322
- var concatB = (...arrs) => {
2323
- const r = u8n(arrs.reduce((sum, a) => sum + au8(a).length, 0));
2324
- let pad = 0;
2325
- arrs.forEach((a) => {
2326
- r.set(a, pad);
2327
- pad += a.length;
2328
- });
2329
- return r;
2330
- };
2331
- var invert = (num, md = P) => {
2332
- if (num === 0n || md <= 0n)
2333
- err("no inverse n=" + num + " mod=" + md);
2334
- let a = mod(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
2335
- while (a !== 0n) {
2336
- const q = b / a, r = b % a;
2337
- const m = x - u * q, n = y - v * q;
2338
- b = a, a = r, x = u, y = v, u = m, v = n;
2339
- }
2340
- return b === 1n ? mod(x, md) : err("no inverse");
2341
- };
2342
- var pow2 = (x, power) => {
2343
- let r = x;
2344
- while (power-- > 0n) {
2345
- r *= r;
2346
- r %= P;
2347
- }
2348
- return r;
2349
- };
2350
- var pow_2_252_3 = (x) => {
2351
- const x2 = x * x % P;
2352
- const b2 = x2 * x % P;
2353
- const b4 = pow2(b2, 2n) * b2 % P;
2354
- const b5 = pow2(b4, 1n) * x % P;
2355
- const b10 = pow2(b5, 5n) * b5 % P;
2356
- const b20 = pow2(b10, 10n) * b10 % P;
2357
- const b40 = pow2(b20, 20n) * b20 % P;
2358
- const b80 = pow2(b40, 40n) * b40 % P;
2359
- const b160 = pow2(b80, 80n) * b80 % P;
2360
- const b240 = pow2(b160, 80n) * b80 % P;
2361
- const b250 = pow2(b240, 10n) * b10 % P;
2362
- const pow_p_5_8 = pow2(b250, 2n) * x % P;
2363
- return { pow_p_5_8, b2 };
2364
- };
2365
- var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
2366
- var uvRatio = (u, v) => {
2367
- const v3 = mod(v * v * v);
2368
- const v7 = mod(v3 * v3 * v);
2369
- const pow = pow_2_252_3(u * v7).pow_p_5_8;
2370
- let x = mod(u * v3 * pow);
2371
- const vx2 = mod(v * x * x);
2372
- const root1 = x;
2373
- const root2 = mod(x * RM1);
2374
- const useRoot1 = vx2 === u;
2375
- const useRoot2 = vx2 === mod(-u);
2376
- const noRoot = vx2 === mod(-u * RM1);
2377
- if (useRoot1)
2378
- x = root1;
2379
- if (useRoot2 || noRoot)
2380
- x = root2;
2381
- if ((mod(x) & 1n) === 1n)
2382
- x = mod(-x);
2383
- return { isValid: useRoot1 || useRoot2, value: x };
2384
- };
2385
- var modL_LE = (hash) => mod(b2n_LE(hash), N);
2386
- var _shaS;
2387
- var sha512a = (...m) => etc.sha512Async(...m);
2388
- var sha512s = (...m) => (
2389
- // Sync SHA512, not set by default
2390
- typeof _shaS === "function" ? _shaS(...m) : err("etc.sha512Sync not set")
2391
- );
2392
- var hash2extK = (hashed) => {
2393
- const head = hashed.slice(0, 32);
2394
- head[0] &= 248;
2395
- head[31] &= 127;
2396
- head[31] |= 64;
2397
- const prefix = hashed.slice(32, 64);
2398
- const scalar = modL_LE(head);
2399
- const point = G.mul(scalar);
2400
- const pointBytes = point.toRawBytes();
2401
- return { head, prefix, scalar, point, pointBytes };
2402
- };
2403
- var getExtendedPublicKeyAsync = (priv) => sha512a(toU8(priv, 32)).then(hash2extK);
2404
- var getExtendedPublicKey = (priv) => hash2extK(sha512s(toU8(priv, 32)));
2405
- var getPublicKeyAsync = (priv) => getExtendedPublicKeyAsync(priv).then((p) => p.pointBytes);
2406
- function hashFinish(asynchronous, res) {
2407
- if (asynchronous)
2408
- return sha512a(res.hashable).then(res.finish);
2409
- return res.finish(sha512s(res.hashable));
2410
- }
2411
- var _sign = (e, rBytes, msg) => {
2412
- const { pointBytes: P2, scalar: s } = e;
2413
- const r = modL_LE(rBytes);
2414
- const R = G.mul(r).toRawBytes();
2415
- const hashable = concatB(R, P2, msg);
2416
- const finish = (hashed) => {
2417
- const S = mod(r + modL_LE(hashed) * s, N);
2418
- return au8(concatB(R, n2b_32LE(S)), 64);
2419
- };
2420
- return { hashable, finish };
2421
- };
2422
- var signAsync = async (msg, privKey) => {
2423
- const m = toU8(msg);
2424
- const e = await getExtendedPublicKeyAsync(privKey);
2425
- const rBytes = await sha512a(e.prefix, m);
2426
- return hashFinish(true, _sign(e, rBytes, m));
2427
- };
2428
- var cr = () => (
2429
- // We support: 1) browsers 2) node.js 19+
2430
- typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0
2431
- );
2432
- var etc = {
2433
- bytesToHex: b2h,
2434
- hexToBytes: h2b,
2435
- concatBytes: concatB,
2436
- mod,
2437
- invert,
2438
- randomBytes: (len) => {
2439
- const crypto = cr();
2440
- if (!crypto)
2441
- err("crypto.getRandomValues must be defined");
2442
- return crypto.getRandomValues(u8n(len));
2443
- },
2444
- sha512Async: async (...messages) => {
2445
- const crypto = cr();
2446
- if (!crypto)
2447
- err("crypto.subtle or etc.sha512Async must be defined");
2448
- const m = concatB(...messages);
2449
- return u8n(await crypto.subtle.digest("SHA-512", m.buffer));
2450
- },
2451
- sha512Sync: void 0
2452
- // Actual logic below
2453
- };
2454
- Object.defineProperties(etc, { sha512Sync: {
2455
- configurable: false,
2456
- get() {
2457
- return _shaS;
2458
- },
2459
- set(f) {
2460
- if (!_shaS)
2461
- _shaS = f;
2462
- }
2463
- } });
2464
- var utils = {
2465
- getExtendedPublicKeyAsync,
2466
- getExtendedPublicKey,
2467
- randomPrivateKey: () => etc.randomBytes(32),
2468
- precompute(w = 8, p = G) {
2469
- p.multiply(3n);
2470
- return p;
2471
- }
2472
- // no-op
2473
- };
2474
- var W = 8;
2475
- var precompute = () => {
2476
- const points = [];
2477
- const windows = 256 / W + 1;
2478
- let p = G, b = p;
2479
- for (let w = 0; w < windows; w++) {
2480
- b = p;
2481
- points.push(b);
2482
- for (let i = 1; i < 2 ** (W - 1); i++) {
2483
- b = b.add(p);
2484
- points.push(b);
2485
- }
2486
- p = b.double();
2487
- }
2488
- return points;
2489
- };
2490
- var wNAF = (n) => {
2491
- const comp = Gpows || (Gpows = precompute());
2492
- const neg = (cnd, p2) => {
2493
- let n2 = p2.negate();
2494
- return cnd ? n2 : p2;
2495
- };
2496
- let p = I, f = G;
2497
- const windows = 1 + 256 / W;
2498
- const wsize = 2 ** (W - 1);
2499
- const mask = BigInt(2 ** W - 1);
2500
- const maxNum = 2 ** W;
2501
- const shiftBy = BigInt(W);
2502
- for (let w = 0; w < windows; w++) {
2503
- const off = w * wsize;
2504
- let wbits = Number(n & mask);
2505
- n >>= shiftBy;
2506
- if (wbits > wsize) {
2507
- wbits -= maxNum;
2508
- n += 1n;
2509
- }
2510
- const off1 = off, off2 = off + Math.abs(wbits) - 1;
2511
- const cnd1 = w % 2 !== 0, cnd2 = wbits < 0;
2512
- if (wbits === 0) {
2513
- f = f.add(neg(cnd1, comp[off1]));
2514
- } else {
2515
- p = p.add(neg(cnd2, comp[off2]));
2516
- }
2517
- }
2518
- return { p, f };
2519
- };
2520
-
2521
- // src/keyPair.ts
2522
- var BaseOrderlyKeyPair = class _BaseOrderlyKeyPair {
2523
- static generateKey() {
2524
- let privKey, secretKey;
2525
- do {
2526
- privKey = utils.randomPrivateKey();
2527
- secretKey = (0, import_bs58.encode)(privKey);
2528
- } while (secretKey.length !== 44);
2529
- return new _BaseOrderlyKeyPair(secretKey);
2530
- }
2531
- constructor(secretKey) {
2532
- this.secretKey = secretKey;
2533
- const bytes = (0, import_bs58.decode)(secretKey);
2534
- this.privateKey = Buffer2.from(bytes).toString("hex");
2535
- }
2536
- async sign(message) {
2537
- return await signAsync(message, this.privateKey);
2538
- }
2539
- async getPublicKey() {
2540
- const pubKey = await getPublicKeyAsync(this.privateKey);
2541
- const publicKey = `ed25519:${(0, import_bs58.encode)(pubKey)}`;
2542
- return publicKey;
2543
- }
2544
- toString() {
2545
- return this.privateKey;
2546
- }
2547
- };
2548
-
2549
- // src/keyStore.ts
2550
- var BaseKeyStore = class {
2551
- constructor(networkId = "testnet") {
2552
- this.networkId = networkId;
2553
- }
2554
- get keyPrefix() {
2555
- return `orderly_${this.networkId}_`;
2556
- }
2557
- };
2558
- var LocalStorageStore = class extends BaseKeyStore {
2559
- getOrderlyKey(address) {
2560
- let orderlyKey;
2561
- if (address) {
2562
- orderlyKey = this.getItem(address, "orderlyKey");
2563
- } else {
2564
- const address2 = this.getAddress();
2565
- if (!address2)
2566
- return null;
2567
- orderlyKey = this.getItem(address2, "orderlyKey");
2568
- }
2569
- if (!orderlyKey) {
2570
- return null;
2571
- }
2572
- return new BaseOrderlyKeyPair(orderlyKey);
2573
- }
2574
- getAccountId(address) {
2575
- return this.getItem(address, "accountId");
2576
- }
2577
- setAccountId(address, accountId) {
2578
- this.setItem(address, { accountId });
2579
- }
2580
- getAddress() {
2581
- return localStorage.getItem(`${this.keyPrefix}address`);
2582
- }
2583
- setAddress(address) {
2584
- localStorage.setItem(`${this.keyPrefix}address`, address);
2585
- }
2586
- generateKey() {
2587
- return BaseOrderlyKeyPair.generateKey();
2588
- }
2589
- setKey(address, orderlyKey) {
2590
- this.setItem(address, { orderlyKey: orderlyKey.secretKey });
2591
- }
2592
- cleanAllKey(address) {
2593
- localStorage.removeItem(`${this.keyPrefix}${address}`);
2594
- localStorage.removeItem(`${this.keyPrefix}address`);
2595
- }
2596
- cleanKey(address, key) {
2597
- const data = this.getItem(address);
2598
- delete data[key];
2599
- localStorage.setItem(`${this.keyPrefix}${address}`, JSON.stringify(data));
2600
- }
2601
- setItem(address, value) {
2602
- const key = `${this.keyPrefix}${address}`;
2603
- let oldValue = localStorage.getItem(key);
2604
- if (oldValue) {
2605
- oldValue = JSON.parse(oldValue);
2606
- } else {
2607
- oldValue = {};
2608
- }
2609
- localStorage.setItem(
2610
- key,
2611
- JSON.stringify({
2612
- ...oldValue,
2613
- ...value
2614
- })
2615
- );
2616
- }
2617
- getItem(address, name) {
2618
- const key = `${this.keyPrefix}${address}`;
2619
- let value = localStorage.getItem(key);
2620
- if (value) {
2621
- value = JSON.parse(value);
2622
- } else {
2623
- value = {};
2624
- }
2625
- if (typeof name === "undefined") {
2626
- return value;
2627
- }
2628
- return value[name];
2629
- }
2630
- };
2631
- var MockKeyStore = class {
2632
- constructor(secretKey) {
2633
- this.secretKey = secretKey;
2634
- }
2635
- generateKey() {
2636
- return new BaseOrderlyKeyPair(this.secretKey);
2637
- }
2638
- getOrderlyKey() {
2639
- return new BaseOrderlyKeyPair(this.secretKey);
2640
- }
2641
- getAccountId() {
2642
- return "";
2643
- }
2644
- setAccountId(accountId) {
2645
- }
2646
- getAddress() {
2647
- return "";
2648
- }
2649
- setAddress(address) {
2650
- }
2651
- setKey(orderlyKey, secretKey) {
2652
- }
2653
- cleanAllKey() {
2654
- }
2655
- cleanKey(key) {
2656
- }
2657
- };
2658
-
2659
- // src/signer.ts
2660
- init_dirname();
2661
- init_buffer2();
2662
- init_process2();
2663
-
2664
- // src/utils.ts
2665
- init_dirname();
2666
- init_buffer2();
2667
- init_process2();
2668
-
2669
- // src/constants.ts
2670
- init_dirname();
2671
- init_buffer2();
2672
- init_process2();
2673
- var definedTypes = {
2674
- EIP712Domain: [
2675
- { name: "name", type: "string" },
2676
- { name: "version", type: "string" },
2677
- { name: "chainId", type: "uint256" },
2678
- { name: "verifyingContract", type: "address" }
2679
- ],
2680
- Registration: [
2681
- { name: "brokerId", type: "string" },
2682
- { name: "chainId", type: "uint256" },
2683
- { name: "timestamp", type: "uint64" },
2684
- { name: "registrationNonce", type: "uint256" }
2685
- ],
2686
- Withdraw: [
2687
- { name: "brokerId", type: "string" },
2688
- { name: "chainId", type: "uint256" },
2689
- { name: "receiver", type: "address" },
2690
- { name: "token", type: "string" },
2691
- { name: "amount", type: "uint256" },
2692
- { name: "withdrawNonce", type: "uint64" },
2693
- { name: "timestamp", type: "uint64" }
2694
- ],
2695
- AddOrderlyKey: [
2696
- { name: "brokerId", type: "string" },
2697
- { name: "chainId", type: "uint256" },
2698
- { name: "orderlyKey", type: "string" },
2699
- { name: "scope", type: "string" },
2700
- { name: "timestamp", type: "uint64" },
2701
- { name: "expiration", type: "uint64" }
2702
- ],
2703
- SettlePnl: [
2704
- { name: "brokerId", type: "string" },
2705
- { name: "chainId", type: "uint256" },
2706
- { name: "settleNonce", type: "uint64" },
2707
- { name: "timestamp", type: "uint64" }
2708
- ]
2709
- };
2710
- var stagingUSDCAddressOnArbitrumTestnet = "0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291";
2711
- var stagingVaultAddressOnArbitrumTestnet = "0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D";
2712
- var stagingVerifyAddressOnArbitrumTestnet = "0x1826B75e2ef249173FC735149AE4B8e9ea10abff";
2713
-
2714
- // src/utils.ts
2715
- import { keccak256, AbiCoder, solidityPackedKeccak256 } from "ethers";
2716
- var base64url = function(aStr) {
2717
- return aStr.replace(/\+/g, "-").replace(/\//g, "_");
2718
- };
2719
- function getVerifyingContract() {
2720
- return "0x8794E7260517B1766fc7b55cAfcd56e6bf08600e";
2721
- }
2722
- function getDomain(chainId, onChainDomain) {
2723
- return {
2724
- name: "Orderly",
2725
- version: "1",
2726
- chainId,
2727
- verifyingContract: onChainDomain ? getVerifyingContract() : "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
2728
- };
2729
- }
2730
- function generateRegisterAccountMessage(inputs) {
2731
- const { chainId, registrationNonce, brokerId } = inputs;
2732
- const now = Date.now();
2733
- const primaryType = "Registration";
2734
- const message = {
2735
- brokerId,
2736
- chainId,
2737
- timestamp: now,
2738
- registrationNonce
2739
- };
2740
- const typeDefinition = {
2741
- EIP712Domain: definedTypes.EIP712Domain,
2742
- [primaryType]: definedTypes[primaryType]
2743
- };
2744
- return [
2745
- message,
2746
- {
2747
- domain: getDomain(chainId),
2748
- message,
2749
- primaryType,
2750
- types: typeDefinition
2751
- }
2752
- ];
2753
- }
2754
- function generateAddOrderlyKeyMessage(inputs) {
2755
- const {
2756
- publicKey,
2757
- chainId,
2758
- primaryType,
2759
- brokerId,
2760
- expiration = 365
2761
- } = inputs;
2762
- const now = Date.now();
2763
- const message = {
2764
- brokerId,
2765
- orderlyKey: publicKey,
2766
- scope: "read,trading",
2767
- chainId,
2768
- timestamp: now,
2769
- expiration: now + 1e3 * 60 * 60 * 24 * expiration
2770
- };
2771
- const typeDefinition = {
2772
- EIP712Domain: definedTypes.EIP712Domain,
2773
- [primaryType]: definedTypes[primaryType]
2774
- };
2775
- const toSignatureMessage = {
2776
- domain: getDomain(chainId),
2777
- message,
2778
- primaryType,
2779
- types: typeDefinition
2780
- };
2781
- return [message, toSignatureMessage];
2782
- }
2783
- function generateSettleMessage(inputs) {
2784
- const { chainId, settlePnlNonce, domain, brokerId } = inputs;
2785
- const primaryType = "SettlePnl";
2786
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
2787
- const typeDefinition = {
2788
- EIP712Domain: definedTypes.EIP712Domain,
2789
- [primaryType]: definedTypes[primaryType]
2790
- };
2791
- const message = {
2792
- brokerId,
2793
- chainId,
2794
- timestamp,
2795
- settleNonce: settlePnlNonce
2796
- };
2797
- const toSignatureMessage = {
2798
- domain,
2799
- message,
2800
- primaryType,
2801
- types: typeDefinition
2802
- };
2803
- return [message, toSignatureMessage];
2804
- }
2805
- function parseBrokerHash(brokerId) {
2806
- return calculateStringHash(brokerId);
2807
- }
2808
- function parseAccountId(userAddress, brokerId) {
2809
- const abicoder = AbiCoder.defaultAbiCoder();
2810
- return keccak256(
2811
- abicoder.encode(
2812
- ["address", "bytes32"],
2813
- [userAddress, parseBrokerHash(brokerId)]
2814
- )
2815
- );
2816
- }
2817
- function parseTokenHash(tokenSymbol) {
2818
- return calculateStringHash(tokenSymbol);
2819
- }
2820
- function calculateStringHash(input) {
2821
- return solidityPackedKeccak256(["string"], [input]);
2822
- }
2823
-
2824
- // src/signer.ts
2825
- init_buffer();
2826
- var BaseSigner = class {
2827
- constructor(keyStore) {
2828
- this.keyStore = keyStore;
2829
- }
2830
- async sign(message) {
2831
- const timestamp = Date.now().toString();
2832
- let msgStr = [timestamp, message.method.toUpperCase(), message.url].join(
2833
- ""
2834
- );
2835
- if (message.data && Object.keys(message.data).length) {
2836
- msgStr += JSON.stringify(message.data);
2837
- }
2838
- const { signature, publicKey } = await this.signText(msgStr);
2839
- return {
2840
- "orderly-key": publicKey,
2841
- "orderly-timestamp": timestamp,
2842
- "orderly-signature": signature
2843
- };
2844
- }
2845
- async signText(text) {
2846
- const orderlyKeyPair = this.keyStore.getOrderlyKey();
2847
- if (!orderlyKeyPair) {
2848
- throw new Error("orderlyKeyPair is not defined");
2849
- }
2850
- const u8 = Buffer2.from(text);
2851
- const signature = await orderlyKeyPair.sign(u8);
2852
- const signHex = Buffer2.from(signature).toString("base64");
2853
- const b64 = base64url(signHex);
2854
- return {
2855
- signature: b64,
2856
- publicKey: await orderlyKeyPair.getPublicKey()
2857
- };
2858
- }
2859
- };
2860
-
2861
- // src/index.ts
2862
- import { default as default2 } from "eventemitter3";
2863
-
2864
- // src/helper.ts
2865
- init_dirname();
2866
- init_buffer2();
2867
- init_process2();
2868
-
2869
- // src/configStore.ts
2870
- init_dirname();
2871
- init_buffer2();
2872
- init_process2();
2873
- var MemoryConfigStore = class {
2874
- constructor() {
2875
- this._restore();
2876
- }
2877
- _restore() {
2878
- this.map = /* @__PURE__ */ new Map([
2879
- // ["apiBaseUrl", "https://testnet-api-evm.orderly.org"],
2880
- ["apiBaseUrl", "https://dev-api-iap-v2.orderly.org"],
2881
- // ["apiBaseUrl", "https://qa-api-evm.orderly.org"],
2882
- ["klineDataUrl", "https://testnet-api-evm.orderly.org"],
2883
- // ["publicWsUrl", "wss://testnet-ws-evm.orderly.org"],
2884
- ["publicWsUrl", "wss://dev-ws-v2.orderly.org"],
2885
- ["publicWebsocketKey", "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],
2886
- ["privateWsUrl", "wss://dev-ws-private-v2.orderly.org"],
2887
- // ["privateWsUrl", "wss://testnet-ws-private-evm.orderly.org"],
2888
- ["operatorUrl", "https://testnet-operator-evm.orderly.org"],
2889
- ["swapSupportApiUrl", "https://woofi-api.mer1in.com"],
2890
- ["brokerId", "woofi_dex"],
2891
- ["env", "dev-evm"]
2892
- ]);
2893
- }
2894
- get(key) {
2895
- return this.map.get(key);
2896
- }
2897
- set(key, value) {
2898
- this.map.set(key, value);
2899
- }
2900
- clear() {
2901
- }
2902
- };
2903
- var BaseConfigStore = class extends MemoryConfigStore {
2904
- constructor(configMap) {
2905
- super();
2906
- this.configMap = configMap;
2907
- }
2908
- _restore() {
2909
- const arr = Object.entries(this.configMap);
2910
- this.map = new Map(arr);
2911
- }
2912
- };
2913
-
2914
- // src/helper.ts
2915
- var getMockSigner = (secretKey) => {
2916
- const mockKeyStore = new MockKeyStore(
2917
- secretKey || "AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF"
2918
- // "c24fe227663f5a73493cad3f4049514f70623177272d57fffa8cb895fa1f92de"
2919
- );
2920
- return new BaseSigner(mockKeyStore);
2921
- };
2922
- var getDefaultSigner = () => {
2923
- if (typeof window === "undefined") {
2924
- throw new Error("the default signer only supports browsers.");
2925
- }
2926
- const localStorageStore = new LocalStorageStore("");
2927
- return new BaseSigner(localStorageStore);
2928
- };
2929
-
2930
- // src/contract.ts
2931
- init_dirname();
2932
- init_buffer2();
2933
- init_process2();
2934
-
2935
- // src/wallet/abis/stagingUSDCAbi.json
2936
- var stagingUSDCAbi_default = [
2937
- {
2938
- inputs: [
2939
- {
2940
- internalType: "string",
2941
- name: "name_",
2942
- type: "string"
2943
- },
2944
- {
2945
- internalType: "string",
2946
- name: "symbol_",
2947
- type: "string"
2948
- },
2949
- {
2950
- internalType: "uint8",
2951
- name: "decimals_",
2952
- type: "uint8"
2953
- }
2954
- ],
2955
- stateMutability: "nonpayable",
2956
- type: "constructor"
2957
- },
2958
- {
2959
- anonymous: false,
2960
- inputs: [
2961
- {
2962
- indexed: true,
2963
- internalType: "address",
2964
- name: "owner",
2965
- type: "address"
2966
- },
2967
- {
2968
- indexed: true,
2969
- internalType: "address",
2970
- name: "spender",
2971
- type: "address"
2972
- },
2973
- {
2974
- indexed: false,
2975
- internalType: "uint256",
2976
- name: "value",
2977
- type: "uint256"
2978
- }
2979
- ],
2980
- name: "Approval",
2981
- type: "event"
2982
- },
2983
- {
2984
- anonymous: false,
2985
- inputs: [
2986
- {
2987
- indexed: true,
2988
- internalType: "address",
2989
- name: "from",
2990
- type: "address"
2991
- },
2992
- {
2993
- indexed: true,
2994
- internalType: "address",
2995
- name: "to",
2996
- type: "address"
2997
- },
2998
- {
2999
- indexed: false,
3000
- internalType: "uint256",
3001
- name: "value",
3002
- type: "uint256"
3003
- }
3004
- ],
3005
- name: "Transfer",
3006
- type: "event"
3007
- },
3008
- {
3009
- inputs: [
3010
- {
3011
- internalType: "address",
3012
- name: "owner",
3013
- type: "address"
3014
- },
3015
- {
3016
- internalType: "address",
3017
- name: "spender",
3018
- type: "address"
3019
- }
3020
- ],
3021
- name: "allowance",
3022
- outputs: [
3023
- {
3024
- internalType: "uint256",
3025
- name: "",
3026
- type: "uint256"
3027
- }
3028
- ],
3029
- stateMutability: "view",
3030
- type: "function"
3031
- },
3032
- {
3033
- inputs: [
3034
- {
3035
- internalType: "address",
3036
- name: "spender",
3037
- type: "address"
3038
- },
3039
- {
3040
- internalType: "uint256",
3041
- name: "amount",
3042
- type: "uint256"
3043
- }
3044
- ],
3045
- name: "approve",
3046
- outputs: [
3047
- {
3048
- internalType: "bool",
3049
- name: "",
3050
- type: "bool"
3051
- }
3052
- ],
3053
- stateMutability: "nonpayable",
3054
- type: "function"
3055
- },
3056
- {
3057
- inputs: [
3058
- {
3059
- internalType: "address",
3060
- name: "account",
3061
- type: "address"
3062
- }
3063
- ],
3064
- name: "balanceOf",
3065
- outputs: [
3066
- {
3067
- internalType: "uint256",
3068
- name: "",
3069
- type: "uint256"
3070
- }
3071
- ],
3072
- stateMutability: "view",
3073
- type: "function"
3074
- },
3075
- {
3076
- inputs: [],
3077
- name: "decimals",
3078
- outputs: [
3079
- {
3080
- internalType: "uint8",
3081
- name: "",
3082
- type: "uint8"
3083
- }
3084
- ],
3085
- stateMutability: "view",
3086
- type: "function"
3087
- },
3088
- {
3089
- inputs: [
3090
- {
3091
- internalType: "address",
3092
- name: "spender",
3093
- type: "address"
3094
- },
3095
- {
3096
- internalType: "uint256",
3097
- name: "subtractedValue",
3098
- type: "uint256"
3099
- }
3100
- ],
3101
- name: "decreaseAllowance",
3102
- outputs: [
3103
- {
3104
- internalType: "bool",
3105
- name: "",
3106
- type: "bool"
3107
- }
3108
- ],
3109
- stateMutability: "nonpayable",
3110
- type: "function"
3111
- },
3112
- {
3113
- inputs: [
3114
- {
3115
- internalType: "address",
3116
- name: "spender",
3117
- type: "address"
3118
- },
3119
- {
3120
- internalType: "uint256",
3121
- name: "addedValue",
3122
- type: "uint256"
3123
- }
3124
- ],
3125
- name: "increaseAllowance",
3126
- outputs: [
3127
- {
3128
- internalType: "bool",
3129
- name: "",
3130
- type: "bool"
3131
- }
3132
- ],
3133
- stateMutability: "nonpayable",
3134
- type: "function"
3135
- },
3136
- {
3137
- inputs: [
3138
- {
3139
- internalType: "uint256",
3140
- name: "amount",
3141
- type: "uint256"
3142
- }
3143
- ],
3144
- name: "issue",
3145
- outputs: [],
3146
- stateMutability: "nonpayable",
3147
- type: "function"
3148
- },
3149
- {
3150
- inputs: [
3151
- {
3152
- internalType: "address",
3153
- name: "_to",
3154
- type: "address"
3155
- },
3156
- {
3157
- internalType: "uint256",
3158
- name: "_amount",
3159
- type: "uint256"
3160
- }
3161
- ],
3162
- name: "mint",
3163
- outputs: [],
3164
- stateMutability: "nonpayable",
3165
- type: "function"
3166
- },
3167
- {
3168
- inputs: [],
3169
- name: "name",
3170
- outputs: [
3171
- {
3172
- internalType: "string",
3173
- name: "",
3174
- type: "string"
3175
- }
3176
- ],
3177
- stateMutability: "view",
3178
- type: "function"
3179
- },
3180
- {
3181
- inputs: [
3182
- {
3183
- internalType: "bool",
3184
- name: "_paused",
3185
- type: "bool"
3186
- }
3187
- ],
3188
- name: "pauseTransfers",
3189
- outputs: [],
3190
- stateMutability: "nonpayable",
3191
- type: "function"
3192
- },
3193
- {
3194
- inputs: [],
3195
- name: "symbol",
3196
- outputs: [
3197
- {
3198
- internalType: "string",
3199
- name: "",
3200
- type: "string"
3201
- }
3202
- ],
3203
- stateMutability: "view",
3204
- type: "function"
3205
- },
3206
- {
3207
- inputs: [],
3208
- name: "totalSupply",
3209
- outputs: [
3210
- {
3211
- internalType: "uint256",
3212
- name: "",
3213
- type: "uint256"
3214
- }
3215
- ],
3216
- stateMutability: "view",
3217
- type: "function"
3218
- },
3219
- {
3220
- inputs: [
3221
- {
3222
- internalType: "address",
3223
- name: "recipient",
3224
- type: "address"
3225
- },
3226
- {
3227
- internalType: "uint256",
3228
- name: "amount",
3229
- type: "uint256"
3230
- }
3231
- ],
3232
- name: "transfer",
3233
- outputs: [
3234
- {
3235
- internalType: "bool",
3236
- name: "",
3237
- type: "bool"
3238
- }
3239
- ],
3240
- stateMutability: "nonpayable",
3241
- type: "function"
3242
- },
3243
- {
3244
- inputs: [
3245
- {
3246
- internalType: "address",
3247
- name: "sender",
3248
- type: "address"
3249
- },
3250
- {
3251
- internalType: "address",
3252
- name: "recipient",
3253
- type: "address"
3254
- },
3255
- {
3256
- internalType: "uint256",
3257
- name: "amount",
3258
- type: "uint256"
3259
- }
3260
- ],
3261
- name: "transferFrom",
3262
- outputs: [
3263
- {
3264
- internalType: "bool",
3265
- name: "",
3266
- type: "bool"
3267
- }
3268
- ],
3269
- stateMutability: "nonpayable",
3270
- type: "function"
3271
- }
3272
- ];
3273
-
3274
- // src/wallet/abis/stagingVaultAbi.json
3275
- var stagingVaultAbi_default = [
3276
- {
3277
- inputs: [],
3278
- stateMutability: "nonpayable",
3279
- type: "constructor"
3280
- },
3281
- {
3282
- inputs: [],
3283
- name: "AccountIdInvalid",
3284
- type: "error"
3285
- },
3286
- {
3287
- inputs: [
3288
- {
3289
- internalType: "uint256",
3290
- name: "balance",
3291
- type: "uint256"
3292
- },
3293
- {
3294
- internalType: "uint128",
3295
- name: "amount",
3296
- type: "uint128"
3297
- }
3298
- ],
3299
- name: "BalanceNotEnough",
3300
- type: "error"
3301
- },
3302
- {
3303
- inputs: [],
3304
- name: "BrokerNotAllowed",
3305
- type: "error"
3306
- },
3307
- {
3308
- inputs: [],
3309
- name: "OnlyCrossChainManagerCanCall",
3310
- type: "error"
3311
- },
3312
- {
3313
- inputs: [],
3314
- name: "TokenNotAllowed",
3315
- type: "error"
3316
- },
3317
- {
3318
- anonymous: false,
3319
- inputs: [
3320
- {
3321
- indexed: true,
3322
- internalType: "bytes32",
3323
- name: "accountId",
3324
- type: "bytes32"
3325
- },
3326
- {
3327
- indexed: true,
3328
- internalType: "address",
3329
- name: "userAddress",
3330
- type: "address"
3331
- },
3332
- {
3333
- indexed: true,
3334
- internalType: "uint64",
3335
- name: "depositNonce",
3336
- type: "uint64"
3337
- },
3338
- {
3339
- indexed: false,
3340
- internalType: "bytes32",
3341
- name: "tokenHash",
3342
- type: "bytes32"
3343
- },
3344
- {
3345
- indexed: false,
3346
- internalType: "uint128",
3347
- name: "tokenAmount",
3348
- type: "uint128"
3349
- }
3350
- ],
3351
- name: "AccountDeposit",
3352
- type: "event"
3353
- },
3354
- {
3355
- anonymous: false,
3356
- inputs: [
3357
- {
3358
- indexed: true,
3359
- internalType: "bytes32",
3360
- name: "accountId",
3361
- type: "bytes32"
3362
- },
3363
- {
3364
- indexed: true,
3365
- internalType: "address",
3366
- name: "userAddress",
3367
- type: "address"
3368
- },
3369
- {
3370
- indexed: true,
3371
- internalType: "uint64",
3372
- name: "depositNonce",
3373
- type: "uint64"
3374
- },
3375
- {
3376
- indexed: false,
3377
- internalType: "bytes32",
3378
- name: "tokenHash",
3379
- type: "bytes32"
3380
- },
3381
- {
3382
- indexed: false,
3383
- internalType: "uint128",
3384
- name: "tokenAmount",
3385
- type: "uint128"
3386
- }
3387
- ],
3388
- name: "AccountDepositTo",
3389
- type: "event"
3390
- },
3391
- {
3392
- anonymous: false,
3393
- inputs: [
3394
- {
3395
- indexed: true,
3396
- internalType: "bytes32",
3397
- name: "accountId",
3398
- type: "bytes32"
3399
- },
3400
- {
3401
- indexed: true,
3402
- internalType: "uint64",
3403
- name: "withdrawNonce",
3404
- type: "uint64"
3405
- },
3406
- {
3407
- indexed: false,
3408
- internalType: "bytes32",
3409
- name: "brokerHash",
3410
- type: "bytes32"
3411
- },
3412
- {
3413
- indexed: false,
3414
- internalType: "address",
3415
- name: "sender",
3416
- type: "address"
3417
- },
3418
- {
3419
- indexed: false,
3420
- internalType: "address",
3421
- name: "receiver",
3422
- type: "address"
3423
- },
3424
- {
3425
- indexed: false,
3426
- internalType: "bytes32",
3427
- name: "tokenHash",
3428
- type: "bytes32"
3429
- },
3430
- {
3431
- indexed: false,
3432
- internalType: "uint128",
3433
- name: "tokenAmount",
3434
- type: "uint128"
3435
- },
3436
- {
3437
- indexed: false,
3438
- internalType: "uint128",
3439
- name: "fee",
3440
- type: "uint128"
3441
- },
3442
- {
3443
- indexed: false,
3444
- internalType: "uint256",
3445
- name: "blocktime",
3446
- type: "uint256"
3447
- }
3448
- ],
3449
- name: "AccountWithdraw",
3450
- type: "event"
3451
- },
3452
- {
3453
- anonymous: false,
3454
- inputs: [
3455
- {
3456
- indexed: true,
3457
- internalType: "bytes32",
3458
- name: "_tokenHash",
3459
- type: "bytes32"
3460
- },
3461
- {
3462
- indexed: false,
3463
- internalType: "address",
3464
- name: "_tokenAddress",
3465
- type: "address"
3466
- }
3467
- ],
3468
- name: "ChangeTokenAddressAndAllow",
3469
- type: "event"
3470
- },
3471
- {
3472
- anonymous: false,
3473
- inputs: [
3474
- {
3475
- indexed: false,
3476
- internalType: "uint8",
3477
- name: "version",
3478
- type: "uint8"
3479
- }
3480
- ],
3481
- name: "Initialized",
3482
- type: "event"
3483
- },
3484
- {
3485
- anonymous: false,
3486
- inputs: [
3487
- {
3488
- indexed: true,
3489
- internalType: "address",
3490
- name: "previousOwner",
3491
- type: "address"
3492
- },
3493
- {
3494
- indexed: true,
3495
- internalType: "address",
3496
- name: "newOwner",
3497
- type: "address"
3498
- }
3499
- ],
3500
- name: "OwnershipTransferred",
3501
- type: "event"
3502
- },
3503
- {
3504
- anonymous: false,
3505
- inputs: [
3506
- {
3507
- indexed: false,
3508
- internalType: "address",
3509
- name: "account",
3510
- type: "address"
3511
- }
3512
- ],
3513
- name: "Paused",
3514
- type: "event"
3515
- },
3516
- {
3517
- anonymous: false,
3518
- inputs: [
3519
- {
3520
- indexed: true,
3521
- internalType: "bytes32",
3522
- name: "_brokerHash",
3523
- type: "bytes32"
3524
- },
3525
- {
3526
- indexed: false,
3527
- internalType: "bool",
3528
- name: "_allowed",
3529
- type: "bool"
3530
- }
3531
- ],
3532
- name: "SetAllowedBroker",
3533
- type: "event"
3534
- },
3535
- {
3536
- anonymous: false,
3537
- inputs: [
3538
- {
3539
- indexed: true,
3540
- internalType: "bytes32",
3541
- name: "_tokenHash",
3542
- type: "bytes32"
3543
- },
3544
- {
3545
- indexed: false,
3546
- internalType: "bool",
3547
- name: "_allowed",
3548
- type: "bool"
3549
- }
3550
- ],
3551
- name: "SetAllowedToken",
3552
- type: "event"
3553
- },
3554
- {
3555
- anonymous: false,
3556
- inputs: [
3557
- {
3558
- indexed: false,
3559
- internalType: "address",
3560
- name: "account",
3561
- type: "address"
3562
- }
3563
- ],
3564
- name: "Unpaused",
3565
- type: "event"
3566
- },
3567
- {
3568
- inputs: [
3569
- {
3570
- internalType: "bytes32",
3571
- name: "",
3572
- type: "bytes32"
3573
- }
3574
- ],
3575
- name: "allowedToken",
3576
- outputs: [
3577
- {
3578
- internalType: "address",
3579
- name: "",
3580
- type: "address"
3581
- }
3582
- ],
3583
- stateMutability: "view",
3584
- type: "function"
3585
- },
3586
- {
3587
- inputs: [
3588
- {
3589
- internalType: "bytes32",
3590
- name: "_tokenHash",
3591
- type: "bytes32"
3592
- },
3593
- {
3594
- internalType: "address",
3595
- name: "_tokenAddress",
3596
- type: "address"
3597
- }
3598
- ],
3599
- name: "changeTokenAddressAndAllow",
3600
- outputs: [],
3601
- stateMutability: "nonpayable",
3602
- type: "function"
3603
- },
3604
- {
3605
- inputs: [],
3606
- name: "crossChainManagerAddress",
3607
- outputs: [
3608
- {
3609
- internalType: "address",
3610
- name: "",
3611
- type: "address"
3612
- }
3613
- ],
3614
- stateMutability: "view",
3615
- type: "function"
3616
- },
3617
- {
3618
- inputs: [
3619
- {
3620
- components: [
3621
- {
3622
- internalType: "bytes32",
3623
- name: "accountId",
3624
- type: "bytes32"
3625
- },
3626
- {
3627
- internalType: "bytes32",
3628
- name: "brokerHash",
3629
- type: "bytes32"
3630
- },
3631
- {
3632
- internalType: "bytes32",
3633
- name: "tokenHash",
3634
- type: "bytes32"
3635
- },
3636
- {
3637
- internalType: "uint128",
3638
- name: "tokenAmount",
3639
- type: "uint128"
3640
- }
3641
- ],
3642
- internalType: "struct VaultTypes.VaultDepositFE",
3643
- name: "data",
3644
- type: "tuple"
3645
- }
3646
- ],
3647
- name: "deposit",
3648
- outputs: [],
3649
- stateMutability: "nonpayable",
3650
- type: "function"
3651
- },
3652
- {
3653
- inputs: [],
3654
- name: "depositId",
3655
- outputs: [
3656
- {
3657
- internalType: "uint64",
3658
- name: "",
3659
- type: "uint64"
3660
- }
3661
- ],
3662
- stateMutability: "view",
3663
- type: "function"
3664
- },
3665
- {
3666
- inputs: [
3667
- {
3668
- internalType: "address",
3669
- name: "receiver",
3670
- type: "address"
3671
- },
3672
- {
3673
- components: [
3674
- {
3675
- internalType: "bytes32",
3676
- name: "accountId",
3677
- type: "bytes32"
3678
- },
3679
- {
3680
- internalType: "bytes32",
3681
- name: "brokerHash",
3682
- type: "bytes32"
3683
- },
3684
- {
3685
- internalType: "bytes32",
3686
- name: "tokenHash",
3687
- type: "bytes32"
3688
- },
3689
- {
3690
- internalType: "uint128",
3691
- name: "tokenAmount",
3692
- type: "uint128"
3693
- }
3694
- ],
3695
- internalType: "struct VaultTypes.VaultDepositFE",
3696
- name: "data",
3697
- type: "tuple"
3698
- }
3699
- ],
3700
- name: "depositTo",
3701
- outputs: [],
3702
- stateMutability: "nonpayable",
3703
- type: "function"
3704
- },
3705
- {
3706
- inputs: [],
3707
- name: "emergencyPause",
3708
- outputs: [],
3709
- stateMutability: "nonpayable",
3710
- type: "function"
3711
- },
3712
- {
3713
- inputs: [],
3714
- name: "emergencyUnpause",
3715
- outputs: [],
3716
- stateMutability: "nonpayable",
3717
- type: "function"
3718
- },
3719
- {
3720
- inputs: [],
3721
- name: "getAllAllowedBroker",
3722
- outputs: [
3723
- {
3724
- internalType: "bytes32[]",
3725
- name: "",
3726
- type: "bytes32[]"
3727
- }
3728
- ],
3729
- stateMutability: "view",
3730
- type: "function"
3731
- },
3732
- {
3733
- inputs: [],
3734
- name: "getAllAllowedToken",
3735
- outputs: [
3736
- {
3737
- internalType: "bytes32[]",
3738
- name: "",
3739
- type: "bytes32[]"
3740
- }
3741
- ],
3742
- stateMutability: "view",
3743
- type: "function"
3744
- },
3745
- {
3746
- inputs: [
3747
- {
3748
- internalType: "bytes32",
3749
- name: "_brokerHash",
3750
- type: "bytes32"
3751
- }
3752
- ],
3753
- name: "getAllowedBroker",
3754
- outputs: [
3755
- {
3756
- internalType: "bool",
3757
- name: "",
3758
- type: "bool"
3759
- }
3760
- ],
3761
- stateMutability: "view",
3762
- type: "function"
3763
- },
3764
- {
3765
- inputs: [
3766
- {
3767
- internalType: "bytes32",
3768
- name: "_tokenHash",
3769
- type: "bytes32"
3770
- }
3771
- ],
3772
- name: "getAllowedToken",
3773
- outputs: [
3774
- {
3775
- internalType: "address",
3776
- name: "",
3777
- type: "address"
3778
- }
3779
- ],
3780
- stateMutability: "view",
3781
- type: "function"
3782
- },
3783
- {
3784
- inputs: [],
3785
- name: "initialize",
3786
- outputs: [],
3787
- stateMutability: "nonpayable",
3788
- type: "function"
3789
- },
3790
- {
3791
- inputs: [],
3792
- name: "owner",
3793
- outputs: [
3794
- {
3795
- internalType: "address",
3796
- name: "",
3797
- type: "address"
3798
- }
3799
- ],
3800
- stateMutability: "view",
3801
- type: "function"
3802
- },
3803
- {
3804
- inputs: [],
3805
- name: "paused",
3806
- outputs: [
3807
- {
3808
- internalType: "bool",
3809
- name: "",
3810
- type: "bool"
3811
- }
3812
- ],
3813
- stateMutability: "view",
3814
- type: "function"
3815
- },
3816
- {
3817
- inputs: [],
3818
- name: "renounceOwnership",
3819
- outputs: [],
3820
- stateMutability: "nonpayable",
3821
- type: "function"
3822
- },
3823
- {
3824
- inputs: [
3825
- {
3826
- internalType: "bytes32",
3827
- name: "_brokerHash",
3828
- type: "bytes32"
3829
- },
3830
- {
3831
- internalType: "bool",
3832
- name: "_allowed",
3833
- type: "bool"
3834
- }
3835
- ],
3836
- name: "setAllowedBroker",
3837
- outputs: [],
3838
- stateMutability: "nonpayable",
3839
- type: "function"
3840
- },
3841
- {
3842
- inputs: [
3843
- {
3844
- internalType: "bytes32",
3845
- name: "_tokenHash",
3846
- type: "bytes32"
3847
- },
3848
- {
3849
- internalType: "bool",
3850
- name: "_allowed",
3851
- type: "bool"
3852
- }
3853
- ],
3854
- name: "setAllowedToken",
3855
- outputs: [],
3856
- stateMutability: "nonpayable",
3857
- type: "function"
3858
- },
3859
- {
3860
- inputs: [
3861
- {
3862
- internalType: "address",
3863
- name: "_crossChainManagerAddress",
3864
- type: "address"
3865
- }
3866
- ],
3867
- name: "setCrossChainManager",
3868
- outputs: [],
3869
- stateMutability: "nonpayable",
3870
- type: "function"
3871
- },
3872
- {
3873
- inputs: [
3874
- {
3875
- internalType: "address",
3876
- name: "newOwner",
3877
- type: "address"
3878
- }
3879
- ],
3880
- name: "transferOwnership",
3881
- outputs: [],
3882
- stateMutability: "nonpayable",
3883
- type: "function"
3884
- },
3885
- {
3886
- inputs: [
3887
- {
3888
- components: [
3889
- {
3890
- internalType: "bytes32",
3891
- name: "accountId",
3892
- type: "bytes32"
3893
- },
3894
- {
3895
- internalType: "bytes32",
3896
- name: "brokerHash",
3897
- type: "bytes32"
3898
- },
3899
- {
3900
- internalType: "bytes32",
3901
- name: "tokenHash",
3902
- type: "bytes32"
3903
- },
3904
- {
3905
- internalType: "uint128",
3906
- name: "tokenAmount",
3907
- type: "uint128"
3908
- },
3909
- {
3910
- internalType: "uint128",
3911
- name: "fee",
3912
- type: "uint128"
3913
- },
3914
- {
3915
- internalType: "address",
3916
- name: "sender",
3917
- type: "address"
3918
- },
3919
- {
3920
- internalType: "address",
3921
- name: "receiver",
3922
- type: "address"
3923
- },
3924
- {
3925
- internalType: "uint64",
3926
- name: "withdrawNonce",
3927
- type: "uint64"
3928
- }
3929
- ],
3930
- internalType: "struct VaultTypes.VaultWithdraw",
3931
- name: "data",
3932
- type: "tuple"
3933
- }
3934
- ],
3935
- name: "withdraw",
3936
- outputs: [],
3937
- stateMutability: "nonpayable",
3938
- type: "function"
3939
- }
3940
- ];
3941
-
3942
- // src/contract.ts
3943
- var BaseContract = class {
3944
- constructor(configStore) {
3945
- this.configStore = configStore;
3946
- }
3947
- getContractInfoByEnv() {
3948
- return {
3949
- usdcAddress: stagingUSDCAddressOnArbitrumTestnet,
3950
- usdcAbi: stagingUSDCAbi_default,
3951
- vaultAddress: stagingVaultAddressOnArbitrumTestnet,
3952
- vaultAbi: stagingVaultAbi_default,
3953
- verifyContractAddress: stagingVerifyAddressOnArbitrumTestnet
3954
- };
3955
- }
3956
- };
3957
-
3958
- // src/di/simpleDI.ts
3959
- init_dirname();
3960
- init_buffer2();
3961
- init_process2();
3962
-
3963
- // src/di/container.ts
3964
- init_dirname();
3965
- init_buffer2();
3966
- init_process2();
3967
- var Container = class {
3968
- constructor(providers = [], services = {}) {
3969
- this.providers = providers;
3970
- this.services = services;
3971
- this.injectProperties = {};
3972
- }
3973
- register(...serviceClasses) {
3974
- this.providers.push(...serviceClasses);
3975
- serviceClasses.forEach((serviceClass) => {
3976
- let service = serviceClass;
3977
- if (service instanceof Function) {
3978
- service = new serviceClass();
3979
- }
3980
- this.add(service);
3981
- });
3982
- }
3983
- registerByName(name, serviceClass) {
3984
- let service = serviceClass;
3985
- if (service instanceof Function) {
3986
- service = new serviceClass();
3987
- }
3988
- this.addByName(name, service);
3989
- }
3990
- get(name) {
3991
- return this.services[name];
3992
- }
3993
- //
3994
- // getByType<T>(c: new (...args: any[]) => T): T {
3995
- // return this.get<T>(c.name.toLowerCase());
3996
- // }
3997
- getAll() {
3998
- return Object.assign({}, this.services);
3999
- }
4000
- // addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
4001
- // if (target) {
4002
- // this.getInjectProperty(serviceName.toLowerCase()).push({ target, propertyKey, serviceName });
4003
- // this.inject(target, propertyKey, this.services[serviceName.toLowerCase()]);
4004
- // }
4005
- // }
4006
- add(service) {
4007
- return this.addByName(service.constructor.name, service);
4008
- }
4009
- // //
4010
- addByName(name, service) {
4011
- this.services[name] = service;
4012
- this.services[name.toLowerCase()] = service;
4013
- this.injectIntoProperties(service, name);
4014
- return this.get(name);
4015
- }
4016
- inject(target, propertyKey, service) {
4017
- if (target && service) {
4018
- target[propertyKey] = service;
4019
- }
4020
- }
4021
- injectIntoProperties(service, name = service.constructor.name) {
4022
- this.getInjectProperty(name.toLowerCase()).forEach((property) => {
4023
- this.inject(property.target, property.propertyKey, service);
4024
- });
4025
- }
4026
- //
4027
- getInjectProperty(key) {
4028
- if (!this.injectProperties[key]) {
4029
- this.injectProperties[key] = [];
4030
- }
4031
- return this.injectProperties[key];
4032
- }
4033
- };
4034
- var container_default = Container;
4035
-
4036
- // src/di/simpleDI.ts
4037
- var SimpleDI = class _SimpleDI {
4038
- static getContainer() {
4039
- if (!_SimpleDI.container) {
4040
- _SimpleDI.container = new container_default();
4041
- }
4042
- return _SimpleDI.container;
4043
- }
4044
- static register(...serviceClasses) {
4045
- this.getContainer().register(...serviceClasses);
4046
- }
4047
- static registerByName(name, serviceClass) {
4048
- this.getContainer().registerByName(name, serviceClass);
4049
- }
4050
- // static addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
4051
- // this.getContainer().addInjectProperty(target, propertyKey, serviceName);
4052
- // }
4053
- static get(name) {
4054
- return this.getContainer().get(name);
4055
- }
4056
- // static getByType<T>(c: new (...args: any[]) => T): T {
4057
- // return this.getContainer().getByType(c);
4058
- // }
4059
- static getAll() {
4060
- return this.getContainer().getAll();
4061
- }
4062
- constructor() {
4063
- }
4064
- };
4065
- var simpleDI_default = SimpleDI;
4066
-
4067
- // src/account.ts
4068
- init_dirname();
4069
- init_buffer2();
4070
- init_process2();
4071
- import { AccountStatusEnum } from "@orderly.network/types";
4072
- import EventEmitter from "eventemitter3";
4073
-
4074
- // src/assets.ts
4075
- init_dirname();
4076
- init_buffer2();
4077
- init_process2();
4078
- import { ethers } from "ethers";
4079
- var Assets = class {
4080
- constructor(configStore, contractManger, account) {
4081
- this.configStore = configStore;
4082
- this.contractManger = contractManger;
4083
- this.account = account;
4084
- }
4085
- async withdraw(inputs) {
4086
- if (!this.account.walletClient) {
4087
- throw new Error("walletClient is undefined");
4088
- }
4089
- if (!this.account.stateValue.address)
4090
- throw new Error("account address is rqeuired");
4091
- const { chainId, token, amount } = inputs;
4092
- const url = "/v1/withdraw_request";
4093
- const nonce = await this.getWithdrawalNonce();
4094
- const domain = this.account.getDomain(true);
4095
- const [message, toSignatureMessage] = this._generateWithdrawMessage({
4096
- chainId,
4097
- receiver: this.account.stateValue.address,
4098
- token,
4099
- amount: this.account.walletClient.parseUnits(amount.toString()),
4100
- nonce,
4101
- domain
4102
- });
4103
- const EIP_712signatured = await this.account.signTypedData(
4104
- toSignatureMessage
4105
- );
4106
- const data = {
4107
- signature: EIP_712signatured,
4108
- message,
4109
- userAddress: this.account.stateValue.address,
4110
- verifyingContract: domain.verifyingContract
4111
- };
4112
- const payload = {
4113
- method: "POST",
4114
- url,
4115
- data
4116
- };
4117
- const signature = await this.account.signer.sign(payload);
4118
- const res = await this._simpleFetch(url, {
4119
- method: "POST",
4120
- body: JSON.stringify(data),
4121
- headers: {
4122
- "Content-Type": "application/json",
4123
- "orderly-account-id": this.account.stateValue.accountId,
4124
- ...signature
4125
- }
4126
- });
4127
- return res;
4128
- }
4129
- _generateWithdrawMessage(inputs) {
4130
- const { chainId, receiver, token, amount, domain, nonce } = inputs;
4131
- const primaryType = "Withdraw";
4132
- const timestamp = Date.now();
4133
- const typeDefinition = {
4134
- EIP712Domain: definedTypes.EIP712Domain,
4135
- [primaryType]: definedTypes[primaryType]
4136
- };
4137
- const message = {
4138
- brokerId: this.configStore.get("brokerId"),
4139
- chainId,
4140
- receiver,
4141
- token,
4142
- amount,
4143
- timestamp,
4144
- withdrawNonce: nonce
4145
- };
4146
- const toSignatureMessage = {
4147
- domain,
4148
- message,
4149
- primaryType,
4150
- types: typeDefinition
4151
- };
4152
- return [message, toSignatureMessage];
4153
- }
4154
- async getWithdrawalNonce() {
4155
- const timestamp = Date.now().toString();
4156
- const url = "/v1/withdraw_nonce";
4157
- const message = [timestamp, "GET", url].join("");
4158
- const signer = this.account.signer;
4159
- const { publicKey, signature } = await signer.signText(message);
4160
- const res = await this._simpleFetch(url, {
4161
- headers: {
4162
- "orderly-account-id": this.account.stateValue.accountId,
4163
- "orderly-key": publicKey,
4164
- "orderly-timestamp": timestamp,
4165
- "orderly-signature": signature
4166
- }
4167
- });
4168
- if (res.success) {
4169
- return res.data?.withdraw_nonce;
4170
- } else {
4171
- throw new Error(res.message);
4172
- }
4173
- }
4174
- async getBalance() {
4175
- if (!this.account.walletClient) {
4176
- return "0";
4177
- }
4178
- const contractAddress = this.contractManger.getContractInfoByEnv();
4179
- const result = await this.account.walletClient?.call(
4180
- contractAddress.usdcAddress,
4181
- "balanceOf",
4182
- [this.account.stateValue.address],
4183
- {
4184
- abi: contractAddress.usdcAbi
4185
- }
4186
- );
4187
- return this.account.walletClient?.fromUnits(result);
4188
- }
4189
- async getAllowance() {
4190
- if (!this.account.walletClient) {
4191
- return "0";
4192
- }
4193
- const contractAddress = this.contractManger.getContractInfoByEnv();
4194
- const result = await this.account.walletClient?.call(
4195
- contractAddress.usdcAddress,
4196
- "allowance",
4197
- [this.account.stateValue.address, contractAddress.vaultAddress],
4198
- {
4199
- abi: contractAddress.usdcAbi
4200
- }
4201
- );
4202
- return this.account.walletClient?.fromUnits(result);
4203
- }
4204
- async approve(amount) {
4205
- if (!this.account.walletClient) {
4206
- throw new Error("walletClient is undefined");
4207
- }
4208
- const contractAddress = this.contractManger.getContractInfoByEnv();
4209
- const parsedAmount = typeof amount !== "undefined" && amount !== "" ? this.account.walletClient.parseUnits(amount) : ethers.MaxUint256.toString();
4210
- const result = await this.account.walletClient?.call(
4211
- contractAddress.usdcAddress,
4212
- "approve",
4213
- [contractAddress.vaultAddress, parsedAmount],
4214
- {
4215
- abi: contractAddress.usdcAbi
4216
- }
4217
- );
4218
- console.log("-----*****-----", result);
4219
- return result;
4220
- }
4221
- async deposit(amount) {
4222
- console.log("deposit amount:", amount);
4223
- const brokerId = this.configStore.get("brokerId");
4224
- if (!brokerId)
4225
- throw new Error("brokerId is required");
4226
- const contractAddress = this.contractManger.getContractInfoByEnv();
4227
- const depositData = {
4228
- accountId: parseAccountId(this.account.stateValue.address, brokerId),
4229
- brokerHash: parseBrokerHash(brokerId),
4230
- tokenHash: parseTokenHash("USDC"),
4231
- tokenAmount: this.account.walletClient?.parseUnits(amount)
4232
- };
4233
- const result = await this.account.walletClient?.call(
4234
- contractAddress.vaultAddress,
4235
- "deposit",
4236
- [depositData],
4237
- {
4238
- abi: contractAddress.vaultAbi
4239
- }
4240
- );
4241
- return result;
4242
- }
4243
- async _simpleFetch(url, init = {}) {
4244
- const requestUrl = `${this.configStore.get("apiBaseUrl")}${url}`;
4245
- return fetch(requestUrl, init).then((res) => res.json());
4246
- }
4247
- };
4248
-
4249
- // src/account.ts
4250
- var Account = class {
4251
- // private config =
4252
- constructor(configStore, keyStore, contractManger, getWalletAdapter) {
4253
- this.configStore = configStore;
4254
- this.keyStore = keyStore;
4255
- this.contractManger = contractManger;
4256
- this.getWalletAdapter = getWalletAdapter;
4257
- // private _state$ = new BehaviorSubject<AccountState>({
4258
- // status: AccountStatusEnum.NotConnected,
4259
- // balance: "",
4260
- // leverage: Number.NaN,
4261
- // });
4262
- this._ee = new EventEmitter();
4263
- this._state = {
4264
- status: AccountStatusEnum.NotConnected,
4265
- balance: "",
4266
- checking: false,
4267
- leverage: Number.NaN
4268
- };
4269
- this.assetsManager = new Assets(configStore, contractManger, this);
4270
- this._bindEvents();
4271
- }
4272
- /**
4273
- * 登录
4274
- * @param address 钱包地址
4275
- */
4276
- login(address) {
4277
- if (!address)
4278
- throw new Error("address is required");
4279
- }
4280
- logout() {
4281
- }
4282
- /**
4283
- * 连接钱包先用第三方的React版本,不用自己实现
4284
- */
4285
- // connectWallet() {
4286
- // // this.wallet.connect();
4287
- // }
4288
- async setAddress(address, wallet) {
4289
- if (!address)
4290
- throw new Error("address is required");
4291
- this.keyStore.setAddress(address);
4292
- const nextState = {
4293
- ...this.stateValue,
4294
- status: AccountStatusEnum.Connected,
4295
- address,
4296
- connectWallet: wallet?.wallet
4297
- };
4298
- this._ee.emit("change:status", nextState);
4299
- if (wallet) {
4300
- this.walletClient = this.getWalletAdapter({ ...wallet, address });
4301
- }
4302
- return await this._checkAccount(address);
4303
- }
4304
- // subscribe the account state change
4305
- // get state$(): BehaviorSubject<AccountState> {
4306
- // return this._state$;
4307
- // }
4308
- // public get select(): EventEmitter {
4309
- // return this._ee;
4310
- // }
4311
- get stateValue() {
4312
- return this._state;
4313
- }
4314
- get accountId() {
4315
- const state = this.stateValue;
4316
- return state.accountId;
4317
- }
4318
- get address() {
4319
- return this.stateValue.address;
4320
- }
4321
- get chainId() {
4322
- return this.walletClient?.chainId;
4323
- }
4324
- /**
4325
- * set user positions count
4326
- */
4327
- set position(position) {
4328
- const nextState = {
4329
- ...this.stateValue,
4330
- positon: position
4331
- };
4332
- this._ee.emit("change:status", nextState);
4333
- }
4334
- set orders(orders) {
4335
- const nextState = {
4336
- ...this.stateValue,
4337
- orders
4338
- };
4339
- this._ee.emit("change:status", nextState);
4340
- }
4341
- _bindEvents() {
4342
- this._ee.addListener("change:status", (state) => {
4343
- console.log("change:status", state);
4344
- this._state = state;
4345
- });
4346
- }
4347
- // 检查账户状态
4348
- async _checkAccount(address) {
4349
- let nextState;
4350
- try {
4351
- const accountInfo = await this._checkAccountExist(address);
4352
- if (accountInfo && accountInfo.account_id) {
4353
- console.log("account is exist");
4354
- this.keyStore.setAccountId(address, accountInfo.account_id);
4355
- nextState = {
4356
- ...this.stateValue,
4357
- status: AccountStatusEnum.SignedIn,
4358
- accountId: accountInfo.account_id,
4359
- userId: accountInfo.user_id
4360
- };
4361
- this._ee.emit("change:status", nextState);
4362
- } else {
4363
- nextState = {
4364
- ...this.stateValue,
4365
- status: AccountStatusEnum.NotSignedIn
4366
- };
4367
- this._ee.emit("change:status", nextState);
4368
- return AccountStatusEnum.NotSignedIn;
4369
- }
4370
- const orderlyKey = this.keyStore.getOrderlyKey();
4371
- nextState = {
4372
- ...this.stateValue,
4373
- status: AccountStatusEnum.DisabledTrading
4374
- };
4375
- if (!orderlyKey) {
4376
- console.log("orderlyKey is null");
4377
- this._ee.emit("change:status", nextState);
4378
- return AccountStatusEnum.DisabledTrading;
4379
- }
4380
- const publicKey = await orderlyKey.getPublicKey();
4381
- const orderlyKeyStatus = await this._checkOrderlyKeyState(
4382
- accountInfo.account_id,
4383
- publicKey
4384
- );
4385
- if (orderlyKeyStatus && orderlyKeyStatus.orderly_key && orderlyKeyStatus.key_status === "ACTIVE") {
4386
- const now = Date.now();
4387
- const expiration = orderlyKeyStatus.expiration;
4388
- if (now > expiration) {
4389
- this.keyStore.cleanKey(address, "orderlyKey");
4390
- return AccountStatusEnum.DisabledTrading;
4391
- }
4392
- const nextState2 = {
4393
- ...this.stateValue,
4394
- status: AccountStatusEnum.EnableTrading
4395
- };
4396
- this._ee.emit("change:status", nextState2);
4397
- return AccountStatusEnum.EnableTrading;
4398
- }
4399
- this.keyStore.cleanKey(address, "orderlyKey");
4400
- return AccountStatusEnum.NotConnected;
4401
- } catch (err2) {
4402
- console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:", err2);
4403
- }
4404
- return AccountStatusEnum.NotSignedIn;
4405
- }
4406
- async _checkAccountExist(address) {
4407
- const res = await this._simpleFetch(
4408
- `/v1/get_account?address=${address}&broker_id=woofi_dex`
4409
- );
4410
- if (res.success) {
4411
- return res.data;
4412
- } else {
4413
- return null;
4414
- }
4415
- }
4416
- async createAccount() {
4417
- if (!this.walletClient) {
4418
- return Promise.reject("walletClient is undefined");
4419
- }
4420
- const nonce = await this._getRegisterationNonce();
4421
- const address = this.stateValue.address;
4422
- if (!address) {
4423
- throw new Error("address is undefined");
4424
- }
4425
- const [message, toSignatureMessage] = generateRegisterAccountMessage({
4426
- registrationNonce: nonce,
4427
- chainId: this.walletClient.chainId,
4428
- brokerId: this.configStore.get("brokerId")
4429
- });
4430
- const signatured = await this.signTypedData(toSignatureMessage);
4431
- const res = await this._simpleFetch("/v1/register_account", {
4432
- method: "POST",
4433
- body: JSON.stringify({
4434
- signature: signatured,
4435
- message,
4436
- userAddress: address
4437
- }),
4438
- headers: {
4439
- "Content-Type": "application/json"
4440
- }
4441
- });
4442
- if (res.success) {
4443
- this.keyStore.setAccountId(address, res.data.account_id);
4444
- const nextState = {
4445
- ...this.stateValue,
4446
- status: AccountStatusEnum.DisabledTrading,
4447
- accountId: res.data.account_id,
4448
- userId: res.data.user_id
4449
- };
4450
- this._ee.emit("change:status", nextState);
4451
- return res;
4452
- }
4453
- }
4454
- async signTypedData(toSignatureMessage) {
4455
- if (!this.walletClient) {
4456
- return Promise.reject("walletClient is undefined");
4457
- }
4458
- return await this.walletClient.signTypedData(
4459
- // address,
4460
- this.stateValue.address,
4461
- JSON.stringify(toSignatureMessage)
4462
- );
4463
- }
4464
- async createOrderlyKey(expiration) {
4465
- if (this.stateValue.accountId === void 0) {
4466
- throw new Error("account id is undefined");
4467
- }
4468
- if (!this.walletClient) {
4469
- throw new Error("walletClient is undefined");
4470
- }
4471
- const primaryType = "AddOrderlyKey";
4472
- const keyPair = this.keyStore.generateKey();
4473
- const publicKey = await keyPair.getPublicKey();
4474
- const [message, toSignatureMessage] = generateAddOrderlyKeyMessage({
4475
- publicKey,
4476
- chainId: this.walletClient.chainId,
4477
- primaryType,
4478
- expiration,
4479
- brokerId: this.configStore.get("brokerId")
4480
- });
4481
- const address = this.stateValue.address;
4482
- if (!address) {
4483
- throw new Error("address is undefined");
4484
- }
4485
- const signatured = await this.signTypedData(toSignatureMessage);
4486
- const res = await this._simpleFetch("/v1/orderly_key", {
4487
- method: "POST",
4488
- body: JSON.stringify({
4489
- signature: signatured,
4490
- message,
4491
- userAddress: address
4492
- }),
4493
- headers: {
4494
- "X-Account-Id": this.stateValue.accountId,
4495
- "Content-Type": "application/json"
4496
- }
4497
- });
4498
- if (res.success) {
4499
- this.keyStore.setKey(address, keyPair);
4500
- const nextState = {
4501
- ...this.stateValue,
4502
- status: AccountStatusEnum.EnableTrading
4503
- // accountId: res.data.account_id,
4504
- // userId: res.data.user_id,
4505
- };
4506
- this._ee.emit("change:status", nextState);
4507
- return res;
4508
- } else {
4509
- throw new Error(res.message);
4510
- }
4511
- }
4512
- async settle() {
4513
- if (!this.walletClient) {
4514
- return Promise.reject("walletClient is undefined");
4515
- }
4516
- const nonce = await this._getSettleNonce();
4517
- const address = this.stateValue.address;
4518
- const domain = this.getDomain(true);
4519
- const url = "/v1/settle_pnl";
4520
- const [message, toSignatureMessage] = generateSettleMessage({
4521
- settlePnlNonce: nonce,
4522
- chainId: this.walletClient.chainId,
4523
- brokerId: this.configStore.get("brokerId"),
4524
- domain
4525
- });
4526
- const EIP_712signatured = await this.signTypedData(toSignatureMessage);
4527
- const data = {
4528
- signature: EIP_712signatured,
4529
- message,
4530
- userAddress: address,
4531
- verifyingContract: domain.verifyingContract
4532
- };
4533
- const payload = {
4534
- method: "POST",
4535
- url,
4536
- data
4537
- };
4538
- const signature = await this.signer.sign(payload);
4539
- const res = await this._simpleFetch(url, {
4540
- method: "POST",
4541
- body: JSON.stringify(data),
4542
- headers: {
4543
- "Content-Type": "application/json",
4544
- "orderly-account-id": this.stateValue.accountId,
4545
- ...signature
4546
- }
4547
- });
4548
- if (res.success) {
4549
- return res;
4550
- } else {
4551
- throw new Error(res.message);
4552
- }
4553
- }
4554
- async disconnect() {
4555
- const nextState = {
4556
- ...this.stateValue,
4557
- status: AccountStatusEnum.NotConnected,
4558
- accountId: void 0,
4559
- userId: void 0,
4560
- address: void 0
4561
- };
4562
- this._ee.emit("change:status", nextState);
4563
- }
4564
- async _checkOrderlyKeyState(accountId, orderlyKey) {
4565
- const res = await this._simpleFetch(
4566
- `/v1/get_orderly_key?account_id=${accountId}&orderly_key=${orderlyKey}`
4567
- );
4568
- if (res.success) {
4569
- return res.data;
4570
- } else {
4571
- throw new Error(res.message);
4572
- }
4573
- }
4574
- get signer() {
4575
- if (!this._singer) {
4576
- this._singer = new BaseSigner(this.keyStore);
4577
- }
4578
- return this._singer;
4579
- }
4580
- get wallet() {
4581
- return this.walletClient;
4582
- }
4583
- async _getRegisterationNonce() {
4584
- const res = await this._simpleFetch("/v1/registration_nonce", {
4585
- headers: {
4586
- "orderly-account-id": this.stateValue.accountId
4587
- }
4588
- });
4589
- if (res.success) {
4590
- return res.data?.registration_nonce;
4591
- } else {
4592
- throw new Error(res.message);
4593
- }
4594
- }
4595
- async _getSettleNonce() {
4596
- const timestamp = Date.now().toString();
4597
- const url = "/v1/settle_nonce";
4598
- const message = [timestamp, "GET", url].join("");
4599
- const signer = this.signer;
4600
- const { publicKey, signature } = await signer.signText(message);
4601
- const res = await this._simpleFetch("/v1/settle_nonce", {
4602
- headers: {
4603
- "orderly-account-id": this.stateValue.accountId,
4604
- "orderly-key": publicKey,
4605
- "orderly-timestamp": timestamp,
4606
- "orderly-signature": signature
4607
- }
4608
- });
4609
- if (res.success) {
4610
- return res.data?.settle_nonce;
4611
- } else {
4612
- throw new Error(res.message);
4613
- }
4614
- }
4615
- async _simpleFetch(url, init = {}) {
4616
- const requestUrl = `${this.configStore.get("apiBaseUrl")}${url}`;
4617
- return fetch(requestUrl, init).then((res) => res.json());
4618
- }
4619
- getDomain(onChainDomain) {
4620
- if (!this.walletClient) {
4621
- throw new Error("walletClient is undefined");
4622
- }
4623
- const chainId = this.walletClient.chainId;
4624
- return {
4625
- name: "Orderly",
4626
- version: "1",
4627
- chainId,
4628
- verifyingContract: onChainDomain ? this.contractManger.getContractInfoByEnv().verifyContractAddress : "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
4629
- };
4630
- }
4631
- get on() {
4632
- return this._ee.on.bind(this._ee);
4633
- }
4634
- get once() {
4635
- return this._ee.once.bind(this._ee);
4636
- }
4637
- get off() {
4638
- return this._ee.off.bind(this._ee);
4639
- }
4640
- };
4641
- Account.instanceName = "account";
4642
-
4643
- // src/wallet/index.ts
4644
- init_dirname();
4645
- init_buffer2();
4646
- init_process2();
4647
-
4648
- // src/wallet/etherAdapter.ts
4649
- init_dirname();
4650
- init_buffer2();
4651
- init_process2();
4652
- import { BrowserProvider, ethers as ethers2 } from "ethers";
4653
- import { getParsedEthersError } from "@enzoferey/ethers-error-parser";
4654
- var EtherAdapter = class {
4655
- constructor(options) {
4656
- console.log("EtherAdapter constructor", options);
4657
- this._chainId = parseInt(options.chain.id, 16);
4658
- this.provider = new BrowserProvider(options.provider, "any");
4659
- this._address = options.address;
4660
- }
4661
- parseUnits(amount) {
4662
- return ethers2.parseUnits(amount, 6).toString();
4663
- }
4664
- fromUnits(amount) {
4665
- return ethers2.formatUnits(amount, 6);
4666
- }
4667
- getBalance(contractId, userAddress, options) {
4668
- const contract = new ethers2.Contract(
4669
- contractId,
4670
- options.abi,
4671
- this.provider
4672
- );
4673
- return contract.balanceOf(userAddress);
4674
- }
4675
- deposit(from, to, amount) {
4676
- throw new Error("Method not implemented.");
4677
- }
4678
- async call(address, method, params, options) {
4679
- const singer = await this.provider?.getSigner();
4680
- const contract = new ethers2.Contract(address, options.abi, singer);
4681
- return contract[method].apply(null, params).catch((error) => {
4682
- const parsedEthersError = getParsedEthersError(error);
4683
- throw parsedEthersError;
4684
- });
4685
- }
4686
- get chainId() {
4687
- return this._chainId;
4688
- }
4689
- get addresses() {
4690
- return this._address;
4691
- }
4692
- async send(method, params) {
4693
- return await this.provider?.send(method, params);
4694
- }
4695
- async signTypedData(address, data) {
4696
- return await this.provider?.send("eth_signTypedData_v4", [address, data]);
4697
- }
4698
- async verify(data, signature) {
4699
- const { domain, types, message } = data;
4700
- const recovered = ethers2.verifyTypedData(domain, types, message, signature);
4701
- console.log("recovered", recovered);
4702
- }
4703
- };
4704
- export {
4705
- Account,
4706
- BaseConfigStore,
4707
- BaseContract as BaseContractManager,
4708
- BaseKeyStore,
4709
- BaseOrderlyKeyPair,
4710
- BaseSigner,
4711
- EtherAdapter,
4712
- default2 as EventEmitter,
4713
- LocalStorageStore,
4714
- MemoryConfigStore,
4715
- MockKeyStore,
4716
- simpleDI_default as SimpleDI,
4717
- getDefaultSigner,
4718
- getMockSigner
4719
- };
1
+ var dn=Object.create;var Ke=Object.defineProperty;var pn=Object.getOwnPropertyDescriptor;var yn=Object.getOwnPropertyNames;var hn=Object.getPrototypeOf,gn=Object.prototype.hasOwnProperty;var pe=(o,n)=>()=>(o&&(n=o(o=0)),n);var pt=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports),fn=(o,n)=>{for(var s in n)Ke(o,s,{get:n[s],enumerable:!0})},mn=(o,n,s,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let d of yn(n))!gn.call(o,d)&&d!==s&&Ke(o,d,{get:()=>n[d],enumerable:!(c=pn(n,d))||c.enumerable});return o};var wn=(o,n,s)=>(s=o!=null?dn(hn(o)):{},mn(n||!o||!o.__esModule?Ke(s,"default",{value:o,enumerable:!0}):s,o));var E=pe(()=>{"use strict"});function bn(o,n){this.fun=o,this.array=n}function yt(o){var n=Math.floor((Date.now()-te.now())*.001),s=te.now()*.001,c=Math.floor(s)+n,d=Math.floor(s%1*1e9);return o&&(c=c-o[0],d=d-o[1],d<0&&(c--,d+=Oe)),[c,d]}var Gn,te,Ne,Oe,ht=pe(()=>{"use strict";E();T();v();bn.prototype.run=function(){this.fun.apply(null,this.array)};Gn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},te={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};te.now===void 0&&(Ne=Date.now(),te.timing&&te.timing.navigationStart&&(Ne=te.timing.navigationStart),te.now=()=>Date.now()-Ne);Oe=1e9;yt.bigint=function(o){var n=yt(o);return typeof BigInt>"u"?n[0]*Oe+n[1]:BigInt(n[0]*Oe)+BigInt(n[1])}});var v=pe(()=>{"use strict";ht()});function An(){if(gt)return ye;gt=!0,ye.byteLength=g,ye.toByteArray=I,ye.fromByteArray=_;for(var o=[],n=[],s=typeof Uint8Array<"u"?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=0,p=c.length;d<p;++d)o[d]=c[d],n[c.charCodeAt(d)]=d;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function a(h){var m=h.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=m);var x=B===m?0:4-B%4;return[B,x]}function g(h){var m=a(h),B=m[0],x=m[1];return(B+x)*3/4-x}function w(h,m,B){return(m+B)*3/4-B}function I(h){var m,B=a(h),x=B[0],k=B[1],C=new s(w(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)m=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=m>>16&255,C[U++]=m>>8&255,C[U++]=m&255;return k===2&&(m=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=m&255),k===1&&(m=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=m>>8&255,C[U++]=m&255),C}function f(h){return o[h>>18&63]+o[h>>12&63]+o[h>>6&63]+o[h&63]}function A(h,m,B){for(var x,k=[],C=m;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(f(x));return k.join("")}function _(h){for(var m,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(m=h[B-1],k.push(o[m>>2]+o[m<<4&63]+"==")):x===2&&(m=(h[B-2]<<8)+h[B-1],k.push(o[m>>10]+o[m>>4&63]+o[m<<2&63]+"=")),k.join("")}return ye}function In(){if(ft)return be;ft=!0;return be.read=function(o,n,s,c,d){var p,a,g=d*8-c-1,w=(1<<g)-1,I=w>>1,f=-7,A=s?d-1:0,_=s?-1:1,h=o[n+A];for(A+=_,p=h&(1<<-f)-1,h>>=-f,f+=g;f>0;p=p*256+o[n+A],A+=_,f-=8);for(a=p&(1<<-f)-1,p>>=-f,f+=c;f>0;a=a*256+o[n+A],A+=_,f-=8);if(p===0)p=1-I;else{if(p===w)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,c),p=p-I}return(h?-1:1)*a*Math.pow(2,p-c)},be.write=function(o,n,s,c,d,p){var a,g,w,I=p*8-d-1,f=(1<<I)-1,A=f>>1,_=d===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=c?0:p-1,m=c?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(g=isNaN(n)?1:0,a=f):(a=Math.floor(Math.log(n)/Math.LN2),n*(w=Math.pow(2,-a))<1&&(a--,w*=2),a+A>=1?n+=_/w:n+=_*Math.pow(2,1-A),n*w>=2&&(a++,w/=2),a+A>=f?(g=0,a=f):a+A>=1?(g=(n*w-1)*Math.pow(2,d),a=a+A):(g=n*Math.pow(2,A-1)*Math.pow(2,d),a=0));d>=8;o[s+h]=g&255,h+=m,g/=256,d-=8);for(a=a<<d|g,I+=d;I>0;o[s+h]=a&255,h+=m,a/=256,I-=8);o[s+h-m]|=B*128},be}function En(){if(mt)return ne;mt=!0;let o=An(),n=In(),s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ne.Buffer=a,ne.SlowBuffer=k,ne.INSPECT_MAX_BYTES=50;let c=2147483647;ne.kMaxLength=c,a.TYPED_ARRAY_SUPPORT=d(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function d(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function p(r){if(r>c)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,a.prototype),e}function a(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return f(r)}return g(r,e,t)}a.poolSize=8192;function g(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Y(r,ArrayBuffer)||r&&Y(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Y(r,SharedArrayBuffer)||r&&Y(r.buffer,SharedArrayBuffer)))return m(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return a.from(i,e,t);let u=B(r);if(u)return u;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,e,t){return g(r,e,t)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function w(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return w(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}a.alloc=function(r,e,t){return I(r,e,t)};function f(r){return w(r),p(r<0?0:x(r)|0)}a.allocUnsafe=function(r){return f(r)},a.allocUnsafeSlow=function(r){return f(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),u=i.write(r,e);return u!==t&&(i=i.slice(0,u)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(Y(r,Uint8Array)){let e=new Uint8Array(r);return m(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function m(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,a.prototype),i}function B(r){if(a.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Me(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=c)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+c.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==a.prototype},a.compare=function(e,t){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),Y(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,u=t.length;for(let l=0,y=Math.min(i,u);l<y;++l)if(e[l]!==t[l]){i=e[l],u=t[l];break}return i<u?-1:u<i?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return a.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let u=a.allocUnsafe(t),l=0;for(i=0;i<e.length;++i){let y=e[i];if(Y(y,Uint8Array))l+y.length>u.length?(a.isBuffer(y)||(y=a.from(y)),y.copy(u,l)):Uint8Array.prototype.set.call(u,y,l);else if(a.isBuffer(y))y.copy(u,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=y.length}return u};function C(r,e){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Y(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let u=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Pe(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return dt(r).length;default:if(u)return i?-1:Pe(r).length;e=(""+e).toLowerCase(),u=!0}}a.byteLength=C;function U(r,e,t){let i=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return tn(this,e,t);case"utf8":case"utf-8":return nt(this,e,t);case"ascii":return Qt(this,e,t);case"latin1":case"binary":return en(this,e,t);case"base64":return Zt(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nn(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}a.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}a.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},a.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},a.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},a.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?nt(this,0,e):U.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:a.compare(this,e)===0},a.prototype.inspect=function(){let e="",t=ne.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(a.prototype[s]=a.prototype.inspect),a.prototype.compare=function(e,t,i,u,l){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),u===void 0&&(u=0),l===void 0&&(l=this.length),t<0||i>e.length||u<0||l>this.length)throw new RangeError("out of range index");if(u>=l&&t>=i)return 0;if(u>=l)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,u>>>=0,l>>>=0,this===e)return 0;let y=l-u,S=i-t,R=Math.min(y,S),N=this.slice(u,l),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,u){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Me(t)&&(t=u?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(u)return-1;t=r.length-1}else if(t<0)if(u)t=0;else return-1;if(typeof e=="string"&&(e=a.from(e,i)),a.isBuffer(e))return e.length===0?-1:H(r,e,t,i,u);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?u?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,u);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,u){let l=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;l=2,y/=2,S/=2,t/=2}function R(D,P){return l===1?D[P]:D.readUInt16BE(P*l)}let N;if(u){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*l}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}a.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},a.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},a.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function q(r,e,t,i){t=Number(t)||0;let u=r.length-t;i?(i=Number(i),i>u&&(i=u)):i=u;let l=e.length;i>l/2&&(i=l/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Me(S))return y;r[t+y]=S}return y}function ae(r,e,t,i){return we(Pe(e,r.length-t),r,t,i)}function Yt(r,e,t,i){return we(on(e),r,t,i)}function Gt(r,e,t,i){return we(dt(e),r,t,i)}function Xt(r,e,t,i){return we(cn(e,r.length-t),r,t,i)}a.prototype.write=function(e,t,i,u){if(t===void 0)u="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")u=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,u===void 0&&(u="utf8")):(u=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let l=this.length-t;if((i===void 0||i>l)&&(i=l),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");u||(u="utf8");let y=!1;for(;;)switch(u){case"hex":return q(this,e,t,i);case"utf8":case"utf-8":return ae(this,e,t,i);case"ascii":case"latin1":case"binary":return Yt(this,e,t,i);case"base64":return Gt(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Xt(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+u);u=(""+u).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Zt(r,e,t){return e===0&&t===r.length?o.fromByteArray(r):o.fromByteArray(r.slice(e,t))}function nt(r,e,t){t=Math.min(r.length,t);let i=[],u=e;for(;u<t;){let l=r[u],y=null,S=l>239?4:l>223?3:l>191?2:1;if(u+S<=t){let R,N,D,P;switch(S){case 1:l<128&&(y=l);break;case 2:R=r[u+1],(R&192)===128&&(P=(l&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[u+1],N=r[u+2],(R&192)===128&&(N&192)===128&&(P=(l&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[u+1],N=r[u+2],D=r[u+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(l&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),u+=S}return Jt(i)}let rt=4096;function Jt(r){let e=r.length;if(e<=rt)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=rt));return t}function Qt(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]&127);return i}function en(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]);return i}function tn(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let u="";for(let l=e;l<t;++l)u+=un[r[l]];return u}function nn(r,e,t){let i=r.slice(e,t),u="";for(let l=0;l<i.length-1;l+=2)u+=String.fromCharCode(i[l]+i[l+1]*256);return u}a.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let u=this.subarray(e,t);return Object.setPrototypeOf(u,a.prototype),u};function V(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e],l=1,y=0;for(;++y<t&&(l*=256);)u+=this[e+y]*l;return u},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e+--t],l=1;for(;t>0&&(l*=256);)u+=this[e+--t]*l;return u},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&de(e,this.length-8);let u=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,l=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(u)+(BigInt(l)<<BigInt(32))}),a.prototype.readBigUInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&de(e,this.length-8);let u=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],l=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(u)<<BigInt(32))+BigInt(l)}),a.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e],l=1,y=0;for(;++y<t&&(l*=256);)u+=this[e+y]*l;return l*=128,u>=l&&(u-=Math.pow(2,8*t)),u},a.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=t,l=1,y=this[e+--u];for(;u>0&&(l*=256);)y+=this[e+--u]*l;return l*=128,y>=l&&(y-=Math.pow(2,8*t)),y},a.prototype.readInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},a.prototype.readInt16LE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},a.prototype.readInt16BE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},a.prototype.readInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&de(e,this.length-8);let u=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(u)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),a.prototype.readBigInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&de(e,this.length-8);let u=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(u)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),a.prototype.readFloatLE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!1,52,8)};function z(r,e,t,i,u,l){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>u||e<l)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=1,y=0;for(this[t]=e&255;++y<i&&(l*=256);)this[t+y]=e/l&255;return t+i},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=i-1,y=1;for(this[t+l]=e&255;--l>=0&&(y*=256);)this[t+l]=e/y&255;return t+i},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,255,0),this[t]=e&255,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function it(r,e,t,i,u){lt(e,i,u,r,t,7);let l=Number(e&BigInt(4294967295));r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function st(r,e,t,i,u){lt(e,i,u,r,t,7);let l=Number(e&BigInt(4294967295));r[t+7]=l,l=l>>8,r[t+6]=l,l=l>>8,r[t+5]=l,l=l>>8,r[t+4]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}a.prototype.writeBigUInt64LE=Z(function(e,t=0){return it(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Z(function(e,t=0){return st(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=0,y=1,S=0;for(this[t]=e&255;++l<i&&(y*=256);)e<0&&S===0&&this[t+l-1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=i-1,y=1,S=0;for(this[t+l]=e&255;--l>=0&&(y*=256);)e<0&&S===0&&this[t+l+1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},a.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},a.prototype.writeBigInt64LE=Z(function(e,t=0){return it(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Z(function(e,t=0){return st(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function at(r,e,t,i,u,l){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function ot(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,4),n.write(r,e,t,i,23,4),t+4}a.prototype.writeFloatLE=function(e,t,i){return ot(this,e,t,!0,i)},a.prototype.writeFloatBE=function(e,t,i){return ot(this,e,t,!1,i)};function ct(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,8),n.write(r,e,t,i,52,8),t+8}a.prototype.writeDoubleLE=function(e,t,i){return ct(this,e,t,!0,i)},a.prototype.writeDoubleBE=function(e,t,i){return ct(this,e,t,!1,i)},a.prototype.copy=function(e,t,i,u){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!u&&u!==0&&(u=this.length),t>=e.length&&(t=e.length),t||(t=0),u>0&&u<i&&(u=i),u===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("sourceEnd out of bounds");u>this.length&&(u=this.length),e.length-t<u-i&&(u=e.length-t+i);let l=u-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,u):Uint8Array.prototype.set.call(e,this.subarray(i,u),t),l},a.prototype.fill=function(e,t,i,u){if(typeof e=="string"){if(typeof t=="string"?(u=t,t=0,i=this.length):typeof i=="string"&&(u=i,i=this.length),u!==void 0&&typeof u!="string")throw new TypeError("encoding must be a string");if(typeof u=="string"&&!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);if(e.length===1){let y=e.charCodeAt(0);(u==="utf8"&&y<128||u==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let l;if(typeof e=="number")for(l=t;l<i;++l)this[l]=e;else{let y=a.isBuffer(e)?e:a.from(e,u),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(l=0;l<i-t;++l)this[l+t]=y[l%S]}return this};let oe={};function Ue(r,e,t){oe[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(u){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:u,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Ue("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Ue("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Ue("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,u=t;return Number.isInteger(t)&&Math.abs(t)>2**32?u=ut(String(t)):typeof t=="bigint"&&(u=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(u=ut(u)),u+="n"),i+=` It must be ${e}. Received ${u}`,i},RangeError);function ut(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function rn(r,e,t){ce(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&de(e,r.length-(t+1))}function lt(r,e,t,i,u,l){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw l>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(l+1)*8}${y}`:S=`>= -(2${y} ** ${(l+1)*8-1}${y}) and < 2 ** ${(l+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new oe.ERR_OUT_OF_RANGE("value",S,r)}rn(i,u,l)}function ce(r,e){if(typeof r!="number")throw new oe.ERR_INVALID_ARG_TYPE(e,"number",r)}function de(r,e,t){throw Math.floor(r)!==r?(ce(r,t),new oe.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new oe.ERR_BUFFER_OUT_OF_BOUNDS:new oe.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let sn=/[^+/0-9A-Za-z-_]/g;function an(r){if(r=r.split("=")[0],r=r.trim().replace(sn,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Pe(r,e){e=e||1/0;let t,i=r.length,u=null,l=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!u){if(t>56319){(e-=3)>-1&&l.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&l.push(239,191,189);continue}u=t;continue}if(t<56320){(e-=3)>-1&&l.push(239,191,189),u=t;continue}t=(u-55296<<10|t-56320)+65536}else u&&(e-=3)>-1&&l.push(239,191,189);if(u=null,t<128){if((e-=1)<0)break;l.push(t)}else if(t<2048){if((e-=2)<0)break;l.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;l.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;l.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return l}function on(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function cn(r,e){let t,i,u,l=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,u=t%256,l.push(u),l.push(i);return l}function dt(r){return o.toByteArray(an(r))}function we(r,e,t,i){let u;for(u=0;u<i&&!(u+t>=e.length||u>=r.length);++u)e[u+t]=r[u];return u}function Y(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Me(r){return r!==r}let un=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let u=0;u<16;++u)e[i+u]=r[t]+r[u]}return e}();function Z(r){return typeof BigInt>"u"?ln:r}function ln(){throw new Error("BigInt not supported")}return ne}var ye,gt,be,ft,ne,mt,re,O,tr,nr,Re=pe(()=>{"use strict";E();T();v();ye={},gt=!1;be={},ft=!1;ne={},mt=!1;re=En();re.Buffer;re.SlowBuffer;re.INSPECT_MAX_BYTES;re.kMaxLength;O=re.Buffer,tr=re.INSPECT_MAX_BYTES,nr=re.kMaxLength});var T=pe(()=>{"use strict";Re()});var bt=pt((ur,wt)=>{"use strict";E();T();v();function vn(o){if(o.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var c=0;c<o.length;c++){var d=o.charAt(c),p=d.charCodeAt(0);if(n[p]!==255)throw new TypeError(d+" is ambiguous");n[p]=c}var a=o.length,g=o.charAt(0),w=Math.log(a)/Math.log(256),I=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,m++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%a>>>0,M=M/a>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var q=C-B;q!==C&&U[q]===0;)q++;for(var ae=g.repeat(m);q<C;++q)ae+=o.charAt(U[q]);return ae}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,B=0,x=0;h[m]===g;)B++,m++;for(var k=(h.length-m)*w+1>>>0,C=new Uint8Array(k);h[m];){var U=n[h.charCodeAt(m)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=a*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,m++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var q=new Uint8Array(B+(k-H)),ae=B;H!==k;)q[ae++]=C[H++];return q}function _(h){var m=A(h);if(m)return m;throw new Error("Non-base"+a+" character")}return{encode:f,decodeUnsafe:A,decode:_}}wt.exports=vn});var It=pt((yr,At)=>{"use strict";E();T();v();var Tn=bt(),Bn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";At.exports=Tn(Bn)});E();T();v();E();T();v();E();T();v();var ge=wn(It());E();T();v();var $=2n**255n-19n,ue=2n**252n+27742317777372353535851937790883648493n,De=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Fe=0x6666666666666666666666666666666666666666666666666666666666666658n,Ae={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:ue,h:8,Gx:De,Gy:Fe},W=(o="")=>{throw new Error(o)},xt=o=>typeof o=="string",ve=(o,n)=>!(o instanceof Uint8Array)||typeof n=="number"&&n>0&&o.length!==n?W("Uint8Array expected"):o,le=o=>new Uint8Array(o),Te=(o,n)=>ve(xt(o)?$e(o):le(o),n),b=(o,n=$)=>{let s=o%n;return s>=0n?s:n+s},Et=o=>o instanceof J?o:W("Point expected"),vt,J=class o{constructor(n,s,c,d){this.ex=n,this.ey=s,this.ez=c,this.et=d}static fromAffine(n){return new o(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,s=!0){let{d:c}=Ae;n=Te(n,32);let d=n.slice();d[31]=n[31]&-129;let p=_t(d);p===0n||(s&&!(0n<p&&p<$)&&W("bad y coord 1"),!s&&!(0n<p&&p<2n**256n)&&W("bad y coord 2"));let a=b(p*p),g=b(a-1n),w=b(c*a+1n),{isValid:I,value:f}=Sn(g,w);I||W("bad y coordinate 3");let A=(f&1n)===1n;return(n[31]&128)!==0!==A&&(f=b(-f)),new o(f,p,1n,b(f*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:s,ey:c,ez:d}=this,{ex:p,ey:a,ez:g}=Et(n),w=b(s*g),I=b(p*d),f=b(c*g),A=b(a*d);return w===I&&f===A}is0(){return this.equals(Ie)}negate(){return new o(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:s,ez:c}=this,{a:d}=Ae,p=b(n*n),a=b(s*s),g=b(2n*b(c*c)),w=b(d*p),I=n+s,f=b(b(I*I)-p-a),A=w+a,_=A-g,h=w-a,m=b(f*_),B=b(A*h),x=b(f*h),k=b(_*A);return new o(m,B,k,x)}add(n){let{ex:s,ey:c,ez:d,et:p}=this,{ex:a,ey:g,ez:w,et:I}=Et(n),{a:f,d:A}=Ae,_=b(s*a),h=b(c*g),m=b(p*A*I),B=b(d*w),x=b((s+c)*(a+g)-_-h),k=b(B-m),C=b(B+m),U=b(h-f*_),M=b(x*k),K=b(C*U),H=b(x*U),q=b(k*C);return new o(M,K,q,H)}mul(n,s=!0){if(n===0n)return s===!0?W("cannot multiply by 0"):Ie;if(typeof n=="bigint"&&0n<n&&n<ue||W("invalid scalar, must be < L"),!s&&this.is0()||n===1n)return this;if(this.equals(se))return Pn(n).p;let c=Ie,d=se;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?c=c.add(p):s&&(d=d.add(p));return c}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(Ae.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(ue/2n,!1).double();return ue%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:s,ez:c}=this;if(this.is0())return{x:0n,y:0n};let d=kt(c);return b(c*d)!==1n&&W("invalid inverse"),{x:b(n*d),y:b(s*d)}}toRawBytes(){let{x:n,y:s}=this.toAffine(),c=Ct(s);return c[31]|=n&1n?128:0,c}toHex(){return Ve(this.toRawBytes())}};J.BASE=new J(De,Fe,1n,b(De*Fe));J.ZERO=new J(0n,1n,1n,0n);var{BASE:se,ZERO:Ie}=J,St=(o,n)=>o.toString(16).padStart(n,"0"),Ve=o=>Array.from(o).map(n=>St(n,2)).join(""),$e=o=>{let n=o.length;(!xt(o)||n%2)&&W("hex invalid 1");let s=le(n/2);for(let c=0;c<s.length;c++){let d=c*2,p=o.slice(d,d+2),a=Number.parseInt(p,16);(Number.isNaN(a)||a<0)&&W("hex invalid 2"),s[c]=a}return s},Ct=o=>$e(St(o,32*2)).reverse(),_t=o=>BigInt("0x"+Ve(le(ve(o)).reverse())),Ee=(...o)=>{let n=le(o.reduce((c,d)=>c+ve(d).length,0)),s=0;return o.forEach(c=>{n.set(c,s),s+=c.length}),n},kt=(o,n=$)=>{(o===0n||n<=0n)&&W("no inverse n="+o+" mod="+n);let s=b(o,n),c=n,d=0n,p=1n,a=1n,g=0n;for(;s!==0n;){let w=c/s,I=c%s,f=d-a*w,A=p-g*w;c=s,s=I,d=a,p=g,a=f,g=A}return c===1n?b(d,n):W("no inverse")},G=(o,n)=>{let s=o;for(;n-- >0n;)s*=s,s%=$;return s},xn=o=>{let s=o*o%$*o%$,c=G(s,2n)*s%$,d=G(c,1n)*o%$,p=G(d,5n)*d%$,a=G(p,10n)*p%$,g=G(a,20n)*a%$,w=G(g,40n)*g%$,I=G(w,80n)*w%$,f=G(I,80n)*w%$,A=G(f,10n)*p%$;return{pow_p_5_8:G(A,2n)*o%$,b2:s}},Tt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Sn=(o,n)=>{let s=b(n*n*n),c=b(s*s*n),d=xn(o*c).pow_p_5_8,p=b(o*s*d),a=b(n*p*p),g=p,w=b(p*Tt),I=a===o,f=a===b(-o),A=a===b(-o*Tt);return I&&(p=g),(f||A)&&(p=w),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||f,value:p}},Le=o=>b(_t(o),ue),he,He=(...o)=>je.sha512Async(...o),Ut=(...o)=>typeof he=="function"?he(...o):W("etc.sha512Sync not set"),Pt=o=>{let n=o.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let s=o.slice(32,64),c=Le(n),d=se.mul(c),p=d.toRawBytes();return{head:n,prefix:s,scalar:c,point:d,pointBytes:p}},We=o=>He(Te(o,32)).then(Pt),Cn=o=>Pt(Ut(Te(o,32))),Mt=o=>We(o).then(n=>n.pointBytes);function _n(o,n){return o?He(n.hashable).then(n.finish):n.finish(Ut(n.hashable))}var kn=(o,n,s)=>{let{pointBytes:c,scalar:d}=o,p=Le(n),a=se.mul(p).toRawBytes();return{hashable:Ee(a,c,s),finish:I=>{let f=b(p+Le(I)*d,ue);return ve(Ee(a,Ct(f)),64)}}},Kt=async(o,n)=>{let s=Te(o),c=await We(n),d=await He(c.prefix,s);return _n(!0,kn(c,d,s))};var Bt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,je={bytesToHex:Ve,hexToBytes:$e,concatBytes:Ee,mod:b,invert:kt,randomBytes:o=>{let n=Bt();return n||W("crypto.getRandomValues must be defined"),n.getRandomValues(le(o))},sha512Async:async(...o)=>{let n=Bt();n||W("crypto.subtle or etc.sha512Async must be defined");let s=Ee(...o);return le(await n.subtle.digest("SHA-512",s.buffer))},sha512Sync:void 0};Object.defineProperties(je,{sha512Sync:{configurable:!1,get(){return he},set(o){he||(he=o)}}});var Nt={getExtendedPublicKeyAsync:We,getExtendedPublicKey:Cn,randomPrivateKey:()=>je.randomBytes(32),precompute(o=8,n=se){return n.multiply(3n),n}},ie=8,Un=()=>{let o=[],n=256/ie+1,s=se,c=s;for(let d=0;d<n;d++){c=s,o.push(c);for(let p=1;p<2**(ie-1);p++)c=c.add(s),o.push(c);s=c.double()}return o},Pn=o=>{let n=vt||(vt=Un()),s=(f,A)=>{let _=A.negate();return f?_:A},c=Ie,d=se,p=1+256/ie,a=2**(ie-1),g=BigInt(2**ie-1),w=2**ie,I=BigInt(ie);for(let f=0;f<p;f++){let A=f*a,_=Number(o&g);o>>=I,_>a&&(_-=w,o+=1n);let h=A,m=A+Math.abs(_)-1,B=f%2!==0,x=_<0;_===0?d=d.add(s(B,n[h])):c=c.add(s(x,n[m]))}return{p:c,f:d}};var Q=class o{static generateKey(){let n,s;do n=Nt.randomPrivateKey(),s=(0,ge.encode)(n);while(s.length!==44);return new o(s)}constructor(n){this.secretKey=n;let s=(0,ge.decode)(n);this.privateKey=O.from(s).toString("hex")}async sign(n){return await Kt(n,this.privateKey)}async getPublicKey(){let n=await Mt(this.privateKey);return`ed25519:${(0,ge.encode)(n)}`}toString(){return this.privateKey}};var Be=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},fe=class extends Be{getOrderlyKey(n){let s;if(n)s=this.getItem(n,"orderlyKey");else{let c=this.getAddress();if(!c)return null;s=this.getItem(c,"orderlyKey")}return s?new Q(s):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,s){this.setItem(n,{accountId:s})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Q.generateKey()}setKey(n,s){this.setItem(n,{orderlyKey:s.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,s){let c=this.getItem(n);delete c[s],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(c))}setItem(n,s){let c=`${this.keyPrefix}${n}`,d=localStorage.getItem(c);d?d=JSON.parse(d):d={},localStorage.setItem(c,JSON.stringify({...d,...s}))}getItem(n,s){let c=`${this.keyPrefix}${n}`,d=localStorage.getItem(c);return d?d=JSON.parse(d):d={},typeof s>"u"?d:d[s]}},me=class{constructor(n){this.secretKey=n}generateKey(){return new Q(this.secretKey)}getOrderlyKey(){return new Q(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,s){}cleanAllKey(){}cleanKey(n){}};E();T();v();var Ot={};fn(Ot,{base64url:()=>ze,calculateStringHash:()=>Ge,formatByUnits:()=>Xe,parseAccountId:()=>qe,parseBrokerHash:()=>xe,parseTokenHash:()=>Ye});E();T();v();import{keccak256 as Kn,AbiCoder as Nn,solidityPackedKeccak256 as On,formatUnits as Rn}from"ethers";var ze=function(o){return o.replace(/\+/g,"-").replace(/\//g,"_")};function xe(o){return Ge(o)}function qe(o,n){let s=Nn.defaultAbiCoder();return Kn(s.encode(["address","bytes32"],[o,xe(n)]))}function Ye(o){return Ge(o)}function Ge(o){return On(["string"],[o])}function Xe(o,n="ether"){return Rn(o,n)}Re();var ee=class{constructor(n){this.keyStore=n}async sign(n){let s=Date.now().toString(),c=[s,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(c+=JSON.stringify(n.data));let{signature:d,publicKey:p}=await this.signText(c);return{"orderly-key":p,"orderly-timestamp":s,"orderly-signature":d}}async signText(n){let s=this.keyStore.getOrderlyKey();if(!s)throw new Error("orderlyKeyPair is not defined");let c=O.from(n),d=await s.sign(c),p=O.from(d).toString("base64");return{signature:ze(p),publicKey:await s.getPublicKey()}}};import{default as cs}from"eventemitter3";E();T();v();E();T();v();var Se=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://testnet-api-evm.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://testnet-ws-evm.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://testnet-ws-private-evm.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["swapSupportApiUrl","https://fi-api.woo.org"],["brokerId","woofi_dex"],["env","dev-evm"]])}get(n){return this.map.get(n)}set(n,s){this.map.set(n,s)}clear(){}},Rt=class extends Se{constructor(s){super();this.configMap=s}_restore(){let s=Object.entries(this.configMap);this.map=new Map(s)}};E();T();v();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Dt="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Ft="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Lt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var Dn=o=>{let n=new me(o||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new ee(n)},Fn=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let o=new fe("");return new ee(o)};function Ln(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Vt(o,n){return{name:"Orderly",version:"1",chainId:o,verifyingContract:n?Ln():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function $t(o){let{chainId:n,registrationNonce:s,brokerId:c}=o,d=Date.now(),p="Registration",a={brokerId:c,chainId:n,timestamp:d,registrationNonce:s},g={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[a,{domain:Vt(n),message:a,primaryType:p,types:g}]}function Ht(o){let{publicKey:n,chainId:s,primaryType:c,brokerId:d,expiration:p=365}=o,a=Date.now(),g={brokerId:d,orderlyKey:n,scope:"read,trading",chainId:s,timestamp:a,expiration:a+1e3*60*60*24*p},w={EIP712Domain:X.EIP712Domain,[c]:X[c]},I={domain:Vt(s),message:g,primaryType:c,types:w};return[g,I]}function Wt(o){let{chainId:n,settlePnlNonce:s,domain:c,brokerId:d}=o,p="SettlePnl",a=new Date().getTime(),g={EIP712Domain:X.EIP712Domain,[p]:X[p]},w={brokerId:d,chainId:n,timestamp:a,settleNonce:s};return[w,{domain:c,message:w,primaryType:p,types:g}]}E();T();v();var Ze=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"issue",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_to",type:"address"},{internalType:"uint256",name:"_amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"_paused",type:"bool"}],name:"pauseTransfers",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var jt=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccountIdInvalid",type:"error"},{inputs:[{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],name:"BalanceNotEnough",type:"error"},{inputs:[],name:"BrokerNotAllowed",type:"error"},{inputs:[],name:"OnlyCrossChainManagerCanCall",type:"error"},{inputs:[],name:"TokenNotAllowed",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDeposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDepositTo",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"uint64",name:"withdrawNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"brokerHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"address",name:"receiver",type:"address"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"},{indexed:!1,internalType:"uint128",name:"fee",type:"uint128"},{indexed:!1,internalType:"uint256",name:"blocktime",type:"uint256"}],name:"AccountWithdraw",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"_tokenAddress",type:"address"}],name:"ChangeTokenAddressAndAllow",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedBroker",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"allowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"address",name:"_tokenAddress",type:"address"}],name:"changeTokenAddressAndAllow",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"crossChainManagerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"depositId",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"receiver",type:"address"},{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"depositTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyPause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyUnpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getAllAllowedBroker",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAllAllowedToken",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"}],name:"getAllowedBroker",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"}],name:"getAllowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedBroker",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_crossChainManagerAddress",type:"address"}],name:"setCrossChainManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"},{internalType:"uint128",name:"fee",type:"uint128"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint64",name:"withdrawNonce",type:"uint64"}],internalType:"struct VaultTypes.VaultWithdraw",name:"data",type:"tuple"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];var Je=class{constructor(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Dt,usdcAbi:Ze,vaultAddress:Ft,vaultAbi:jt,verifyContractAddress:Lt,erc20Abi:Ze}}};E();T();v();E();T();v();var Qe=class{constructor(n=[],s={}){this.providers=n;this.services=s;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(s=>{let c=s;c instanceof Function&&(c=new s),this.add(c)})}registerByName(n,s){let c=s;c instanceof Function&&(c=new s),this.addByName(n,c)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,s){return this.services[n]=s,this.services[n.toLowerCase()]=s,this.injectIntoProperties(s,n),this.get(n)}inject(n,s,c){n&&c&&(n[s]=c)}injectIntoProperties(n,s=n.constructor.name){this.getInjectProperty(s.toLowerCase()).forEach(c=>{this.inject(c.target,c.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},zt=Qe;var et=class o{static getContainer(){return o.container||(o.container=new zt),o.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,s){this.getContainer().registerByName(n,s)}static get(n){return this.getContainer().get(n)}static getAll(){return this.getContainer().getAll()}constructor(){}},Hn=et;E();T();v();import{AccountStatusEnum as j}from"@orderly.network/types";import Wn from"eventemitter3";E();T();v();import{ethers as qt}from"ethers";var Ce=class{constructor(n,s,c){this.configStore=n;this.contractManger=s;this.account=c}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:s,token:c,amount:d}=n,p="/v1/withdraw_request",a=await this.getWithdrawalNonce(),g=this.account.getDomain(!0),[w,I]=this._generateWithdrawMessage({chainId:s,receiver:this.account.stateValue.address,token:c,amount:this.account.walletClient.parseUnits(d.toString()),nonce:a,domain:g}),A={signature:await this.account.signTypedData(I),message:w,userAddress:this.account.stateValue.address,verifyingContract:g.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:s,receiver:c,token:d,amount:p,domain:a,nonce:g}=n,w="Withdraw",I=Date.now(),f={EIP712Domain:X.EIP712Domain,[w]:X[w]},A={brokerId:this.configStore.get("brokerId"),chainId:s,receiver:c,token:d,amount:p,timestamp:I,withdrawNonce:g};return[A,{domain:a,message:A,primaryType:w,types:f}]}async getWithdrawalNonce(){let n=Date.now().toString(),s="/v1/withdraw_nonce",c=[n,"GET",s].join(""),d=this.account.signer,{publicKey:p,signature:a}=await d.signText(c),g=await this._simpleFetch(s,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.withdraw_nonce;throw new Error(g.message)}async getNativeBalance(n){console.log("getNativeBalance",this.account.stateValue.address);let s=await this.account.walletClient?.getBalance(this.account.stateValue.address);return Xe(s,n?.decimals)}async getBalance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n??s.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:s.usdcAbi});return console.log("-----*****-----",c),this.account.walletClient?.formatUnits(c)}async getBalanceByAddress(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n,"balanceOf",[this.account.stateValue.address],{abi:s.erc20Abi});return this.account.walletClient?.formatUnits(c)}async getAllowance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n??s.usdcAddress,"allowance",[this.account.stateValue.address,s.vaultAddress],{abi:s.usdcAbi});return this.account.walletClient?.formatUnits(c)}async approve(n,s){if(!n)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let c=this.contractManger.getContractInfoByEnv(),d=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):qt.MaxUint256.toString(),p=await this.account.walletClient?.call(n,"approve",[c.vaultAddress,d],{abi:c.usdcAbi});return console.log("-----*****-----",p),p}async approveByAddress(n){let{amount:s,address:c}=n;return this._approve(c,s)}async _approve(n,s){if(!this.account.walletClient)throw new Error("walletClient is undefined");let c=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):qt.MaxUint256.toString(),d=this.contractManger.getContractInfoByEnv(),p=await this.account.walletClient?.call(n,"approve",[d.vaultAddress,c],{abi:d.erc20Abi});return console.log("-----*****-----",p),p}async deposit(n){console.log("deposit amount:",n);let s=this.configStore.get("brokerId");if(!s)throw new Error("brokerId is required");let c=this.contractManger.getContractInfoByEnv(),d={accountId:this.account.accountIdHashStr,brokerHash:xe(s),tokenHash:Ye("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.call(c.vaultAddress,"deposit",[d],{abi:c.vaultAbi})}async _simpleFetch(n,s={}){let c=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(c,s).then(d=>d.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var _e=class{constructor(n,s,c,d){this.configStore=n;this.keyStore=s;this.contractManger=c;this.getWalletAdapter=d;this._ee=new Wn;this._state={status:j.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new Ce(n,c,this),this._bindEvents()}login(n){if(!n)throw new Error("address is required")}logout(){}async setAddress(n,s){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let c={...this.stateValue,status:j.Connected,address:n,connectWallet:s?.wallet};return this._ee.emit("change:status",c),s&&(this.walletClient=this.getWalletAdapter({...s,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");if(!this.configStore.get("brokerId"))throw new Error("brokerId is undefined");return qe(this.address,this.configStore.get("brokerId"))}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let s={...this.stateValue,positon:n};this._ee.emit("change:status",s)}set orders(n){let s={...this.stateValue,orders:n};this._ee.emit("change:status",s)}_bindEvents(){this._ee.addListener("change:status",n=>{console.log("change:status",n),this._state=n})}async _checkAccount(n){let s;try{let c=await this._checkAccountExist(n);if(c&&c.account_id)console.log("account is exist"),this.keyStore.setAccountId(n,c.account_id),s={...this.stateValue,status:j.SignedIn,accountId:c.account_id,userId:c.user_id},this._ee.emit("change:status",s);else return s={...this.stateValue,status:j.NotSignedIn},this._ee.emit("change:status",s),j.NotSignedIn;let d=this.keyStore.getOrderlyKey();if(s={...this.stateValue,status:j.DisabledTrading},!d)return console.log("orderlyKey is null"),this._ee.emit("change:status",s),j.DisabledTrading;let p=await d.getPublicKey(),a=await this._checkOrderlyKeyState(c.account_id,p);if(a&&a.orderly_key&&a.key_status==="ACTIVE"){let g=Date.now(),w=a.expiration;if(g>w)return this.keyStore.cleanKey(n,"orderlyKey"),j.DisabledTrading;let I={...this.stateValue,status:j.EnableTrading};return this._ee.emit("change:status",I),j.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),j.NotConnected}catch(c){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",c)}return j.NotSignedIn}async _checkAccountExist(n){let s=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=woofi_dex`);return s.success?s.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),s=this.stateValue.address;if(!s)throw new Error("address is undefined");let[c,d]=$t({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(d),a=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:c,userAddress:s}),headers:{"Content-Type":"application/json"}});if(a.success){this.keyStore.setAccountId(s,a.data.account_id);let g={...this.stateValue,status:j.DisabledTrading,accountId:a.data.account_id,userId:a.data.user_id};return this._ee.emit("change:status",g),a}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let s="AddOrderlyKey",c=this.keyStore.generateKey(),d=await c.getPublicKey(),[p,a]=Ht({publicKey:d,chainId:this.walletClient.chainId,primaryType:s,expiration:n,brokerId:this.configStore.get("brokerId")}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let w=await this.signTypedData(a),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:w,message:p,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(g,c);let f={...this.stateValue,status:j.EnableTrading};return this._ee.emit("change:status",f),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),s=this.stateValue.address,c=this.getDomain(!0),d="/v1/settle_pnl",[p,a]=Wt({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:c}),w={signature:await this.signTypedData(a),message:p,userAddress:s,verifyingContract:c.verifyingContract},I={method:"POST",url:d,data:w},f=await this.signer.sign(I),A=await this._simpleFetch(d,{method:"POST",body:JSON.stringify(w),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...f}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:j.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,s){let c=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${s}`);if(c.success)return c.data;throw new Error(c.message)}get signer(){return this._singer||(this._singer=new ee(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),c=[n,"GET","/v1/settle_nonce"].join(""),d=this.signer,{publicKey:p,signature:a}=await d.signText(c),g=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.settle_nonce;throw new Error(g.message)}async _simpleFetch(n,s={}){let c=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(c,s).then(d=>d.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};_e.instanceName="account";E();T();v();E();T();v();import{BrowserProvider as jn,ethers as ke}from"ethers";import{getParsedEthersError as zn}from"@enzoferey/ethers-error-parser";var tt=class{constructor(n){console.log("EtherAdapter constructor",n),this._chainId=parseInt(n.chain.id,16),this.provider=new jn(n.provider,"any"),this._address=n.address}parseUnits(n){return ke.parseUnits(n,6).toString()}formatUnits(n){return ke.formatUnits(n,6)}getBalance(n){return console.log("*********",n),this.provider.getBalance(n).then(s=>(console.log("getBalance",s),s),s=>{console.log("get native token balance error",s)})}deposit(n,s,c){throw new Error("Method not implemented.")}async call(n,s,c,d){let p=await this.provider?.getSigner();return new ke.Contract(n,d.abi,p)[s].apply(null,c).catch(g=>{throw zn(g)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,s){return await this.provider?.send(n,s)}async signTypedData(n,s){return await this.provider?.send("eth_signTypedData_v4",[n,s])}async verify(n,s){let{domain:c,types:d,message:p}=n,a=ke.verifyTypedData(c,d,p,s);console.log("recovered",a)}on(n,s){this.provider?.on(n,s)}off(n,s){this.provider?.off(n,s)}};export{_e as Account,Rt as BaseConfigStore,Je as BaseContractManager,Be as BaseKeyStore,Q as BaseOrderlyKeyPair,ee as BaseSigner,tt as EtherAdapter,cs as EventEmitter,fe as LocalStorageStore,Se as MemoryConfigStore,me as MockKeyStore,Hn as SimpleDI,Fn as getDefaultSigner,Dn as getMockSigner,Ot as utils};
4720
2
  /*! Bundled license information:
4721
3
 
4722
4
  @jspm/core/nodelibs/browser/buffer.js: