@depthhq/sdk 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/confirm.d.ts +5 -0
- package/dist/account/discovery.d.ts +49 -0
- package/dist/account/funding.d.ts +86 -0
- package/dist/account/funding.js +498 -0
- package/dist/account/release.d.ts +8 -0
- package/dist/account/token.d.ts +5 -0
- package/dist/app/app.d.ts +50 -0
- package/dist/catalog/catalog.d.ts +50 -0
- package/dist/catalog/data.d.ts +30 -0
- package/dist/catalog/data.js +169 -0
- package/dist/chain/arcium.d.ts +10 -0
- package/dist/chain/connection.d.ts +4 -0
- package/dist/chain/environment.d.ts +20 -0
- package/dist/chain/manifest.d.ts +36 -0
- package/dist/chain/network.d.ts +18 -0
- package/dist/chain/provider.d.ts +6 -0
- package/dist/chain/random.d.ts +1 -0
- package/dist/chain/settlement.d.ts +15 -0
- package/dist/chain/transaction.d.ts +12 -0
- package/dist/client/client.d.ts +137 -0
- package/dist/client/types.d.ts +105 -0
- package/dist/history/history.d.ts +26 -0
- package/dist/history/replay.d.ts +13 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +47534 -0
- package/dist/operation/error.d.ts +10 -0
- package/dist/operation/operation.d.ts +49 -0
- package/dist/operator.d.ts +6 -0
- package/dist/operator.js +25383 -0
- package/dist/position/pnl.d.ts +14 -0
- package/dist/recovery/coordinator.d.ts +17 -0
- package/dist/recovery/recovery.d.ts +26 -0
- package/dist/recovery/recovery.js +1420 -0
- package/dist/recovery/shares.d.ts +26 -0
- package/dist/recovery/winddown.d.ts +38 -0
- package/dist/recovery/witness.d.ts +16 -0
- package/dist/trade/amount.d.ts +2 -0
- package/dist/trade/flow.d.ts +21 -0
- package/dist/trade/input.d.ts +3 -0
- package/dist/trade/terms.d.ts +3 -0
- package/dist/view/view.d.ts +59 -0
- package/dist/view/view.js +26681 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1420 @@
|
|
|
1
|
+
// node:buffer
|
|
2
|
+
var lookup = [];
|
|
3
|
+
var revLookup = [];
|
|
4
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5
|
+
for (i = 0, len = code.length;i < len; ++i)
|
|
6
|
+
lookup[i] = code[i], revLookup[code.charCodeAt(i)] = i;
|
|
7
|
+
var i;
|
|
8
|
+
var len;
|
|
9
|
+
revLookup[45] = 62;
|
|
10
|
+
revLookup[95] = 63;
|
|
11
|
+
function getLens(b64) {
|
|
12
|
+
var len2 = b64.length;
|
|
13
|
+
if (len2 % 4 > 0)
|
|
14
|
+
throw Error("Invalid string. Length must be a multiple of 4");
|
|
15
|
+
var validLen = b64.indexOf("=");
|
|
16
|
+
if (validLen === -1)
|
|
17
|
+
validLen = len2;
|
|
18
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
19
|
+
return [validLen, placeHoldersLen];
|
|
20
|
+
}
|
|
21
|
+
function _byteLength(validLen, placeHoldersLen) {
|
|
22
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
23
|
+
}
|
|
24
|
+
function toByteArray(b64) {
|
|
25
|
+
var tmp, lens = getLens(b64), validLen = lens[0], placeHoldersLen = lens[1], arr = new Uint8Array(_byteLength(validLen, placeHoldersLen)), curByte = 0, len2 = placeHoldersLen > 0 ? validLen - 4 : validLen, i2;
|
|
26
|
+
for (i2 = 0;i2 < len2; i2 += 4)
|
|
27
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)], arr[curByte++] = tmp >> 16 & 255, arr[curByte++] = tmp >> 8 & 255, arr[curByte++] = tmp & 255;
|
|
28
|
+
if (placeHoldersLen === 2)
|
|
29
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4, arr[curByte++] = tmp & 255;
|
|
30
|
+
if (placeHoldersLen === 1)
|
|
31
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2, arr[curByte++] = tmp >> 8 & 255, arr[curByte++] = tmp & 255;
|
|
32
|
+
return arr;
|
|
33
|
+
}
|
|
34
|
+
function tripletToBase64(num) {
|
|
35
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
36
|
+
}
|
|
37
|
+
function encodeChunk(uint8, start, end) {
|
|
38
|
+
var tmp, output = [];
|
|
39
|
+
for (var i2 = start;i2 < end; i2 += 3)
|
|
40
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255), output.push(tripletToBase64(tmp));
|
|
41
|
+
return output.join("");
|
|
42
|
+
}
|
|
43
|
+
function fromByteArray(uint8) {
|
|
44
|
+
var tmp, len2 = uint8.length, extraBytes = len2 % 3, parts = [], maxChunkLength = 16383;
|
|
45
|
+
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength)
|
|
46
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
47
|
+
if (extraBytes === 1)
|
|
48
|
+
tmp = uint8[len2 - 1], parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
49
|
+
else if (extraBytes === 2)
|
|
50
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1], parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
51
|
+
return parts.join("");
|
|
52
|
+
}
|
|
53
|
+
function read(buffer, offset, isLE, mLen, nBytes) {
|
|
54
|
+
var e, m, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, nBits = -7, i2 = isLE ? nBytes - 1 : 0, d = isLE ? -1 : 1, s = buffer[offset + i2];
|
|
55
|
+
i2 += d, e = s & (1 << -nBits) - 1, s >>= -nBits, nBits += eLen;
|
|
56
|
+
for (;nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8)
|
|
57
|
+
;
|
|
58
|
+
m = e & (1 << -nBits) - 1, e >>= -nBits, nBits += mLen;
|
|
59
|
+
for (;nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8)
|
|
60
|
+
;
|
|
61
|
+
if (e === 0)
|
|
62
|
+
e = 1 - eBias;
|
|
63
|
+
else if (e === eMax)
|
|
64
|
+
return m ? NaN : (s ? -1 : 1) * (1 / 0);
|
|
65
|
+
else
|
|
66
|
+
m = m + Math.pow(2, mLen), e = e - eBias;
|
|
67
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
68
|
+
}
|
|
69
|
+
function write(buffer, value, offset, isLE, mLen, nBytes) {
|
|
70
|
+
var e, m, c, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, i2 = isLE ? 0 : nBytes - 1, d = isLE ? 1 : -1, s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
71
|
+
if (value = Math.abs(value), isNaN(value) || value === 1 / 0)
|
|
72
|
+
m = isNaN(value) ? 1 : 0, e = eMax;
|
|
73
|
+
else {
|
|
74
|
+
if (e = Math.floor(Math.log(value) / Math.LN2), value * (c = Math.pow(2, -e)) < 1)
|
|
75
|
+
e--, c *= 2;
|
|
76
|
+
if (e + eBias >= 1)
|
|
77
|
+
value += rt / c;
|
|
78
|
+
else
|
|
79
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
80
|
+
if (value * c >= 2)
|
|
81
|
+
e++, c /= 2;
|
|
82
|
+
if (e + eBias >= eMax)
|
|
83
|
+
m = 0, e = eMax;
|
|
84
|
+
else if (e + eBias >= 1)
|
|
85
|
+
m = (value * c - 1) * Math.pow(2, mLen), e = e + eBias;
|
|
86
|
+
else
|
|
87
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen), e = 0;
|
|
88
|
+
}
|
|
89
|
+
for (;mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8)
|
|
90
|
+
;
|
|
91
|
+
e = e << mLen | m, eLen += mLen;
|
|
92
|
+
for (;eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8)
|
|
93
|
+
;
|
|
94
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
95
|
+
}
|
|
96
|
+
var customInspectSymbol = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
97
|
+
var INSPECT_MAX_BYTES = 50;
|
|
98
|
+
var kMaxLength = 2147483647;
|
|
99
|
+
var btoa = globalThis.btoa;
|
|
100
|
+
var atob = globalThis.atob;
|
|
101
|
+
var File = globalThis.File;
|
|
102
|
+
var Blob = globalThis.Blob;
|
|
103
|
+
function createBuffer(length) {
|
|
104
|
+
if (length > kMaxLength)
|
|
105
|
+
throw RangeError('The value "' + length + '" is invalid for option "size"');
|
|
106
|
+
let buf = new Uint8Array(length);
|
|
107
|
+
return Object.setPrototypeOf(buf, Buffer.prototype), buf;
|
|
108
|
+
}
|
|
109
|
+
function E(sym, getMessage, Base) {
|
|
110
|
+
return class extends Base {
|
|
111
|
+
constructor() {
|
|
112
|
+
super();
|
|
113
|
+
Object.defineProperty(this, "message", { value: getMessage.apply(this, arguments), writable: true, configurable: true }), this.name = `${this.name} [${sym}]`, this.stack, delete this.name;
|
|
114
|
+
}
|
|
115
|
+
get code() {
|
|
116
|
+
return sym;
|
|
117
|
+
}
|
|
118
|
+
set code(value) {
|
|
119
|
+
Object.defineProperty(this, "code", { configurable: true, enumerable: true, value, writable: true });
|
|
120
|
+
}
|
|
121
|
+
toString() {
|
|
122
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
var ERR_BUFFER_OUT_OF_BOUNDS = E("ERR_BUFFER_OUT_OF_BOUNDS", function(name) {
|
|
127
|
+
if (name)
|
|
128
|
+
return `${name} is outside of buffer bounds`;
|
|
129
|
+
return "Attempt to access memory outside buffer bounds";
|
|
130
|
+
}, RangeError);
|
|
131
|
+
var ERR_INVALID_ARG_TYPE = E("ERR_INVALID_ARG_TYPE", function(name, actual) {
|
|
132
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
133
|
+
}, TypeError);
|
|
134
|
+
var ERR_OUT_OF_RANGE = E("ERR_OUT_OF_RANGE", function(str, range, input) {
|
|
135
|
+
let msg = `The value of "${str}" is out of range.`, received = input;
|
|
136
|
+
if (Number.isInteger(input) && Math.abs(input) > 4294967296)
|
|
137
|
+
received = addNumericalSeparator(String(input));
|
|
138
|
+
else if (typeof input === "bigint") {
|
|
139
|
+
if (received = String(input), input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32)))
|
|
140
|
+
received = addNumericalSeparator(received);
|
|
141
|
+
received += "n";
|
|
142
|
+
}
|
|
143
|
+
return msg += ` It must be ${range}. Received ${received}`, msg;
|
|
144
|
+
}, RangeError);
|
|
145
|
+
function Buffer(arg, encodingOrOffset, length) {
|
|
146
|
+
if (typeof arg === "number") {
|
|
147
|
+
if (typeof encodingOrOffset === "string")
|
|
148
|
+
throw TypeError('The "string" argument must be of type string. Received type number');
|
|
149
|
+
return allocUnsafe(arg);
|
|
150
|
+
}
|
|
151
|
+
return from(arg, encodingOrOffset, length);
|
|
152
|
+
}
|
|
153
|
+
Object.defineProperty(Buffer.prototype, "parent", { enumerable: true, get: function() {
|
|
154
|
+
if (!Buffer.isBuffer(this))
|
|
155
|
+
return;
|
|
156
|
+
return this.buffer;
|
|
157
|
+
} });
|
|
158
|
+
Object.defineProperty(Buffer.prototype, "offset", { enumerable: true, get: function() {
|
|
159
|
+
if (!Buffer.isBuffer(this))
|
|
160
|
+
return;
|
|
161
|
+
return this.byteOffset;
|
|
162
|
+
} });
|
|
163
|
+
Buffer.poolSize = 8192;
|
|
164
|
+
function from(value, encodingOrOffset, length) {
|
|
165
|
+
if (typeof value === "string")
|
|
166
|
+
return fromString(value, encodingOrOffset);
|
|
167
|
+
if (ArrayBuffer.isView(value))
|
|
168
|
+
return fromArrayView(value);
|
|
169
|
+
if (value == null)
|
|
170
|
+
throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
171
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer))
|
|
172
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
173
|
+
if (typeof SharedArrayBuffer < "u" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer)))
|
|
174
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
175
|
+
if (typeof value === "number")
|
|
176
|
+
throw TypeError('The "value" argument must not be of type number. Received type number');
|
|
177
|
+
let valueOf = value.valueOf && value.valueOf();
|
|
178
|
+
if (valueOf != null && valueOf !== value)
|
|
179
|
+
return Buffer.from(valueOf, encodingOrOffset, length);
|
|
180
|
+
let b = fromObject(value);
|
|
181
|
+
if (b)
|
|
182
|
+
return b;
|
|
183
|
+
if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function")
|
|
184
|
+
return Buffer.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
185
|
+
throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
186
|
+
}
|
|
187
|
+
Buffer.from = function(value, encodingOrOffset, length) {
|
|
188
|
+
return from(value, encodingOrOffset, length);
|
|
189
|
+
};
|
|
190
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
191
|
+
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
192
|
+
function assertSize(size) {
|
|
193
|
+
if (typeof size !== "number")
|
|
194
|
+
throw TypeError('"size" argument must be of type number');
|
|
195
|
+
else if (size < 0)
|
|
196
|
+
throw RangeError('The value "' + size + '" is invalid for option "size"');
|
|
197
|
+
}
|
|
198
|
+
function alloc(size, fill, encoding) {
|
|
199
|
+
if (assertSize(size), size <= 0)
|
|
200
|
+
return createBuffer(size);
|
|
201
|
+
if (fill !== undefined)
|
|
202
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
203
|
+
return createBuffer(size);
|
|
204
|
+
}
|
|
205
|
+
Buffer.alloc = function(size, fill, encoding) {
|
|
206
|
+
return alloc(size, fill, encoding);
|
|
207
|
+
};
|
|
208
|
+
function allocUnsafe(size) {
|
|
209
|
+
return assertSize(size), createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
210
|
+
}
|
|
211
|
+
Buffer.allocUnsafe = function(size) {
|
|
212
|
+
return allocUnsafe(size);
|
|
213
|
+
};
|
|
214
|
+
Buffer.allocUnsafeSlow = function(size) {
|
|
215
|
+
return allocUnsafe(size);
|
|
216
|
+
};
|
|
217
|
+
function fromString(string, encoding) {
|
|
218
|
+
if (typeof encoding !== "string" || encoding === "")
|
|
219
|
+
encoding = "utf8";
|
|
220
|
+
if (!Buffer.isEncoding(encoding))
|
|
221
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
222
|
+
let length = byteLength(string, encoding) | 0, buf = createBuffer(length), actual = buf.write(string, encoding);
|
|
223
|
+
if (actual !== length)
|
|
224
|
+
buf = buf.slice(0, actual);
|
|
225
|
+
return buf;
|
|
226
|
+
}
|
|
227
|
+
function fromArrayLike(array) {
|
|
228
|
+
let length = array.length < 0 ? 0 : checked(array.length) | 0, buf = createBuffer(length);
|
|
229
|
+
for (let i2 = 0;i2 < length; i2 += 1)
|
|
230
|
+
buf[i2] = array[i2] & 255;
|
|
231
|
+
return buf;
|
|
232
|
+
}
|
|
233
|
+
function fromArrayView(arrayView) {
|
|
234
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
235
|
+
let copy = new Uint8Array(arrayView);
|
|
236
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
237
|
+
}
|
|
238
|
+
return fromArrayLike(arrayView);
|
|
239
|
+
}
|
|
240
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
241
|
+
if (byteOffset < 0 || array.byteLength < byteOffset)
|
|
242
|
+
throw RangeError('"offset" is outside of buffer bounds');
|
|
243
|
+
if (array.byteLength < byteOffset + (length || 0))
|
|
244
|
+
throw RangeError('"length" is outside of buffer bounds');
|
|
245
|
+
let buf;
|
|
246
|
+
if (byteOffset === undefined && length === undefined)
|
|
247
|
+
buf = new Uint8Array(array);
|
|
248
|
+
else if (length === undefined)
|
|
249
|
+
buf = new Uint8Array(array, byteOffset);
|
|
250
|
+
else
|
|
251
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
252
|
+
return Object.setPrototypeOf(buf, Buffer.prototype), buf;
|
|
253
|
+
}
|
|
254
|
+
function fromObject(obj) {
|
|
255
|
+
if (Buffer.isBuffer(obj)) {
|
|
256
|
+
let len2 = checked(obj.length) | 0, buf = createBuffer(len2);
|
|
257
|
+
if (buf.length === 0)
|
|
258
|
+
return buf;
|
|
259
|
+
return obj.copy(buf, 0, 0, len2), buf;
|
|
260
|
+
}
|
|
261
|
+
if (obj.length !== undefined) {
|
|
262
|
+
if (typeof obj.length !== "number" || Number.isNaN(obj.length))
|
|
263
|
+
return createBuffer(0);
|
|
264
|
+
return fromArrayLike(obj);
|
|
265
|
+
}
|
|
266
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data))
|
|
267
|
+
return fromArrayLike(obj.data);
|
|
268
|
+
}
|
|
269
|
+
function checked(length) {
|
|
270
|
+
if (length >= kMaxLength)
|
|
271
|
+
throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength.toString(16) + " bytes");
|
|
272
|
+
return length | 0;
|
|
273
|
+
}
|
|
274
|
+
Buffer.isBuffer = function(b) {
|
|
275
|
+
return b != null && b._isBuffer === true && b !== Buffer.prototype;
|
|
276
|
+
};
|
|
277
|
+
Buffer.compare = function(a, b) {
|
|
278
|
+
if (isInstance(a, Uint8Array))
|
|
279
|
+
a = Buffer.from(a, a.offset, a.byteLength);
|
|
280
|
+
if (isInstance(b, Uint8Array))
|
|
281
|
+
b = Buffer.from(b, b.offset, b.byteLength);
|
|
282
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
|
|
283
|
+
throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
284
|
+
if (a === b)
|
|
285
|
+
return 0;
|
|
286
|
+
let x = a.length, y = b.length;
|
|
287
|
+
for (let i2 = 0, len2 = Math.min(x, y);i2 < len2; ++i2)
|
|
288
|
+
if (a[i2] !== b[i2]) {
|
|
289
|
+
x = a[i2], y = b[i2];
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
if (x < y)
|
|
293
|
+
return -1;
|
|
294
|
+
if (y < x)
|
|
295
|
+
return 1;
|
|
296
|
+
return 0;
|
|
297
|
+
};
|
|
298
|
+
Buffer.isEncoding = function(encoding) {
|
|
299
|
+
switch (String(encoding).toLowerCase()) {
|
|
300
|
+
case "hex":
|
|
301
|
+
case "utf8":
|
|
302
|
+
case "utf-8":
|
|
303
|
+
case "ascii":
|
|
304
|
+
case "latin1":
|
|
305
|
+
case "binary":
|
|
306
|
+
case "base64":
|
|
307
|
+
case "ucs2":
|
|
308
|
+
case "ucs-2":
|
|
309
|
+
case "utf16le":
|
|
310
|
+
case "utf-16le":
|
|
311
|
+
return true;
|
|
312
|
+
default:
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
Buffer.concat = function(list, length) {
|
|
317
|
+
if (!Array.isArray(list))
|
|
318
|
+
throw TypeError('"list" argument must be an Array of Buffers');
|
|
319
|
+
if (list.length === 0)
|
|
320
|
+
return Buffer.alloc(0);
|
|
321
|
+
let i2;
|
|
322
|
+
if (length === undefined) {
|
|
323
|
+
length = 0;
|
|
324
|
+
for (i2 = 0;i2 < list.length; ++i2)
|
|
325
|
+
length += list[i2].length;
|
|
326
|
+
}
|
|
327
|
+
let buffer = Buffer.allocUnsafe(length), pos = 0;
|
|
328
|
+
for (i2 = 0;i2 < list.length; ++i2) {
|
|
329
|
+
let buf = list[i2];
|
|
330
|
+
if (isInstance(buf, Uint8Array))
|
|
331
|
+
if (pos + buf.length > buffer.length) {
|
|
332
|
+
if (!Buffer.isBuffer(buf))
|
|
333
|
+
buf = Buffer.from(buf);
|
|
334
|
+
buf.copy(buffer, pos);
|
|
335
|
+
} else
|
|
336
|
+
Uint8Array.prototype.set.call(buffer, buf, pos);
|
|
337
|
+
else if (!Buffer.isBuffer(buf))
|
|
338
|
+
throw TypeError('"list" argument must be an Array of Buffers');
|
|
339
|
+
else
|
|
340
|
+
buf.copy(buffer, pos);
|
|
341
|
+
pos += buf.length;
|
|
342
|
+
}
|
|
343
|
+
return buffer;
|
|
344
|
+
};
|
|
345
|
+
function byteLength(string, encoding) {
|
|
346
|
+
if (Buffer.isBuffer(string))
|
|
347
|
+
return string.length;
|
|
348
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer))
|
|
349
|
+
return string.byteLength;
|
|
350
|
+
if (typeof string !== "string")
|
|
351
|
+
throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string);
|
|
352
|
+
let len2 = string.length, mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
353
|
+
if (!mustMatch && len2 === 0)
|
|
354
|
+
return 0;
|
|
355
|
+
let loweredCase = false;
|
|
356
|
+
for (;; )
|
|
357
|
+
switch (encoding) {
|
|
358
|
+
case "ascii":
|
|
359
|
+
case "latin1":
|
|
360
|
+
case "binary":
|
|
361
|
+
return len2;
|
|
362
|
+
case "utf8":
|
|
363
|
+
case "utf-8":
|
|
364
|
+
return utf8ToBytes(string).length;
|
|
365
|
+
case "ucs2":
|
|
366
|
+
case "ucs-2":
|
|
367
|
+
case "utf16le":
|
|
368
|
+
case "utf-16le":
|
|
369
|
+
return len2 * 2;
|
|
370
|
+
case "hex":
|
|
371
|
+
return len2 >>> 1;
|
|
372
|
+
case "base64":
|
|
373
|
+
return base64ToBytes(string).length;
|
|
374
|
+
default:
|
|
375
|
+
if (loweredCase)
|
|
376
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
377
|
+
encoding = ("" + encoding).toLowerCase(), loweredCase = true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
Buffer.byteLength = byteLength;
|
|
381
|
+
function slowToString(encoding, start, end) {
|
|
382
|
+
let loweredCase = false;
|
|
383
|
+
if (start === undefined || start < 0)
|
|
384
|
+
start = 0;
|
|
385
|
+
if (start > this.length)
|
|
386
|
+
return "";
|
|
387
|
+
if (end === undefined || end > this.length)
|
|
388
|
+
end = this.length;
|
|
389
|
+
if (end <= 0)
|
|
390
|
+
return "";
|
|
391
|
+
if (end >>>= 0, start >>>= 0, end <= start)
|
|
392
|
+
return "";
|
|
393
|
+
if (!encoding)
|
|
394
|
+
encoding = "utf8";
|
|
395
|
+
while (true)
|
|
396
|
+
switch (encoding) {
|
|
397
|
+
case "hex":
|
|
398
|
+
return hexSlice(this, start, end);
|
|
399
|
+
case "utf8":
|
|
400
|
+
case "utf-8":
|
|
401
|
+
return utf8Slice(this, start, end);
|
|
402
|
+
case "ascii":
|
|
403
|
+
return asciiSlice(this, start, end);
|
|
404
|
+
case "latin1":
|
|
405
|
+
case "binary":
|
|
406
|
+
return latin1Slice(this, start, end);
|
|
407
|
+
case "base64":
|
|
408
|
+
return base64Slice(this, start, end);
|
|
409
|
+
case "ucs2":
|
|
410
|
+
case "ucs-2":
|
|
411
|
+
case "utf16le":
|
|
412
|
+
case "utf-16le":
|
|
413
|
+
return utf16leSlice(this, start, end);
|
|
414
|
+
default:
|
|
415
|
+
if (loweredCase)
|
|
416
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
417
|
+
encoding = (encoding + "").toLowerCase(), loweredCase = true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
Buffer.prototype._isBuffer = true;
|
|
421
|
+
function swap(b, n, m) {
|
|
422
|
+
let i2 = b[n];
|
|
423
|
+
b[n] = b[m], b[m] = i2;
|
|
424
|
+
}
|
|
425
|
+
Buffer.prototype.swap16 = function() {
|
|
426
|
+
let len2 = this.length;
|
|
427
|
+
if (len2 % 2 !== 0)
|
|
428
|
+
throw RangeError("Buffer size must be a multiple of 16-bits");
|
|
429
|
+
for (let i2 = 0;i2 < len2; i2 += 2)
|
|
430
|
+
swap(this, i2, i2 + 1);
|
|
431
|
+
return this;
|
|
432
|
+
};
|
|
433
|
+
Buffer.prototype.swap32 = function() {
|
|
434
|
+
let len2 = this.length;
|
|
435
|
+
if (len2 % 4 !== 0)
|
|
436
|
+
throw RangeError("Buffer size must be a multiple of 32-bits");
|
|
437
|
+
for (let i2 = 0;i2 < len2; i2 += 4)
|
|
438
|
+
swap(this, i2, i2 + 3), swap(this, i2 + 1, i2 + 2);
|
|
439
|
+
return this;
|
|
440
|
+
};
|
|
441
|
+
Buffer.prototype.swap64 = function() {
|
|
442
|
+
let len2 = this.length;
|
|
443
|
+
if (len2 % 8 !== 0)
|
|
444
|
+
throw RangeError("Buffer size must be a multiple of 64-bits");
|
|
445
|
+
for (let i2 = 0;i2 < len2; i2 += 8)
|
|
446
|
+
swap(this, i2, i2 + 7), swap(this, i2 + 1, i2 + 6), swap(this, i2 + 2, i2 + 5), swap(this, i2 + 3, i2 + 4);
|
|
447
|
+
return this;
|
|
448
|
+
};
|
|
449
|
+
Buffer.prototype.toString = function() {
|
|
450
|
+
let length = this.length;
|
|
451
|
+
if (length === 0)
|
|
452
|
+
return "";
|
|
453
|
+
if (arguments.length === 0)
|
|
454
|
+
return utf8Slice(this, 0, length);
|
|
455
|
+
return slowToString.apply(this, arguments);
|
|
456
|
+
};
|
|
457
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
458
|
+
Buffer.prototype.equals = function(b) {
|
|
459
|
+
if (!Buffer.isBuffer(b))
|
|
460
|
+
throw TypeError("Argument must be a Buffer");
|
|
461
|
+
if (this === b)
|
|
462
|
+
return true;
|
|
463
|
+
return Buffer.compare(this, b) === 0;
|
|
464
|
+
};
|
|
465
|
+
Buffer.prototype.inspect = function() {
|
|
466
|
+
let str = "", max = INSPECT_MAX_BYTES;
|
|
467
|
+
if (str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim(), this.length > max)
|
|
468
|
+
str += " ... ";
|
|
469
|
+
return "<Buffer " + str + ">";
|
|
470
|
+
};
|
|
471
|
+
if (customInspectSymbol)
|
|
472
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
473
|
+
Buffer.prototype.compare = function(target, start, end, thisStart, thisEnd) {
|
|
474
|
+
if (isInstance(target, Uint8Array))
|
|
475
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
476
|
+
if (!Buffer.isBuffer(target))
|
|
477
|
+
throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target);
|
|
478
|
+
if (start === undefined)
|
|
479
|
+
start = 0;
|
|
480
|
+
if (end === undefined)
|
|
481
|
+
end = target ? target.length : 0;
|
|
482
|
+
if (thisStart === undefined)
|
|
483
|
+
thisStart = 0;
|
|
484
|
+
if (thisEnd === undefined)
|
|
485
|
+
thisEnd = this.length;
|
|
486
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length)
|
|
487
|
+
throw RangeError("out of range index");
|
|
488
|
+
if (thisStart >= thisEnd && start >= end)
|
|
489
|
+
return 0;
|
|
490
|
+
if (thisStart >= thisEnd)
|
|
491
|
+
return -1;
|
|
492
|
+
if (start >= end)
|
|
493
|
+
return 1;
|
|
494
|
+
if (start >>>= 0, end >>>= 0, thisStart >>>= 0, thisEnd >>>= 0, this === target)
|
|
495
|
+
return 0;
|
|
496
|
+
let x = thisEnd - thisStart, y = end - start, len2 = Math.min(x, y), thisCopy = this.slice(thisStart, thisEnd), targetCopy = target.slice(start, end);
|
|
497
|
+
for (let i2 = 0;i2 < len2; ++i2)
|
|
498
|
+
if (thisCopy[i2] !== targetCopy[i2]) {
|
|
499
|
+
x = thisCopy[i2], y = targetCopy[i2];
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
if (x < y)
|
|
503
|
+
return -1;
|
|
504
|
+
if (y < x)
|
|
505
|
+
return 1;
|
|
506
|
+
return 0;
|
|
507
|
+
};
|
|
508
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
509
|
+
if (buffer.length === 0)
|
|
510
|
+
return -1;
|
|
511
|
+
if (typeof byteOffset === "string")
|
|
512
|
+
encoding = byteOffset, byteOffset = 0;
|
|
513
|
+
else if (byteOffset > 2147483647)
|
|
514
|
+
byteOffset = 2147483647;
|
|
515
|
+
else if (byteOffset < -2147483648)
|
|
516
|
+
byteOffset = -2147483648;
|
|
517
|
+
if (byteOffset = +byteOffset, Number.isNaN(byteOffset))
|
|
518
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
519
|
+
if (byteOffset < 0)
|
|
520
|
+
byteOffset = buffer.length + byteOffset;
|
|
521
|
+
if (byteOffset >= buffer.length)
|
|
522
|
+
if (dir)
|
|
523
|
+
return -1;
|
|
524
|
+
else
|
|
525
|
+
byteOffset = buffer.length - 1;
|
|
526
|
+
else if (byteOffset < 0)
|
|
527
|
+
if (dir)
|
|
528
|
+
byteOffset = 0;
|
|
529
|
+
else
|
|
530
|
+
return -1;
|
|
531
|
+
if (typeof val === "string")
|
|
532
|
+
val = Buffer.from(val, encoding);
|
|
533
|
+
if (Buffer.isBuffer(val)) {
|
|
534
|
+
if (val.length === 0)
|
|
535
|
+
return -1;
|
|
536
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
537
|
+
} else if (typeof val === "number") {
|
|
538
|
+
if (val = val & 255, typeof Uint8Array.prototype.indexOf === "function")
|
|
539
|
+
if (dir)
|
|
540
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
541
|
+
else
|
|
542
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
543
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
544
|
+
}
|
|
545
|
+
throw TypeError("val must be string, number or Buffer");
|
|
546
|
+
}
|
|
547
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
548
|
+
let indexSize = 1, arrLength = arr.length, valLength = val.length;
|
|
549
|
+
if (encoding !== undefined) {
|
|
550
|
+
if (encoding = String(encoding).toLowerCase(), encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
551
|
+
if (arr.length < 2 || val.length < 2)
|
|
552
|
+
return -1;
|
|
553
|
+
indexSize = 2, arrLength /= 2, valLength /= 2, byteOffset /= 2;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function read2(buf, i3) {
|
|
557
|
+
if (indexSize === 1)
|
|
558
|
+
return buf[i3];
|
|
559
|
+
else
|
|
560
|
+
return buf.readUInt16BE(i3 * indexSize);
|
|
561
|
+
}
|
|
562
|
+
let i2;
|
|
563
|
+
if (dir) {
|
|
564
|
+
let foundIndex = -1;
|
|
565
|
+
for (i2 = byteOffset;i2 < arrLength; i2++)
|
|
566
|
+
if (read2(arr, i2) === read2(val, foundIndex === -1 ? 0 : i2 - foundIndex)) {
|
|
567
|
+
if (foundIndex === -1)
|
|
568
|
+
foundIndex = i2;
|
|
569
|
+
if (i2 - foundIndex + 1 === valLength)
|
|
570
|
+
return foundIndex * indexSize;
|
|
571
|
+
} else {
|
|
572
|
+
if (foundIndex !== -1)
|
|
573
|
+
i2 -= i2 - foundIndex;
|
|
574
|
+
foundIndex = -1;
|
|
575
|
+
}
|
|
576
|
+
} else {
|
|
577
|
+
if (byteOffset + valLength > arrLength)
|
|
578
|
+
byteOffset = arrLength - valLength;
|
|
579
|
+
for (i2 = byteOffset;i2 >= 0; i2--) {
|
|
580
|
+
let found = true;
|
|
581
|
+
for (let j = 0;j < valLength; j++)
|
|
582
|
+
if (read2(arr, i2 + j) !== read2(val, j)) {
|
|
583
|
+
found = false;
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
if (found)
|
|
587
|
+
return i2;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return -1;
|
|
591
|
+
}
|
|
592
|
+
Buffer.prototype.includes = function(val, byteOffset, encoding) {
|
|
593
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
594
|
+
};
|
|
595
|
+
Buffer.prototype.indexOf = function(val, byteOffset, encoding) {
|
|
596
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
597
|
+
};
|
|
598
|
+
Buffer.prototype.lastIndexOf = function(val, byteOffset, encoding) {
|
|
599
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
600
|
+
};
|
|
601
|
+
function hexWrite(buf, string, offset, length) {
|
|
602
|
+
offset = Number(offset) || 0;
|
|
603
|
+
let remaining = buf.length - offset;
|
|
604
|
+
if (!length)
|
|
605
|
+
length = remaining;
|
|
606
|
+
else if (length = Number(length), length > remaining)
|
|
607
|
+
length = remaining;
|
|
608
|
+
let strLen = string.length;
|
|
609
|
+
if (length > strLen / 2)
|
|
610
|
+
length = strLen / 2;
|
|
611
|
+
let i2;
|
|
612
|
+
for (i2 = 0;i2 < length; ++i2) {
|
|
613
|
+
let parsed = parseInt(string.substr(i2 * 2, 2), 16);
|
|
614
|
+
if (Number.isNaN(parsed))
|
|
615
|
+
return i2;
|
|
616
|
+
buf[offset + i2] = parsed;
|
|
617
|
+
}
|
|
618
|
+
return i2;
|
|
619
|
+
}
|
|
620
|
+
function utf8Write(buf, string, offset, length) {
|
|
621
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
622
|
+
}
|
|
623
|
+
function asciiWrite(buf, string, offset, length) {
|
|
624
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
625
|
+
}
|
|
626
|
+
function base64Write(buf, string, offset, length) {
|
|
627
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
628
|
+
}
|
|
629
|
+
function ucs2Write(buf, string, offset, length) {
|
|
630
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
631
|
+
}
|
|
632
|
+
Buffer.prototype.write = function(string, offset, length, encoding) {
|
|
633
|
+
if (offset === undefined)
|
|
634
|
+
encoding = "utf8", length = this.length, offset = 0;
|
|
635
|
+
else if (length === undefined && typeof offset === "string")
|
|
636
|
+
encoding = offset, length = this.length, offset = 0;
|
|
637
|
+
else if (isFinite(offset))
|
|
638
|
+
if (offset = offset >>> 0, isFinite(length)) {
|
|
639
|
+
if (length = length >>> 0, encoding === undefined)
|
|
640
|
+
encoding = "utf8";
|
|
641
|
+
} else
|
|
642
|
+
encoding = length, length = undefined;
|
|
643
|
+
else
|
|
644
|
+
throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
645
|
+
let remaining = this.length - offset;
|
|
646
|
+
if (length === undefined || length > remaining)
|
|
647
|
+
length = remaining;
|
|
648
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length)
|
|
649
|
+
throw RangeError("Attempt to write outside buffer bounds");
|
|
650
|
+
if (!encoding)
|
|
651
|
+
encoding = "utf8";
|
|
652
|
+
let loweredCase = false;
|
|
653
|
+
for (;; )
|
|
654
|
+
switch (encoding) {
|
|
655
|
+
case "hex":
|
|
656
|
+
return hexWrite(this, string, offset, length);
|
|
657
|
+
case "utf8":
|
|
658
|
+
case "utf-8":
|
|
659
|
+
return utf8Write(this, string, offset, length);
|
|
660
|
+
case "ascii":
|
|
661
|
+
case "latin1":
|
|
662
|
+
case "binary":
|
|
663
|
+
return asciiWrite(this, string, offset, length);
|
|
664
|
+
case "base64":
|
|
665
|
+
return base64Write(this, string, offset, length);
|
|
666
|
+
case "ucs2":
|
|
667
|
+
case "ucs-2":
|
|
668
|
+
case "utf16le":
|
|
669
|
+
case "utf-16le":
|
|
670
|
+
return ucs2Write(this, string, offset, length);
|
|
671
|
+
default:
|
|
672
|
+
if (loweredCase)
|
|
673
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
674
|
+
encoding = ("" + encoding).toLowerCase(), loweredCase = true;
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
Buffer.prototype.toJSON = function() {
|
|
678
|
+
return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
|
|
679
|
+
};
|
|
680
|
+
function base64Slice(buf, start, end) {
|
|
681
|
+
if (start === 0 && end === buf.length)
|
|
682
|
+
return fromByteArray(buf);
|
|
683
|
+
else
|
|
684
|
+
return fromByteArray(buf.slice(start, end));
|
|
685
|
+
}
|
|
686
|
+
function utf8Slice(buf, start, end) {
|
|
687
|
+
end = Math.min(buf.length, end);
|
|
688
|
+
let res = [], i2 = start;
|
|
689
|
+
while (i2 < end) {
|
|
690
|
+
let firstByte = buf[i2], codePoint = null, bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
691
|
+
if (i2 + bytesPerSequence <= end) {
|
|
692
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
693
|
+
switch (bytesPerSequence) {
|
|
694
|
+
case 1:
|
|
695
|
+
if (firstByte < 128)
|
|
696
|
+
codePoint = firstByte;
|
|
697
|
+
break;
|
|
698
|
+
case 2:
|
|
699
|
+
if (secondByte = buf[i2 + 1], (secondByte & 192) === 128) {
|
|
700
|
+
if (tempCodePoint = (firstByte & 31) << 6 | secondByte & 63, tempCodePoint > 127)
|
|
701
|
+
codePoint = tempCodePoint;
|
|
702
|
+
}
|
|
703
|
+
break;
|
|
704
|
+
case 3:
|
|
705
|
+
if (secondByte = buf[i2 + 1], thirdByte = buf[i2 + 2], (secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
706
|
+
if (tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63, tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343))
|
|
707
|
+
codePoint = tempCodePoint;
|
|
708
|
+
}
|
|
709
|
+
break;
|
|
710
|
+
case 4:
|
|
711
|
+
if (secondByte = buf[i2 + 1], thirdByte = buf[i2 + 2], fourthByte = buf[i2 + 3], (secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
712
|
+
if (tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63, tempCodePoint > 65535 && tempCodePoint < 1114112)
|
|
713
|
+
codePoint = tempCodePoint;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (codePoint === null)
|
|
718
|
+
codePoint = 65533, bytesPerSequence = 1;
|
|
719
|
+
else if (codePoint > 65535)
|
|
720
|
+
codePoint -= 65536, res.push(codePoint >>> 10 & 1023 | 55296), codePoint = 56320 | codePoint & 1023;
|
|
721
|
+
res.push(codePoint), i2 += bytesPerSequence;
|
|
722
|
+
}
|
|
723
|
+
return decodeCodePointsArray(res);
|
|
724
|
+
}
|
|
725
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
726
|
+
function decodeCodePointsArray(codePoints) {
|
|
727
|
+
let len2 = codePoints.length;
|
|
728
|
+
if (len2 <= MAX_ARGUMENTS_LENGTH)
|
|
729
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
730
|
+
let res = "", i2 = 0;
|
|
731
|
+
while (i2 < len2)
|
|
732
|
+
res += String.fromCharCode.apply(String, codePoints.slice(i2, i2 += MAX_ARGUMENTS_LENGTH));
|
|
733
|
+
return res;
|
|
734
|
+
}
|
|
735
|
+
function asciiSlice(buf, start, end) {
|
|
736
|
+
let ret = "";
|
|
737
|
+
end = Math.min(buf.length, end);
|
|
738
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
739
|
+
ret += String.fromCharCode(buf[i2] & 127);
|
|
740
|
+
return ret;
|
|
741
|
+
}
|
|
742
|
+
function latin1Slice(buf, start, end) {
|
|
743
|
+
let ret = "";
|
|
744
|
+
end = Math.min(buf.length, end);
|
|
745
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
746
|
+
ret += String.fromCharCode(buf[i2]);
|
|
747
|
+
return ret;
|
|
748
|
+
}
|
|
749
|
+
function hexSlice(buf, start, end) {
|
|
750
|
+
let len2 = buf.length;
|
|
751
|
+
if (!start || start < 0)
|
|
752
|
+
start = 0;
|
|
753
|
+
if (!end || end < 0 || end > len2)
|
|
754
|
+
end = len2;
|
|
755
|
+
let out = "";
|
|
756
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
757
|
+
out += hexSliceLookupTable[buf[i2]];
|
|
758
|
+
return out;
|
|
759
|
+
}
|
|
760
|
+
function utf16leSlice(buf, start, end) {
|
|
761
|
+
let bytes = buf.slice(start, end), res = "";
|
|
762
|
+
for (let i2 = 0;i2 < bytes.length - 1; i2 += 2)
|
|
763
|
+
res += String.fromCharCode(bytes[i2] + bytes[i2 + 1] * 256);
|
|
764
|
+
return res;
|
|
765
|
+
}
|
|
766
|
+
Buffer.prototype.slice = function(start, end) {
|
|
767
|
+
let len2 = this.length;
|
|
768
|
+
if (start = ~~start, end = end === undefined ? len2 : ~~end, start < 0) {
|
|
769
|
+
if (start += len2, start < 0)
|
|
770
|
+
start = 0;
|
|
771
|
+
} else if (start > len2)
|
|
772
|
+
start = len2;
|
|
773
|
+
if (end < 0) {
|
|
774
|
+
if (end += len2, end < 0)
|
|
775
|
+
end = 0;
|
|
776
|
+
} else if (end > len2)
|
|
777
|
+
end = len2;
|
|
778
|
+
if (end < start)
|
|
779
|
+
end = start;
|
|
780
|
+
let newBuf = this.subarray(start, end);
|
|
781
|
+
return Object.setPrototypeOf(newBuf, Buffer.prototype), newBuf;
|
|
782
|
+
};
|
|
783
|
+
function checkOffset(offset, ext, length) {
|
|
784
|
+
if (offset % 1 !== 0 || offset < 0)
|
|
785
|
+
throw RangeError("offset is not uint");
|
|
786
|
+
if (offset + ext > length)
|
|
787
|
+
throw RangeError("Trying to access beyond buffer length");
|
|
788
|
+
}
|
|
789
|
+
Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function(offset, byteLength2, noAssert) {
|
|
790
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
791
|
+
checkOffset(offset, byteLength2, this.length);
|
|
792
|
+
let val = this[offset], mul = 1, i2 = 0;
|
|
793
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
794
|
+
val += this[offset + i2] * mul;
|
|
795
|
+
return val;
|
|
796
|
+
};
|
|
797
|
+
Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function(offset, byteLength2, noAssert) {
|
|
798
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
799
|
+
checkOffset(offset, byteLength2, this.length);
|
|
800
|
+
let val = this[offset + --byteLength2], mul = 1;
|
|
801
|
+
while (byteLength2 > 0 && (mul *= 256))
|
|
802
|
+
val += this[offset + --byteLength2] * mul;
|
|
803
|
+
return val;
|
|
804
|
+
};
|
|
805
|
+
Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function(offset, noAssert) {
|
|
806
|
+
if (offset = offset >>> 0, !noAssert)
|
|
807
|
+
checkOffset(offset, 1, this.length);
|
|
808
|
+
return this[offset];
|
|
809
|
+
};
|
|
810
|
+
Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function(offset, noAssert) {
|
|
811
|
+
if (offset = offset >>> 0, !noAssert)
|
|
812
|
+
checkOffset(offset, 2, this.length);
|
|
813
|
+
return this[offset] | this[offset + 1] << 8;
|
|
814
|
+
};
|
|
815
|
+
Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function(offset, noAssert) {
|
|
816
|
+
if (offset = offset >>> 0, !noAssert)
|
|
817
|
+
checkOffset(offset, 2, this.length);
|
|
818
|
+
return this[offset] << 8 | this[offset + 1];
|
|
819
|
+
};
|
|
820
|
+
Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function(offset, noAssert) {
|
|
821
|
+
if (offset = offset >>> 0, !noAssert)
|
|
822
|
+
checkOffset(offset, 4, this.length);
|
|
823
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
824
|
+
};
|
|
825
|
+
Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function(offset, noAssert) {
|
|
826
|
+
if (offset = offset >>> 0, !noAssert)
|
|
827
|
+
checkOffset(offset, 4, this.length);
|
|
828
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
829
|
+
};
|
|
830
|
+
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function(offset) {
|
|
831
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
832
|
+
let first = this[offset], last = this[offset + 7];
|
|
833
|
+
if (first === undefined || last === undefined)
|
|
834
|
+
boundsError(offset, this.length - 8);
|
|
835
|
+
let lo = first + this[++offset] * 256 + this[++offset] * 65536 + this[++offset] * 16777216, hi = this[++offset] + this[++offset] * 256 + this[++offset] * 65536 + last * 16777216;
|
|
836
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
837
|
+
});
|
|
838
|
+
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function(offset) {
|
|
839
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
840
|
+
let first = this[offset], last = this[offset + 7];
|
|
841
|
+
if (first === undefined || last === undefined)
|
|
842
|
+
boundsError(offset, this.length - 8);
|
|
843
|
+
let hi = first * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + this[++offset], lo = this[++offset] * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + last;
|
|
844
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
845
|
+
});
|
|
846
|
+
Buffer.prototype.readIntLE = function(offset, byteLength2, noAssert) {
|
|
847
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
848
|
+
checkOffset(offset, byteLength2, this.length);
|
|
849
|
+
let val = this[offset], mul = 1, i2 = 0;
|
|
850
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
851
|
+
val += this[offset + i2] * mul;
|
|
852
|
+
if (mul *= 128, val >= mul)
|
|
853
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
854
|
+
return val;
|
|
855
|
+
};
|
|
856
|
+
Buffer.prototype.readIntBE = function(offset, byteLength2, noAssert) {
|
|
857
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
858
|
+
checkOffset(offset, byteLength2, this.length);
|
|
859
|
+
let i2 = byteLength2, mul = 1, val = this[offset + --i2];
|
|
860
|
+
while (i2 > 0 && (mul *= 256))
|
|
861
|
+
val += this[offset + --i2] * mul;
|
|
862
|
+
if (mul *= 128, val >= mul)
|
|
863
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
864
|
+
return val;
|
|
865
|
+
};
|
|
866
|
+
Buffer.prototype.readInt8 = function(offset, noAssert) {
|
|
867
|
+
if (offset = offset >>> 0, !noAssert)
|
|
868
|
+
checkOffset(offset, 1, this.length);
|
|
869
|
+
if (!(this[offset] & 128))
|
|
870
|
+
return this[offset];
|
|
871
|
+
return (255 - this[offset] + 1) * -1;
|
|
872
|
+
};
|
|
873
|
+
Buffer.prototype.readInt16LE = function(offset, noAssert) {
|
|
874
|
+
if (offset = offset >>> 0, !noAssert)
|
|
875
|
+
checkOffset(offset, 2, this.length);
|
|
876
|
+
let val = this[offset] | this[offset + 1] << 8;
|
|
877
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
878
|
+
};
|
|
879
|
+
Buffer.prototype.readInt16BE = function(offset, noAssert) {
|
|
880
|
+
if (offset = offset >>> 0, !noAssert)
|
|
881
|
+
checkOffset(offset, 2, this.length);
|
|
882
|
+
let val = this[offset + 1] | this[offset] << 8;
|
|
883
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
884
|
+
};
|
|
885
|
+
Buffer.prototype.readInt32LE = function(offset, noAssert) {
|
|
886
|
+
if (offset = offset >>> 0, !noAssert)
|
|
887
|
+
checkOffset(offset, 4, this.length);
|
|
888
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
889
|
+
};
|
|
890
|
+
Buffer.prototype.readInt32BE = function(offset, noAssert) {
|
|
891
|
+
if (offset = offset >>> 0, !noAssert)
|
|
892
|
+
checkOffset(offset, 4, this.length);
|
|
893
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
894
|
+
};
|
|
895
|
+
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function(offset) {
|
|
896
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
897
|
+
let first = this[offset], last = this[offset + 7];
|
|
898
|
+
if (first === undefined || last === undefined)
|
|
899
|
+
boundsError(offset, this.length - 8);
|
|
900
|
+
let val = this[offset + 4] + this[offset + 5] * 256 + this[offset + 6] * 65536 + (last << 24);
|
|
901
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 256 + this[++offset] * 65536 + this[++offset] * 16777216);
|
|
902
|
+
});
|
|
903
|
+
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function(offset) {
|
|
904
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
905
|
+
let first = this[offset], last = this[offset + 7];
|
|
906
|
+
if (first === undefined || last === undefined)
|
|
907
|
+
boundsError(offset, this.length - 8);
|
|
908
|
+
let val = (first << 24) + this[++offset] * 65536 + this[++offset] * 256 + this[++offset];
|
|
909
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + last);
|
|
910
|
+
});
|
|
911
|
+
Buffer.prototype.readFloatLE = function(offset, noAssert) {
|
|
912
|
+
if (offset = offset >>> 0, !noAssert)
|
|
913
|
+
checkOffset(offset, 4, this.length);
|
|
914
|
+
return read(this, offset, true, 23, 4);
|
|
915
|
+
};
|
|
916
|
+
Buffer.prototype.readFloatBE = function(offset, noAssert) {
|
|
917
|
+
if (offset = offset >>> 0, !noAssert)
|
|
918
|
+
checkOffset(offset, 4, this.length);
|
|
919
|
+
return read(this, offset, false, 23, 4);
|
|
920
|
+
};
|
|
921
|
+
Buffer.prototype.readDoubleLE = function(offset, noAssert) {
|
|
922
|
+
if (offset = offset >>> 0, !noAssert)
|
|
923
|
+
checkOffset(offset, 8, this.length);
|
|
924
|
+
return read(this, offset, true, 52, 8);
|
|
925
|
+
};
|
|
926
|
+
Buffer.prototype.readDoubleBE = function(offset, noAssert) {
|
|
927
|
+
if (offset = offset >>> 0, !noAssert)
|
|
928
|
+
checkOffset(offset, 8, this.length);
|
|
929
|
+
return read(this, offset, false, 52, 8);
|
|
930
|
+
};
|
|
931
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
932
|
+
if (!Buffer.isBuffer(buf))
|
|
933
|
+
throw TypeError('"buffer" argument must be a Buffer instance');
|
|
934
|
+
if (value > max || value < min)
|
|
935
|
+
throw RangeError('"value" argument is out of bounds');
|
|
936
|
+
if (offset + ext > buf.length)
|
|
937
|
+
throw RangeError("Index out of range");
|
|
938
|
+
}
|
|
939
|
+
Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function(value, offset, byteLength2, noAssert) {
|
|
940
|
+
if (value = +value, offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert) {
|
|
941
|
+
let maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
942
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
943
|
+
}
|
|
944
|
+
let mul = 1, i2 = 0;
|
|
945
|
+
this[offset] = value & 255;
|
|
946
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
947
|
+
this[offset + i2] = value / mul & 255;
|
|
948
|
+
return offset + byteLength2;
|
|
949
|
+
};
|
|
950
|
+
Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function(value, offset, byteLength2, noAssert) {
|
|
951
|
+
if (value = +value, offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert) {
|
|
952
|
+
let maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
953
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
954
|
+
}
|
|
955
|
+
let i2 = byteLength2 - 1, mul = 1;
|
|
956
|
+
this[offset + i2] = value & 255;
|
|
957
|
+
while (--i2 >= 0 && (mul *= 256))
|
|
958
|
+
this[offset + i2] = value / mul & 255;
|
|
959
|
+
return offset + byteLength2;
|
|
960
|
+
};
|
|
961
|
+
Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
|
|
962
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
963
|
+
checkInt(this, value, offset, 1, 255, 0);
|
|
964
|
+
return this[offset] = value & 255, offset + 1;
|
|
965
|
+
};
|
|
966
|
+
Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
|
|
967
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
968
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
969
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, offset + 2;
|
|
970
|
+
};
|
|
971
|
+
Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
|
|
972
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
973
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
974
|
+
return this[offset] = value >>> 8, this[offset + 1] = value & 255, offset + 2;
|
|
975
|
+
};
|
|
976
|
+
Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
|
|
977
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
978
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
979
|
+
return this[offset + 3] = value >>> 24, this[offset + 2] = value >>> 16, this[offset + 1] = value >>> 8, this[offset] = value & 255, offset + 4;
|
|
980
|
+
};
|
|
981
|
+
Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
|
|
982
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
983
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
984
|
+
return this[offset] = value >>> 24, this[offset + 1] = value >>> 16, this[offset + 2] = value >>> 8, this[offset + 3] = value & 255, offset + 4;
|
|
985
|
+
};
|
|
986
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
987
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
988
|
+
let lo = Number(value & BigInt(4294967295));
|
|
989
|
+
buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo;
|
|
990
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
991
|
+
return buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, offset;
|
|
992
|
+
}
|
|
993
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
994
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
995
|
+
let lo = Number(value & BigInt(4294967295));
|
|
996
|
+
buf[offset + 7] = lo, lo = lo >> 8, buf[offset + 6] = lo, lo = lo >> 8, buf[offset + 5] = lo, lo = lo >> 8, buf[offset + 4] = lo;
|
|
997
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
998
|
+
return buf[offset + 3] = hi, hi = hi >> 8, buf[offset + 2] = hi, hi = hi >> 8, buf[offset + 1] = hi, hi = hi >> 8, buf[offset] = hi, offset + 8;
|
|
999
|
+
}
|
|
1000
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function(value, offset = 0) {
|
|
1001
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1002
|
+
});
|
|
1003
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function(value, offset = 0) {
|
|
1004
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1005
|
+
});
|
|
1006
|
+
Buffer.prototype.writeIntLE = function(value, offset, byteLength2, noAssert) {
|
|
1007
|
+
if (value = +value, offset = offset >>> 0, !noAssert) {
|
|
1008
|
+
let limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1009
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1010
|
+
}
|
|
1011
|
+
let i2 = 0, mul = 1, sub = 0;
|
|
1012
|
+
this[offset] = value & 255;
|
|
1013
|
+
while (++i2 < byteLength2 && (mul *= 256)) {
|
|
1014
|
+
if (value < 0 && sub === 0 && this[offset + i2 - 1] !== 0)
|
|
1015
|
+
sub = 1;
|
|
1016
|
+
this[offset + i2] = (value / mul >> 0) - sub & 255;
|
|
1017
|
+
}
|
|
1018
|
+
return offset + byteLength2;
|
|
1019
|
+
};
|
|
1020
|
+
Buffer.prototype.writeIntBE = function(value, offset, byteLength2, noAssert) {
|
|
1021
|
+
if (value = +value, offset = offset >>> 0, !noAssert) {
|
|
1022
|
+
let limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1023
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1024
|
+
}
|
|
1025
|
+
let i2 = byteLength2 - 1, mul = 1, sub = 0;
|
|
1026
|
+
this[offset + i2] = value & 255;
|
|
1027
|
+
while (--i2 >= 0 && (mul *= 256)) {
|
|
1028
|
+
if (value < 0 && sub === 0 && this[offset + i2 + 1] !== 0)
|
|
1029
|
+
sub = 1;
|
|
1030
|
+
this[offset + i2] = (value / mul >> 0) - sub & 255;
|
|
1031
|
+
}
|
|
1032
|
+
return offset + byteLength2;
|
|
1033
|
+
};
|
|
1034
|
+
Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
|
|
1035
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1036
|
+
checkInt(this, value, offset, 1, 127, -128);
|
|
1037
|
+
if (value < 0)
|
|
1038
|
+
value = 255 + value + 1;
|
|
1039
|
+
return this[offset] = value & 255, offset + 1;
|
|
1040
|
+
};
|
|
1041
|
+
Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
|
|
1042
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1043
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1044
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, offset + 2;
|
|
1045
|
+
};
|
|
1046
|
+
Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
|
|
1047
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1048
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1049
|
+
return this[offset] = value >>> 8, this[offset + 1] = value & 255, offset + 2;
|
|
1050
|
+
};
|
|
1051
|
+
Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
|
|
1052
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1053
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1054
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, this[offset + 2] = value >>> 16, this[offset + 3] = value >>> 24, offset + 4;
|
|
1055
|
+
};
|
|
1056
|
+
Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
|
|
1057
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1058
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1059
|
+
if (value < 0)
|
|
1060
|
+
value = 4294967295 + value + 1;
|
|
1061
|
+
return this[offset] = value >>> 24, this[offset + 1] = value >>> 16, this[offset + 2] = value >>> 8, this[offset + 3] = value & 255, offset + 4;
|
|
1062
|
+
};
|
|
1063
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function(value, offset = 0) {
|
|
1064
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1065
|
+
});
|
|
1066
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function(value, offset = 0) {
|
|
1067
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1068
|
+
});
|
|
1069
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1070
|
+
if (offset + ext > buf.length)
|
|
1071
|
+
throw RangeError("Index out of range");
|
|
1072
|
+
if (offset < 0)
|
|
1073
|
+
throw RangeError("Index out of range");
|
|
1074
|
+
}
|
|
1075
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1076
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1077
|
+
checkIEEE754(buf, value, offset, 4, 340282346638528860000000000000000000000, -340282346638528860000000000000000000000);
|
|
1078
|
+
return write(buf, value, offset, littleEndian, 23, 4), offset + 4;
|
|
1079
|
+
}
|
|
1080
|
+
Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
|
|
1081
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1082
|
+
};
|
|
1083
|
+
Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
|
|
1084
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1085
|
+
};
|
|
1086
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1087
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1088
|
+
checkIEEE754(buf, value, offset, 8, 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
|
|
1089
|
+
return write(buf, value, offset, littleEndian, 52, 8), offset + 8;
|
|
1090
|
+
}
|
|
1091
|
+
Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
|
|
1092
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1093
|
+
};
|
|
1094
|
+
Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
|
|
1095
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1096
|
+
};
|
|
1097
|
+
Buffer.prototype.copy = function(target, targetStart, start, end) {
|
|
1098
|
+
if (!Buffer.isBuffer(target))
|
|
1099
|
+
throw TypeError("argument should be a Buffer");
|
|
1100
|
+
if (!start)
|
|
1101
|
+
start = 0;
|
|
1102
|
+
if (!end && end !== 0)
|
|
1103
|
+
end = this.length;
|
|
1104
|
+
if (targetStart >= target.length)
|
|
1105
|
+
targetStart = target.length;
|
|
1106
|
+
if (!targetStart)
|
|
1107
|
+
targetStart = 0;
|
|
1108
|
+
if (end > 0 && end < start)
|
|
1109
|
+
end = start;
|
|
1110
|
+
if (end === start)
|
|
1111
|
+
return 0;
|
|
1112
|
+
if (target.length === 0 || this.length === 0)
|
|
1113
|
+
return 0;
|
|
1114
|
+
if (targetStart < 0)
|
|
1115
|
+
throw RangeError("targetStart out of bounds");
|
|
1116
|
+
if (start < 0 || start >= this.length)
|
|
1117
|
+
throw RangeError("Index out of range");
|
|
1118
|
+
if (end < 0)
|
|
1119
|
+
throw RangeError("sourceEnd out of bounds");
|
|
1120
|
+
if (end > this.length)
|
|
1121
|
+
end = this.length;
|
|
1122
|
+
if (target.length - targetStart < end - start)
|
|
1123
|
+
end = target.length - targetStart + start;
|
|
1124
|
+
let len2 = end - start;
|
|
1125
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function")
|
|
1126
|
+
this.copyWithin(targetStart, start, end);
|
|
1127
|
+
else
|
|
1128
|
+
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
1129
|
+
return len2;
|
|
1130
|
+
};
|
|
1131
|
+
Buffer.prototype.fill = function(val, start, end, encoding) {
|
|
1132
|
+
if (typeof val === "string") {
|
|
1133
|
+
if (typeof start === "string")
|
|
1134
|
+
encoding = start, start = 0, end = this.length;
|
|
1135
|
+
else if (typeof end === "string")
|
|
1136
|
+
encoding = end, end = this.length;
|
|
1137
|
+
if (encoding !== undefined && typeof encoding !== "string")
|
|
1138
|
+
throw TypeError("encoding must be a string");
|
|
1139
|
+
if (typeof encoding === "string" && !Buffer.isEncoding(encoding))
|
|
1140
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
1141
|
+
if (val.length === 1) {
|
|
1142
|
+
let code2 = val.charCodeAt(0);
|
|
1143
|
+
if (encoding === "utf8" && code2 < 128 || encoding === "latin1")
|
|
1144
|
+
val = code2;
|
|
1145
|
+
}
|
|
1146
|
+
} else if (typeof val === "number")
|
|
1147
|
+
val = val & 255;
|
|
1148
|
+
else if (typeof val === "boolean")
|
|
1149
|
+
val = Number(val);
|
|
1150
|
+
if (start < 0 || this.length < start || this.length < end)
|
|
1151
|
+
throw RangeError("Out of range index");
|
|
1152
|
+
if (end <= start)
|
|
1153
|
+
return this;
|
|
1154
|
+
if (start = start >>> 0, end = end === undefined ? this.length : end >>> 0, !val)
|
|
1155
|
+
val = 0;
|
|
1156
|
+
let i2;
|
|
1157
|
+
if (typeof val === "number")
|
|
1158
|
+
for (i2 = start;i2 < end; ++i2)
|
|
1159
|
+
this[i2] = val;
|
|
1160
|
+
else {
|
|
1161
|
+
let bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding), len2 = bytes.length;
|
|
1162
|
+
if (len2 === 0)
|
|
1163
|
+
throw TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1164
|
+
for (i2 = 0;i2 < end - start; ++i2)
|
|
1165
|
+
this[i2 + start] = bytes[i2 % len2];
|
|
1166
|
+
}
|
|
1167
|
+
return this;
|
|
1168
|
+
};
|
|
1169
|
+
function addNumericalSeparator(val) {
|
|
1170
|
+
let res = "", i2 = val.length, start = val[0] === "-" ? 1 : 0;
|
|
1171
|
+
for (;i2 >= start + 4; i2 -= 3)
|
|
1172
|
+
res = `_${val.slice(i2 - 3, i2)}${res}`;
|
|
1173
|
+
return `${val.slice(0, i2)}${res}`;
|
|
1174
|
+
}
|
|
1175
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1176
|
+
if (validateNumber(offset, "offset"), buf[offset] === undefined || buf[offset + byteLength2] === undefined)
|
|
1177
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1178
|
+
}
|
|
1179
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1180
|
+
if (value > max || value < min) {
|
|
1181
|
+
let n = typeof min === "bigint" ? "n" : "", range;
|
|
1182
|
+
if (byteLength2 > 3)
|
|
1183
|
+
if (min === 0 || min === BigInt(0))
|
|
1184
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1185
|
+
else
|
|
1186
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1187
|
+
else
|
|
1188
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1189
|
+
throw new ERR_OUT_OF_RANGE("value", range, value);
|
|
1190
|
+
}
|
|
1191
|
+
checkBounds(buf, offset, byteLength2);
|
|
1192
|
+
}
|
|
1193
|
+
function validateNumber(value, name) {
|
|
1194
|
+
if (typeof value !== "number")
|
|
1195
|
+
throw new ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1196
|
+
}
|
|
1197
|
+
function boundsError(value, length, type) {
|
|
1198
|
+
if (Math.floor(value) !== value)
|
|
1199
|
+
throw validateNumber(value, type), new ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1200
|
+
if (length < 0)
|
|
1201
|
+
throw new ERR_BUFFER_OUT_OF_BOUNDS;
|
|
1202
|
+
throw new ERR_OUT_OF_RANGE(type || "offset", `>= ${type ? 1 : 0} and <= ${length}`, value);
|
|
1203
|
+
}
|
|
1204
|
+
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1205
|
+
function base64clean(str) {
|
|
1206
|
+
if (str = str.split("=")[0], str = str.trim().replace(INVALID_BASE64_RE, ""), str.length < 2)
|
|
1207
|
+
return "";
|
|
1208
|
+
while (str.length % 4 !== 0)
|
|
1209
|
+
str = str + "=";
|
|
1210
|
+
return str;
|
|
1211
|
+
}
|
|
1212
|
+
function utf8ToBytes(string, units) {
|
|
1213
|
+
units = units || 1 / 0;
|
|
1214
|
+
let codePoint, length = string.length, leadSurrogate = null, bytes = [];
|
|
1215
|
+
for (let i2 = 0;i2 < length; ++i2) {
|
|
1216
|
+
if (codePoint = string.charCodeAt(i2), codePoint > 55295 && codePoint < 57344) {
|
|
1217
|
+
if (!leadSurrogate) {
|
|
1218
|
+
if (codePoint > 56319) {
|
|
1219
|
+
if ((units -= 3) > -1)
|
|
1220
|
+
bytes.push(239, 191, 189);
|
|
1221
|
+
continue;
|
|
1222
|
+
} else if (i2 + 1 === length) {
|
|
1223
|
+
if ((units -= 3) > -1)
|
|
1224
|
+
bytes.push(239, 191, 189);
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
leadSurrogate = codePoint;
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
if (codePoint < 56320) {
|
|
1231
|
+
if ((units -= 3) > -1)
|
|
1232
|
+
bytes.push(239, 191, 189);
|
|
1233
|
+
leadSurrogate = codePoint;
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1237
|
+
} else if (leadSurrogate) {
|
|
1238
|
+
if ((units -= 3) > -1)
|
|
1239
|
+
bytes.push(239, 191, 189);
|
|
1240
|
+
}
|
|
1241
|
+
if (leadSurrogate = null, codePoint < 128) {
|
|
1242
|
+
if ((units -= 1) < 0)
|
|
1243
|
+
break;
|
|
1244
|
+
bytes.push(codePoint);
|
|
1245
|
+
} else if (codePoint < 2048) {
|
|
1246
|
+
if ((units -= 2) < 0)
|
|
1247
|
+
break;
|
|
1248
|
+
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
|
1249
|
+
} else if (codePoint < 65536) {
|
|
1250
|
+
if ((units -= 3) < 0)
|
|
1251
|
+
break;
|
|
1252
|
+
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1253
|
+
} else if (codePoint < 1114112) {
|
|
1254
|
+
if ((units -= 4) < 0)
|
|
1255
|
+
break;
|
|
1256
|
+
bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1257
|
+
} else
|
|
1258
|
+
throw Error("Invalid code point");
|
|
1259
|
+
}
|
|
1260
|
+
return bytes;
|
|
1261
|
+
}
|
|
1262
|
+
function asciiToBytes(str) {
|
|
1263
|
+
let byteArray = [];
|
|
1264
|
+
for (let i2 = 0;i2 < str.length; ++i2)
|
|
1265
|
+
byteArray.push(str.charCodeAt(i2) & 255);
|
|
1266
|
+
return byteArray;
|
|
1267
|
+
}
|
|
1268
|
+
function utf16leToBytes(str, units) {
|
|
1269
|
+
let c, hi, lo, byteArray = [];
|
|
1270
|
+
for (let i2 = 0;i2 < str.length; ++i2) {
|
|
1271
|
+
if ((units -= 2) < 0)
|
|
1272
|
+
break;
|
|
1273
|
+
c = str.charCodeAt(i2), hi = c >> 8, lo = c % 256, byteArray.push(lo), byteArray.push(hi);
|
|
1274
|
+
}
|
|
1275
|
+
return byteArray;
|
|
1276
|
+
}
|
|
1277
|
+
function base64ToBytes(str) {
|
|
1278
|
+
return toByteArray(base64clean(str));
|
|
1279
|
+
}
|
|
1280
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1281
|
+
let i2;
|
|
1282
|
+
for (i2 = 0;i2 < length; ++i2) {
|
|
1283
|
+
if (i2 + offset >= dst.length || i2 >= src.length)
|
|
1284
|
+
break;
|
|
1285
|
+
dst[i2 + offset] = src[i2];
|
|
1286
|
+
}
|
|
1287
|
+
return i2;
|
|
1288
|
+
}
|
|
1289
|
+
function isInstance(obj, type) {
|
|
1290
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1291
|
+
}
|
|
1292
|
+
var hexSliceLookupTable = function() {
|
|
1293
|
+
let table = Array(256);
|
|
1294
|
+
for (let i2 = 0;i2 < 16; ++i2) {
|
|
1295
|
+
let i16 = i2 * 16;
|
|
1296
|
+
for (let j = 0;j < 16; ++j)
|
|
1297
|
+
table[i16 + j] = "0123456789abcdef"[i2] + "0123456789abcdef"[j];
|
|
1298
|
+
}
|
|
1299
|
+
return table;
|
|
1300
|
+
}();
|
|
1301
|
+
function defineBigIntMethod(fn) {
|
|
1302
|
+
return typeof BigInt > "u" ? BufferBigIntNotDefined : fn;
|
|
1303
|
+
}
|
|
1304
|
+
function BufferBigIntNotDefined() {
|
|
1305
|
+
throw Error("BigInt not supported");
|
|
1306
|
+
}
|
|
1307
|
+
function notimpl(name) {
|
|
1308
|
+
return () => {
|
|
1309
|
+
throw Error(name + " is not implemented for node:buffer browser polyfill");
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
var resolveObjectURL = notimpl("resolveObjectURL");
|
|
1313
|
+
var isUtf8 = notimpl("isUtf8");
|
|
1314
|
+
var transcode = notimpl("transcode");
|
|
1315
|
+
|
|
1316
|
+
// src/recovery/recovery.ts
|
|
1317
|
+
import {
|
|
1318
|
+
DEPTH_PROGRAM_ID,
|
|
1319
|
+
marketAddress,
|
|
1320
|
+
protocolAddress
|
|
1321
|
+
} from "@depthhq/bindings";
|
|
1322
|
+
import { PublicKey } from "@solana/web3.js";
|
|
1323
|
+
|
|
1324
|
+
class DepthRecovery {
|
|
1325
|
+
program;
|
|
1326
|
+
connection;
|
|
1327
|
+
owner;
|
|
1328
|
+
market = marketAddress();
|
|
1329
|
+
winddown = PublicKey.findProgramAddressSync([Buffer.from("winddown"), this.market.toBuffer()], DEPTH_PROGRAM_ID)[0];
|
|
1330
|
+
marketAccount;
|
|
1331
|
+
claim;
|
|
1332
|
+
constructor(program, connection, owner) {
|
|
1333
|
+
this.program = program;
|
|
1334
|
+
this.connection = connection;
|
|
1335
|
+
this.owner = owner;
|
|
1336
|
+
this.marketAccount = PublicKey.findProgramAddressSync([Buffer.from("market-account"), this.market.toBuffer(), owner.toBuffer()], DEPTH_PROGRAM_ID)[0];
|
|
1337
|
+
this.claim = PublicKey.findProgramAddressSync([Buffer.from("winddown-claim"), this.marketAccount.toBuffer()], DEPTH_PROGRAM_ID)[0];
|
|
1338
|
+
}
|
|
1339
|
+
async read(address, name) {
|
|
1340
|
+
const result = await this.connection.getAccountInfoAndContext(address, "confirmed");
|
|
1341
|
+
if (!result.value)
|
|
1342
|
+
return;
|
|
1343
|
+
if (!result.value.owner.equals(DEPTH_PROGRAM_ID)) {
|
|
1344
|
+
throw new Error(`${name} is not owned by Depth`);
|
|
1345
|
+
}
|
|
1346
|
+
return {
|
|
1347
|
+
value: this.program.coder.accounts.decode(name[0].toLowerCase() + name.slice(1), result.value.data),
|
|
1348
|
+
slot: result.context.slot
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
async status() {
|
|
1352
|
+
const winddown = await this.read(this.winddown, "Winddown");
|
|
1353
|
+
if (!winddown) {
|
|
1354
|
+
return {
|
|
1355
|
+
status: "unavailable",
|
|
1356
|
+
winddown: this.winddown,
|
|
1357
|
+
claim: this.claim,
|
|
1358
|
+
slot: 0
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
if (!winddown.value.market.equals(this.market)) {
|
|
1362
|
+
throw new Error("Winddown belongs to another market");
|
|
1363
|
+
}
|
|
1364
|
+
const base = {
|
|
1365
|
+
winddown: this.winddown,
|
|
1366
|
+
claim: this.claim,
|
|
1367
|
+
expectedAccounts: winddown.value.expectedAccounts,
|
|
1368
|
+
revealedAccounts: winddown.value.revealedAccounts,
|
|
1369
|
+
paidAccounts: winddown.value.paidAccounts,
|
|
1370
|
+
slot: winddown.slot
|
|
1371
|
+
};
|
|
1372
|
+
const claim = await this.read(this.claim, "WinddownClaim");
|
|
1373
|
+
if (!claim) {
|
|
1374
|
+
const account = await this.connection.getAccountInfo(this.marketAccount, "confirmed");
|
|
1375
|
+
return { ...base, status: account ? "revealing" : "unavailable" };
|
|
1376
|
+
}
|
|
1377
|
+
if (!claim.value.winddown.equals(this.winddown) || !claim.value.marketAccount.equals(this.marketAccount) || !claim.value.owner.equals(this.owner)) {
|
|
1378
|
+
throw new Error("Recovery claim does not match this account");
|
|
1379
|
+
}
|
|
1380
|
+
const positiveEquity = BigInt(claim.value.positiveEquity.toString());
|
|
1381
|
+
if (!winddown.value.finalized) {
|
|
1382
|
+
return { ...base, status: "revealing", positiveEquity };
|
|
1383
|
+
}
|
|
1384
|
+
const pool = BigInt(winddown.value.payoutPool.toString());
|
|
1385
|
+
const gross = BigInt(winddown.value.grossPositive.toString());
|
|
1386
|
+
const payout = gross <= pool ? positiveEquity : positiveEquity * pool / gross;
|
|
1387
|
+
return {
|
|
1388
|
+
...base,
|
|
1389
|
+
status: claim.value.paid ? "claimed" : "claimable",
|
|
1390
|
+
positiveEquity,
|
|
1391
|
+
payout
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
async claimTo(destination) {
|
|
1395
|
+
const wallet = this.program.provider.wallet;
|
|
1396
|
+
if (!wallet.publicKey.equals(this.owner)) {
|
|
1397
|
+
throw new Error("Only the market account owner can claim its payout");
|
|
1398
|
+
}
|
|
1399
|
+
if ((await this.status()).status !== "claimable") {
|
|
1400
|
+
throw new Error("The market payout is not claimable yet");
|
|
1401
|
+
}
|
|
1402
|
+
const protocol = await this.read(protocolAddress(), "Protocol");
|
|
1403
|
+
if (!protocol)
|
|
1404
|
+
throw new Error("Protocol account is unavailable");
|
|
1405
|
+
return this.program.methods.claimWinddown().accountsPartial({
|
|
1406
|
+
owner: this.owner,
|
|
1407
|
+
protocol: protocolAddress(),
|
|
1408
|
+
settlementMint: protocol.value.settlementMint,
|
|
1409
|
+
vault: protocol.value.vault,
|
|
1410
|
+
market: this.market,
|
|
1411
|
+
winddown: this.winddown,
|
|
1412
|
+
marketAccount: this.marketAccount,
|
|
1413
|
+
claim: this.claim,
|
|
1414
|
+
destination
|
|
1415
|
+
}).rpc({ commitment: "confirmed" });
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
export {
|
|
1419
|
+
DepthRecovery
|
|
1420
|
+
};
|