@orderly.network/core 0.0.12 → 0.0.13
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.js +1 -2720
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2674
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,2723 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __pow = Math.pow;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __export = (target, all) => {
|
|
27
|
-
for (var name in all)
|
|
28
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
-
};
|
|
30
|
-
var __copyProps = (to, from, except, desc) => {
|
|
31
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
-
for (let key of __getOwnPropNames(from))
|
|
33
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
-
}
|
|
36
|
-
return to;
|
|
37
|
-
};
|
|
38
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
39
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
40
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
41
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
42
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
43
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
44
|
-
mod
|
|
45
|
-
));
|
|
46
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
47
|
-
var __async = (__this, __arguments, generator) => {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
var fulfilled = (value) => {
|
|
50
|
-
try {
|
|
51
|
-
step(generator.next(value));
|
|
52
|
-
} catch (e) {
|
|
53
|
-
reject(e);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
var rejected = (value) => {
|
|
57
|
-
try {
|
|
58
|
-
step(generator.throw(value));
|
|
59
|
-
} catch (e) {
|
|
60
|
-
reject(e);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
64
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/index.ts
|
|
69
|
-
var src_exports = {};
|
|
70
|
-
__export(src_exports, {
|
|
71
|
-
Account: () => Account,
|
|
72
|
-
BaseConfigStore: () => BaseConfigStore,
|
|
73
|
-
BaseKeyStore: () => BaseKeyStore,
|
|
74
|
-
BaseOrderlyKeyPair: () => BaseOrderlyKeyPair,
|
|
75
|
-
BaseSigner: () => BaseSigner,
|
|
76
|
-
EtherAdapter: () => EtherAdapter,
|
|
77
|
-
LocalStorageStore: () => LocalStorageStore,
|
|
78
|
-
MemoryConfigStore: () => MemoryConfigStore,
|
|
79
|
-
MockKeyStore: () => MockKeyStore,
|
|
80
|
-
SimpleDI: () => simpleDI_default,
|
|
81
|
-
Web3WalletAdapter: () => Web3WalletAdapter,
|
|
82
|
-
getDefaultSigner: () => getDefaultSigner,
|
|
83
|
-
getMockSigner: () => getMockSigner
|
|
84
|
-
});
|
|
85
|
-
module.exports = __toCommonJS(src_exports);
|
|
86
|
-
|
|
87
|
-
// ../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/buffer.js
|
|
88
|
-
var exports$3 = {};
|
|
89
|
-
var _dewExec$2 = false;
|
|
90
|
-
function dew$2() {
|
|
91
|
-
if (_dewExec$2)
|
|
92
|
-
return exports$3;
|
|
93
|
-
_dewExec$2 = true;
|
|
94
|
-
exports$3.byteLength = byteLength;
|
|
95
|
-
exports$3.toByteArray = toByteArray;
|
|
96
|
-
exports$3.fromByteArray = fromByteArray;
|
|
97
|
-
var lookup = [];
|
|
98
|
-
var revLookup = [];
|
|
99
|
-
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
100
|
-
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
101
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
|
102
|
-
lookup[i] = code[i];
|
|
103
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
104
|
-
}
|
|
105
|
-
revLookup["-".charCodeAt(0)] = 62;
|
|
106
|
-
revLookup["_".charCodeAt(0)] = 63;
|
|
107
|
-
function getLens(b64) {
|
|
108
|
-
var len2 = b64.length;
|
|
109
|
-
if (len2 % 4 > 0) {
|
|
110
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
111
|
-
}
|
|
112
|
-
var validLen = b64.indexOf("=");
|
|
113
|
-
if (validLen === -1)
|
|
114
|
-
validLen = len2;
|
|
115
|
-
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
116
|
-
return [validLen, placeHoldersLen];
|
|
117
|
-
}
|
|
118
|
-
function byteLength(b64) {
|
|
119
|
-
var lens = getLens(b64);
|
|
120
|
-
var validLen = lens[0];
|
|
121
|
-
var placeHoldersLen = lens[1];
|
|
122
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
123
|
-
}
|
|
124
|
-
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
125
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
126
|
-
}
|
|
127
|
-
function toByteArray(b64) {
|
|
128
|
-
var tmp;
|
|
129
|
-
var lens = getLens(b64);
|
|
130
|
-
var validLen = lens[0];
|
|
131
|
-
var placeHoldersLen = lens[1];
|
|
132
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
133
|
-
var curByte = 0;
|
|
134
|
-
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
135
|
-
var i2;
|
|
136
|
-
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
137
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
138
|
-
arr[curByte++] = tmp >> 16 & 255;
|
|
139
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
140
|
-
arr[curByte++] = tmp & 255;
|
|
141
|
-
}
|
|
142
|
-
if (placeHoldersLen === 2) {
|
|
143
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
144
|
-
arr[curByte++] = tmp & 255;
|
|
145
|
-
}
|
|
146
|
-
if (placeHoldersLen === 1) {
|
|
147
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
148
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
149
|
-
arr[curByte++] = tmp & 255;
|
|
150
|
-
}
|
|
151
|
-
return arr;
|
|
152
|
-
}
|
|
153
|
-
function tripletToBase64(num) {
|
|
154
|
-
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
155
|
-
}
|
|
156
|
-
function encodeChunk(uint8, start, end) {
|
|
157
|
-
var tmp;
|
|
158
|
-
var output = [];
|
|
159
|
-
for (var i2 = start; i2 < end; i2 += 3) {
|
|
160
|
-
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
161
|
-
output.push(tripletToBase64(tmp));
|
|
162
|
-
}
|
|
163
|
-
return output.join("");
|
|
164
|
-
}
|
|
165
|
-
function fromByteArray(uint8) {
|
|
166
|
-
var tmp;
|
|
167
|
-
var len2 = uint8.length;
|
|
168
|
-
var extraBytes = len2 % 3;
|
|
169
|
-
var parts = [];
|
|
170
|
-
var maxChunkLength = 16383;
|
|
171
|
-
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
172
|
-
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
173
|
-
}
|
|
174
|
-
if (extraBytes === 1) {
|
|
175
|
-
tmp = uint8[len2 - 1];
|
|
176
|
-
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
177
|
-
} else if (extraBytes === 2) {
|
|
178
|
-
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
179
|
-
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
180
|
-
}
|
|
181
|
-
return parts.join("");
|
|
182
|
-
}
|
|
183
|
-
return exports$3;
|
|
184
|
-
}
|
|
185
|
-
var exports$2 = {};
|
|
186
|
-
var _dewExec$1 = false;
|
|
187
|
-
function dew$1() {
|
|
188
|
-
if (_dewExec$1)
|
|
189
|
-
return exports$2;
|
|
190
|
-
_dewExec$1 = true;
|
|
191
|
-
exports$2.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
192
|
-
var e, m;
|
|
193
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
194
|
-
var eMax = (1 << eLen) - 1;
|
|
195
|
-
var eBias = eMax >> 1;
|
|
196
|
-
var nBits = -7;
|
|
197
|
-
var i = isLE ? nBytes - 1 : 0;
|
|
198
|
-
var d = isLE ? -1 : 1;
|
|
199
|
-
var s = buffer[offset + i];
|
|
200
|
-
i += d;
|
|
201
|
-
e = s & (1 << -nBits) - 1;
|
|
202
|
-
s >>= -nBits;
|
|
203
|
-
nBits += eLen;
|
|
204
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
205
|
-
}
|
|
206
|
-
m = e & (1 << -nBits) - 1;
|
|
207
|
-
e >>= -nBits;
|
|
208
|
-
nBits += mLen;
|
|
209
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
210
|
-
}
|
|
211
|
-
if (e === 0) {
|
|
212
|
-
e = 1 - eBias;
|
|
213
|
-
} else if (e === eMax) {
|
|
214
|
-
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
215
|
-
} else {
|
|
216
|
-
m = m + Math.pow(2, mLen);
|
|
217
|
-
e = e - eBias;
|
|
218
|
-
}
|
|
219
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
220
|
-
};
|
|
221
|
-
exports$2.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
222
|
-
var e, m, c;
|
|
223
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
224
|
-
var eMax = (1 << eLen) - 1;
|
|
225
|
-
var eBias = eMax >> 1;
|
|
226
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
227
|
-
var i = isLE ? 0 : nBytes - 1;
|
|
228
|
-
var d = isLE ? 1 : -1;
|
|
229
|
-
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
230
|
-
value = Math.abs(value);
|
|
231
|
-
if (isNaN(value) || value === Infinity) {
|
|
232
|
-
m = isNaN(value) ? 1 : 0;
|
|
233
|
-
e = eMax;
|
|
234
|
-
} else {
|
|
235
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
236
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
237
|
-
e--;
|
|
238
|
-
c *= 2;
|
|
239
|
-
}
|
|
240
|
-
if (e + eBias >= 1) {
|
|
241
|
-
value += rt / c;
|
|
242
|
-
} else {
|
|
243
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
244
|
-
}
|
|
245
|
-
if (value * c >= 2) {
|
|
246
|
-
e++;
|
|
247
|
-
c /= 2;
|
|
248
|
-
}
|
|
249
|
-
if (e + eBias >= eMax) {
|
|
250
|
-
m = 0;
|
|
251
|
-
e = eMax;
|
|
252
|
-
} else if (e + eBias >= 1) {
|
|
253
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
254
|
-
e = e + eBias;
|
|
255
|
-
} else {
|
|
256
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
257
|
-
e = 0;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
261
|
-
}
|
|
262
|
-
e = e << mLen | m;
|
|
263
|
-
eLen += mLen;
|
|
264
|
-
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
265
|
-
}
|
|
266
|
-
buffer[offset + i - d] |= s * 128;
|
|
267
|
-
};
|
|
268
|
-
return exports$2;
|
|
269
|
-
}
|
|
270
|
-
var exports$1 = {};
|
|
271
|
-
var _dewExec = false;
|
|
272
|
-
function dew() {
|
|
273
|
-
if (_dewExec)
|
|
274
|
-
return exports$1;
|
|
275
|
-
_dewExec = true;
|
|
276
|
-
const base64 = dew$2();
|
|
277
|
-
const ieee754 = dew$1();
|
|
278
|
-
const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
279
|
-
exports$1.Buffer = Buffer3;
|
|
280
|
-
exports$1.SlowBuffer = SlowBuffer;
|
|
281
|
-
exports$1.INSPECT_MAX_BYTES = 50;
|
|
282
|
-
const K_MAX_LENGTH = 2147483647;
|
|
283
|
-
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
284
|
-
Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
285
|
-
if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
286
|
-
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.");
|
|
287
|
-
}
|
|
288
|
-
function typedArraySupport() {
|
|
289
|
-
try {
|
|
290
|
-
const arr = new Uint8Array(1);
|
|
291
|
-
const proto = {
|
|
292
|
-
foo: function() {
|
|
293
|
-
return 42;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
297
|
-
Object.setPrototypeOf(arr, proto);
|
|
298
|
-
return arr.foo() === 42;
|
|
299
|
-
} catch (e) {
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
Object.defineProperty(Buffer3.prototype, "parent", {
|
|
304
|
-
enumerable: true,
|
|
305
|
-
get: function() {
|
|
306
|
-
if (!Buffer3.isBuffer(this))
|
|
307
|
-
return void 0;
|
|
308
|
-
return this.buffer;
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
Object.defineProperty(Buffer3.prototype, "offset", {
|
|
312
|
-
enumerable: true,
|
|
313
|
-
get: function() {
|
|
314
|
-
if (!Buffer3.isBuffer(this))
|
|
315
|
-
return void 0;
|
|
316
|
-
return this.byteOffset;
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
function createBuffer(length) {
|
|
320
|
-
if (length > K_MAX_LENGTH) {
|
|
321
|
-
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
322
|
-
}
|
|
323
|
-
const buf = new Uint8Array(length);
|
|
324
|
-
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
325
|
-
return buf;
|
|
326
|
-
}
|
|
327
|
-
function Buffer3(arg, encodingOrOffset, length) {
|
|
328
|
-
if (typeof arg === "number") {
|
|
329
|
-
if (typeof encodingOrOffset === "string") {
|
|
330
|
-
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
331
|
-
}
|
|
332
|
-
return allocUnsafe(arg);
|
|
333
|
-
}
|
|
334
|
-
return from(arg, encodingOrOffset, length);
|
|
335
|
-
}
|
|
336
|
-
Buffer3.poolSize = 8192;
|
|
337
|
-
function from(value, encodingOrOffset, length) {
|
|
338
|
-
if (typeof value === "string") {
|
|
339
|
-
return fromString(value, encodingOrOffset);
|
|
340
|
-
}
|
|
341
|
-
if (ArrayBuffer.isView(value)) {
|
|
342
|
-
return fromArrayView(value);
|
|
343
|
-
}
|
|
344
|
-
if (value == null) {
|
|
345
|
-
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
346
|
-
}
|
|
347
|
-
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
348
|
-
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
349
|
-
}
|
|
350
|
-
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
351
|
-
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
352
|
-
}
|
|
353
|
-
if (typeof value === "number") {
|
|
354
|
-
throw new TypeError('The "value" argument must not be of type number. Received type number');
|
|
355
|
-
}
|
|
356
|
-
const valueOf = value.valueOf && value.valueOf();
|
|
357
|
-
if (valueOf != null && valueOf !== value) {
|
|
358
|
-
return Buffer3.from(valueOf, encodingOrOffset, length);
|
|
359
|
-
}
|
|
360
|
-
const b = fromObject(value);
|
|
361
|
-
if (b)
|
|
362
|
-
return b;
|
|
363
|
-
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
364
|
-
return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
365
|
-
}
|
|
366
|
-
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
367
|
-
}
|
|
368
|
-
Buffer3.from = function(value, encodingOrOffset, length) {
|
|
369
|
-
return from(value, encodingOrOffset, length);
|
|
370
|
-
};
|
|
371
|
-
Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
|
|
372
|
-
Object.setPrototypeOf(Buffer3, Uint8Array);
|
|
373
|
-
function assertSize(size) {
|
|
374
|
-
if (typeof size !== "number") {
|
|
375
|
-
throw new TypeError('"size" argument must be of type number');
|
|
376
|
-
} else if (size < 0) {
|
|
377
|
-
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function alloc(size, fill, encoding) {
|
|
381
|
-
assertSize(size);
|
|
382
|
-
if (size <= 0) {
|
|
383
|
-
return createBuffer(size);
|
|
384
|
-
}
|
|
385
|
-
if (fill !== void 0) {
|
|
386
|
-
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
387
|
-
}
|
|
388
|
-
return createBuffer(size);
|
|
389
|
-
}
|
|
390
|
-
Buffer3.alloc = function(size, fill, encoding) {
|
|
391
|
-
return alloc(size, fill, encoding);
|
|
392
|
-
};
|
|
393
|
-
function allocUnsafe(size) {
|
|
394
|
-
assertSize(size);
|
|
395
|
-
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
396
|
-
}
|
|
397
|
-
Buffer3.allocUnsafe = function(size) {
|
|
398
|
-
return allocUnsafe(size);
|
|
399
|
-
};
|
|
400
|
-
Buffer3.allocUnsafeSlow = function(size) {
|
|
401
|
-
return allocUnsafe(size);
|
|
402
|
-
};
|
|
403
|
-
function fromString(string, encoding) {
|
|
404
|
-
if (typeof encoding !== "string" || encoding === "") {
|
|
405
|
-
encoding = "utf8";
|
|
406
|
-
}
|
|
407
|
-
if (!Buffer3.isEncoding(encoding)) {
|
|
408
|
-
throw new TypeError("Unknown encoding: " + encoding);
|
|
409
|
-
}
|
|
410
|
-
const length = byteLength(string, encoding) | 0;
|
|
411
|
-
let buf = createBuffer(length);
|
|
412
|
-
const actual = buf.write(string, encoding);
|
|
413
|
-
if (actual !== length) {
|
|
414
|
-
buf = buf.slice(0, actual);
|
|
415
|
-
}
|
|
416
|
-
return buf;
|
|
417
|
-
}
|
|
418
|
-
function fromArrayLike(array) {
|
|
419
|
-
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
420
|
-
const buf = createBuffer(length);
|
|
421
|
-
for (let i = 0; i < length; i += 1) {
|
|
422
|
-
buf[i] = array[i] & 255;
|
|
423
|
-
}
|
|
424
|
-
return buf;
|
|
425
|
-
}
|
|
426
|
-
function fromArrayView(arrayView) {
|
|
427
|
-
if (isInstance(arrayView, Uint8Array)) {
|
|
428
|
-
const copy = new Uint8Array(arrayView);
|
|
429
|
-
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
430
|
-
}
|
|
431
|
-
return fromArrayLike(arrayView);
|
|
432
|
-
}
|
|
433
|
-
function fromArrayBuffer(array, byteOffset, length) {
|
|
434
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
435
|
-
throw new RangeError('"offset" is outside of buffer bounds');
|
|
436
|
-
}
|
|
437
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
438
|
-
throw new RangeError('"length" is outside of buffer bounds');
|
|
439
|
-
}
|
|
440
|
-
let buf;
|
|
441
|
-
if (byteOffset === void 0 && length === void 0) {
|
|
442
|
-
buf = new Uint8Array(array);
|
|
443
|
-
} else if (length === void 0) {
|
|
444
|
-
buf = new Uint8Array(array, byteOffset);
|
|
445
|
-
} else {
|
|
446
|
-
buf = new Uint8Array(array, byteOffset, length);
|
|
447
|
-
}
|
|
448
|
-
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
449
|
-
return buf;
|
|
450
|
-
}
|
|
451
|
-
function fromObject(obj) {
|
|
452
|
-
if (Buffer3.isBuffer(obj)) {
|
|
453
|
-
const len = checked(obj.length) | 0;
|
|
454
|
-
const buf = createBuffer(len);
|
|
455
|
-
if (buf.length === 0) {
|
|
456
|
-
return buf;
|
|
457
|
-
}
|
|
458
|
-
obj.copy(buf, 0, 0, len);
|
|
459
|
-
return buf;
|
|
460
|
-
}
|
|
461
|
-
if (obj.length !== void 0) {
|
|
462
|
-
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
463
|
-
return createBuffer(0);
|
|
464
|
-
}
|
|
465
|
-
return fromArrayLike(obj);
|
|
466
|
-
}
|
|
467
|
-
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
468
|
-
return fromArrayLike(obj.data);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
function checked(length) {
|
|
472
|
-
if (length >= K_MAX_LENGTH) {
|
|
473
|
-
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
474
|
-
}
|
|
475
|
-
return length | 0;
|
|
476
|
-
}
|
|
477
|
-
function SlowBuffer(length) {
|
|
478
|
-
if (+length != length) {
|
|
479
|
-
length = 0;
|
|
480
|
-
}
|
|
481
|
-
return Buffer3.alloc(+length);
|
|
482
|
-
}
|
|
483
|
-
Buffer3.isBuffer = function isBuffer(b) {
|
|
484
|
-
return b != null && b._isBuffer === true && b !== Buffer3.prototype;
|
|
485
|
-
};
|
|
486
|
-
Buffer3.compare = function compare(a, b) {
|
|
487
|
-
if (isInstance(a, Uint8Array))
|
|
488
|
-
a = Buffer3.from(a, a.offset, a.byteLength);
|
|
489
|
-
if (isInstance(b, Uint8Array))
|
|
490
|
-
b = Buffer3.from(b, b.offset, b.byteLength);
|
|
491
|
-
if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
|
|
492
|
-
throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
493
|
-
}
|
|
494
|
-
if (a === b)
|
|
495
|
-
return 0;
|
|
496
|
-
let x = a.length;
|
|
497
|
-
let y = b.length;
|
|
498
|
-
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
499
|
-
if (a[i] !== b[i]) {
|
|
500
|
-
x = a[i];
|
|
501
|
-
y = b[i];
|
|
502
|
-
break;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (x < y)
|
|
506
|
-
return -1;
|
|
507
|
-
if (y < x)
|
|
508
|
-
return 1;
|
|
509
|
-
return 0;
|
|
510
|
-
};
|
|
511
|
-
Buffer3.isEncoding = function isEncoding(encoding) {
|
|
512
|
-
switch (String(encoding).toLowerCase()) {
|
|
513
|
-
case "hex":
|
|
514
|
-
case "utf8":
|
|
515
|
-
case "utf-8":
|
|
516
|
-
case "ascii":
|
|
517
|
-
case "latin1":
|
|
518
|
-
case "binary":
|
|
519
|
-
case "base64":
|
|
520
|
-
case "ucs2":
|
|
521
|
-
case "ucs-2":
|
|
522
|
-
case "utf16le":
|
|
523
|
-
case "utf-16le":
|
|
524
|
-
return true;
|
|
525
|
-
default:
|
|
526
|
-
return false;
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
Buffer3.concat = function concat(list, length) {
|
|
530
|
-
if (!Array.isArray(list)) {
|
|
531
|
-
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
532
|
-
}
|
|
533
|
-
if (list.length === 0) {
|
|
534
|
-
return Buffer3.alloc(0);
|
|
535
|
-
}
|
|
536
|
-
let i;
|
|
537
|
-
if (length === void 0) {
|
|
538
|
-
length = 0;
|
|
539
|
-
for (i = 0; i < list.length; ++i) {
|
|
540
|
-
length += list[i].length;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
const buffer = Buffer3.allocUnsafe(length);
|
|
544
|
-
let pos = 0;
|
|
545
|
-
for (i = 0; i < list.length; ++i) {
|
|
546
|
-
let buf = list[i];
|
|
547
|
-
if (isInstance(buf, Uint8Array)) {
|
|
548
|
-
if (pos + buf.length > buffer.length) {
|
|
549
|
-
if (!Buffer3.isBuffer(buf))
|
|
550
|
-
buf = Buffer3.from(buf);
|
|
551
|
-
buf.copy(buffer, pos);
|
|
552
|
-
} else {
|
|
553
|
-
Uint8Array.prototype.set.call(buffer, buf, pos);
|
|
554
|
-
}
|
|
555
|
-
} else if (!Buffer3.isBuffer(buf)) {
|
|
556
|
-
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
557
|
-
} else {
|
|
558
|
-
buf.copy(buffer, pos);
|
|
559
|
-
}
|
|
560
|
-
pos += buf.length;
|
|
561
|
-
}
|
|
562
|
-
return buffer;
|
|
563
|
-
};
|
|
564
|
-
function byteLength(string, encoding) {
|
|
565
|
-
if (Buffer3.isBuffer(string)) {
|
|
566
|
-
return string.length;
|
|
567
|
-
}
|
|
568
|
-
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
569
|
-
return string.byteLength;
|
|
570
|
-
}
|
|
571
|
-
if (typeof string !== "string") {
|
|
572
|
-
throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string);
|
|
573
|
-
}
|
|
574
|
-
const len = string.length;
|
|
575
|
-
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
576
|
-
if (!mustMatch && len === 0)
|
|
577
|
-
return 0;
|
|
578
|
-
let loweredCase = false;
|
|
579
|
-
for (; ; ) {
|
|
580
|
-
switch (encoding) {
|
|
581
|
-
case "ascii":
|
|
582
|
-
case "latin1":
|
|
583
|
-
case "binary":
|
|
584
|
-
return len;
|
|
585
|
-
case "utf8":
|
|
586
|
-
case "utf-8":
|
|
587
|
-
return utf8ToBytes(string).length;
|
|
588
|
-
case "ucs2":
|
|
589
|
-
case "ucs-2":
|
|
590
|
-
case "utf16le":
|
|
591
|
-
case "utf-16le":
|
|
592
|
-
return len * 2;
|
|
593
|
-
case "hex":
|
|
594
|
-
return len >>> 1;
|
|
595
|
-
case "base64":
|
|
596
|
-
return base64ToBytes(string).length;
|
|
597
|
-
default:
|
|
598
|
-
if (loweredCase) {
|
|
599
|
-
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
600
|
-
}
|
|
601
|
-
encoding = ("" + encoding).toLowerCase();
|
|
602
|
-
loweredCase = true;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
Buffer3.byteLength = byteLength;
|
|
607
|
-
function slowToString(encoding, start, end) {
|
|
608
|
-
let loweredCase = false;
|
|
609
|
-
if (start === void 0 || start < 0) {
|
|
610
|
-
start = 0;
|
|
611
|
-
}
|
|
612
|
-
if (start > this.length) {
|
|
613
|
-
return "";
|
|
614
|
-
}
|
|
615
|
-
if (end === void 0 || end > this.length) {
|
|
616
|
-
end = this.length;
|
|
617
|
-
}
|
|
618
|
-
if (end <= 0) {
|
|
619
|
-
return "";
|
|
620
|
-
}
|
|
621
|
-
end >>>= 0;
|
|
622
|
-
start >>>= 0;
|
|
623
|
-
if (end <= start) {
|
|
624
|
-
return "";
|
|
625
|
-
}
|
|
626
|
-
if (!encoding)
|
|
627
|
-
encoding = "utf8";
|
|
628
|
-
while (true) {
|
|
629
|
-
switch (encoding) {
|
|
630
|
-
case "hex":
|
|
631
|
-
return hexSlice(this, start, end);
|
|
632
|
-
case "utf8":
|
|
633
|
-
case "utf-8":
|
|
634
|
-
return utf8Slice(this, start, end);
|
|
635
|
-
case "ascii":
|
|
636
|
-
return asciiSlice(this, start, end);
|
|
637
|
-
case "latin1":
|
|
638
|
-
case "binary":
|
|
639
|
-
return latin1Slice(this, start, end);
|
|
640
|
-
case "base64":
|
|
641
|
-
return base64Slice(this, start, end);
|
|
642
|
-
case "ucs2":
|
|
643
|
-
case "ucs-2":
|
|
644
|
-
case "utf16le":
|
|
645
|
-
case "utf-16le":
|
|
646
|
-
return utf16leSlice(this, start, end);
|
|
647
|
-
default:
|
|
648
|
-
if (loweredCase)
|
|
649
|
-
throw new TypeError("Unknown encoding: " + encoding);
|
|
650
|
-
encoding = (encoding + "").toLowerCase();
|
|
651
|
-
loweredCase = true;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
Buffer3.prototype._isBuffer = true;
|
|
656
|
-
function swap(b, n, m) {
|
|
657
|
-
const i = b[n];
|
|
658
|
-
b[n] = b[m];
|
|
659
|
-
b[m] = i;
|
|
660
|
-
}
|
|
661
|
-
Buffer3.prototype.swap16 = function swap16() {
|
|
662
|
-
const len = this.length;
|
|
663
|
-
if (len % 2 !== 0) {
|
|
664
|
-
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
665
|
-
}
|
|
666
|
-
for (let i = 0; i < len; i += 2) {
|
|
667
|
-
swap(this, i, i + 1);
|
|
668
|
-
}
|
|
669
|
-
return this;
|
|
670
|
-
};
|
|
671
|
-
Buffer3.prototype.swap32 = function swap32() {
|
|
672
|
-
const len = this.length;
|
|
673
|
-
if (len % 4 !== 0) {
|
|
674
|
-
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
675
|
-
}
|
|
676
|
-
for (let i = 0; i < len; i += 4) {
|
|
677
|
-
swap(this, i, i + 3);
|
|
678
|
-
swap(this, i + 1, i + 2);
|
|
679
|
-
}
|
|
680
|
-
return this;
|
|
681
|
-
};
|
|
682
|
-
Buffer3.prototype.swap64 = function swap64() {
|
|
683
|
-
const len = this.length;
|
|
684
|
-
if (len % 8 !== 0) {
|
|
685
|
-
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
686
|
-
}
|
|
687
|
-
for (let i = 0; i < len; i += 8) {
|
|
688
|
-
swap(this, i, i + 7);
|
|
689
|
-
swap(this, i + 1, i + 6);
|
|
690
|
-
swap(this, i + 2, i + 5);
|
|
691
|
-
swap(this, i + 3, i + 4);
|
|
692
|
-
}
|
|
693
|
-
return this;
|
|
694
|
-
};
|
|
695
|
-
Buffer3.prototype.toString = function toString() {
|
|
696
|
-
const length = this.length;
|
|
697
|
-
if (length === 0)
|
|
698
|
-
return "";
|
|
699
|
-
if (arguments.length === 0)
|
|
700
|
-
return utf8Slice(this, 0, length);
|
|
701
|
-
return slowToString.apply(this, arguments);
|
|
702
|
-
};
|
|
703
|
-
Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
|
|
704
|
-
Buffer3.prototype.equals = function equals(b) {
|
|
705
|
-
if (!Buffer3.isBuffer(b))
|
|
706
|
-
throw new TypeError("Argument must be a Buffer");
|
|
707
|
-
if (this === b)
|
|
708
|
-
return true;
|
|
709
|
-
return Buffer3.compare(this, b) === 0;
|
|
710
|
-
};
|
|
711
|
-
Buffer3.prototype.inspect = function inspect() {
|
|
712
|
-
let str = "";
|
|
713
|
-
const max = exports$1.INSPECT_MAX_BYTES;
|
|
714
|
-
str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
715
|
-
if (this.length > max)
|
|
716
|
-
str += " ... ";
|
|
717
|
-
return "<Buffer " + str + ">";
|
|
718
|
-
};
|
|
719
|
-
if (customInspectSymbol) {
|
|
720
|
-
Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
|
|
721
|
-
}
|
|
722
|
-
Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
723
|
-
if (isInstance(target, Uint8Array)) {
|
|
724
|
-
target = Buffer3.from(target, target.offset, target.byteLength);
|
|
725
|
-
}
|
|
726
|
-
if (!Buffer3.isBuffer(target)) {
|
|
727
|
-
throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target);
|
|
728
|
-
}
|
|
729
|
-
if (start === void 0) {
|
|
730
|
-
start = 0;
|
|
731
|
-
}
|
|
732
|
-
if (end === void 0) {
|
|
733
|
-
end = target ? target.length : 0;
|
|
734
|
-
}
|
|
735
|
-
if (thisStart === void 0) {
|
|
736
|
-
thisStart = 0;
|
|
737
|
-
}
|
|
738
|
-
if (thisEnd === void 0) {
|
|
739
|
-
thisEnd = this.length;
|
|
740
|
-
}
|
|
741
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
742
|
-
throw new RangeError("out of range index");
|
|
743
|
-
}
|
|
744
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
745
|
-
return 0;
|
|
746
|
-
}
|
|
747
|
-
if (thisStart >= thisEnd) {
|
|
748
|
-
return -1;
|
|
749
|
-
}
|
|
750
|
-
if (start >= end) {
|
|
751
|
-
return 1;
|
|
752
|
-
}
|
|
753
|
-
start >>>= 0;
|
|
754
|
-
end >>>= 0;
|
|
755
|
-
thisStart >>>= 0;
|
|
756
|
-
thisEnd >>>= 0;
|
|
757
|
-
if (this === target)
|
|
758
|
-
return 0;
|
|
759
|
-
let x = thisEnd - thisStart;
|
|
760
|
-
let y = end - start;
|
|
761
|
-
const len = Math.min(x, y);
|
|
762
|
-
const thisCopy = this.slice(thisStart, thisEnd);
|
|
763
|
-
const targetCopy = target.slice(start, end);
|
|
764
|
-
for (let i = 0; i < len; ++i) {
|
|
765
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
766
|
-
x = thisCopy[i];
|
|
767
|
-
y = targetCopy[i];
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
if (x < y)
|
|
772
|
-
return -1;
|
|
773
|
-
if (y < x)
|
|
774
|
-
return 1;
|
|
775
|
-
return 0;
|
|
776
|
-
};
|
|
777
|
-
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
778
|
-
if (buffer.length === 0)
|
|
779
|
-
return -1;
|
|
780
|
-
if (typeof byteOffset === "string") {
|
|
781
|
-
encoding = byteOffset;
|
|
782
|
-
byteOffset = 0;
|
|
783
|
-
} else if (byteOffset > 2147483647) {
|
|
784
|
-
byteOffset = 2147483647;
|
|
785
|
-
} else if (byteOffset < -2147483648) {
|
|
786
|
-
byteOffset = -2147483648;
|
|
787
|
-
}
|
|
788
|
-
byteOffset = +byteOffset;
|
|
789
|
-
if (numberIsNaN(byteOffset)) {
|
|
790
|
-
byteOffset = dir ? 0 : buffer.length - 1;
|
|
791
|
-
}
|
|
792
|
-
if (byteOffset < 0)
|
|
793
|
-
byteOffset = buffer.length + byteOffset;
|
|
794
|
-
if (byteOffset >= buffer.length) {
|
|
795
|
-
if (dir)
|
|
796
|
-
return -1;
|
|
797
|
-
else
|
|
798
|
-
byteOffset = buffer.length - 1;
|
|
799
|
-
} else if (byteOffset < 0) {
|
|
800
|
-
if (dir)
|
|
801
|
-
byteOffset = 0;
|
|
802
|
-
else
|
|
803
|
-
return -1;
|
|
804
|
-
}
|
|
805
|
-
if (typeof val === "string") {
|
|
806
|
-
val = Buffer3.from(val, encoding);
|
|
807
|
-
}
|
|
808
|
-
if (Buffer3.isBuffer(val)) {
|
|
809
|
-
if (val.length === 0) {
|
|
810
|
-
return -1;
|
|
811
|
-
}
|
|
812
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
813
|
-
} else if (typeof val === "number") {
|
|
814
|
-
val = val & 255;
|
|
815
|
-
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
816
|
-
if (dir) {
|
|
817
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
818
|
-
} else {
|
|
819
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
823
|
-
}
|
|
824
|
-
throw new TypeError("val must be string, number or Buffer");
|
|
825
|
-
}
|
|
826
|
-
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
827
|
-
let indexSize = 1;
|
|
828
|
-
let arrLength = arr.length;
|
|
829
|
-
let valLength = val.length;
|
|
830
|
-
if (encoding !== void 0) {
|
|
831
|
-
encoding = String(encoding).toLowerCase();
|
|
832
|
-
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
833
|
-
if (arr.length < 2 || val.length < 2) {
|
|
834
|
-
return -1;
|
|
835
|
-
}
|
|
836
|
-
indexSize = 2;
|
|
837
|
-
arrLength /= 2;
|
|
838
|
-
valLength /= 2;
|
|
839
|
-
byteOffset /= 2;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
function read(buf, i2) {
|
|
843
|
-
if (indexSize === 1) {
|
|
844
|
-
return buf[i2];
|
|
845
|
-
} else {
|
|
846
|
-
return buf.readUInt16BE(i2 * indexSize);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
let i;
|
|
850
|
-
if (dir) {
|
|
851
|
-
let foundIndex = -1;
|
|
852
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
853
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
854
|
-
if (foundIndex === -1)
|
|
855
|
-
foundIndex = i;
|
|
856
|
-
if (i - foundIndex + 1 === valLength)
|
|
857
|
-
return foundIndex * indexSize;
|
|
858
|
-
} else {
|
|
859
|
-
if (foundIndex !== -1)
|
|
860
|
-
i -= i - foundIndex;
|
|
861
|
-
foundIndex = -1;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
} else {
|
|
865
|
-
if (byteOffset + valLength > arrLength)
|
|
866
|
-
byteOffset = arrLength - valLength;
|
|
867
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
868
|
-
let found = true;
|
|
869
|
-
for (let j = 0; j < valLength; j++) {
|
|
870
|
-
if (read(arr, i + j) !== read(val, j)) {
|
|
871
|
-
found = false;
|
|
872
|
-
break;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
if (found)
|
|
876
|
-
return i;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
return -1;
|
|
880
|
-
}
|
|
881
|
-
Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
882
|
-
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
883
|
-
};
|
|
884
|
-
Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
885
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
886
|
-
};
|
|
887
|
-
Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
888
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
889
|
-
};
|
|
890
|
-
function hexWrite(buf, string, offset, length) {
|
|
891
|
-
offset = Number(offset) || 0;
|
|
892
|
-
const remaining = buf.length - offset;
|
|
893
|
-
if (!length) {
|
|
894
|
-
length = remaining;
|
|
895
|
-
} else {
|
|
896
|
-
length = Number(length);
|
|
897
|
-
if (length > remaining) {
|
|
898
|
-
length = remaining;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
const strLen = string.length;
|
|
902
|
-
if (length > strLen / 2) {
|
|
903
|
-
length = strLen / 2;
|
|
904
|
-
}
|
|
905
|
-
let i;
|
|
906
|
-
for (i = 0; i < length; ++i) {
|
|
907
|
-
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
908
|
-
if (numberIsNaN(parsed))
|
|
909
|
-
return i;
|
|
910
|
-
buf[offset + i] = parsed;
|
|
911
|
-
}
|
|
912
|
-
return i;
|
|
913
|
-
}
|
|
914
|
-
function utf8Write(buf, string, offset, length) {
|
|
915
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
916
|
-
}
|
|
917
|
-
function asciiWrite(buf, string, offset, length) {
|
|
918
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
919
|
-
}
|
|
920
|
-
function base64Write(buf, string, offset, length) {
|
|
921
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
922
|
-
}
|
|
923
|
-
function ucs2Write(buf, string, offset, length) {
|
|
924
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
925
|
-
}
|
|
926
|
-
Buffer3.prototype.write = function write(string, offset, length, encoding) {
|
|
927
|
-
if (offset === void 0) {
|
|
928
|
-
encoding = "utf8";
|
|
929
|
-
length = this.length;
|
|
930
|
-
offset = 0;
|
|
931
|
-
} else if (length === void 0 && typeof offset === "string") {
|
|
932
|
-
encoding = offset;
|
|
933
|
-
length = this.length;
|
|
934
|
-
offset = 0;
|
|
935
|
-
} else if (isFinite(offset)) {
|
|
936
|
-
offset = offset >>> 0;
|
|
937
|
-
if (isFinite(length)) {
|
|
938
|
-
length = length >>> 0;
|
|
939
|
-
if (encoding === void 0)
|
|
940
|
-
encoding = "utf8";
|
|
941
|
-
} else {
|
|
942
|
-
encoding = length;
|
|
943
|
-
length = void 0;
|
|
944
|
-
}
|
|
945
|
-
} else {
|
|
946
|
-
throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
947
|
-
}
|
|
948
|
-
const remaining = this.length - offset;
|
|
949
|
-
if (length === void 0 || length > remaining)
|
|
950
|
-
length = remaining;
|
|
951
|
-
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
952
|
-
throw new RangeError("Attempt to write outside buffer bounds");
|
|
953
|
-
}
|
|
954
|
-
if (!encoding)
|
|
955
|
-
encoding = "utf8";
|
|
956
|
-
let loweredCase = false;
|
|
957
|
-
for (; ; ) {
|
|
958
|
-
switch (encoding) {
|
|
959
|
-
case "hex":
|
|
960
|
-
return hexWrite(this, string, offset, length);
|
|
961
|
-
case "utf8":
|
|
962
|
-
case "utf-8":
|
|
963
|
-
return utf8Write(this, string, offset, length);
|
|
964
|
-
case "ascii":
|
|
965
|
-
case "latin1":
|
|
966
|
-
case "binary":
|
|
967
|
-
return asciiWrite(this, string, offset, length);
|
|
968
|
-
case "base64":
|
|
969
|
-
return base64Write(this, string, offset, length);
|
|
970
|
-
case "ucs2":
|
|
971
|
-
case "ucs-2":
|
|
972
|
-
case "utf16le":
|
|
973
|
-
case "utf-16le":
|
|
974
|
-
return ucs2Write(this, string, offset, length);
|
|
975
|
-
default:
|
|
976
|
-
if (loweredCase)
|
|
977
|
-
throw new TypeError("Unknown encoding: " + encoding);
|
|
978
|
-
encoding = ("" + encoding).toLowerCase();
|
|
979
|
-
loweredCase = true;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
Buffer3.prototype.toJSON = function toJSON() {
|
|
984
|
-
return {
|
|
985
|
-
type: "Buffer",
|
|
986
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
987
|
-
};
|
|
988
|
-
};
|
|
989
|
-
function base64Slice(buf, start, end) {
|
|
990
|
-
if (start === 0 && end === buf.length) {
|
|
991
|
-
return base64.fromByteArray(buf);
|
|
992
|
-
} else {
|
|
993
|
-
return base64.fromByteArray(buf.slice(start, end));
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
function utf8Slice(buf, start, end) {
|
|
997
|
-
end = Math.min(buf.length, end);
|
|
998
|
-
const res = [];
|
|
999
|
-
let i = start;
|
|
1000
|
-
while (i < end) {
|
|
1001
|
-
const firstByte = buf[i];
|
|
1002
|
-
let codePoint = null;
|
|
1003
|
-
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
1004
|
-
if (i + bytesPerSequence <= end) {
|
|
1005
|
-
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1006
|
-
switch (bytesPerSequence) {
|
|
1007
|
-
case 1:
|
|
1008
|
-
if (firstByte < 128) {
|
|
1009
|
-
codePoint = firstByte;
|
|
1010
|
-
}
|
|
1011
|
-
break;
|
|
1012
|
-
case 2:
|
|
1013
|
-
secondByte = buf[i + 1];
|
|
1014
|
-
if ((secondByte & 192) === 128) {
|
|
1015
|
-
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
1016
|
-
if (tempCodePoint > 127) {
|
|
1017
|
-
codePoint = tempCodePoint;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
break;
|
|
1021
|
-
case 3:
|
|
1022
|
-
secondByte = buf[i + 1];
|
|
1023
|
-
thirdByte = buf[i + 2];
|
|
1024
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
1025
|
-
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
1026
|
-
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
1027
|
-
codePoint = tempCodePoint;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
break;
|
|
1031
|
-
case 4:
|
|
1032
|
-
secondByte = buf[i + 1];
|
|
1033
|
-
thirdByte = buf[i + 2];
|
|
1034
|
-
fourthByte = buf[i + 3];
|
|
1035
|
-
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
1036
|
-
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
1037
|
-
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
1038
|
-
codePoint = tempCodePoint;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
if (codePoint === null) {
|
|
1044
|
-
codePoint = 65533;
|
|
1045
|
-
bytesPerSequence = 1;
|
|
1046
|
-
} else if (codePoint > 65535) {
|
|
1047
|
-
codePoint -= 65536;
|
|
1048
|
-
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
1049
|
-
codePoint = 56320 | codePoint & 1023;
|
|
1050
|
-
}
|
|
1051
|
-
res.push(codePoint);
|
|
1052
|
-
i += bytesPerSequence;
|
|
1053
|
-
}
|
|
1054
|
-
return decodeCodePointsArray(res);
|
|
1055
|
-
}
|
|
1056
|
-
const MAX_ARGUMENTS_LENGTH = 4096;
|
|
1057
|
-
function decodeCodePointsArray(codePoints) {
|
|
1058
|
-
const len = codePoints.length;
|
|
1059
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1060
|
-
return String.fromCharCode.apply(String, codePoints);
|
|
1061
|
-
}
|
|
1062
|
-
let res = "";
|
|
1063
|
-
let i = 0;
|
|
1064
|
-
while (i < len) {
|
|
1065
|
-
res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
|
1066
|
-
}
|
|
1067
|
-
return res;
|
|
1068
|
-
}
|
|
1069
|
-
function asciiSlice(buf, start, end) {
|
|
1070
|
-
let ret = "";
|
|
1071
|
-
end = Math.min(buf.length, end);
|
|
1072
|
-
for (let i = start; i < end; ++i) {
|
|
1073
|
-
ret += String.fromCharCode(buf[i] & 127);
|
|
1074
|
-
}
|
|
1075
|
-
return ret;
|
|
1076
|
-
}
|
|
1077
|
-
function latin1Slice(buf, start, end) {
|
|
1078
|
-
let ret = "";
|
|
1079
|
-
end = Math.min(buf.length, end);
|
|
1080
|
-
for (let i = start; i < end; ++i) {
|
|
1081
|
-
ret += String.fromCharCode(buf[i]);
|
|
1082
|
-
}
|
|
1083
|
-
return ret;
|
|
1084
|
-
}
|
|
1085
|
-
function hexSlice(buf, start, end) {
|
|
1086
|
-
const len = buf.length;
|
|
1087
|
-
if (!start || start < 0)
|
|
1088
|
-
start = 0;
|
|
1089
|
-
if (!end || end < 0 || end > len)
|
|
1090
|
-
end = len;
|
|
1091
|
-
let out = "";
|
|
1092
|
-
for (let i = start; i < end; ++i) {
|
|
1093
|
-
out += hexSliceLookupTable[buf[i]];
|
|
1094
|
-
}
|
|
1095
|
-
return out;
|
|
1096
|
-
}
|
|
1097
|
-
function utf16leSlice(buf, start, end) {
|
|
1098
|
-
const bytes = buf.slice(start, end);
|
|
1099
|
-
let res = "";
|
|
1100
|
-
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1101
|
-
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1102
|
-
}
|
|
1103
|
-
return res;
|
|
1104
|
-
}
|
|
1105
|
-
Buffer3.prototype.slice = function slice(start, end) {
|
|
1106
|
-
const len = this.length;
|
|
1107
|
-
start = ~~start;
|
|
1108
|
-
end = end === void 0 ? len : ~~end;
|
|
1109
|
-
if (start < 0) {
|
|
1110
|
-
start += len;
|
|
1111
|
-
if (start < 0)
|
|
1112
|
-
start = 0;
|
|
1113
|
-
} else if (start > len) {
|
|
1114
|
-
start = len;
|
|
1115
|
-
}
|
|
1116
|
-
if (end < 0) {
|
|
1117
|
-
end += len;
|
|
1118
|
-
if (end < 0)
|
|
1119
|
-
end = 0;
|
|
1120
|
-
} else if (end > len) {
|
|
1121
|
-
end = len;
|
|
1122
|
-
}
|
|
1123
|
-
if (end < start)
|
|
1124
|
-
end = start;
|
|
1125
|
-
const newBuf = this.subarray(start, end);
|
|
1126
|
-
Object.setPrototypeOf(newBuf, Buffer3.prototype);
|
|
1127
|
-
return newBuf;
|
|
1128
|
-
};
|
|
1129
|
-
function checkOffset(offset, ext, length) {
|
|
1130
|
-
if (offset % 1 !== 0 || offset < 0)
|
|
1131
|
-
throw new RangeError("offset is not uint");
|
|
1132
|
-
if (offset + ext > length)
|
|
1133
|
-
throw new RangeError("Trying to access beyond buffer length");
|
|
1134
|
-
}
|
|
1135
|
-
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1136
|
-
offset = offset >>> 0;
|
|
1137
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1138
|
-
if (!noAssert)
|
|
1139
|
-
checkOffset(offset, byteLength2, this.length);
|
|
1140
|
-
let val = this[offset];
|
|
1141
|
-
let mul = 1;
|
|
1142
|
-
let i = 0;
|
|
1143
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1144
|
-
val += this[offset + i] * mul;
|
|
1145
|
-
}
|
|
1146
|
-
return val;
|
|
1147
|
-
};
|
|
1148
|
-
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1149
|
-
offset = offset >>> 0;
|
|
1150
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1151
|
-
if (!noAssert) {
|
|
1152
|
-
checkOffset(offset, byteLength2, this.length);
|
|
1153
|
-
}
|
|
1154
|
-
let val = this[offset + --byteLength2];
|
|
1155
|
-
let mul = 1;
|
|
1156
|
-
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1157
|
-
val += this[offset + --byteLength2] * mul;
|
|
1158
|
-
}
|
|
1159
|
-
return val;
|
|
1160
|
-
};
|
|
1161
|
-
Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1162
|
-
offset = offset >>> 0;
|
|
1163
|
-
if (!noAssert)
|
|
1164
|
-
checkOffset(offset, 1, this.length);
|
|
1165
|
-
return this[offset];
|
|
1166
|
-
};
|
|
1167
|
-
Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1168
|
-
offset = offset >>> 0;
|
|
1169
|
-
if (!noAssert)
|
|
1170
|
-
checkOffset(offset, 2, this.length);
|
|
1171
|
-
return this[offset] | this[offset + 1] << 8;
|
|
1172
|
-
};
|
|
1173
|
-
Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1174
|
-
offset = offset >>> 0;
|
|
1175
|
-
if (!noAssert)
|
|
1176
|
-
checkOffset(offset, 2, this.length);
|
|
1177
|
-
return this[offset] << 8 | this[offset + 1];
|
|
1178
|
-
};
|
|
1179
|
-
Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1180
|
-
offset = offset >>> 0;
|
|
1181
|
-
if (!noAssert)
|
|
1182
|
-
checkOffset(offset, 4, this.length);
|
|
1183
|
-
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1184
|
-
};
|
|
1185
|
-
Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1186
|
-
offset = offset >>> 0;
|
|
1187
|
-
if (!noAssert)
|
|
1188
|
-
checkOffset(offset, 4, this.length);
|
|
1189
|
-
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1190
|
-
};
|
|
1191
|
-
Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1192
|
-
offset = offset >>> 0;
|
|
1193
|
-
validateNumber(offset, "offset");
|
|
1194
|
-
const first = this[offset];
|
|
1195
|
-
const last = this[offset + 7];
|
|
1196
|
-
if (first === void 0 || last === void 0) {
|
|
1197
|
-
boundsError(offset, this.length - 8);
|
|
1198
|
-
}
|
|
1199
|
-
const lo = first + this[++offset] * __pow(2, 8) + this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 24);
|
|
1200
|
-
const hi = this[++offset] + this[++offset] * __pow(2, 8) + this[++offset] * __pow(2, 16) + last * __pow(2, 24);
|
|
1201
|
-
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1202
|
-
});
|
|
1203
|
-
Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1204
|
-
offset = offset >>> 0;
|
|
1205
|
-
validateNumber(offset, "offset");
|
|
1206
|
-
const first = this[offset];
|
|
1207
|
-
const last = this[offset + 7];
|
|
1208
|
-
if (first === void 0 || last === void 0) {
|
|
1209
|
-
boundsError(offset, this.length - 8);
|
|
1210
|
-
}
|
|
1211
|
-
const hi = first * __pow(2, 24) + this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 8) + this[++offset];
|
|
1212
|
-
const lo = this[++offset] * __pow(2, 24) + this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 8) + last;
|
|
1213
|
-
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1214
|
-
});
|
|
1215
|
-
Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1216
|
-
offset = offset >>> 0;
|
|
1217
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1218
|
-
if (!noAssert)
|
|
1219
|
-
checkOffset(offset, byteLength2, this.length);
|
|
1220
|
-
let val = this[offset];
|
|
1221
|
-
let mul = 1;
|
|
1222
|
-
let i = 0;
|
|
1223
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1224
|
-
val += this[offset + i] * mul;
|
|
1225
|
-
}
|
|
1226
|
-
mul *= 128;
|
|
1227
|
-
if (val >= mul)
|
|
1228
|
-
val -= Math.pow(2, 8 * byteLength2);
|
|
1229
|
-
return val;
|
|
1230
|
-
};
|
|
1231
|
-
Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1232
|
-
offset = offset >>> 0;
|
|
1233
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1234
|
-
if (!noAssert)
|
|
1235
|
-
checkOffset(offset, byteLength2, this.length);
|
|
1236
|
-
let i = byteLength2;
|
|
1237
|
-
let mul = 1;
|
|
1238
|
-
let val = this[offset + --i];
|
|
1239
|
-
while (i > 0 && (mul *= 256)) {
|
|
1240
|
-
val += this[offset + --i] * mul;
|
|
1241
|
-
}
|
|
1242
|
-
mul *= 128;
|
|
1243
|
-
if (val >= mul)
|
|
1244
|
-
val -= Math.pow(2, 8 * byteLength2);
|
|
1245
|
-
return val;
|
|
1246
|
-
};
|
|
1247
|
-
Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1248
|
-
offset = offset >>> 0;
|
|
1249
|
-
if (!noAssert)
|
|
1250
|
-
checkOffset(offset, 1, this.length);
|
|
1251
|
-
if (!(this[offset] & 128))
|
|
1252
|
-
return this[offset];
|
|
1253
|
-
return (255 - this[offset] + 1) * -1;
|
|
1254
|
-
};
|
|
1255
|
-
Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1256
|
-
offset = offset >>> 0;
|
|
1257
|
-
if (!noAssert)
|
|
1258
|
-
checkOffset(offset, 2, this.length);
|
|
1259
|
-
const val = this[offset] | this[offset + 1] << 8;
|
|
1260
|
-
return val & 32768 ? val | 4294901760 : val;
|
|
1261
|
-
};
|
|
1262
|
-
Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1263
|
-
offset = offset >>> 0;
|
|
1264
|
-
if (!noAssert)
|
|
1265
|
-
checkOffset(offset, 2, this.length);
|
|
1266
|
-
const val = this[offset + 1] | this[offset] << 8;
|
|
1267
|
-
return val & 32768 ? val | 4294901760 : val;
|
|
1268
|
-
};
|
|
1269
|
-
Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1270
|
-
offset = offset >>> 0;
|
|
1271
|
-
if (!noAssert)
|
|
1272
|
-
checkOffset(offset, 4, this.length);
|
|
1273
|
-
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1274
|
-
};
|
|
1275
|
-
Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1276
|
-
offset = offset >>> 0;
|
|
1277
|
-
if (!noAssert)
|
|
1278
|
-
checkOffset(offset, 4, this.length);
|
|
1279
|
-
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1280
|
-
};
|
|
1281
|
-
Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1282
|
-
offset = offset >>> 0;
|
|
1283
|
-
validateNumber(offset, "offset");
|
|
1284
|
-
const first = this[offset];
|
|
1285
|
-
const last = this[offset + 7];
|
|
1286
|
-
if (first === void 0 || last === void 0) {
|
|
1287
|
-
boundsError(offset, this.length - 8);
|
|
1288
|
-
}
|
|
1289
|
-
const val = this[offset + 4] + this[offset + 5] * __pow(2, 8) + this[offset + 6] * __pow(2, 16) + (last << 24);
|
|
1290
|
-
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * __pow(2, 8) + this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 24));
|
|
1291
|
-
});
|
|
1292
|
-
Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(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 = (first << 24) + // Overflow
|
|
1301
|
-
this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 8) + this[++offset];
|
|
1302
|
-
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * __pow(2, 24) + this[++offset] * __pow(2, 16) + this[++offset] * __pow(2, 8) + last);
|
|
1303
|
-
});
|
|
1304
|
-
Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1305
|
-
offset = offset >>> 0;
|
|
1306
|
-
if (!noAssert)
|
|
1307
|
-
checkOffset(offset, 4, this.length);
|
|
1308
|
-
return ieee754.read(this, offset, true, 23, 4);
|
|
1309
|
-
};
|
|
1310
|
-
Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1311
|
-
offset = offset >>> 0;
|
|
1312
|
-
if (!noAssert)
|
|
1313
|
-
checkOffset(offset, 4, this.length);
|
|
1314
|
-
return ieee754.read(this, offset, false, 23, 4);
|
|
1315
|
-
};
|
|
1316
|
-
Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1317
|
-
offset = offset >>> 0;
|
|
1318
|
-
if (!noAssert)
|
|
1319
|
-
checkOffset(offset, 8, this.length);
|
|
1320
|
-
return ieee754.read(this, offset, true, 52, 8);
|
|
1321
|
-
};
|
|
1322
|
-
Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1323
|
-
offset = offset >>> 0;
|
|
1324
|
-
if (!noAssert)
|
|
1325
|
-
checkOffset(offset, 8, this.length);
|
|
1326
|
-
return ieee754.read(this, offset, false, 52, 8);
|
|
1327
|
-
};
|
|
1328
|
-
function checkInt(buf, value, offset, ext, max, min) {
|
|
1329
|
-
if (!Buffer3.isBuffer(buf))
|
|
1330
|
-
throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1331
|
-
if (value > max || value < min)
|
|
1332
|
-
throw new RangeError('"value" argument is out of bounds');
|
|
1333
|
-
if (offset + ext > buf.length)
|
|
1334
|
-
throw new RangeError("Index out of range");
|
|
1335
|
-
}
|
|
1336
|
-
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1337
|
-
value = +value;
|
|
1338
|
-
offset = offset >>> 0;
|
|
1339
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1340
|
-
if (!noAssert) {
|
|
1341
|
-
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1342
|
-
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1343
|
-
}
|
|
1344
|
-
let mul = 1;
|
|
1345
|
-
let i = 0;
|
|
1346
|
-
this[offset] = value & 255;
|
|
1347
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1348
|
-
this[offset + i] = value / mul & 255;
|
|
1349
|
-
}
|
|
1350
|
-
return offset + byteLength2;
|
|
1351
|
-
};
|
|
1352
|
-
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1353
|
-
value = +value;
|
|
1354
|
-
offset = offset >>> 0;
|
|
1355
|
-
byteLength2 = byteLength2 >>> 0;
|
|
1356
|
-
if (!noAssert) {
|
|
1357
|
-
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1358
|
-
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1359
|
-
}
|
|
1360
|
-
let i = byteLength2 - 1;
|
|
1361
|
-
let mul = 1;
|
|
1362
|
-
this[offset + i] = value & 255;
|
|
1363
|
-
while (--i >= 0 && (mul *= 256)) {
|
|
1364
|
-
this[offset + i] = value / mul & 255;
|
|
1365
|
-
}
|
|
1366
|
-
return offset + byteLength2;
|
|
1367
|
-
};
|
|
1368
|
-
Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1369
|
-
value = +value;
|
|
1370
|
-
offset = offset >>> 0;
|
|
1371
|
-
if (!noAssert)
|
|
1372
|
-
checkInt(this, value, offset, 1, 255, 0);
|
|
1373
|
-
this[offset] = value & 255;
|
|
1374
|
-
return offset + 1;
|
|
1375
|
-
};
|
|
1376
|
-
Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1377
|
-
value = +value;
|
|
1378
|
-
offset = offset >>> 0;
|
|
1379
|
-
if (!noAssert)
|
|
1380
|
-
checkInt(this, value, offset, 2, 65535, 0);
|
|
1381
|
-
this[offset] = value & 255;
|
|
1382
|
-
this[offset + 1] = value >>> 8;
|
|
1383
|
-
return offset + 2;
|
|
1384
|
-
};
|
|
1385
|
-
Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1386
|
-
value = +value;
|
|
1387
|
-
offset = offset >>> 0;
|
|
1388
|
-
if (!noAssert)
|
|
1389
|
-
checkInt(this, value, offset, 2, 65535, 0);
|
|
1390
|
-
this[offset] = value >>> 8;
|
|
1391
|
-
this[offset + 1] = value & 255;
|
|
1392
|
-
return offset + 2;
|
|
1393
|
-
};
|
|
1394
|
-
Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1395
|
-
value = +value;
|
|
1396
|
-
offset = offset >>> 0;
|
|
1397
|
-
if (!noAssert)
|
|
1398
|
-
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1399
|
-
this[offset + 3] = value >>> 24;
|
|
1400
|
-
this[offset + 2] = value >>> 16;
|
|
1401
|
-
this[offset + 1] = value >>> 8;
|
|
1402
|
-
this[offset] = value & 255;
|
|
1403
|
-
return offset + 4;
|
|
1404
|
-
};
|
|
1405
|
-
Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1406
|
-
value = +value;
|
|
1407
|
-
offset = offset >>> 0;
|
|
1408
|
-
if (!noAssert)
|
|
1409
|
-
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1410
|
-
this[offset] = value >>> 24;
|
|
1411
|
-
this[offset + 1] = value >>> 16;
|
|
1412
|
-
this[offset + 2] = value >>> 8;
|
|
1413
|
-
this[offset + 3] = value & 255;
|
|
1414
|
-
return offset + 4;
|
|
1415
|
-
};
|
|
1416
|
-
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1417
|
-
checkIntBI(value, min, max, buf, offset, 7);
|
|
1418
|
-
let lo = Number(value & BigInt(4294967295));
|
|
1419
|
-
buf[offset++] = lo;
|
|
1420
|
-
lo = lo >> 8;
|
|
1421
|
-
buf[offset++] = lo;
|
|
1422
|
-
lo = lo >> 8;
|
|
1423
|
-
buf[offset++] = lo;
|
|
1424
|
-
lo = lo >> 8;
|
|
1425
|
-
buf[offset++] = lo;
|
|
1426
|
-
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1427
|
-
buf[offset++] = hi;
|
|
1428
|
-
hi = hi >> 8;
|
|
1429
|
-
buf[offset++] = hi;
|
|
1430
|
-
hi = hi >> 8;
|
|
1431
|
-
buf[offset++] = hi;
|
|
1432
|
-
hi = hi >> 8;
|
|
1433
|
-
buf[offset++] = hi;
|
|
1434
|
-
return offset;
|
|
1435
|
-
}
|
|
1436
|
-
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1437
|
-
checkIntBI(value, min, max, buf, offset, 7);
|
|
1438
|
-
let lo = Number(value & BigInt(4294967295));
|
|
1439
|
-
buf[offset + 7] = lo;
|
|
1440
|
-
lo = lo >> 8;
|
|
1441
|
-
buf[offset + 6] = lo;
|
|
1442
|
-
lo = lo >> 8;
|
|
1443
|
-
buf[offset + 5] = lo;
|
|
1444
|
-
lo = lo >> 8;
|
|
1445
|
-
buf[offset + 4] = lo;
|
|
1446
|
-
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1447
|
-
buf[offset + 3] = hi;
|
|
1448
|
-
hi = hi >> 8;
|
|
1449
|
-
buf[offset + 2] = hi;
|
|
1450
|
-
hi = hi >> 8;
|
|
1451
|
-
buf[offset + 1] = hi;
|
|
1452
|
-
hi = hi >> 8;
|
|
1453
|
-
buf[offset] = hi;
|
|
1454
|
-
return offset + 8;
|
|
1455
|
-
}
|
|
1456
|
-
Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1457
|
-
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1458
|
-
});
|
|
1459
|
-
Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1460
|
-
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1461
|
-
});
|
|
1462
|
-
Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1463
|
-
value = +value;
|
|
1464
|
-
offset = offset >>> 0;
|
|
1465
|
-
if (!noAssert) {
|
|
1466
|
-
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1467
|
-
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1468
|
-
}
|
|
1469
|
-
let i = 0;
|
|
1470
|
-
let mul = 1;
|
|
1471
|
-
let sub = 0;
|
|
1472
|
-
this[offset] = value & 255;
|
|
1473
|
-
while (++i < byteLength2 && (mul *= 256)) {
|
|
1474
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1475
|
-
sub = 1;
|
|
1476
|
-
}
|
|
1477
|
-
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1478
|
-
}
|
|
1479
|
-
return offset + byteLength2;
|
|
1480
|
-
};
|
|
1481
|
-
Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1482
|
-
value = +value;
|
|
1483
|
-
offset = offset >>> 0;
|
|
1484
|
-
if (!noAssert) {
|
|
1485
|
-
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1486
|
-
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1487
|
-
}
|
|
1488
|
-
let i = byteLength2 - 1;
|
|
1489
|
-
let mul = 1;
|
|
1490
|
-
let sub = 0;
|
|
1491
|
-
this[offset + i] = value & 255;
|
|
1492
|
-
while (--i >= 0 && (mul *= 256)) {
|
|
1493
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1494
|
-
sub = 1;
|
|
1495
|
-
}
|
|
1496
|
-
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1497
|
-
}
|
|
1498
|
-
return offset + byteLength2;
|
|
1499
|
-
};
|
|
1500
|
-
Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1501
|
-
value = +value;
|
|
1502
|
-
offset = offset >>> 0;
|
|
1503
|
-
if (!noAssert)
|
|
1504
|
-
checkInt(this, value, offset, 1, 127, -128);
|
|
1505
|
-
if (value < 0)
|
|
1506
|
-
value = 255 + value + 1;
|
|
1507
|
-
this[offset] = value & 255;
|
|
1508
|
-
return offset + 1;
|
|
1509
|
-
};
|
|
1510
|
-
Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1511
|
-
value = +value;
|
|
1512
|
-
offset = offset >>> 0;
|
|
1513
|
-
if (!noAssert)
|
|
1514
|
-
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1515
|
-
this[offset] = value & 255;
|
|
1516
|
-
this[offset + 1] = value >>> 8;
|
|
1517
|
-
return offset + 2;
|
|
1518
|
-
};
|
|
1519
|
-
Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1520
|
-
value = +value;
|
|
1521
|
-
offset = offset >>> 0;
|
|
1522
|
-
if (!noAssert)
|
|
1523
|
-
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1524
|
-
this[offset] = value >>> 8;
|
|
1525
|
-
this[offset + 1] = value & 255;
|
|
1526
|
-
return offset + 2;
|
|
1527
|
-
};
|
|
1528
|
-
Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1529
|
-
value = +value;
|
|
1530
|
-
offset = offset >>> 0;
|
|
1531
|
-
if (!noAssert)
|
|
1532
|
-
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1533
|
-
this[offset] = value & 255;
|
|
1534
|
-
this[offset + 1] = value >>> 8;
|
|
1535
|
-
this[offset + 2] = value >>> 16;
|
|
1536
|
-
this[offset + 3] = value >>> 24;
|
|
1537
|
-
return offset + 4;
|
|
1538
|
-
};
|
|
1539
|
-
Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1540
|
-
value = +value;
|
|
1541
|
-
offset = offset >>> 0;
|
|
1542
|
-
if (!noAssert)
|
|
1543
|
-
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1544
|
-
if (value < 0)
|
|
1545
|
-
value = 4294967295 + value + 1;
|
|
1546
|
-
this[offset] = value >>> 24;
|
|
1547
|
-
this[offset + 1] = value >>> 16;
|
|
1548
|
-
this[offset + 2] = value >>> 8;
|
|
1549
|
-
this[offset + 3] = value & 255;
|
|
1550
|
-
return offset + 4;
|
|
1551
|
-
};
|
|
1552
|
-
Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1553
|
-
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1554
|
-
});
|
|
1555
|
-
Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1556
|
-
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1557
|
-
});
|
|
1558
|
-
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1559
|
-
if (offset + ext > buf.length)
|
|
1560
|
-
throw new RangeError("Index out of range");
|
|
1561
|
-
if (offset < 0)
|
|
1562
|
-
throw new RangeError("Index out of range");
|
|
1563
|
-
}
|
|
1564
|
-
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1565
|
-
value = +value;
|
|
1566
|
-
offset = offset >>> 0;
|
|
1567
|
-
if (!noAssert) {
|
|
1568
|
-
checkIEEE754(buf, value, offset, 4);
|
|
1569
|
-
}
|
|
1570
|
-
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1571
|
-
return offset + 4;
|
|
1572
|
-
}
|
|
1573
|
-
Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1574
|
-
return writeFloat(this, value, offset, true, noAssert);
|
|
1575
|
-
};
|
|
1576
|
-
Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1577
|
-
return writeFloat(this, value, offset, false, noAssert);
|
|
1578
|
-
};
|
|
1579
|
-
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1580
|
-
value = +value;
|
|
1581
|
-
offset = offset >>> 0;
|
|
1582
|
-
if (!noAssert) {
|
|
1583
|
-
checkIEEE754(buf, value, offset, 8);
|
|
1584
|
-
}
|
|
1585
|
-
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1586
|
-
return offset + 8;
|
|
1587
|
-
}
|
|
1588
|
-
Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1589
|
-
return writeDouble(this, value, offset, true, noAssert);
|
|
1590
|
-
};
|
|
1591
|
-
Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1592
|
-
return writeDouble(this, value, offset, false, noAssert);
|
|
1593
|
-
};
|
|
1594
|
-
Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1595
|
-
if (!Buffer3.isBuffer(target))
|
|
1596
|
-
throw new TypeError("argument should be a Buffer");
|
|
1597
|
-
if (!start)
|
|
1598
|
-
start = 0;
|
|
1599
|
-
if (!end && end !== 0)
|
|
1600
|
-
end = this.length;
|
|
1601
|
-
if (targetStart >= target.length)
|
|
1602
|
-
targetStart = target.length;
|
|
1603
|
-
if (!targetStart)
|
|
1604
|
-
targetStart = 0;
|
|
1605
|
-
if (end > 0 && end < start)
|
|
1606
|
-
end = start;
|
|
1607
|
-
if (end === start)
|
|
1608
|
-
return 0;
|
|
1609
|
-
if (target.length === 0 || this.length === 0)
|
|
1610
|
-
return 0;
|
|
1611
|
-
if (targetStart < 0) {
|
|
1612
|
-
throw new RangeError("targetStart out of bounds");
|
|
1613
|
-
}
|
|
1614
|
-
if (start < 0 || start >= this.length)
|
|
1615
|
-
throw new RangeError("Index out of range");
|
|
1616
|
-
if (end < 0)
|
|
1617
|
-
throw new RangeError("sourceEnd out of bounds");
|
|
1618
|
-
if (end > this.length)
|
|
1619
|
-
end = this.length;
|
|
1620
|
-
if (target.length - targetStart < end - start) {
|
|
1621
|
-
end = target.length - targetStart + start;
|
|
1622
|
-
}
|
|
1623
|
-
const len = end - start;
|
|
1624
|
-
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1625
|
-
this.copyWithin(targetStart, start, end);
|
|
1626
|
-
} else {
|
|
1627
|
-
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
1628
|
-
}
|
|
1629
|
-
return len;
|
|
1630
|
-
};
|
|
1631
|
-
Buffer3.prototype.fill = function fill(val, start, end, encoding) {
|
|
1632
|
-
if (typeof val === "string") {
|
|
1633
|
-
if (typeof start === "string") {
|
|
1634
|
-
encoding = start;
|
|
1635
|
-
start = 0;
|
|
1636
|
-
end = this.length;
|
|
1637
|
-
} else if (typeof end === "string") {
|
|
1638
|
-
encoding = end;
|
|
1639
|
-
end = this.length;
|
|
1640
|
-
}
|
|
1641
|
-
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1642
|
-
throw new TypeError("encoding must be a string");
|
|
1643
|
-
}
|
|
1644
|
-
if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
|
|
1645
|
-
throw new TypeError("Unknown encoding: " + encoding);
|
|
1646
|
-
}
|
|
1647
|
-
if (val.length === 1) {
|
|
1648
|
-
const code = val.charCodeAt(0);
|
|
1649
|
-
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1650
|
-
val = code;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
} else if (typeof val === "number") {
|
|
1654
|
-
val = val & 255;
|
|
1655
|
-
} else if (typeof val === "boolean") {
|
|
1656
|
-
val = Number(val);
|
|
1657
|
-
}
|
|
1658
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
1659
|
-
throw new RangeError("Out of range index");
|
|
1660
|
-
}
|
|
1661
|
-
if (end <= start) {
|
|
1662
|
-
return this;
|
|
1663
|
-
}
|
|
1664
|
-
start = start >>> 0;
|
|
1665
|
-
end = end === void 0 ? this.length : end >>> 0;
|
|
1666
|
-
if (!val)
|
|
1667
|
-
val = 0;
|
|
1668
|
-
let i;
|
|
1669
|
-
if (typeof val === "number") {
|
|
1670
|
-
for (i = start; i < end; ++i) {
|
|
1671
|
-
this[i] = val;
|
|
1672
|
-
}
|
|
1673
|
-
} else {
|
|
1674
|
-
const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
|
|
1675
|
-
const len = bytes.length;
|
|
1676
|
-
if (len === 0) {
|
|
1677
|
-
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1678
|
-
}
|
|
1679
|
-
for (i = 0; i < end - start; ++i) {
|
|
1680
|
-
this[i + start] = bytes[i % len];
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
return this;
|
|
1684
|
-
};
|
|
1685
|
-
const errors = {};
|
|
1686
|
-
function E(sym, getMessage, Base) {
|
|
1687
|
-
errors[sym] = class NodeError extends Base {
|
|
1688
|
-
constructor() {
|
|
1689
|
-
super();
|
|
1690
|
-
Object.defineProperty(this, "message", {
|
|
1691
|
-
value: getMessage.apply(this, arguments),
|
|
1692
|
-
writable: true,
|
|
1693
|
-
configurable: true
|
|
1694
|
-
});
|
|
1695
|
-
this.name = `${this.name} [${sym}]`;
|
|
1696
|
-
this.stack;
|
|
1697
|
-
delete this.name;
|
|
1698
|
-
}
|
|
1699
|
-
get code() {
|
|
1700
|
-
return sym;
|
|
1701
|
-
}
|
|
1702
|
-
set code(value) {
|
|
1703
|
-
Object.defineProperty(this, "code", {
|
|
1704
|
-
configurable: true,
|
|
1705
|
-
enumerable: true,
|
|
1706
|
-
value,
|
|
1707
|
-
writable: true
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
toString() {
|
|
1711
|
-
return `${this.name} [${sym}]: ${this.message}`;
|
|
1712
|
-
}
|
|
1713
|
-
};
|
|
1714
|
-
}
|
|
1715
|
-
E("ERR_BUFFER_OUT_OF_BOUNDS", function(name) {
|
|
1716
|
-
if (name) {
|
|
1717
|
-
return `${name} is outside of buffer bounds`;
|
|
1718
|
-
}
|
|
1719
|
-
return "Attempt to access memory outside buffer bounds";
|
|
1720
|
-
}, RangeError);
|
|
1721
|
-
E("ERR_INVALID_ARG_TYPE", function(name, actual) {
|
|
1722
|
-
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1723
|
-
}, TypeError);
|
|
1724
|
-
E("ERR_OUT_OF_RANGE", function(str, range, input) {
|
|
1725
|
-
let msg = `The value of "${str}" is out of range.`;
|
|
1726
|
-
let received = input;
|
|
1727
|
-
if (Number.isInteger(input) && Math.abs(input) > __pow(2, 32)) {
|
|
1728
|
-
received = addNumericalSeparator(String(input));
|
|
1729
|
-
} else if (typeof input === "bigint") {
|
|
1730
|
-
received = String(input);
|
|
1731
|
-
if (input > __pow(BigInt(2), BigInt(32)) || input < -__pow(BigInt(2), BigInt(32))) {
|
|
1732
|
-
received = addNumericalSeparator(received);
|
|
1733
|
-
}
|
|
1734
|
-
received += "n";
|
|
1735
|
-
}
|
|
1736
|
-
msg += ` It must be ${range}. Received ${received}`;
|
|
1737
|
-
return msg;
|
|
1738
|
-
}, RangeError);
|
|
1739
|
-
function addNumericalSeparator(val) {
|
|
1740
|
-
let res = "";
|
|
1741
|
-
let i = val.length;
|
|
1742
|
-
const start = val[0] === "-" ? 1 : 0;
|
|
1743
|
-
for (; i >= start + 4; i -= 3) {
|
|
1744
|
-
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1745
|
-
}
|
|
1746
|
-
return `${val.slice(0, i)}${res}`;
|
|
1747
|
-
}
|
|
1748
|
-
function checkBounds(buf, offset, byteLength2) {
|
|
1749
|
-
validateNumber(offset, "offset");
|
|
1750
|
-
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1751
|
-
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1755
|
-
if (value > max || value < min) {
|
|
1756
|
-
const n = typeof min === "bigint" ? "n" : "";
|
|
1757
|
-
let range;
|
|
1758
|
-
if (byteLength2 > 3) {
|
|
1759
|
-
if (min === 0 || min === BigInt(0)) {
|
|
1760
|
-
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1761
|
-
} else {
|
|
1762
|
-
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1763
|
-
}
|
|
1764
|
-
} else {
|
|
1765
|
-
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1766
|
-
}
|
|
1767
|
-
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1768
|
-
}
|
|
1769
|
-
checkBounds(buf, offset, byteLength2);
|
|
1770
|
-
}
|
|
1771
|
-
function validateNumber(value, name) {
|
|
1772
|
-
if (typeof value !== "number") {
|
|
1773
|
-
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
function boundsError(value, length, type) {
|
|
1777
|
-
if (Math.floor(value) !== value) {
|
|
1778
|
-
validateNumber(value, type);
|
|
1779
|
-
throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1780
|
-
}
|
|
1781
|
-
if (length < 0) {
|
|
1782
|
-
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1783
|
-
}
|
|
1784
|
-
throw new errors.ERR_OUT_OF_RANGE(type || "offset", `>= ${type ? 1 : 0} and <= ${length}`, value);
|
|
1785
|
-
}
|
|
1786
|
-
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1787
|
-
function base64clean(str) {
|
|
1788
|
-
str = str.split("=")[0];
|
|
1789
|
-
str = str.trim().replace(INVALID_BASE64_RE, "");
|
|
1790
|
-
if (str.length < 2)
|
|
1791
|
-
return "";
|
|
1792
|
-
while (str.length % 4 !== 0) {
|
|
1793
|
-
str = str + "=";
|
|
1794
|
-
}
|
|
1795
|
-
return str;
|
|
1796
|
-
}
|
|
1797
|
-
function utf8ToBytes(string, units) {
|
|
1798
|
-
units = units || Infinity;
|
|
1799
|
-
let codePoint;
|
|
1800
|
-
const length = string.length;
|
|
1801
|
-
let leadSurrogate = null;
|
|
1802
|
-
const bytes = [];
|
|
1803
|
-
for (let i = 0; i < length; ++i) {
|
|
1804
|
-
codePoint = string.charCodeAt(i);
|
|
1805
|
-
if (codePoint > 55295 && codePoint < 57344) {
|
|
1806
|
-
if (!leadSurrogate) {
|
|
1807
|
-
if (codePoint > 56319) {
|
|
1808
|
-
if ((units -= 3) > -1)
|
|
1809
|
-
bytes.push(239, 191, 189);
|
|
1810
|
-
continue;
|
|
1811
|
-
} else if (i + 1 === length) {
|
|
1812
|
-
if ((units -= 3) > -1)
|
|
1813
|
-
bytes.push(239, 191, 189);
|
|
1814
|
-
continue;
|
|
1815
|
-
}
|
|
1816
|
-
leadSurrogate = codePoint;
|
|
1817
|
-
continue;
|
|
1818
|
-
}
|
|
1819
|
-
if (codePoint < 56320) {
|
|
1820
|
-
if ((units -= 3) > -1)
|
|
1821
|
-
bytes.push(239, 191, 189);
|
|
1822
|
-
leadSurrogate = codePoint;
|
|
1823
|
-
continue;
|
|
1824
|
-
}
|
|
1825
|
-
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1826
|
-
} else if (leadSurrogate) {
|
|
1827
|
-
if ((units -= 3) > -1)
|
|
1828
|
-
bytes.push(239, 191, 189);
|
|
1829
|
-
}
|
|
1830
|
-
leadSurrogate = null;
|
|
1831
|
-
if (codePoint < 128) {
|
|
1832
|
-
if ((units -= 1) < 0)
|
|
1833
|
-
break;
|
|
1834
|
-
bytes.push(codePoint);
|
|
1835
|
-
} else if (codePoint < 2048) {
|
|
1836
|
-
if ((units -= 2) < 0)
|
|
1837
|
-
break;
|
|
1838
|
-
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
|
1839
|
-
} else if (codePoint < 65536) {
|
|
1840
|
-
if ((units -= 3) < 0)
|
|
1841
|
-
break;
|
|
1842
|
-
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1843
|
-
} else if (codePoint < 1114112) {
|
|
1844
|
-
if ((units -= 4) < 0)
|
|
1845
|
-
break;
|
|
1846
|
-
bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1847
|
-
} else {
|
|
1848
|
-
throw new Error("Invalid code point");
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
return bytes;
|
|
1852
|
-
}
|
|
1853
|
-
function asciiToBytes(str) {
|
|
1854
|
-
const byteArray = [];
|
|
1855
|
-
for (let i = 0; i < str.length; ++i) {
|
|
1856
|
-
byteArray.push(str.charCodeAt(i) & 255);
|
|
1857
|
-
}
|
|
1858
|
-
return byteArray;
|
|
1859
|
-
}
|
|
1860
|
-
function utf16leToBytes(str, units) {
|
|
1861
|
-
let c, hi, lo;
|
|
1862
|
-
const byteArray = [];
|
|
1863
|
-
for (let i = 0; i < str.length; ++i) {
|
|
1864
|
-
if ((units -= 2) < 0)
|
|
1865
|
-
break;
|
|
1866
|
-
c = str.charCodeAt(i);
|
|
1867
|
-
hi = c >> 8;
|
|
1868
|
-
lo = c % 256;
|
|
1869
|
-
byteArray.push(lo);
|
|
1870
|
-
byteArray.push(hi);
|
|
1871
|
-
}
|
|
1872
|
-
return byteArray;
|
|
1873
|
-
}
|
|
1874
|
-
function base64ToBytes(str) {
|
|
1875
|
-
return base64.toByteArray(base64clean(str));
|
|
1876
|
-
}
|
|
1877
|
-
function blitBuffer(src, dst, offset, length) {
|
|
1878
|
-
let i;
|
|
1879
|
-
for (i = 0; i < length; ++i) {
|
|
1880
|
-
if (i + offset >= dst.length || i >= src.length)
|
|
1881
|
-
break;
|
|
1882
|
-
dst[i + offset] = src[i];
|
|
1883
|
-
}
|
|
1884
|
-
return i;
|
|
1885
|
-
}
|
|
1886
|
-
function isInstance(obj, type) {
|
|
1887
|
-
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1888
|
-
}
|
|
1889
|
-
function numberIsNaN(obj) {
|
|
1890
|
-
return obj !== obj;
|
|
1891
|
-
}
|
|
1892
|
-
const hexSliceLookupTable = function() {
|
|
1893
|
-
const alphabet = "0123456789abcdef";
|
|
1894
|
-
const table = new Array(256);
|
|
1895
|
-
for (let i = 0; i < 16; ++i) {
|
|
1896
|
-
const i16 = i * 16;
|
|
1897
|
-
for (let j = 0; j < 16; ++j) {
|
|
1898
|
-
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
return table;
|
|
1902
|
-
}();
|
|
1903
|
-
function defineBigIntMethod(fn) {
|
|
1904
|
-
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1905
|
-
}
|
|
1906
|
-
function BufferBigIntNotDefined() {
|
|
1907
|
-
throw new Error("BigInt not supported");
|
|
1908
|
-
}
|
|
1909
|
-
return exports$1;
|
|
1910
|
-
}
|
|
1911
|
-
var exports = dew();
|
|
1912
|
-
exports["Buffer"];
|
|
1913
|
-
exports["SlowBuffer"];
|
|
1914
|
-
exports["INSPECT_MAX_BYTES"];
|
|
1915
|
-
exports["kMaxLength"];
|
|
1916
|
-
var Buffer2 = exports.Buffer;
|
|
1917
|
-
var INSPECT_MAX_BYTES = exports.INSPECT_MAX_BYTES;
|
|
1918
|
-
var kMaxLength = exports.kMaxLength;
|
|
1919
|
-
|
|
1920
|
-
// src/keyPair.ts
|
|
1921
|
-
var import_bs58 = require("bs58");
|
|
1922
|
-
var ed = __toESM(require("@noble/ed25519"));
|
|
1923
|
-
var BaseOrderlyKeyPair = class _BaseOrderlyKeyPair {
|
|
1924
|
-
static generateKey() {
|
|
1925
|
-
const privKey = ed.utils.randomPrivateKey();
|
|
1926
|
-
const secretKey = (0, import_bs58.encode)(privKey);
|
|
1927
|
-
return new _BaseOrderlyKeyPair(secretKey);
|
|
1928
|
-
}
|
|
1929
|
-
constructor(secretKey) {
|
|
1930
|
-
this.secretKey = secretKey;
|
|
1931
|
-
const bytes = (0, import_bs58.decode)(secretKey);
|
|
1932
|
-
this.privateKey = Buffer2.from(bytes).toString("hex");
|
|
1933
|
-
}
|
|
1934
|
-
sign(message) {
|
|
1935
|
-
return __async(this, null, function* () {
|
|
1936
|
-
return yield ed.signAsync(message, this.privateKey);
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
getPublicKey() {
|
|
1940
|
-
return __async(this, null, function* () {
|
|
1941
|
-
const pubKey = yield ed.getPublicKeyAsync(this.privateKey);
|
|
1942
|
-
const publicKey = `ed25519:${(0, import_bs58.encode)(pubKey)}`;
|
|
1943
|
-
return publicKey;
|
|
1944
|
-
});
|
|
1945
|
-
}
|
|
1946
|
-
toString() {
|
|
1947
|
-
return this.privateKey;
|
|
1948
|
-
}
|
|
1949
|
-
};
|
|
1950
|
-
|
|
1951
|
-
// src/keyStore.ts
|
|
1952
|
-
var BaseKeyStore = class {
|
|
1953
|
-
constructor(networkId = "testnet") {
|
|
1954
|
-
this.networkId = networkId;
|
|
1955
|
-
}
|
|
1956
|
-
get keyPrefix() {
|
|
1957
|
-
return `orderly_${this.networkId}_`;
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
var LocalStorageStore = class extends BaseKeyStore {
|
|
1961
|
-
getOrderlyKey(address) {
|
|
1962
|
-
let orderlyKey;
|
|
1963
|
-
if (address) {
|
|
1964
|
-
orderlyKey = this.getItem(address, "orderlyKey");
|
|
1965
|
-
} else {
|
|
1966
|
-
const address2 = this.getAddress();
|
|
1967
|
-
if (!address2)
|
|
1968
|
-
return null;
|
|
1969
|
-
orderlyKey = this.getItem(address2, "orderlyKey");
|
|
1970
|
-
}
|
|
1971
|
-
if (!orderlyKey) {
|
|
1972
|
-
return null;
|
|
1973
|
-
}
|
|
1974
|
-
return new BaseOrderlyKeyPair(orderlyKey);
|
|
1975
|
-
}
|
|
1976
|
-
getAccountId(address) {
|
|
1977
|
-
return this.getItem(address, "accountId");
|
|
1978
|
-
}
|
|
1979
|
-
setAccountId(address, accountId) {
|
|
1980
|
-
this.setItem(address, { accountId });
|
|
1981
|
-
}
|
|
1982
|
-
getAddress() {
|
|
1983
|
-
return localStorage.getItem(`${this.keyPrefix}address`);
|
|
1984
|
-
}
|
|
1985
|
-
setAddress(address) {
|
|
1986
|
-
localStorage.setItem(`${this.keyPrefix}address`, address);
|
|
1987
|
-
}
|
|
1988
|
-
generateKey() {
|
|
1989
|
-
return BaseOrderlyKeyPair.generateKey();
|
|
1990
|
-
}
|
|
1991
|
-
setKey(address, orderlyKey) {
|
|
1992
|
-
this.setItem(address, { orderlyKey: orderlyKey.secretKey });
|
|
1993
|
-
}
|
|
1994
|
-
cleanAllKey(address) {
|
|
1995
|
-
localStorage.removeItem(`${this.keyPrefix}${address}`);
|
|
1996
|
-
localStorage.removeItem(`${this.keyPrefix}address`);
|
|
1997
|
-
}
|
|
1998
|
-
cleanKey(address, key) {
|
|
1999
|
-
const data = this.getItem(address);
|
|
2000
|
-
delete data[key];
|
|
2001
|
-
localStorage.setItem(`${this.keyPrefix}${address}`, JSON.stringify(data));
|
|
2002
|
-
}
|
|
2003
|
-
setItem(address, value) {
|
|
2004
|
-
const key = `${this.keyPrefix}${address}`;
|
|
2005
|
-
let oldValue = localStorage.getItem(key);
|
|
2006
|
-
if (oldValue) {
|
|
2007
|
-
oldValue = JSON.parse(oldValue);
|
|
2008
|
-
} else {
|
|
2009
|
-
oldValue = {};
|
|
2010
|
-
}
|
|
2011
|
-
localStorage.setItem(
|
|
2012
|
-
key,
|
|
2013
|
-
JSON.stringify(__spreadValues(__spreadValues({}, oldValue), value))
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
getItem(address, name) {
|
|
2017
|
-
const key = `${this.keyPrefix}${address}`;
|
|
2018
|
-
let value = localStorage.getItem(key);
|
|
2019
|
-
if (value) {
|
|
2020
|
-
value = JSON.parse(value);
|
|
2021
|
-
} else {
|
|
2022
|
-
value = {};
|
|
2023
|
-
}
|
|
2024
|
-
if (typeof name === "undefined") {
|
|
2025
|
-
return value;
|
|
2026
|
-
}
|
|
2027
|
-
return value[name];
|
|
2028
|
-
}
|
|
2029
|
-
};
|
|
2030
|
-
var MockKeyStore = class {
|
|
2031
|
-
constructor(secretKey) {
|
|
2032
|
-
this.secretKey = secretKey;
|
|
2033
|
-
}
|
|
2034
|
-
generateKey() {
|
|
2035
|
-
return new BaseOrderlyKeyPair(this.secretKey);
|
|
2036
|
-
}
|
|
2037
|
-
getOrderlyKey() {
|
|
2038
|
-
return new BaseOrderlyKeyPair(this.secretKey);
|
|
2039
|
-
}
|
|
2040
|
-
getAccountId() {
|
|
2041
|
-
return "";
|
|
2042
|
-
}
|
|
2043
|
-
setAccountId(accountId) {
|
|
2044
|
-
}
|
|
2045
|
-
getAddress() {
|
|
2046
|
-
return "";
|
|
2047
|
-
}
|
|
2048
|
-
setAddress(address) {
|
|
2049
|
-
}
|
|
2050
|
-
setKey(orderlyKey, secretKey) {
|
|
2051
|
-
}
|
|
2052
|
-
cleanAllKey() {
|
|
2053
|
-
}
|
|
2054
|
-
cleanKey(key) {
|
|
2055
|
-
}
|
|
2056
|
-
};
|
|
2057
|
-
|
|
2058
|
-
// src/constants.ts
|
|
2059
|
-
var definedTypes = {
|
|
2060
|
-
EIP712Domain: [
|
|
2061
|
-
{ name: "name", type: "string" },
|
|
2062
|
-
{ name: "version", type: "string" },
|
|
2063
|
-
{ name: "chainId", type: "uint256" },
|
|
2064
|
-
{ name: "verifyingContract", type: "address" }
|
|
2065
|
-
],
|
|
2066
|
-
Registration: [
|
|
2067
|
-
{ name: "brokerId", type: "string" },
|
|
2068
|
-
{ name: "chainId", type: "uint256" },
|
|
2069
|
-
{ name: "timestamp", type: "uint64" },
|
|
2070
|
-
{ name: "registrationNonce", type: "uint256" }
|
|
2071
|
-
],
|
|
2072
|
-
Withdraw: [
|
|
2073
|
-
{ name: "brokerId", type: "string" },
|
|
2074
|
-
{ name: "chainId", type: "uint256" },
|
|
2075
|
-
{ name: "receiver", type: "address" },
|
|
2076
|
-
{ name: "token", type: "string" },
|
|
2077
|
-
{ name: "amount", type: "uint256" },
|
|
2078
|
-
{ name: "withdrawNonce", type: "uint64" },
|
|
2079
|
-
{ name: "timestamp", type: "uint64" }
|
|
2080
|
-
],
|
|
2081
|
-
AddOrderlyKey: [
|
|
2082
|
-
{ name: "brokerId", type: "string" },
|
|
2083
|
-
{ name: "chainId", type: "uint256" },
|
|
2084
|
-
{ name: "orderlyKey", type: "string" },
|
|
2085
|
-
{ name: "scope", type: "string" },
|
|
2086
|
-
{ name: "timestamp", type: "uint64" },
|
|
2087
|
-
{ name: "expiration", type: "uint64" }
|
|
2088
|
-
],
|
|
2089
|
-
SettlePnl: [
|
|
2090
|
-
{ name: "brokerId", type: "string" },
|
|
2091
|
-
{ name: "chainId", type: "uint256" },
|
|
2092
|
-
{ name: "settleNonce", type: "uint64" },
|
|
2093
|
-
{ name: "timestamp", type: "uint64" }
|
|
2094
|
-
]
|
|
2095
|
-
};
|
|
2096
|
-
|
|
2097
|
-
// src/utils.ts
|
|
2098
|
-
var base64url = function(aStr) {
|
|
2099
|
-
return aStr.replace(/\+/g, "-").replace(/\//g, "_");
|
|
2100
|
-
};
|
|
2101
|
-
function getVerifyingContract() {
|
|
2102
|
-
return "0x8794E7260517B1766fc7b55cAfcd56e6bf08600e";
|
|
2103
|
-
}
|
|
2104
|
-
function getDomain(chainId, onChainDomain) {
|
|
2105
|
-
return {
|
|
2106
|
-
name: "Orderly",
|
|
2107
|
-
version: "1",
|
|
2108
|
-
chainId,
|
|
2109
|
-
verifyingContract: onChainDomain ? getVerifyingContract() : "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
|
|
2110
|
-
};
|
|
2111
|
-
}
|
|
2112
|
-
function generateRegisterAccountMessage(inputs) {
|
|
2113
|
-
const { chainId, registrationNonce } = inputs;
|
|
2114
|
-
const now = Date.now();
|
|
2115
|
-
const primaryType = "Registration";
|
|
2116
|
-
const message = {
|
|
2117
|
-
brokerId: "woofi_dex",
|
|
2118
|
-
chainId,
|
|
2119
|
-
timestamp: now,
|
|
2120
|
-
registrationNonce
|
|
2121
|
-
};
|
|
2122
|
-
const typeDefinition = {
|
|
2123
|
-
EIP712Domain: definedTypes.EIP712Domain,
|
|
2124
|
-
[primaryType]: definedTypes[primaryType]
|
|
2125
|
-
};
|
|
2126
|
-
return [
|
|
2127
|
-
message,
|
|
2128
|
-
{
|
|
2129
|
-
domain: getDomain(chainId),
|
|
2130
|
-
message,
|
|
2131
|
-
primaryType,
|
|
2132
|
-
types: typeDefinition
|
|
2133
|
-
}
|
|
2134
|
-
];
|
|
2135
|
-
}
|
|
2136
|
-
function generateAddOrderlyKeyMessage(inputs) {
|
|
2137
|
-
const { publicKey, chainId, primaryType, expiration = 365 } = inputs;
|
|
2138
|
-
const now = Date.now();
|
|
2139
|
-
const message = {
|
|
2140
|
-
brokerId: "woofi_dex",
|
|
2141
|
-
orderlyKey: publicKey,
|
|
2142
|
-
scope: "read,trading",
|
|
2143
|
-
chainId,
|
|
2144
|
-
timestamp: now,
|
|
2145
|
-
expiration: now + 1e3 * 60 * 60 * 24 * expiration
|
|
2146
|
-
};
|
|
2147
|
-
const typeDefinition = {
|
|
2148
|
-
EIP712Domain: definedTypes.EIP712Domain,
|
|
2149
|
-
[primaryType]: definedTypes[primaryType]
|
|
2150
|
-
};
|
|
2151
|
-
const toSignatureMessage = {
|
|
2152
|
-
domain: getDomain(chainId),
|
|
2153
|
-
message,
|
|
2154
|
-
primaryType,
|
|
2155
|
-
types: typeDefinition
|
|
2156
|
-
};
|
|
2157
|
-
return [message, toSignatureMessage];
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
// src/signer.ts
|
|
2161
|
-
var BaseSigner = class {
|
|
2162
|
-
constructor(keyStore) {
|
|
2163
|
-
this.keyStore = keyStore;
|
|
2164
|
-
}
|
|
2165
|
-
sign(message) {
|
|
2166
|
-
return __async(this, null, function* () {
|
|
2167
|
-
const timestamp = Date.now().toString();
|
|
2168
|
-
let msgStr = [timestamp, message.method.toUpperCase(), message.url].join(
|
|
2169
|
-
""
|
|
2170
|
-
);
|
|
2171
|
-
if (message.data && Object.keys(message.data).length) {
|
|
2172
|
-
msgStr += JSON.stringify(message.data);
|
|
2173
|
-
}
|
|
2174
|
-
const { signature, publicKey } = yield this.signText(msgStr);
|
|
2175
|
-
return {
|
|
2176
|
-
"orderly-key": publicKey,
|
|
2177
|
-
"orderly-timestamp": timestamp,
|
|
2178
|
-
"orderly-signature": signature
|
|
2179
|
-
};
|
|
2180
|
-
});
|
|
2181
|
-
}
|
|
2182
|
-
signText(text) {
|
|
2183
|
-
return __async(this, null, function* () {
|
|
2184
|
-
const orderlyKeyPair = this.keyStore.getOrderlyKey();
|
|
2185
|
-
if (!orderlyKeyPair) {
|
|
2186
|
-
throw new Error("orderlyKeyPair is not defined");
|
|
2187
|
-
}
|
|
2188
|
-
const u8 = Buffer2.from(text);
|
|
2189
|
-
const signature = yield orderlyKeyPair.sign(u8);
|
|
2190
|
-
const signHex = Buffer2.from(signature).toString("base64");
|
|
2191
|
-
const b64 = base64url(signHex);
|
|
2192
|
-
return {
|
|
2193
|
-
signature: b64,
|
|
2194
|
-
publicKey: yield orderlyKeyPair.getPublicKey()
|
|
2195
|
-
};
|
|
2196
|
-
});
|
|
2197
|
-
}
|
|
2198
|
-
};
|
|
2199
|
-
|
|
2200
|
-
// src/configStore.ts
|
|
2201
|
-
var MemoryConfigStore = class {
|
|
2202
|
-
constructor() {
|
|
2203
|
-
this._restore();
|
|
2204
|
-
}
|
|
2205
|
-
_restore() {
|
|
2206
|
-
this.map = /* @__PURE__ */ new Map([
|
|
2207
|
-
["apiBaseUrl", "https://dev-api-v2.orderly.org"],
|
|
2208
|
-
["klineDataUrl", "https://dev-api-v2.orderly.org"]
|
|
2209
|
-
]);
|
|
2210
|
-
}
|
|
2211
|
-
get(key) {
|
|
2212
|
-
return this.map.get(key);
|
|
2213
|
-
}
|
|
2214
|
-
set(key, value) {
|
|
2215
|
-
this.map.set(key, value);
|
|
2216
|
-
}
|
|
2217
|
-
clear() {
|
|
2218
|
-
}
|
|
2219
|
-
};
|
|
2220
|
-
var BaseConfigStore = class extends MemoryConfigStore {
|
|
2221
|
-
constructor(configMap) {
|
|
2222
|
-
super();
|
|
2223
|
-
this.configMap = configMap;
|
|
2224
|
-
}
|
|
2225
|
-
_restore() {
|
|
2226
|
-
const arr = Object.entries(this.configMap);
|
|
2227
|
-
this.map = new Map(arr);
|
|
2228
|
-
}
|
|
2229
|
-
};
|
|
2230
|
-
|
|
2231
|
-
// src/helper.ts
|
|
2232
|
-
var getMockSigner = (secretKey) => {
|
|
2233
|
-
const mockKeyStore = new MockKeyStore(
|
|
2234
|
-
secretKey || "AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF"
|
|
2235
|
-
// "c24fe227663f5a73493cad3f4049514f70623177272d57fffa8cb895fa1f92de"
|
|
2236
|
-
);
|
|
2237
|
-
return new BaseSigner(mockKeyStore);
|
|
2238
|
-
};
|
|
2239
|
-
var getDefaultSigner = () => {
|
|
2240
|
-
if (typeof window === "undefined") {
|
|
2241
|
-
throw new Error("the default signer only supports browsers.");
|
|
2242
|
-
}
|
|
2243
|
-
const localStorageStore = new LocalStorageStore("");
|
|
2244
|
-
return new BaseSigner(localStorageStore);
|
|
2245
|
-
};
|
|
2246
|
-
|
|
2247
|
-
// src/di/container.ts
|
|
2248
|
-
var Container = class {
|
|
2249
|
-
constructor(providers = [], services = {}) {
|
|
2250
|
-
this.providers = providers;
|
|
2251
|
-
this.services = services;
|
|
2252
|
-
this.injectProperties = {};
|
|
2253
|
-
}
|
|
2254
|
-
register(...serviceClasses) {
|
|
2255
|
-
this.providers.push(...serviceClasses);
|
|
2256
|
-
serviceClasses.forEach((serviceClass) => {
|
|
2257
|
-
let service = serviceClass;
|
|
2258
|
-
if (service instanceof Function) {
|
|
2259
|
-
service = new serviceClass();
|
|
2260
|
-
}
|
|
2261
|
-
this.add(service);
|
|
2262
|
-
});
|
|
2263
|
-
}
|
|
2264
|
-
registerByName(name, serviceClass) {
|
|
2265
|
-
let service = serviceClass;
|
|
2266
|
-
if (service instanceof Function) {
|
|
2267
|
-
service = new serviceClass();
|
|
2268
|
-
}
|
|
2269
|
-
this.addByName(name, service);
|
|
2270
|
-
}
|
|
2271
|
-
get(name) {
|
|
2272
|
-
return this.services[name];
|
|
2273
|
-
}
|
|
2274
|
-
//
|
|
2275
|
-
// getByType<T>(c: new (...args: any[]) => T): T {
|
|
2276
|
-
// return this.get<T>(c.name.toLowerCase());
|
|
2277
|
-
// }
|
|
2278
|
-
getAll() {
|
|
2279
|
-
return Object.assign({}, this.services);
|
|
2280
|
-
}
|
|
2281
|
-
// addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
|
|
2282
|
-
// if (target) {
|
|
2283
|
-
// this.getInjectProperty(serviceName.toLowerCase()).push({ target, propertyKey, serviceName });
|
|
2284
|
-
// this.inject(target, propertyKey, this.services[serviceName.toLowerCase()]);
|
|
2285
|
-
// }
|
|
2286
|
-
// }
|
|
2287
|
-
add(service) {
|
|
2288
|
-
return this.addByName(service.constructor.name, service);
|
|
2289
|
-
}
|
|
2290
|
-
// //
|
|
2291
|
-
addByName(name, service) {
|
|
2292
|
-
this.services[name] = service;
|
|
2293
|
-
this.services[name.toLowerCase()] = service;
|
|
2294
|
-
this.injectIntoProperties(service, name);
|
|
2295
|
-
return this.get(name);
|
|
2296
|
-
}
|
|
2297
|
-
inject(target, propertyKey, service) {
|
|
2298
|
-
if (target && service) {
|
|
2299
|
-
target[propertyKey] = service;
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
injectIntoProperties(service, name = service.constructor.name) {
|
|
2303
|
-
this.getInjectProperty(name.toLowerCase()).forEach((property) => {
|
|
2304
|
-
this.inject(property.target, property.propertyKey, service);
|
|
2305
|
-
});
|
|
2306
|
-
}
|
|
2307
|
-
//
|
|
2308
|
-
getInjectProperty(key) {
|
|
2309
|
-
if (!this.injectProperties[key]) {
|
|
2310
|
-
this.injectProperties[key] = [];
|
|
2311
|
-
}
|
|
2312
|
-
return this.injectProperties[key];
|
|
2313
|
-
}
|
|
2314
|
-
};
|
|
2315
|
-
var container_default = Container;
|
|
2316
|
-
|
|
2317
|
-
// src/di/simpleDI.ts
|
|
2318
|
-
var SimpleDI = class _SimpleDI {
|
|
2319
|
-
static getContainer() {
|
|
2320
|
-
if (!_SimpleDI.container) {
|
|
2321
|
-
_SimpleDI.container = new container_default();
|
|
2322
|
-
}
|
|
2323
|
-
return _SimpleDI.container;
|
|
2324
|
-
}
|
|
2325
|
-
static register(...serviceClasses) {
|
|
2326
|
-
this.getContainer().register(...serviceClasses);
|
|
2327
|
-
}
|
|
2328
|
-
static registerByName(name, serviceClass) {
|
|
2329
|
-
this.getContainer().registerByName(name, serviceClass);
|
|
2330
|
-
}
|
|
2331
|
-
// static addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
|
|
2332
|
-
// this.getContainer().addInjectProperty(target, propertyKey, serviceName);
|
|
2333
|
-
// }
|
|
2334
|
-
static get(name) {
|
|
2335
|
-
return this.getContainer().get(name);
|
|
2336
|
-
}
|
|
2337
|
-
// static getByType<T>(c: new (...args: any[]) => T): T {
|
|
2338
|
-
// return this.getContainer().getByType(c);
|
|
2339
|
-
// }
|
|
2340
|
-
static getAll() {
|
|
2341
|
-
return this.getContainer().getAll();
|
|
2342
|
-
}
|
|
2343
|
-
constructor() {
|
|
2344
|
-
}
|
|
2345
|
-
};
|
|
2346
|
-
var simpleDI_default = SimpleDI;
|
|
2347
|
-
|
|
2348
|
-
// src/account.ts
|
|
2349
|
-
var import_rxjs = require("rxjs");
|
|
2350
|
-
var import_types = require("@orderly.network/types");
|
|
2351
|
-
var Account = class {
|
|
2352
|
-
// private config =
|
|
2353
|
-
constructor(configStore, keyStore, walletAdapterClass) {
|
|
2354
|
-
this.configStore = configStore;
|
|
2355
|
-
this.keyStore = keyStore;
|
|
2356
|
-
this.walletAdapterClass = walletAdapterClass;
|
|
2357
|
-
this._state$ = new import_rxjs.BehaviorSubject({
|
|
2358
|
-
status: import_types.AccountStatusEnum.NotConnected,
|
|
2359
|
-
balance: "",
|
|
2360
|
-
leverage: Number.NaN
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
/**
|
|
2364
|
-
* 登录
|
|
2365
|
-
* @param address 钱包地址
|
|
2366
|
-
*/
|
|
2367
|
-
login(address) {
|
|
2368
|
-
if (!address)
|
|
2369
|
-
throw new Error("address is required");
|
|
2370
|
-
}
|
|
2371
|
-
logout() {
|
|
2372
|
-
}
|
|
2373
|
-
/**
|
|
2374
|
-
* 连接钱包先用第三方的React版本,不用自己实现
|
|
2375
|
-
*/
|
|
2376
|
-
// connectWallet() {
|
|
2377
|
-
// // this.wallet.connect();
|
|
2378
|
-
// }
|
|
2379
|
-
setAddress(address, wallet) {
|
|
2380
|
-
return __async(this, null, function* () {
|
|
2381
|
-
if (!address)
|
|
2382
|
-
throw new Error("address is required");
|
|
2383
|
-
this.keyStore.setAddress(address);
|
|
2384
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2385
|
-
status: import_types.AccountStatusEnum.Connected,
|
|
2386
|
-
address
|
|
2387
|
-
}));
|
|
2388
|
-
if (wallet) {
|
|
2389
|
-
this.walletClient = new this.walletAdapterClass(wallet);
|
|
2390
|
-
}
|
|
2391
|
-
return yield this._checkAccount(address);
|
|
2392
|
-
});
|
|
2393
|
-
}
|
|
2394
|
-
// subscribe the account state change
|
|
2395
|
-
get state$() {
|
|
2396
|
-
return this._state$;
|
|
2397
|
-
}
|
|
2398
|
-
get stateValue() {
|
|
2399
|
-
return this._state$.getValue();
|
|
2400
|
-
}
|
|
2401
|
-
get accountId() {
|
|
2402
|
-
const state = this.stateValue;
|
|
2403
|
-
return state.accountId;
|
|
2404
|
-
}
|
|
2405
|
-
/**
|
|
2406
|
-
* set user positions count
|
|
2407
|
-
*/
|
|
2408
|
-
set position(position) {
|
|
2409
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2410
|
-
positon: position
|
|
2411
|
-
}));
|
|
2412
|
-
}
|
|
2413
|
-
set orders(orders) {
|
|
2414
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2415
|
-
orders
|
|
2416
|
-
}));
|
|
2417
|
-
}
|
|
2418
|
-
// 检查账户状态
|
|
2419
|
-
_checkAccount(address) {
|
|
2420
|
-
return __async(this, null, function* () {
|
|
2421
|
-
console.log("check account is esist");
|
|
2422
|
-
try {
|
|
2423
|
-
const accountInfo = yield this._checkAccountExist(address);
|
|
2424
|
-
console.log("accountInfo:", accountInfo);
|
|
2425
|
-
if (accountInfo && accountInfo.account_id) {
|
|
2426
|
-
console.log("account is exist");
|
|
2427
|
-
this.keyStore.setAccountId(address, accountInfo.account_id);
|
|
2428
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2429
|
-
status: import_types.AccountStatusEnum.SignedIn,
|
|
2430
|
-
accountId: accountInfo.account_id,
|
|
2431
|
-
userId: accountInfo.user_id
|
|
2432
|
-
}));
|
|
2433
|
-
} else {
|
|
2434
|
-
return import_types.AccountStatusEnum.NotSignedIn;
|
|
2435
|
-
}
|
|
2436
|
-
const orderlyKey = this.keyStore.getOrderlyKey(address);
|
|
2437
|
-
console.log("orderlyKey:", orderlyKey);
|
|
2438
|
-
if (!orderlyKey) {
|
|
2439
|
-
console.log("orderlyKey is null");
|
|
2440
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2441
|
-
status: import_types.AccountStatusEnum.DisabledTrading
|
|
2442
|
-
}));
|
|
2443
|
-
return import_types.AccountStatusEnum.DisabledTrading;
|
|
2444
|
-
}
|
|
2445
|
-
const publicKey = yield orderlyKey.getPublicKey();
|
|
2446
|
-
const orderlyKeyStatus = yield this._checkOrderlyKeyState(
|
|
2447
|
-
accountInfo.account_id,
|
|
2448
|
-
publicKey
|
|
2449
|
-
);
|
|
2450
|
-
console.log("orderlyKeyStatus:", orderlyKeyStatus);
|
|
2451
|
-
if (orderlyKeyStatus && orderlyKeyStatus.orderly_key && orderlyKeyStatus.key_status === "ACTIVE") {
|
|
2452
|
-
const now = Date.now();
|
|
2453
|
-
const expiration = orderlyKeyStatus.expiration;
|
|
2454
|
-
if (now > expiration) {
|
|
2455
|
-
this.keyStore.cleanKey(address, "orderlyKey");
|
|
2456
|
-
return import_types.AccountStatusEnum.DisabledTrading;
|
|
2457
|
-
}
|
|
2458
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2459
|
-
status: import_types.AccountStatusEnum.EnableTrading
|
|
2460
|
-
}));
|
|
2461
|
-
return import_types.AccountStatusEnum.EnableTrading;
|
|
2462
|
-
}
|
|
2463
|
-
this.keyStore.cleanKey(address, "orderlyKey");
|
|
2464
|
-
return import_types.AccountStatusEnum.NotConnected;
|
|
2465
|
-
} catch (err) {
|
|
2466
|
-
console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:", err);
|
|
2467
|
-
}
|
|
2468
|
-
return import_types.AccountStatusEnum.NotSignedIn;
|
|
2469
|
-
});
|
|
2470
|
-
}
|
|
2471
|
-
_checkAccountExist(address) {
|
|
2472
|
-
return __async(this, null, function* () {
|
|
2473
|
-
const res = yield this._simpleFetch(
|
|
2474
|
-
`/v1/get_account?address=${address}&broker_id=woofi_dex`
|
|
2475
|
-
);
|
|
2476
|
-
if (res.success) {
|
|
2477
|
-
return res.data;
|
|
2478
|
-
} else {
|
|
2479
|
-
throw new Error(res.message);
|
|
2480
|
-
}
|
|
2481
|
-
});
|
|
2482
|
-
}
|
|
2483
|
-
createAccount() {
|
|
2484
|
-
return __async(this, null, function* () {
|
|
2485
|
-
const nonce = yield this._getRegisterationNonce();
|
|
2486
|
-
console.log("nonce:", nonce);
|
|
2487
|
-
const keyPair = this.keyStore.generateKey();
|
|
2488
|
-
const publicKey = yield keyPair.getPublicKey();
|
|
2489
|
-
const address = this.stateValue.address;
|
|
2490
|
-
if (!address) {
|
|
2491
|
-
throw new Error("address is undefined");
|
|
2492
|
-
}
|
|
2493
|
-
const [message, toSignatureMessage] = generateRegisterAccountMessage({
|
|
2494
|
-
registrationNonce: nonce,
|
|
2495
|
-
chainId: this.walletClient.chainId
|
|
2496
|
-
});
|
|
2497
|
-
const signatured = yield this.walletClient.send("eth_signTypedData_v4", [
|
|
2498
|
-
address,
|
|
2499
|
-
JSON.stringify(toSignatureMessage)
|
|
2500
|
-
]);
|
|
2501
|
-
const res = yield this._simpleFetch("/v1/register_account", {
|
|
2502
|
-
method: "POST",
|
|
2503
|
-
body: JSON.stringify({
|
|
2504
|
-
signature: signatured,
|
|
2505
|
-
message,
|
|
2506
|
-
userAddress: address
|
|
2507
|
-
}),
|
|
2508
|
-
headers: {
|
|
2509
|
-
"Content-Type": "application/json"
|
|
2510
|
-
}
|
|
2511
|
-
});
|
|
2512
|
-
console.log("createAccount:", res);
|
|
2513
|
-
if (res.success) {
|
|
2514
|
-
this.keyStore.setAccountId(address, res.data.account_id);
|
|
2515
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2516
|
-
status: import_types.AccountStatusEnum.SignedIn,
|
|
2517
|
-
accountId: res.data.account_id,
|
|
2518
|
-
userId: res.data.user_id
|
|
2519
|
-
}));
|
|
2520
|
-
return res;
|
|
2521
|
-
}
|
|
2522
|
-
});
|
|
2523
|
-
}
|
|
2524
|
-
createOrderlyKey(expiration) {
|
|
2525
|
-
return __async(this, null, function* () {
|
|
2526
|
-
if (this.stateValue.accountId === void 0) {
|
|
2527
|
-
throw new Error("account id is undefined");
|
|
2528
|
-
}
|
|
2529
|
-
if (this.walletClient === void 0) {
|
|
2530
|
-
throw new Error("walletClient is undefined");
|
|
2531
|
-
}
|
|
2532
|
-
const primaryType = "AddOrderlyKey";
|
|
2533
|
-
const keyPair = this.keyStore.generateKey();
|
|
2534
|
-
const publicKey = yield keyPair.getPublicKey();
|
|
2535
|
-
const [message, toSignatureMessage] = generateAddOrderlyKeyMessage({
|
|
2536
|
-
publicKey,
|
|
2537
|
-
chainId: this.walletClient.chainId,
|
|
2538
|
-
primaryType,
|
|
2539
|
-
expiration
|
|
2540
|
-
});
|
|
2541
|
-
const address = this.stateValue.address;
|
|
2542
|
-
if (!address) {
|
|
2543
|
-
throw new Error("address is undefined");
|
|
2544
|
-
}
|
|
2545
|
-
console.log("message:", message, toSignatureMessage, address);
|
|
2546
|
-
const signatured = yield this.walletClient.send("eth_signTypedData_v4", [
|
|
2547
|
-
address,
|
|
2548
|
-
JSON.stringify(toSignatureMessage)
|
|
2549
|
-
]);
|
|
2550
|
-
const res = yield this._simpleFetch("/v1/orderly_key", {
|
|
2551
|
-
method: "POST",
|
|
2552
|
-
body: JSON.stringify({
|
|
2553
|
-
signature: signatured,
|
|
2554
|
-
message,
|
|
2555
|
-
userAddress: address
|
|
2556
|
-
}),
|
|
2557
|
-
headers: {
|
|
2558
|
-
"X-Account-Id": this.stateValue.accountId,
|
|
2559
|
-
"Content-Type": "application/json"
|
|
2560
|
-
}
|
|
2561
|
-
});
|
|
2562
|
-
if (res.success) {
|
|
2563
|
-
this.keyStore.setKey(address, keyPair);
|
|
2564
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2565
|
-
status: import_types.AccountStatusEnum.EnableTrading
|
|
2566
|
-
// accountId: res.data.account_id,
|
|
2567
|
-
// userId: res.data.user_id,
|
|
2568
|
-
}));
|
|
2569
|
-
return res;
|
|
2570
|
-
} else {
|
|
2571
|
-
throw new Error(res.message);
|
|
2572
|
-
}
|
|
2573
|
-
});
|
|
2574
|
-
}
|
|
2575
|
-
disconnect() {
|
|
2576
|
-
return __async(this, null, function* () {
|
|
2577
|
-
this._state$.next(__spreadProps(__spreadValues({}, this.stateValue), {
|
|
2578
|
-
status: import_types.AccountStatusEnum.NotConnected,
|
|
2579
|
-
accountId: void 0,
|
|
2580
|
-
userId: void 0,
|
|
2581
|
-
address: void 0
|
|
2582
|
-
}));
|
|
2583
|
-
});
|
|
2584
|
-
}
|
|
2585
|
-
_checkOrderlyKeyState(accountId, orderlyKey) {
|
|
2586
|
-
return __async(this, null, function* () {
|
|
2587
|
-
const res = yield this._simpleFetch(
|
|
2588
|
-
`/v1/get_orderly_key?account_id=${accountId}&orderly_key=${orderlyKey}`
|
|
2589
|
-
);
|
|
2590
|
-
if (res.success) {
|
|
2591
|
-
return res.data;
|
|
2592
|
-
} else {
|
|
2593
|
-
throw new Error(res.message);
|
|
2594
|
-
}
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
get signer() {
|
|
2598
|
-
if (!this._singer) {
|
|
2599
|
-
this._singer = new BaseSigner(this.keyStore);
|
|
2600
|
-
}
|
|
2601
|
-
return this._singer;
|
|
2602
|
-
}
|
|
2603
|
-
getAccountInfo() {
|
|
2604
|
-
return __async(this, null, function* () {
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
getBalance() {
|
|
2608
|
-
return __async(this, null, function* () {
|
|
2609
|
-
});
|
|
2610
|
-
}
|
|
2611
|
-
_getRegisterationNonce() {
|
|
2612
|
-
return __async(this, null, function* () {
|
|
2613
|
-
var _a;
|
|
2614
|
-
const res = yield this._simpleFetch("/v1/registration_nonce");
|
|
2615
|
-
console.log("getRegisterationNonce:", res);
|
|
2616
|
-
if (res.success) {
|
|
2617
|
-
return (_a = res.data) == null ? void 0 : _a.registration_nonce;
|
|
2618
|
-
} else {
|
|
2619
|
-
throw new Error(res.message);
|
|
2620
|
-
}
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
_simpleFetch(_0) {
|
|
2624
|
-
return __async(this, arguments, function* (url, init = {}) {
|
|
2625
|
-
const requestUrl = `${this.configStore.get("apiBaseUrl")}${url}`;
|
|
2626
|
-
return fetch(requestUrl, init).then((res) => res.json());
|
|
2627
|
-
});
|
|
2628
|
-
}
|
|
2629
|
-
// private async _fetch(url: string) {
|
|
2630
|
-
// const signer = this.signer;
|
|
2631
|
-
// const requestUrl = `${this.configStore.get<string>("apiBaseUrl")}${url}`;
|
|
2632
|
-
// const payload: MessageFactor = {
|
|
2633
|
-
// method: "GET",
|
|
2634
|
-
// url: requestUrl,
|
|
2635
|
-
// };
|
|
2636
|
-
// const signature = await signer.sign(payload);
|
|
2637
|
-
// console.log(requestUrl);
|
|
2638
|
-
// return fetch(requestUrl, {
|
|
2639
|
-
// headers: {
|
|
2640
|
-
// ...signature,
|
|
2641
|
-
// },
|
|
2642
|
-
// }).then((res) => res.json());
|
|
2643
|
-
// }
|
|
2644
|
-
};
|
|
2645
|
-
Account.instanceName = "account";
|
|
2646
|
-
|
|
2647
|
-
// src/wallet/web3Adapter.ts
|
|
2648
|
-
var Web3WalletAdapter = class {
|
|
2649
|
-
constructor(web3) {
|
|
2650
|
-
this.web3 = web3;
|
|
2651
|
-
}
|
|
2652
|
-
getBalance(address) {
|
|
2653
|
-
return __async(this, null, function* () {
|
|
2654
|
-
const balance = yield this.web3.eth.getBalance(address);
|
|
2655
|
-
return balance;
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
deposit(from, to, amount) {
|
|
2659
|
-
return __async(this, null, function* () {
|
|
2660
|
-
const tx = yield this.web3.eth.sendTransaction({
|
|
2661
|
-
from,
|
|
2662
|
-
to,
|
|
2663
|
-
value: amount
|
|
2664
|
-
});
|
|
2665
|
-
return tx;
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
send(method, params) {
|
|
2669
|
-
return __async(this, null, function* () {
|
|
2670
|
-
});
|
|
2671
|
-
}
|
|
2672
|
-
};
|
|
2673
|
-
|
|
2674
|
-
// src/wallet/etherAdapter.ts
|
|
2675
|
-
var import_ethers = require("ethers");
|
|
2676
|
-
var EtherAdapter = class {
|
|
2677
|
-
constructor(options) {
|
|
2678
|
-
console.log("EtherAdapter constructor", options);
|
|
2679
|
-
this._chainId = parseInt(options.chain.id, 16);
|
|
2680
|
-
this.provider = new import_ethers.BrowserProvider(options.provider, "any");
|
|
2681
|
-
}
|
|
2682
|
-
getBalance(address) {
|
|
2683
|
-
throw new Error("Method not implemented.");
|
|
2684
|
-
}
|
|
2685
|
-
deposit(from, to, amount) {
|
|
2686
|
-
throw new Error("Method not implemented.");
|
|
2687
|
-
}
|
|
2688
|
-
get chainId() {
|
|
2689
|
-
return this._chainId;
|
|
2690
|
-
}
|
|
2691
|
-
send(method, params) {
|
|
2692
|
-
return __async(this, null, function* () {
|
|
2693
|
-
var _a;
|
|
2694
|
-
return yield (_a = this.provider) == null ? void 0 : _a.send(method, params);
|
|
2695
|
-
});
|
|
2696
|
-
}
|
|
2697
|
-
verify(data, signature) {
|
|
2698
|
-
return __async(this, null, function* () {
|
|
2699
|
-
const { domain, types, message } = data;
|
|
2700
|
-
const recovered = import_ethers.ethers.verifyTypedData(domain, types, message, signature);
|
|
2701
|
-
console.log("recovered", recovered);
|
|
2702
|
-
});
|
|
2703
|
-
}
|
|
2704
|
-
};
|
|
2705
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2706
|
-
0 && (module.exports = {
|
|
2707
|
-
Account,
|
|
2708
|
-
BaseConfigStore,
|
|
2709
|
-
BaseKeyStore,
|
|
2710
|
-
BaseOrderlyKeyPair,
|
|
2711
|
-
BaseSigner,
|
|
2712
|
-
EtherAdapter,
|
|
2713
|
-
LocalStorageStore,
|
|
2714
|
-
MemoryConfigStore,
|
|
2715
|
-
MockKeyStore,
|
|
2716
|
-
SimpleDI,
|
|
2717
|
-
Web3WalletAdapter,
|
|
2718
|
-
getDefaultSigner,
|
|
2719
|
-
getMockSigner
|
|
2720
|
-
});
|
|
1
|
+
"use strict";var pt=Object.create;var re=Object.defineProperty,ht=Object.defineProperties,yt=Object.getOwnPropertyDescriptor,dt=Object.getOwnPropertyDescriptors,gt=Object.getOwnPropertyNames,ke=Object.getOwnPropertySymbols,mt=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var _=Math.pow,Ce=(p,i,c)=>i in p?re(p,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):p[i]=c,F=(p,i)=>{for(var c in i||(i={}))Re.call(i,c)&&Ce(p,c,i[c]);if(ke)for(var c of ke(i))ft.call(i,c)&&Ce(p,c,i[c]);return p},q=(p,i)=>ht(p,dt(i));var wt=(p,i)=>{for(var c in i)re(p,c,{get:i[c],enumerable:!0})},Me=(p,i,c,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let h of gt(i))!Re.call(p,h)&&h!==c&&re(p,h,{get:()=>i[h],enumerable:!(l=yt(i,h))||l.enumerable});return p};var It=(p,i,c)=>(c=p!=null?pt(mt(p)):{},Me(i||!p||!p.__esModule?re(c,"default",{value:p,enumerable:!0}):c,p)),_t=p=>Me(re({},"__esModule",{value:!0}),p);var B=(p,i,c)=>new Promise((l,h)=>{var y=f=>{try{w(c.next(f))}catch(P){h(P)}},s=f=>{try{w(c.throw(f))}catch(P){h(P)}},w=f=>f.done?l(f.value):Promise.resolve(f.value).then(y,s);w((c=c.apply(p,i)).next())});var xt={};wt(xt,{Account:()=>ce,BaseConfigStore:()=>fe,BaseKeyStore:()=>oe,BaseOrderlyKeyPair:()=>W,BaseSigner:()=>G,EtherAdapter:()=>he,LocalStorageStore:()=>Z,MemoryConfigStore:()=>ae,MockKeyStore:()=>ee,SimpleDI:()=>We,Web3WalletAdapter:()=>pe,getDefaultSigner:()=>Ve,getMockSigner:()=>je});module.exports=_t(xt);var ne={},Ne=!1;function Et(){if(Ne)return ne;Ne=!0,ne.byteLength=w,ne.toByteArray=P,ne.fromByteArray=j;for(var p=[],i=[],c=typeof Uint8Array!="undefined"?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,y=l.length;h<y;++h)p[h]=l[h],i[l.charCodeAt(h)]=h;i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63;function s(d){var m=d.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var E=d.indexOf("=");E===-1&&(E=m);var T=E===m?0:4-E%4;return[E,T]}function w(d){var m=s(d),E=m[0],T=m[1];return(E+T)*3/4-T}function f(d,m,E){return(m+E)*3/4-E}function P(d){var m,E=s(d),T=E[0],$=E[1],K=new c(f(d,T,$)),v=0,L=$>0?T-4:T,R;for(R=0;R<L;R+=4)m=i[d.charCodeAt(R)]<<18|i[d.charCodeAt(R+1)]<<12|i[d.charCodeAt(R+2)]<<6|i[d.charCodeAt(R+3)],K[v++]=m>>16&255,K[v++]=m>>8&255,K[v++]=m&255;return $===2&&(m=i[d.charCodeAt(R)]<<2|i[d.charCodeAt(R+1)]>>4,K[v++]=m&255),$===1&&(m=i[d.charCodeAt(R)]<<10|i[d.charCodeAt(R+1)]<<4|i[d.charCodeAt(R+2)]>>2,K[v++]=m>>8&255,K[v++]=m&255),K}function S(d){return p[d>>18&63]+p[d>>12&63]+p[d>>6&63]+p[d&63]}function C(d,m,E){for(var T,$=[],K=m;K<E;K+=3)T=(d[K]<<16&16711680)+(d[K+1]<<8&65280)+(d[K+2]&255),$.push(S(T));return $.join("")}function j(d){for(var m,E=d.length,T=E%3,$=[],K=16383,v=0,L=E-T;v<L;v+=K)$.push(C(d,v,v+K>L?L:v+K));return T===1?(m=d[E-1],$.push(p[m>>2]+p[m<<4&63]+"==")):T===2&&(m=(d[E-2]<<8)+d[E-1],$.push(p[m>>10]+p[m>>4&63]+p[m<<2&63]+"=")),$.join("")}return ne}var le={},Oe=!1;function Bt(){if(Oe)return le;Oe=!0;return le.read=function(p,i,c,l,h){var y,s,w=h*8-l-1,f=(1<<w)-1,P=f>>1,S=-7,C=c?h-1:0,j=c?-1:1,d=p[i+C];for(C+=j,y=d&(1<<-S)-1,d>>=-S,S+=w;S>0;y=y*256+p[i+C],C+=j,S-=8);for(s=y&(1<<-S)-1,y>>=-S,S+=l;S>0;s=s*256+p[i+C],C+=j,S-=8);if(y===0)y=1-P;else{if(y===f)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,l),y=y-P}return(d?-1:1)*s*Math.pow(2,y-l)},le.write=function(p,i,c,l,h,y){var s,w,f,P=y*8-h-1,S=(1<<P)-1,C=S>>1,j=h===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=l?0:y-1,m=l?1:-1,E=i<0||i===0&&1/i<0?1:0;for(i=Math.abs(i),isNaN(i)||i===1/0?(w=isNaN(i)?1:0,s=S):(s=Math.floor(Math.log(i)/Math.LN2),i*(f=Math.pow(2,-s))<1&&(s--,f*=2),s+C>=1?i+=j/f:i+=j*Math.pow(2,1-C),i*f>=2&&(s++,f/=2),s+C>=S?(w=0,s=S):s+C>=1?(w=(i*f-1)*Math.pow(2,h),s=s+C):(w=i*Math.pow(2,C-1)*Math.pow(2,h),s=0));h>=8;p[c+d]=w&255,d+=m,w/=256,h-=8);for(s=s<<h|w,P+=h;P>0;p[c+d]=s&255,d+=m,s/=256,P-=8);p[c+d-m]|=E*128},le}var Y={},$e=!1;function bt(){if($e)return Y;$e=!0;let p=Et(),i=Bt(),c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Y.Buffer=s,Y.SlowBuffer=$,Y.INSPECT_MAX_BYTES=50;let l=2147483647;Y.kMaxLength=l,s.TYPED_ARRAY_SUPPORT=h(),!s.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&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 h(){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(r){return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function y(r){if(r>l)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,s.prototype),e}function s(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 S(r)}return w(r,e,t)}s.poolSize=8192;function w(r,e,t){if(typeof r=="string")return C(r,e);if(ArrayBuffer.isView(r))return d(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(V(r,ArrayBuffer)||r&&V(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(V(r,SharedArrayBuffer)||r&&V(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 n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return s.from(n,e,t);let o=E(r);if(o)return o;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return s.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)}s.from=function(r,e,t){return w(r,e,t)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array);function f(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 P(r,e,t){return f(r),r<=0?y(r):e!==void 0?typeof t=="string"?y(r).fill(e,t):y(r).fill(e):y(r)}s.alloc=function(r,e,t){return P(r,e,t)};function S(r){return f(r),y(r<0?0:T(r)|0)}s.allocUnsafe=function(r){return S(r)},s.allocUnsafeSlow=function(r){return S(r)};function C(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=K(r,e)|0,n=y(t),o=n.write(r,e);return o!==t&&(n=n.slice(0,o)),n}function j(r){let e=r.length<0?0:T(r.length)|0,t=y(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function d(r){if(V(r,Uint8Array)){let e=new Uint8Array(r);return m(e.buffer,e.byteOffset,e.byteLength)}return j(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 n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,s.prototype),n}function E(r){if(s.isBuffer(r)){let e=T(r.length)|0,t=y(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)?y(0):j(r);if(r.type==="Buffer"&&Array.isArray(r.data))return j(r.data)}function T(r){if(r>=l)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+l.toString(16)+" bytes");return r|0}function $(r){return+r!=r&&(r=0),s.alloc(+r)}s.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==s.prototype},s.compare=function(e,t){if(V(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),V(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(e)||!s.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,o=t.length;for(let a=0,u=Math.min(n,o);a<u;++a)if(e[a]!==t[a]){n=e[a],o=t[a];break}return n<o?-1:o<n?1:0},s.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}},s.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return s.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let o=s.allocUnsafe(t),a=0;for(n=0;n<e.length;++n){let u=e[n];if(V(u,Uint8Array))a+u.length>o.length?(s.isBuffer(u)||(u=s.from(u)),u.copy(o,a)):Uint8Array.prototype.set.call(o,u,a);else if(s.isBuffer(u))u.copy(o,a);else throw new TypeError('"list" argument must be an Array of Buffers');a+=u.length}return o};function K(r,e){if(s.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||V(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,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return ge(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Ue(r).length;default:if(o)return n?-1:ge(r).length;e=(""+e).toLowerCase(),o=!0}}s.byteLength=K;function v(r,e,t){let n=!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 rt(this,e,t);case"utf8":case"utf-8":return Ee(this,e,t);case"ascii":return et(this,e,t);case"latin1":case"binary":return tt(this,e,t);case"base64":return Qe(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nt(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}s.prototype._isBuffer=!0;function L(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}s.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)L(this,t,t+1);return this},s.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)L(this,t,t+3),L(this,t+1,t+2);return this},s.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)L(this,t,t+7),L(this,t+1,t+6),L(this,t+2,t+5),L(this,t+3,t+4);return this},s.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Ee(this,0,e):v.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(e){if(!s.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:s.compare(this,e)===0},s.prototype.inspect=function(){let e="",t=Y.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},c&&(s.prototype[c]=s.prototype.inspect),s.prototype.compare=function(e,t,n,o,a){if(V(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.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),n===void 0&&(n=e?e.length:0),o===void 0&&(o=0),a===void 0&&(a=this.length),t<0||n>e.length||o<0||a>this.length)throw new RangeError("out of range index");if(o>=a&&t>=n)return 0;if(o>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,o>>>=0,a>>>=0,this===e)return 0;let u=a-o,g=n-t,A=Math.min(u,g),b=this.slice(o,a),x=e.slice(t,n);for(let I=0;I<A;++I)if(b[I]!==x[I]){u=b[I],g=x[I];break}return u<g?-1:g<u?1:0};function R(r,e,t,n,o){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,me(t)&&(t=o?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(o)return-1;t=r.length-1}else if(t<0)if(o)t=0;else return-1;if(typeof e=="string"&&(e=s.from(e,n)),s.isBuffer(e))return e.length===0?-1:_e(r,e,t,n,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):_e(r,[e],t,n,o);throw new TypeError("val must be string, number or Buffer")}function _e(r,e,t,n,o){let a=1,u=r.length,g=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;a=2,u/=2,g/=2,t/=2}function A(x,I){return a===1?x[I]:x.readUInt16BE(I*a)}let b;if(o){let x=-1;for(b=t;b<u;b++)if(A(r,b)===A(e,x===-1?0:b-x)){if(x===-1&&(x=b),b-x+1===g)return x*a}else x!==-1&&(b-=b-x),x=-1}else for(t+g>u&&(t=u-g),b=t;b>=0;b--){let x=!0;for(let I=0;I<g;I++)if(A(r,b+I)!==A(e,I)){x=!1;break}if(x)return b}return-1}s.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},s.prototype.indexOf=function(e,t,n){return R(this,e,t,n,!0)},s.prototype.lastIndexOf=function(e,t,n){return R(this,e,t,n,!1)};function Je(r,e,t,n){t=Number(t)||0;let o=r.length-t;n?(n=Number(n),n>o&&(n=o)):n=o;let a=e.length;n>a/2&&(n=a/2);let u;for(u=0;u<n;++u){let g=parseInt(e.substr(u*2,2),16);if(me(g))return u;r[t+u]=g}return u}function Ye(r,e,t,n){return ue(ge(e,r.length-t),r,t,n)}function Xe(r,e,t,n){return ue(at(e),r,t,n)}function He(r,e,t,n){return ue(Ue(e),r,t,n)}function ze(r,e,t,n){return ue(ct(e,r.length-t),r,t,n)}s.prototype.write=function(e,t,n,o){if(t===void 0)o="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")o=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,o===void 0&&(o="utf8")):(o=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let a=this.length-t;if((n===void 0||n>a)&&(n=a),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let u=!1;for(;;)switch(o){case"hex":return Je(this,e,t,n);case"utf8":case"utf-8":return Ye(this,e,t,n);case"ascii":case"latin1":case"binary":return Xe(this,e,t,n);case"base64":return He(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ze(this,e,t,n);default:if(u)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),u=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Qe(r,e,t){return e===0&&t===r.length?p.fromByteArray(r):p.fromByteArray(r.slice(e,t))}function Ee(r,e,t){t=Math.min(r.length,t);let n=[],o=e;for(;o<t;){let a=r[o],u=null,g=a>239?4:a>223?3:a>191?2:1;if(o+g<=t){let A,b,x,I;switch(g){case 1:a<128&&(u=a);break;case 2:A=r[o+1],(A&192)===128&&(I=(a&31)<<6|A&63,I>127&&(u=I));break;case 3:A=r[o+1],b=r[o+2],(A&192)===128&&(b&192)===128&&(I=(a&15)<<12|(A&63)<<6|b&63,I>2047&&(I<55296||I>57343)&&(u=I));break;case 4:A=r[o+1],b=r[o+2],x=r[o+3],(A&192)===128&&(b&192)===128&&(x&192)===128&&(I=(a&15)<<18|(A&63)<<12|(b&63)<<6|x&63,I>65535&&I<1114112&&(u=I))}}u===null?(u=65533,g=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|u&1023),n.push(u),o+=g}return Ze(n)}let Be=4096;function Ze(r){let e=r.length;if(e<=Be)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Be));return t}function et(r,e,t){let n="";t=Math.min(r.length,t);for(let o=e;o<t;++o)n+=String.fromCharCode(r[o]&127);return n}function tt(r,e,t){let n="";t=Math.min(r.length,t);for(let o=e;o<t;++o)n+=String.fromCharCode(r[o]);return n}function rt(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let o="";for(let a=e;a<t;++a)o+=ut[r[a]];return o}function nt(r,e,t){let n=r.slice(e,t),o="";for(let a=0;a<n.length-1;a+=2)o+=String.fromCharCode(n[a]+n[a+1]*256);return o}s.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let o=this.subarray(e,t);return Object.setPrototypeOf(o,s.prototype),o};function k(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")}s.prototype.readUintLE=s.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||k(e,t,this.length);let o=this[e],a=1,u=0;for(;++u<t&&(a*=256);)o+=this[e+u]*a;return o},s.prototype.readUintBE=s.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||k(e,t,this.length);let o=this[e+--t],a=1;for(;t>0&&(a*=256);)o+=this[e+--t]*a;return o},s.prototype.readUint8=s.prototype.readUInt8=function(e,t){return e=e>>>0,t||k(e,1,this.length),this[e]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||k(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||k(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||k(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},s.prototype.readBigUInt64LE=J(function(e){e=e>>>0,z(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&te(e,this.length-8);let o=t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24),a=this[++e]+this[++e]*_(2,8)+this[++e]*_(2,16)+n*_(2,24);return BigInt(o)+(BigInt(a)<<BigInt(32))}),s.prototype.readBigUInt64BE=J(function(e){e=e>>>0,z(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&te(e,this.length-8);let o=t*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e],a=this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n;return(BigInt(o)<<BigInt(32))+BigInt(a)}),s.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||k(e,t,this.length);let o=this[e],a=1,u=0;for(;++u<t&&(a*=256);)o+=this[e+u]*a;return a*=128,o>=a&&(o-=Math.pow(2,8*t)),o},s.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||k(e,t,this.length);let o=t,a=1,u=this[e+--o];for(;o>0&&(a*=256);)u+=this[e+--o]*a;return a*=128,u>=a&&(u-=Math.pow(2,8*t)),u},s.prototype.readInt8=function(e,t){return e=e>>>0,t||k(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},s.prototype.readInt16LE=function(e,t){e=e>>>0,t||k(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},s.prototype.readInt16BE=function(e,t){e=e>>>0,t||k(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},s.prototype.readInt32LE=function(e,t){return e=e>>>0,t||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},s.prototype.readInt32BE=function(e,t){return e=e>>>0,t||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},s.prototype.readBigInt64LE=J(function(e){e=e>>>0,z(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&te(e,this.length-8);let o=this[e+4]+this[e+5]*_(2,8)+this[e+6]*_(2,16)+(n<<24);return(BigInt(o)<<BigInt(32))+BigInt(t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24))}),s.prototype.readBigInt64BE=J(function(e){e=e>>>0,z(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&te(e,this.length-8);let o=(t<<24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e];return(BigInt(o)<<BigInt(32))+BigInt(this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n)}),s.prototype.readFloatLE=function(e,t){return e=e>>>0,t||k(e,4,this.length),i.read(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,t){return e=e>>>0,t||k(e,4,this.length),i.read(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||k(e,8,this.length),i.read(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||k(e,8,this.length),i.read(this,e,!1,52,8)};function D(r,e,t,n,o,a){if(!s.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<a)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(e,t,n,o){if(e=+e,t=t>>>0,n=n>>>0,!o){let g=Math.pow(2,8*n)-1;D(this,e,t,n,g,0)}let a=1,u=0;for(this[t]=e&255;++u<n&&(a*=256);)this[t+u]=e/a&255;return t+n},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(e,t,n,o){if(e=+e,t=t>>>0,n=n>>>0,!o){let g=Math.pow(2,8*n)-1;D(this,e,t,n,g,0)}let a=n-1,u=1;for(this[t+a]=e&255;--a>=0&&(u*=256);)this[t+a]=e/u&255;return t+n},s.prototype.writeUint8=s.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,1,255,0),this[t]=e&255,t+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||D(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},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||D(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 be(r,e,t,n,o){Te(e,n,o,r,t,7);let a=Number(e&BigInt(4294967295));r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,t}function Ae(r,e,t,n,o){Te(e,n,o,r,t,7);let a=Number(e&BigInt(4294967295));r[t+7]=a,a=a>>8,r[t+6]=a,a=a>>8,r[t+5]=a,a=a>>8,r[t+4]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=u,u=u>>8,r[t+2]=u,u=u>>8,r[t+1]=u,u=u>>8,r[t]=u,t+8}s.prototype.writeBigUInt64LE=J(function(e,t=0){return be(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeBigUInt64BE=J(function(e,t=0){return Ae(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeIntLE=function(e,t,n,o){if(e=+e,t=t>>>0,!o){let A=Math.pow(2,8*n-1);D(this,e,t,n,A-1,-A)}let a=0,u=1,g=0;for(this[t]=e&255;++a<n&&(u*=256);)e<0&&g===0&&this[t+a-1]!==0&&(g=1),this[t+a]=(e/u>>0)-g&255;return t+n},s.prototype.writeIntBE=function(e,t,n,o){if(e=+e,t=t>>>0,!o){let A=Math.pow(2,8*n-1);D(this,e,t,n,A-1,-A)}let a=n-1,u=1,g=0;for(this[t+a]=e&255;--a>=0&&(u*=256);)e<0&&g===0&&this[t+a+1]!==0&&(g=1),this[t+a]=(e/u>>0)-g&255;return t+n},s.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},s.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},s.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||D(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},s.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||D(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},s.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||D(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},s.prototype.writeBigInt64LE=J(function(e,t=0){return be(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),s.prototype.writeBigInt64BE=J(function(e,t=0){return Ae(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function xe(r,e,t,n,o,a){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Se(r,e,t,n,o){return e=+e,t=t>>>0,o||xe(r,e,t,4),i.write(r,e,t,n,23,4),t+4}s.prototype.writeFloatLE=function(e,t,n){return Se(this,e,t,!0,n)},s.prototype.writeFloatBE=function(e,t,n){return Se(this,e,t,!1,n)};function Ke(r,e,t,n,o){return e=+e,t=t>>>0,o||xe(r,e,t,8),i.write(r,e,t,n,52,8),t+8}s.prototype.writeDoubleLE=function(e,t,n){return Ke(this,e,t,!0,n)},s.prototype.writeDoubleBE=function(e,t,n){return Ke(this,e,t,!1,n)},s.prototype.copy=function(e,t,n,o){if(!s.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),t>=e.length&&(t=e.length),t||(t=0),o>0&&o<n&&(o=n),o===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-t<o-n&&(o=e.length-t+n);let a=o-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,o):Uint8Array.prototype.set.call(e,this.subarray(n,o),t),a},s.prototype.fill=function(e,t,n,o){if(typeof e=="string"){if(typeof t=="string"?(o=t,t=0,n=this.length):typeof n=="string"&&(o=n,n=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!s.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(e.length===1){let u=e.charCodeAt(0);(o==="utf8"&&u<128||o==="latin1")&&(e=u)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let a;if(typeof e=="number")for(a=t;a<n;++a)this[a]=e;else{let u=s.isBuffer(e)?e:s.from(e,o),g=u.length;if(g===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-t;++a)this[a+t]=u[a%g]}return this};let H={};function de(r,e,t){H[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(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}de("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),de("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),de("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,o=t;return Number.isInteger(t)&&Math.abs(t)>_(2,32)?o=Pe(String(t)):typeof t=="bigint"&&(o=String(t),(t>_(BigInt(2),BigInt(32))||t<-_(BigInt(2),BigInt(32)))&&(o=Pe(o)),o+="n"),n+=` It must be ${e}. Received ${o}`,n},RangeError);function Pe(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function it(r,e,t){z(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&te(e,r.length-(t+1))}function Te(r,e,t,n,o,a){if(r>t||r<e){let u=typeof e=="bigint"?"n":"",g;throw a>3?e===0||e===BigInt(0)?g=`>= 0${u} and < 2${u} ** ${(a+1)*8}${u}`:g=`>= -(2${u} ** ${(a+1)*8-1}${u}) and < 2 ** ${(a+1)*8-1}${u}`:g=`>= ${e}${u} and <= ${t}${u}`,new H.ERR_OUT_OF_RANGE("value",g,r)}it(n,o,a)}function z(r,e){if(typeof r!="number")throw new H.ERR_INVALID_ARG_TYPE(e,"number",r)}function te(r,e,t){throw Math.floor(r)!==r?(z(r,t),new H.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new H.ERR_BUFFER_OUT_OF_BOUNDS:new H.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let ot=/[^+/0-9A-Za-z-_]/g;function st(r){if(r=r.split("=")[0],r=r.trim().replace(ot,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function ge(r,e){e=e||1/0;let t,n=r.length,o=null,a=[];for(let u=0;u<n;++u){if(t=r.charCodeAt(u),t>55295&&t<57344){if(!o){if(t>56319){(e-=3)>-1&&a.push(239,191,189);continue}else if(u+1===n){(e-=3)>-1&&a.push(239,191,189);continue}o=t;continue}if(t<56320){(e-=3)>-1&&a.push(239,191,189),o=t;continue}t=(o-55296<<10|t-56320)+65536}else o&&(e-=3)>-1&&a.push(239,191,189);if(o=null,t<128){if((e-=1)<0)break;a.push(t)}else if(t<2048){if((e-=2)<0)break;a.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;a.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;a.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return a}function at(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function ct(r,e){let t,n,o,a=[];for(let u=0;u<r.length&&!((e-=2)<0);++u)t=r.charCodeAt(u),n=t>>8,o=t%256,a.push(o),a.push(n);return a}function Ue(r){return p.toByteArray(st(r))}function ue(r,e,t,n){let o;for(o=0;o<n&&!(o+t>=e.length||o>=r.length);++o)e[o+t]=r[o];return o}function V(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 ut=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let o=0;o<16;++o)e[n+o]=r[t]+r[o]}return e}();function J(r){return typeof BigInt=="undefined"?lt:r}function lt(){throw new Error("BigInt not supported")}return Y}var X=bt();X.Buffer;X.SlowBuffer;X.INSPECT_MAX_BYTES;X.kMaxLength;var U=X.Buffer,Pt=X.INSPECT_MAX_BYTES,Tt=X.kMaxLength;var ie=require("bs58"),Q=It(require("@noble/ed25519"));var W=class p{static generateKey(){let i=Q.utils.randomPrivateKey(),c=(0,ie.encode)(i);return new p(c)}constructor(i){this.secretKey=i;let c=(0,ie.decode)(i);this.privateKey=U.from(c).toString("hex")}sign(i){return B(this,null,function*(){return yield Q.signAsync(i,this.privateKey)})}getPublicKey(){return B(this,null,function*(){let i=yield Q.getPublicKeyAsync(this.privateKey);return`ed25519:${(0,ie.encode)(i)}`})}toString(){return this.privateKey}};var oe=class{constructor(i="testnet"){this.networkId=i}get keyPrefix(){return`orderly_${this.networkId}_`}},Z=class extends oe{getOrderlyKey(i){let c;if(i)c=this.getItem(i,"orderlyKey");else{let l=this.getAddress();if(!l)return null;c=this.getItem(l,"orderlyKey")}return c?new W(c):null}getAccountId(i){return this.getItem(i,"accountId")}setAccountId(i,c){this.setItem(i,{accountId:c})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(i){localStorage.setItem(`${this.keyPrefix}address`,i)}generateKey(){return W.generateKey()}setKey(i,c){this.setItem(i,{orderlyKey:c.secretKey})}cleanAllKey(i){localStorage.removeItem(`${this.keyPrefix}${i}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(i,c){let l=this.getItem(i);delete l[c],localStorage.setItem(`${this.keyPrefix}${i}`,JSON.stringify(l))}setItem(i,c){let l=`${this.keyPrefix}${i}`,h=localStorage.getItem(l);h?h=JSON.parse(h):h={},localStorage.setItem(l,JSON.stringify(F(F({},h),c)))}getItem(i,c){let l=`${this.keyPrefix}${i}`,h=localStorage.getItem(l);return h?h=JSON.parse(h):h={},typeof c=="undefined"?h:h[c]}},ee=class{constructor(i){this.secretKey=i}generateKey(){return new W(this.secretKey)}getOrderlyKey(){return new W(this.secretKey)}getAccountId(){return""}setAccountId(i){}getAddress(){return""}setAddress(i){}setKey(i,c){}cleanAllKey(){}cleanKey(i){}};var se={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"}]};var ve=function(p){return p.replace(/\+/g,"-").replace(/\//g,"_")};function At(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function De(p,i){return{name:"Orderly",version:"1",chainId:p,verifyingContract:i?At():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Le(p){let{chainId:i,registrationNonce:c}=p,l=Date.now(),h="Registration",y={brokerId:"woofi_dex",chainId:i,timestamp:l,registrationNonce:c},s={EIP712Domain:se.EIP712Domain,[h]:se[h]};return[y,{domain:De(i),message:y,primaryType:h,types:s}]}function Fe(p){let{publicKey:i,chainId:c,primaryType:l,expiration:h=365}=p,y=Date.now(),s={brokerId:"woofi_dex",orderlyKey:i,scope:"read,trading",chainId:c,timestamp:y,expiration:y+1e3*60*60*24*h},w={EIP712Domain:se.EIP712Domain,[l]:se[l]},f={domain:De(c),message:s,primaryType:l,types:w};return[s,f]}var G=class{constructor(i){this.keyStore=i}sign(i){return B(this,null,function*(){let c=Date.now().toString(),l=[c,i.method.toUpperCase(),i.url].join("");i.data&&Object.keys(i.data).length&&(l+=JSON.stringify(i.data));let{signature:h,publicKey:y}=yield this.signText(l);return{"orderly-key":y,"orderly-timestamp":c,"orderly-signature":h}})}signText(i){return B(this,null,function*(){let c=this.keyStore.getOrderlyKey();if(!c)throw new Error("orderlyKeyPair is not defined");let l=U.from(i),h=yield c.sign(l),y=U.from(h).toString("base64");return{signature:ve(y),publicKey:yield c.getPublicKey()}})}};var ae=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://dev-api-v2.orderly.org"],["klineDataUrl","https://dev-api-v2.orderly.org"]])}get(i){return this.map.get(i)}set(i,c){this.map.set(i,c)}clear(){}},fe=class extends ae{constructor(c){super();this.configMap=c}_restore(){let c=Object.entries(this.configMap);this.map=new Map(c)}};var je=p=>{let i=new ee(p||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new G(i)},Ve=()=>{if(typeof window=="undefined")throw new Error("the default signer only supports browsers.");let p=new Z("");return new G(p)};var we=class{constructor(i=[],c={}){this.providers=i;this.services=c;this.injectProperties={}}register(...i){this.providers.push(...i),i.forEach(c=>{let l=c;l instanceof Function&&(l=new c),this.add(l)})}registerByName(i,c){let l=c;l instanceof Function&&(l=new c),this.addByName(i,l)}get(i){return this.services[i]}getAll(){return Object.assign({},this.services)}add(i){return this.addByName(i.constructor.name,i)}addByName(i,c){return this.services[i]=c,this.services[i.toLowerCase()]=c,this.injectIntoProperties(c,i),this.get(i)}inject(i,c,l){i&&l&&(i[c]=l)}injectIntoProperties(i,c=i.constructor.name){this.getInjectProperty(c.toLowerCase()).forEach(l=>{this.inject(l.target,l.propertyKey,i)})}getInjectProperty(i){return this.injectProperties[i]||(this.injectProperties[i]=[]),this.injectProperties[i]}},qe=we;var Ie=class p{static getContainer(){return p.container||(p.container=new qe),p.container}static register(...i){this.getContainer().register(...i)}static registerByName(i,c){this.getContainer().registerByName(i,c)}static get(i){return this.getContainer().get(i)}static getAll(){return this.getContainer().getAll()}constructor(){}},We=Ie;var Ge=require("rxjs");var O=require("@orderly.network/types");var ce=class{constructor(i,c,l){this.configStore=i;this.keyStore=c;this.walletAdapterClass=l;this._state$=new Ge.BehaviorSubject({status:O.AccountStatusEnum.NotConnected,balance:"",leverage:Number.NaN})}login(i){if(!i)throw new Error("address is required")}logout(){}setAddress(i,c){return B(this,null,function*(){if(!i)throw new Error("address is required");return this.keyStore.setAddress(i),this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.Connected,address:i})),c&&(this.walletClient=new this.walletAdapterClass(c)),yield this._checkAccount(i)})}get state$(){return this._state$}get stateValue(){return this._state$.getValue()}get accountId(){return this.stateValue.accountId}set position(i){this._state$.next(q(F({},this.stateValue),{positon:i}))}set orders(i){this._state$.next(q(F({},this.stateValue),{orders:i}))}_checkAccount(i){return B(this,null,function*(){console.log("check account is esist");try{let c=yield this._checkAccountExist(i);if(console.log("accountInfo:",c),c&&c.account_id)console.log("account is exist"),this.keyStore.setAccountId(i,c.account_id),this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.SignedIn,accountId:c.account_id,userId:c.user_id}));else return O.AccountStatusEnum.NotSignedIn;let l=this.keyStore.getOrderlyKey(i);if(console.log("orderlyKey:",l),!l)return console.log("orderlyKey is null"),this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.DisabledTrading})),O.AccountStatusEnum.DisabledTrading;let h=yield l.getPublicKey(),y=yield this._checkOrderlyKeyState(c.account_id,h);if(console.log("orderlyKeyStatus:",y),y&&y.orderly_key&&y.key_status==="ACTIVE"){let s=Date.now(),w=y.expiration;return s>w?(this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.DisabledTrading):(this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading})),O.AccountStatusEnum.EnableTrading)}return this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.NotConnected}catch(c){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",c)}return O.AccountStatusEnum.NotSignedIn})}_checkAccountExist(i){return B(this,null,function*(){let c=yield this._simpleFetch(`/v1/get_account?address=${i}&broker_id=woofi_dex`);if(c.success)return c.data;throw new Error(c.message)})}createAccount(){return B(this,null,function*(){let i=yield this._getRegisterationNonce();console.log("nonce:",i);let l=yield this.keyStore.generateKey().getPublicKey(),h=this.stateValue.address;if(!h)throw new Error("address is undefined");let[y,s]=Le({registrationNonce:i,chainId:this.walletClient.chainId}),w=yield this.walletClient.send("eth_signTypedData_v4",[h,JSON.stringify(s)]),f=yield this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:w,message:y,userAddress:h}),headers:{"Content-Type":"application/json"}});if(console.log("createAccount:",f),f.success)return this.keyStore.setAccountId(h,f.data.account_id),this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.SignedIn,accountId:f.data.account_id,userId:f.data.user_id})),f})}createOrderlyKey(i){return B(this,null,function*(){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(this.walletClient===void 0)throw new Error("walletClient is undefined");let c="AddOrderlyKey",l=this.keyStore.generateKey(),h=yield l.getPublicKey(),[y,s]=Fe({publicKey:h,chainId:this.walletClient.chainId,primaryType:c,expiration:i}),w=this.stateValue.address;if(!w)throw new Error("address is undefined");console.log("message:",y,s,w);let f=yield this.walletClient.send("eth_signTypedData_v4",[w,JSON.stringify(s)]),P=yield this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:f,message:y,userAddress:w}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(P.success)return this.keyStore.setKey(w,l),this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading})),P;throw new Error(P.message)})}disconnect(){return B(this,null,function*(){this._state$.next(q(F({},this.stateValue),{status:O.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0}))})}_checkOrderlyKeyState(i,c){return B(this,null,function*(){let l=yield this._simpleFetch(`/v1/get_orderly_key?account_id=${i}&orderly_key=${c}`);if(l.success)return l.data;throw new Error(l.message)})}get signer(){return this._singer||(this._singer=new G(this.keyStore)),this._singer}getAccountInfo(){return B(this,null,function*(){})}getBalance(){return B(this,null,function*(){})}_getRegisterationNonce(){return B(this,null,function*(){var c;let i=yield this._simpleFetch("/v1/registration_nonce");if(console.log("getRegisterationNonce:",i),i.success)return(c=i.data)==null?void 0:c.registration_nonce;throw new Error(i.message)})}_simpleFetch(l){return B(this,arguments,function*(i,c={}){let h=`${this.configStore.get("apiBaseUrl")}${i}`;return fetch(h,c).then(y=>y.json())})}};ce.instanceName="account";var pe=class{constructor(i){this.web3=i}getBalance(i){return B(this,null,function*(){return yield this.web3.eth.getBalance(i)})}deposit(i,c,l){return B(this,null,function*(){return yield this.web3.eth.sendTransaction({from:i,to:c,value:l})})}send(i,c){return B(this,null,function*(){})}};var ye=require("ethers");var he=class{constructor(i){console.log("EtherAdapter constructor",i),this._chainId=parseInt(i.chain.id,16),this.provider=new ye.BrowserProvider(i.provider,"any")}getBalance(i){throw new Error("Method not implemented.")}deposit(i,c,l){throw new Error("Method not implemented.")}get chainId(){return this._chainId}send(i,c){return B(this,null,function*(){var l;return yield(l=this.provider)==null?void 0:l.send(i,c)})}verify(i,c){return B(this,null,function*(){let{domain:l,types:h,message:y}=i,s=ye.ethers.verifyTypedData(l,h,y,c);console.log("recovered",s)})}};0&&(module.exports={Account,BaseConfigStore,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,EtherAdapter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,Web3WalletAdapter,getDefaultSigner,getMockSigner});
|
|
2721
2
|
/*! Bundled license information:
|
|
2722
3
|
|
|
2723
4
|
@jspm/core/nodelibs/browser/buffer.js:
|