postchain-client 2.0.2 → 2.0.4
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/README.md +5 -0
- package/built/cjs/index.js +144 -70
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +3290 -402
- package/built/esm/index.js.map +1 -1
- package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +1 -0
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js +1 -1
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
- package/built/src/ICCF/error.d.ts +1 -0
- package/built/src/ICCF/error.js.map +1 -1
- package/built/src/ICCF/interfaces.d.ts +1 -0
- package/built/src/ICCF/types.d.ts +1 -0
- package/built/src/ICCF/utils.d.ts +1 -0
- package/built/src/ICCF/utils.js +1 -0
- package/built/src/ICCF/utils.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.js +61 -3
- package/built/src/blockchainClient/blockchainClient.js.map +1 -1
- package/built/src/blockchainClient/clientStub.js +5 -1
- package/built/src/blockchainClient/clientStub.js.map +1 -1
- package/built/src/blockchainClient/enums.d.ts +2 -1
- package/built/src/blockchainClient/enums.js +1 -0
- package/built/src/blockchainClient/enums.js.map +1 -1
- package/built/src/blockchainClient/errors.d.ts +1 -0
- package/built/src/blockchainClient/errors.js.map +1 -1
- package/built/src/blockchainClient/failoverStrategies.js +3 -1
- package/built/src/blockchainClient/failoverStrategies.js.map +1 -1
- package/built/src/blockchainClient/httpUtil.d.ts +1 -0
- package/built/src/blockchainClient/httpUtil.js +1 -0
- package/built/src/blockchainClient/httpUtil.js.map +1 -1
- package/built/src/blockchainClient/interface.d.ts +2 -0
- package/built/src/blockchainClient/requestWithFailoverStrategy.d.ts +1 -0
- package/built/src/blockchainClient/requestWithFailoverStrategy.js.map +1 -1
- package/built/src/blockchainClient/types.d.ts +4 -1
- package/built/src/blockchainClient/utils.d.ts +3 -1
- package/built/src/blockchainClient/utils.js +16 -13
- package/built/src/blockchainClient/utils.js.map +1 -1
- package/built/src/blockchainClient/validation/anchoringTransaction.d.ts +1 -0
- package/built/src/blockchainClient/validation/anchoringTransaction.js +1 -0
- package/built/src/blockchainClient/validation/anchoringTransaction.js.map +1 -1
- package/built/src/blockchainClient/validation/bufferSchema.d.ts +1 -0
- package/built/src/blockchainClient/validation/bufferSchema.js +1 -0
- package/built/src/blockchainClient/validation/bufferSchema.js.map +1 -1
- package/built/src/blockchainClient/validation/merkleHash.js +0 -1
- package/built/src/blockchainClient/validation/merkleHash.js.map +1 -1
- package/built/src/blockchainClient/validation/rawGtx.js +1 -0
- package/built/src/blockchainClient/validation/rawGtx.js.map +1 -1
- package/built/src/blockchainClient/validation/requests.js +1 -0
- package/built/src/blockchainClient/validation/requests.js.map +1 -1
- package/built/src/blockchainClient/validation/txRid.d.ts +1 -0
- package/built/src/blockchainClient/validation/txRid.js.map +1 -1
- package/built/src/encryption/encryption.d.ts +1 -0
- package/built/src/encryption/encryption.js +1 -0
- package/built/src/encryption/encryption.js.map +1 -1
- package/built/src/encryption/errors.d.ts +1 -0
- package/built/src/encryption/errors.js.map +1 -1
- package/built/src/encryption/types.d.ts +1 -0
- package/built/src/formatter.d.ts +1 -0
- package/built/src/formatter.js +1 -0
- package/built/src/formatter.js.map +1 -1
- package/built/src/gtv/index.js +7 -0
- package/built/src/gtv/index.js.map +1 -1
- package/built/src/gtv/types.d.ts +1 -0
- package/built/src/gtx/gtx.d.ts +2 -1
- package/built/src/gtx/gtx.js +4 -3
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/gtx/serialization.d.ts +1 -0
- package/built/src/gtx/serialization.js +1 -0
- package/built/src/gtx/serialization.js.map +1 -1
- package/built/src/gtx/types.d.ts +1 -0
- package/built/src/utils/calculateTransactionRid.d.ts +1 -0
- package/built/src/utils/calculateTransactionRid.js.map +1 -1
- package/built/src/utils/constants.d.ts +1 -0
- package/built/src/utils/constants.js +1 -0
- package/built/src/utils/constants.js.map +1 -1
- package/built/src/utils/decodeTransactionToGtx.d.ts +1 -0
- package/built/src/utils/decodeTransactionToGtx.js.map +1 -1
- package/built/src/utils/dump.js +1 -0
- package/built/src/utils/dump.js.map +1 -1
- package/built/src/utils/encodeTransaction.d.ts +1 -0
- package/built/src/utils/encodeTransaction.js.map +1 -1
- package/built/test/common/mocks.d.ts +17 -0
- package/built/test/common/mocks.js +21 -1
- package/built/test/common/mocks.js.map +1 -1
- package/built/test/integration/clientGetTransactionStatus.test.js +2 -2
- package/built/test/integration/clientGetTransactionStatus.test.js.map +1 -1
- package/built/test/integration/clientQuery.test.js +2 -2
- package/built/test/integration/clientQuery.test.js.map +1 -1
- package/built/test/integration/clientSendTransaction.test.js +1 -1
- package/built/test/integration/clientSendTransaction.test.js.map +1 -1
- package/built/test/integration/clientSignAndSendUniqueTransaction.test.js +1 -1
- package/built/test/integration/clientSignAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/integration/createClientIntegration.test.js +3 -0
- package/built/test/integration/createClientIntegration.test.js.map +1 -1
- package/built/test/integration/signAndSendUniqueTransaction.test.js +7 -6
- package/built/test/integration/signAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/getTransactionConfirmationLevel.test.js +1 -0
- package/built/test/integrationChromiaNetwork/getTransactionConfirmationLevel.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js +4 -3
- package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.js +10 -7
- package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/pcctf/getSuites.test.js +1 -1
- package/built/test/pcctf/getSuites.test.js.map +1 -1
- package/built/test/pcctf/helpers.js +1 -1
- package/built/test/pcctf/helpers.js.map +1 -1
- package/built/test/unit/blockchainClient/client.test.js +2 -1
- package/built/test/unit/blockchainClient/client.test.js.map +1 -1
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js +2 -2
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js.map +1 -1
- package/built/test/unit/blockchainClient/sendTransaction.test.js +14 -8
- package/built/test/unit/blockchainClient/sendTransaction.test.js.map +1 -1
- package/built/test/unit/blockchainClient/statusPollIntervals.test.js +35 -28
- package/built/test/unit/blockchainClient/statusPollIntervals.test.js.map +1 -1
- package/built/test/unit/failoverStrategies.test.js +15 -14
- package/built/test/unit/failoverStrategies.test.js.map +1 -1
- package/built/test/unit/gtv/gtvHash.test.js +44 -0
- package/built/test/unit/gtv/gtvHash.test.js.map +1 -1
- package/built/test/unit/gtx/newSignatureProvider.test.js +4 -4
- package/built/test/unit/gtx/newSignatureProvider.test.js.map +1 -1
- package/built/test/unit/httpUtil.test.js +4 -0
- package/built/test/unit/httpUtil.test.js.map +1 -1
- package/built/umd/index.js +99 -26
- package/built/umd/index.js.map +1 -1
- package/changelog.md +19 -1
- package/package.json +1 -1
package/built/esm/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import require$$0$2, { Buffer as Buffer$G } from 'buffer';
|
|
2
|
-
import require$$0$3, { EventEmitter } from 'events';
|
|
3
|
-
import require$$2$1 from 'string_decoder';
|
|
4
|
-
|
|
5
1
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
6
2
|
|
|
7
3
|
function getDefaultExportFromCjs (x) {
|
|
@@ -38,6 +34,2355 @@ function getAugmentedNamespace(n) {
|
|
|
38
34
|
|
|
39
35
|
var dist = {};
|
|
40
36
|
|
|
37
|
+
var buffer$3 = {};
|
|
38
|
+
|
|
39
|
+
var base64Js = {};
|
|
40
|
+
|
|
41
|
+
base64Js.byteLength = byteLength;
|
|
42
|
+
base64Js.toByteArray = toByteArray;
|
|
43
|
+
base64Js.fromByteArray = fromByteArray;
|
|
44
|
+
|
|
45
|
+
var lookup = [];
|
|
46
|
+
var revLookup = [];
|
|
47
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
48
|
+
|
|
49
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
50
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
51
|
+
lookup[i] = code[i];
|
|
52
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
56
|
+
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
57
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
58
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
59
|
+
|
|
60
|
+
function getLens (b64) {
|
|
61
|
+
var len = b64.length;
|
|
62
|
+
|
|
63
|
+
if (len % 4 > 0) {
|
|
64
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
68
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
69
|
+
var validLen = b64.indexOf('=');
|
|
70
|
+
if (validLen === -1) validLen = len;
|
|
71
|
+
|
|
72
|
+
var placeHoldersLen = validLen === len
|
|
73
|
+
? 0
|
|
74
|
+
: 4 - (validLen % 4);
|
|
75
|
+
|
|
76
|
+
return [validLen, placeHoldersLen]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
80
|
+
function byteLength (b64) {
|
|
81
|
+
var lens = getLens(b64);
|
|
82
|
+
var validLen = lens[0];
|
|
83
|
+
var placeHoldersLen = lens[1];
|
|
84
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
88
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function toByteArray (b64) {
|
|
92
|
+
var tmp;
|
|
93
|
+
var lens = getLens(b64);
|
|
94
|
+
var validLen = lens[0];
|
|
95
|
+
var placeHoldersLen = lens[1];
|
|
96
|
+
|
|
97
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
98
|
+
|
|
99
|
+
var curByte = 0;
|
|
100
|
+
|
|
101
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
102
|
+
var len = placeHoldersLen > 0
|
|
103
|
+
? validLen - 4
|
|
104
|
+
: validLen;
|
|
105
|
+
|
|
106
|
+
var i;
|
|
107
|
+
for (i = 0; i < len; i += 4) {
|
|
108
|
+
tmp =
|
|
109
|
+
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
110
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
111
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
112
|
+
revLookup[b64.charCodeAt(i + 3)];
|
|
113
|
+
arr[curByte++] = (tmp >> 16) & 0xFF;
|
|
114
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
115
|
+
arr[curByte++] = tmp & 0xFF;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (placeHoldersLen === 2) {
|
|
119
|
+
tmp =
|
|
120
|
+
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
121
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
122
|
+
arr[curByte++] = tmp & 0xFF;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (placeHoldersLen === 1) {
|
|
126
|
+
tmp =
|
|
127
|
+
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
128
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
129
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
130
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
131
|
+
arr[curByte++] = tmp & 0xFF;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return arr
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function tripletToBase64 (num) {
|
|
138
|
+
return lookup[num >> 18 & 0x3F] +
|
|
139
|
+
lookup[num >> 12 & 0x3F] +
|
|
140
|
+
lookup[num >> 6 & 0x3F] +
|
|
141
|
+
lookup[num & 0x3F]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function encodeChunk (uint8, start, end) {
|
|
145
|
+
var tmp;
|
|
146
|
+
var output = [];
|
|
147
|
+
for (var i = start; i < end; i += 3) {
|
|
148
|
+
tmp =
|
|
149
|
+
((uint8[i] << 16) & 0xFF0000) +
|
|
150
|
+
((uint8[i + 1] << 8) & 0xFF00) +
|
|
151
|
+
(uint8[i + 2] & 0xFF);
|
|
152
|
+
output.push(tripletToBase64(tmp));
|
|
153
|
+
}
|
|
154
|
+
return output.join('')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function fromByteArray (uint8) {
|
|
158
|
+
var tmp;
|
|
159
|
+
var len = uint8.length;
|
|
160
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
161
|
+
var parts = [];
|
|
162
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
163
|
+
|
|
164
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
165
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
166
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
170
|
+
if (extraBytes === 1) {
|
|
171
|
+
tmp = uint8[len - 1];
|
|
172
|
+
parts.push(
|
|
173
|
+
lookup[tmp >> 2] +
|
|
174
|
+
lookup[(tmp << 4) & 0x3F] +
|
|
175
|
+
'=='
|
|
176
|
+
);
|
|
177
|
+
} else if (extraBytes === 2) {
|
|
178
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
179
|
+
parts.push(
|
|
180
|
+
lookup[tmp >> 10] +
|
|
181
|
+
lookup[(tmp >> 4) & 0x3F] +
|
|
182
|
+
lookup[(tmp << 2) & 0x3F] +
|
|
183
|
+
'='
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return parts.join('')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var ieee754 = {};
|
|
191
|
+
|
|
192
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
193
|
+
|
|
194
|
+
ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
195
|
+
var e, m;
|
|
196
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
197
|
+
var eMax = (1 << eLen) - 1;
|
|
198
|
+
var eBias = eMax >> 1;
|
|
199
|
+
var nBits = -7;
|
|
200
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
201
|
+
var d = isLE ? -1 : 1;
|
|
202
|
+
var s = buffer[offset + i];
|
|
203
|
+
|
|
204
|
+
i += d;
|
|
205
|
+
|
|
206
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
207
|
+
s >>= (-nBits);
|
|
208
|
+
nBits += eLen;
|
|
209
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
210
|
+
|
|
211
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
212
|
+
e >>= (-nBits);
|
|
213
|
+
nBits += mLen;
|
|
214
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
215
|
+
|
|
216
|
+
if (e === 0) {
|
|
217
|
+
e = 1 - eBias;
|
|
218
|
+
} else if (e === eMax) {
|
|
219
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
220
|
+
} else {
|
|
221
|
+
m = m + Math.pow(2, mLen);
|
|
222
|
+
e = e - eBias;
|
|
223
|
+
}
|
|
224
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
228
|
+
var e, m, c;
|
|
229
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
230
|
+
var eMax = (1 << eLen) - 1;
|
|
231
|
+
var eBias = eMax >> 1;
|
|
232
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
233
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
234
|
+
var d = isLE ? 1 : -1;
|
|
235
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
236
|
+
|
|
237
|
+
value = Math.abs(value);
|
|
238
|
+
|
|
239
|
+
if (isNaN(value) || value === Infinity) {
|
|
240
|
+
m = isNaN(value) ? 1 : 0;
|
|
241
|
+
e = eMax;
|
|
242
|
+
} else {
|
|
243
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
244
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
245
|
+
e--;
|
|
246
|
+
c *= 2;
|
|
247
|
+
}
|
|
248
|
+
if (e + eBias >= 1) {
|
|
249
|
+
value += rt / c;
|
|
250
|
+
} else {
|
|
251
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
252
|
+
}
|
|
253
|
+
if (value * c >= 2) {
|
|
254
|
+
e++;
|
|
255
|
+
c /= 2;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (e + eBias >= eMax) {
|
|
259
|
+
m = 0;
|
|
260
|
+
e = eMax;
|
|
261
|
+
} else if (e + eBias >= 1) {
|
|
262
|
+
m = ((value * c) - 1) * Math.pow(2, mLen);
|
|
263
|
+
e = e + eBias;
|
|
264
|
+
} else {
|
|
265
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
266
|
+
e = 0;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
271
|
+
|
|
272
|
+
e = (e << mLen) | m;
|
|
273
|
+
eLen += mLen;
|
|
274
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
275
|
+
|
|
276
|
+
buffer[offset + i - d] |= s * 128;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/*!
|
|
280
|
+
* The buffer module from node.js, for the browser.
|
|
281
|
+
*
|
|
282
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
283
|
+
* @license MIT
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
(function (exports) {
|
|
287
|
+
|
|
288
|
+
const base64 = base64Js;
|
|
289
|
+
const ieee754$1 = ieee754;
|
|
290
|
+
const customInspectSymbol =
|
|
291
|
+
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
292
|
+
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
293
|
+
: null;
|
|
294
|
+
|
|
295
|
+
exports.Buffer = Buffer;
|
|
296
|
+
exports.SlowBuffer = SlowBuffer;
|
|
297
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
298
|
+
|
|
299
|
+
const K_MAX_LENGTH = 0x7fffffff;
|
|
300
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
304
|
+
* === true Use Uint8Array implementation (fastest)
|
|
305
|
+
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
306
|
+
* implementation (most compatible, even IE6)
|
|
307
|
+
*
|
|
308
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
309
|
+
* Opera 11.6+, iOS 4.2+.
|
|
310
|
+
*
|
|
311
|
+
* We report that the browser does not support typed arrays if the are not subclassable
|
|
312
|
+
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
313
|
+
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
314
|
+
* for __proto__ and has a buggy typed array implementation.
|
|
315
|
+
*/
|
|
316
|
+
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
317
|
+
|
|
318
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
319
|
+
typeof console.error === 'function') {
|
|
320
|
+
console.error(
|
|
321
|
+
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
322
|
+
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function typedArraySupport () {
|
|
327
|
+
// Can typed array instances can be augmented?
|
|
328
|
+
try {
|
|
329
|
+
const arr = new Uint8Array(1);
|
|
330
|
+
const proto = { foo: function () { return 42 } };
|
|
331
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
332
|
+
Object.setPrototypeOf(arr, proto);
|
|
333
|
+
return arr.foo() === 42
|
|
334
|
+
} catch (e) {
|
|
335
|
+
return false
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
340
|
+
enumerable: true,
|
|
341
|
+
get: function () {
|
|
342
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
343
|
+
return this.buffer
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
348
|
+
enumerable: true,
|
|
349
|
+
get: function () {
|
|
350
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
351
|
+
return this.byteOffset
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
function createBuffer (length) {
|
|
356
|
+
if (length > K_MAX_LENGTH) {
|
|
357
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
358
|
+
}
|
|
359
|
+
// Return an augmented `Uint8Array` instance
|
|
360
|
+
const buf = new Uint8Array(length);
|
|
361
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
362
|
+
return buf
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
367
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
368
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
369
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
370
|
+
* returns a single octet.
|
|
371
|
+
*
|
|
372
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
376
|
+
// Common case.
|
|
377
|
+
if (typeof arg === 'number') {
|
|
378
|
+
if (typeof encodingOrOffset === 'string') {
|
|
379
|
+
throw new TypeError(
|
|
380
|
+
'The "string" argument must be of type string. Received type number'
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
return allocUnsafe(arg)
|
|
384
|
+
}
|
|
385
|
+
return from(arg, encodingOrOffset, length)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
389
|
+
|
|
390
|
+
function from (value, encodingOrOffset, length) {
|
|
391
|
+
if (typeof value === 'string') {
|
|
392
|
+
return fromString(value, encodingOrOffset)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (ArrayBuffer.isView(value)) {
|
|
396
|
+
return fromArrayView(value)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (value == null) {
|
|
400
|
+
throw new TypeError(
|
|
401
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
402
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (isInstance(value, ArrayBuffer) ||
|
|
407
|
+
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
408
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
412
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
413
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
414
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (typeof value === 'number') {
|
|
418
|
+
throw new TypeError(
|
|
419
|
+
'The "value" argument must not be of type number. Received type number'
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
424
|
+
if (valueOf != null && valueOf !== value) {
|
|
425
|
+
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const b = fromObject(value);
|
|
429
|
+
if (b) return b
|
|
430
|
+
|
|
431
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
432
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
433
|
+
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
throw new TypeError(
|
|
437
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
438
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
439
|
+
)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
444
|
+
* if value is a number.
|
|
445
|
+
* Buffer.from(str[, encoding])
|
|
446
|
+
* Buffer.from(array)
|
|
447
|
+
* Buffer.from(buffer)
|
|
448
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
449
|
+
**/
|
|
450
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
451
|
+
return from(value, encodingOrOffset, length)
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
455
|
+
// https://github.com/feross/buffer/pull/148
|
|
456
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
457
|
+
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
458
|
+
|
|
459
|
+
function assertSize (size) {
|
|
460
|
+
if (typeof size !== 'number') {
|
|
461
|
+
throw new TypeError('"size" argument must be of type number')
|
|
462
|
+
} else if (size < 0) {
|
|
463
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function alloc (size, fill, encoding) {
|
|
468
|
+
assertSize(size);
|
|
469
|
+
if (size <= 0) {
|
|
470
|
+
return createBuffer(size)
|
|
471
|
+
}
|
|
472
|
+
if (fill !== undefined) {
|
|
473
|
+
// Only pay attention to encoding if it's a string. This
|
|
474
|
+
// prevents accidentally sending in a number that would
|
|
475
|
+
// be interpreted as a start offset.
|
|
476
|
+
return typeof encoding === 'string'
|
|
477
|
+
? createBuffer(size).fill(fill, encoding)
|
|
478
|
+
: createBuffer(size).fill(fill)
|
|
479
|
+
}
|
|
480
|
+
return createBuffer(size)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Creates a new filled Buffer instance.
|
|
485
|
+
* alloc(size[, fill[, encoding]])
|
|
486
|
+
**/
|
|
487
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
488
|
+
return alloc(size, fill, encoding)
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
function allocUnsafe (size) {
|
|
492
|
+
assertSize(size);
|
|
493
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
498
|
+
* */
|
|
499
|
+
Buffer.allocUnsafe = function (size) {
|
|
500
|
+
return allocUnsafe(size)
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
504
|
+
*/
|
|
505
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
506
|
+
return allocUnsafe(size)
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
function fromString (string, encoding) {
|
|
510
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
511
|
+
encoding = 'utf8';
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
515
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const length = byteLength(string, encoding) | 0;
|
|
519
|
+
let buf = createBuffer(length);
|
|
520
|
+
|
|
521
|
+
const actual = buf.write(string, encoding);
|
|
522
|
+
|
|
523
|
+
if (actual !== length) {
|
|
524
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
525
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
526
|
+
// 'abxxcd' will be treated as 'ab')
|
|
527
|
+
buf = buf.slice(0, actual);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return buf
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function fromArrayLike (array) {
|
|
534
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
535
|
+
const buf = createBuffer(length);
|
|
536
|
+
for (let i = 0; i < length; i += 1) {
|
|
537
|
+
buf[i] = array[i] & 255;
|
|
538
|
+
}
|
|
539
|
+
return buf
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function fromArrayView (arrayView) {
|
|
543
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
544
|
+
const copy = new Uint8Array(arrayView);
|
|
545
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
546
|
+
}
|
|
547
|
+
return fromArrayLike(arrayView)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function fromArrayBuffer (array, byteOffset, length) {
|
|
551
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
552
|
+
throw new RangeError('"offset" is outside of buffer bounds')
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
556
|
+
throw new RangeError('"length" is outside of buffer bounds')
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
let buf;
|
|
560
|
+
if (byteOffset === undefined && length === undefined) {
|
|
561
|
+
buf = new Uint8Array(array);
|
|
562
|
+
} else if (length === undefined) {
|
|
563
|
+
buf = new Uint8Array(array, byteOffset);
|
|
564
|
+
} else {
|
|
565
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Return an augmented `Uint8Array` instance
|
|
569
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
570
|
+
|
|
571
|
+
return buf
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function fromObject (obj) {
|
|
575
|
+
if (Buffer.isBuffer(obj)) {
|
|
576
|
+
const len = checked(obj.length) | 0;
|
|
577
|
+
const buf = createBuffer(len);
|
|
578
|
+
|
|
579
|
+
if (buf.length === 0) {
|
|
580
|
+
return buf
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
obj.copy(buf, 0, 0, len);
|
|
584
|
+
return buf
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (obj.length !== undefined) {
|
|
588
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
589
|
+
return createBuffer(0)
|
|
590
|
+
}
|
|
591
|
+
return fromArrayLike(obj)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
595
|
+
return fromArrayLike(obj.data)
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function checked (length) {
|
|
600
|
+
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
601
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
602
|
+
if (length >= K_MAX_LENGTH) {
|
|
603
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
604
|
+
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
605
|
+
}
|
|
606
|
+
return length | 0
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function SlowBuffer (length) {
|
|
610
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
|
611
|
+
length = 0;
|
|
612
|
+
}
|
|
613
|
+
return Buffer.alloc(+length)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
Buffer.isBuffer = function isBuffer (b) {
|
|
617
|
+
return b != null && b._isBuffer === true &&
|
|
618
|
+
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
Buffer.compare = function compare (a, b) {
|
|
622
|
+
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
623
|
+
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
624
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
625
|
+
throw new TypeError(
|
|
626
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
627
|
+
)
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (a === b) return 0
|
|
631
|
+
|
|
632
|
+
let x = a.length;
|
|
633
|
+
let y = b.length;
|
|
634
|
+
|
|
635
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
636
|
+
if (a[i] !== b[i]) {
|
|
637
|
+
x = a[i];
|
|
638
|
+
y = b[i];
|
|
639
|
+
break
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
if (x < y) return -1
|
|
644
|
+
if (y < x) return 1
|
|
645
|
+
return 0
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
649
|
+
switch (String(encoding).toLowerCase()) {
|
|
650
|
+
case 'hex':
|
|
651
|
+
case 'utf8':
|
|
652
|
+
case 'utf-8':
|
|
653
|
+
case 'ascii':
|
|
654
|
+
case 'latin1':
|
|
655
|
+
case 'binary':
|
|
656
|
+
case 'base64':
|
|
657
|
+
case 'ucs2':
|
|
658
|
+
case 'ucs-2':
|
|
659
|
+
case 'utf16le':
|
|
660
|
+
case 'utf-16le':
|
|
661
|
+
return true
|
|
662
|
+
default:
|
|
663
|
+
return false
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
Buffer.concat = function concat (list, length) {
|
|
668
|
+
if (!Array.isArray(list)) {
|
|
669
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if (list.length === 0) {
|
|
673
|
+
return Buffer.alloc(0)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
let i;
|
|
677
|
+
if (length === undefined) {
|
|
678
|
+
length = 0;
|
|
679
|
+
for (i = 0; i < list.length; ++i) {
|
|
680
|
+
length += list[i].length;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
685
|
+
let pos = 0;
|
|
686
|
+
for (i = 0; i < list.length; ++i) {
|
|
687
|
+
let buf = list[i];
|
|
688
|
+
if (isInstance(buf, Uint8Array)) {
|
|
689
|
+
if (pos + buf.length > buffer.length) {
|
|
690
|
+
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
691
|
+
buf.copy(buffer, pos);
|
|
692
|
+
} else {
|
|
693
|
+
Uint8Array.prototype.set.call(
|
|
694
|
+
buffer,
|
|
695
|
+
buf,
|
|
696
|
+
pos
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
} else if (!Buffer.isBuffer(buf)) {
|
|
700
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
701
|
+
} else {
|
|
702
|
+
buf.copy(buffer, pos);
|
|
703
|
+
}
|
|
704
|
+
pos += buf.length;
|
|
705
|
+
}
|
|
706
|
+
return buffer
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
function byteLength (string, encoding) {
|
|
710
|
+
if (Buffer.isBuffer(string)) {
|
|
711
|
+
return string.length
|
|
712
|
+
}
|
|
713
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
714
|
+
return string.byteLength
|
|
715
|
+
}
|
|
716
|
+
if (typeof string !== 'string') {
|
|
717
|
+
throw new TypeError(
|
|
718
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
719
|
+
'Received type ' + typeof string
|
|
720
|
+
)
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const len = string.length;
|
|
724
|
+
const mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
725
|
+
if (!mustMatch && len === 0) return 0
|
|
726
|
+
|
|
727
|
+
// Use a for loop to avoid recursion
|
|
728
|
+
let loweredCase = false;
|
|
729
|
+
for (;;) {
|
|
730
|
+
switch (encoding) {
|
|
731
|
+
case 'ascii':
|
|
732
|
+
case 'latin1':
|
|
733
|
+
case 'binary':
|
|
734
|
+
return len
|
|
735
|
+
case 'utf8':
|
|
736
|
+
case 'utf-8':
|
|
737
|
+
return utf8ToBytes(string).length
|
|
738
|
+
case 'ucs2':
|
|
739
|
+
case 'ucs-2':
|
|
740
|
+
case 'utf16le':
|
|
741
|
+
case 'utf-16le':
|
|
742
|
+
return len * 2
|
|
743
|
+
case 'hex':
|
|
744
|
+
return len >>> 1
|
|
745
|
+
case 'base64':
|
|
746
|
+
return base64ToBytes(string).length
|
|
747
|
+
default:
|
|
748
|
+
if (loweredCase) {
|
|
749
|
+
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
750
|
+
}
|
|
751
|
+
encoding = ('' + encoding).toLowerCase();
|
|
752
|
+
loweredCase = true;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
Buffer.byteLength = byteLength;
|
|
757
|
+
|
|
758
|
+
function slowToString (encoding, start, end) {
|
|
759
|
+
let loweredCase = false;
|
|
760
|
+
|
|
761
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
762
|
+
// property of a typed array.
|
|
763
|
+
|
|
764
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
765
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
766
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
767
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
768
|
+
if (start === undefined || start < 0) {
|
|
769
|
+
start = 0;
|
|
770
|
+
}
|
|
771
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
772
|
+
// coercion fail below.
|
|
773
|
+
if (start > this.length) {
|
|
774
|
+
return ''
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (end === undefined || end > this.length) {
|
|
778
|
+
end = this.length;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
if (end <= 0) {
|
|
782
|
+
return ''
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
786
|
+
end >>>= 0;
|
|
787
|
+
start >>>= 0;
|
|
788
|
+
|
|
789
|
+
if (end <= start) {
|
|
790
|
+
return ''
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
if (!encoding) encoding = 'utf8';
|
|
794
|
+
|
|
795
|
+
while (true) {
|
|
796
|
+
switch (encoding) {
|
|
797
|
+
case 'hex':
|
|
798
|
+
return hexSlice(this, start, end)
|
|
799
|
+
|
|
800
|
+
case 'utf8':
|
|
801
|
+
case 'utf-8':
|
|
802
|
+
return utf8Slice(this, start, end)
|
|
803
|
+
|
|
804
|
+
case 'ascii':
|
|
805
|
+
return asciiSlice(this, start, end)
|
|
806
|
+
|
|
807
|
+
case 'latin1':
|
|
808
|
+
case 'binary':
|
|
809
|
+
return latin1Slice(this, start, end)
|
|
810
|
+
|
|
811
|
+
case 'base64':
|
|
812
|
+
return base64Slice(this, start, end)
|
|
813
|
+
|
|
814
|
+
case 'ucs2':
|
|
815
|
+
case 'ucs-2':
|
|
816
|
+
case 'utf16le':
|
|
817
|
+
case 'utf-16le':
|
|
818
|
+
return utf16leSlice(this, start, end)
|
|
819
|
+
|
|
820
|
+
default:
|
|
821
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
822
|
+
encoding = (encoding + '').toLowerCase();
|
|
823
|
+
loweredCase = true;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
829
|
+
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
830
|
+
// reliably in a browserify context because there could be multiple different
|
|
831
|
+
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
832
|
+
// instances that were created from another copy of the `buffer` package.
|
|
833
|
+
// See: https://github.com/feross/buffer/issues/154
|
|
834
|
+
Buffer.prototype._isBuffer = true;
|
|
835
|
+
|
|
836
|
+
function swap (b, n, m) {
|
|
837
|
+
const i = b[n];
|
|
838
|
+
b[n] = b[m];
|
|
839
|
+
b[m] = i;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
843
|
+
const len = this.length;
|
|
844
|
+
if (len % 2 !== 0) {
|
|
845
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
846
|
+
}
|
|
847
|
+
for (let i = 0; i < len; i += 2) {
|
|
848
|
+
swap(this, i, i + 1);
|
|
849
|
+
}
|
|
850
|
+
return this
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
854
|
+
const len = this.length;
|
|
855
|
+
if (len % 4 !== 0) {
|
|
856
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
857
|
+
}
|
|
858
|
+
for (let i = 0; i < len; i += 4) {
|
|
859
|
+
swap(this, i, i + 3);
|
|
860
|
+
swap(this, i + 1, i + 2);
|
|
861
|
+
}
|
|
862
|
+
return this
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
866
|
+
const len = this.length;
|
|
867
|
+
if (len % 8 !== 0) {
|
|
868
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
869
|
+
}
|
|
870
|
+
for (let i = 0; i < len; i += 8) {
|
|
871
|
+
swap(this, i, i + 7);
|
|
872
|
+
swap(this, i + 1, i + 6);
|
|
873
|
+
swap(this, i + 2, i + 5);
|
|
874
|
+
swap(this, i + 3, i + 4);
|
|
875
|
+
}
|
|
876
|
+
return this
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
Buffer.prototype.toString = function toString () {
|
|
880
|
+
const length = this.length;
|
|
881
|
+
if (length === 0) return ''
|
|
882
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
883
|
+
return slowToString.apply(this, arguments)
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
887
|
+
|
|
888
|
+
Buffer.prototype.equals = function equals (b) {
|
|
889
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
890
|
+
if (this === b) return true
|
|
891
|
+
return Buffer.compare(this, b) === 0
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
Buffer.prototype.inspect = function inspect () {
|
|
895
|
+
let str = '';
|
|
896
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
897
|
+
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
898
|
+
if (this.length > max) str += ' ... ';
|
|
899
|
+
return '<Buffer ' + str + '>'
|
|
900
|
+
};
|
|
901
|
+
if (customInspectSymbol) {
|
|
902
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
906
|
+
if (isInstance(target, Uint8Array)) {
|
|
907
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
908
|
+
}
|
|
909
|
+
if (!Buffer.isBuffer(target)) {
|
|
910
|
+
throw new TypeError(
|
|
911
|
+
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
912
|
+
'Received type ' + (typeof target)
|
|
913
|
+
)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (start === undefined) {
|
|
917
|
+
start = 0;
|
|
918
|
+
}
|
|
919
|
+
if (end === undefined) {
|
|
920
|
+
end = target ? target.length : 0;
|
|
921
|
+
}
|
|
922
|
+
if (thisStart === undefined) {
|
|
923
|
+
thisStart = 0;
|
|
924
|
+
}
|
|
925
|
+
if (thisEnd === undefined) {
|
|
926
|
+
thisEnd = this.length;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
930
|
+
throw new RangeError('out of range index')
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
934
|
+
return 0
|
|
935
|
+
}
|
|
936
|
+
if (thisStart >= thisEnd) {
|
|
937
|
+
return -1
|
|
938
|
+
}
|
|
939
|
+
if (start >= end) {
|
|
940
|
+
return 1
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
start >>>= 0;
|
|
944
|
+
end >>>= 0;
|
|
945
|
+
thisStart >>>= 0;
|
|
946
|
+
thisEnd >>>= 0;
|
|
947
|
+
|
|
948
|
+
if (this === target) return 0
|
|
949
|
+
|
|
950
|
+
let x = thisEnd - thisStart;
|
|
951
|
+
let y = end - start;
|
|
952
|
+
const len = Math.min(x, y);
|
|
953
|
+
|
|
954
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
955
|
+
const targetCopy = target.slice(start, end);
|
|
956
|
+
|
|
957
|
+
for (let i = 0; i < len; ++i) {
|
|
958
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
959
|
+
x = thisCopy[i];
|
|
960
|
+
y = targetCopy[i];
|
|
961
|
+
break
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (x < y) return -1
|
|
966
|
+
if (y < x) return 1
|
|
967
|
+
return 0
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
971
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
972
|
+
//
|
|
973
|
+
// Arguments:
|
|
974
|
+
// - buffer - a Buffer to search
|
|
975
|
+
// - val - a string, Buffer, or number
|
|
976
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
977
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
978
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
979
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
980
|
+
// Empty buffer means no match
|
|
981
|
+
if (buffer.length === 0) return -1
|
|
982
|
+
|
|
983
|
+
// Normalize byteOffset
|
|
984
|
+
if (typeof byteOffset === 'string') {
|
|
985
|
+
encoding = byteOffset;
|
|
986
|
+
byteOffset = 0;
|
|
987
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
988
|
+
byteOffset = 0x7fffffff;
|
|
989
|
+
} else if (byteOffset < -0x80000000) {
|
|
990
|
+
byteOffset = -0x80000000;
|
|
991
|
+
}
|
|
992
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
993
|
+
if (numberIsNaN(byteOffset)) {
|
|
994
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
995
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
999
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
1000
|
+
if (byteOffset >= buffer.length) {
|
|
1001
|
+
if (dir) return -1
|
|
1002
|
+
else byteOffset = buffer.length - 1;
|
|
1003
|
+
} else if (byteOffset < 0) {
|
|
1004
|
+
if (dir) byteOffset = 0;
|
|
1005
|
+
else return -1
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// Normalize val
|
|
1009
|
+
if (typeof val === 'string') {
|
|
1010
|
+
val = Buffer.from(val, encoding);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
1014
|
+
if (Buffer.isBuffer(val)) {
|
|
1015
|
+
// Special case: looking for empty string/buffer always fails
|
|
1016
|
+
if (val.length === 0) {
|
|
1017
|
+
return -1
|
|
1018
|
+
}
|
|
1019
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
1020
|
+
} else if (typeof val === 'number') {
|
|
1021
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
1022
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
1023
|
+
if (dir) {
|
|
1024
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
1025
|
+
} else {
|
|
1026
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
1036
|
+
let indexSize = 1;
|
|
1037
|
+
let arrLength = arr.length;
|
|
1038
|
+
let valLength = val.length;
|
|
1039
|
+
|
|
1040
|
+
if (encoding !== undefined) {
|
|
1041
|
+
encoding = String(encoding).toLowerCase();
|
|
1042
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
1043
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
1044
|
+
if (arr.length < 2 || val.length < 2) {
|
|
1045
|
+
return -1
|
|
1046
|
+
}
|
|
1047
|
+
indexSize = 2;
|
|
1048
|
+
arrLength /= 2;
|
|
1049
|
+
valLength /= 2;
|
|
1050
|
+
byteOffset /= 2;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function read (buf, i) {
|
|
1055
|
+
if (indexSize === 1) {
|
|
1056
|
+
return buf[i]
|
|
1057
|
+
} else {
|
|
1058
|
+
return buf.readUInt16BE(i * indexSize)
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
let i;
|
|
1063
|
+
if (dir) {
|
|
1064
|
+
let foundIndex = -1;
|
|
1065
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
1066
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
1067
|
+
if (foundIndex === -1) foundIndex = i;
|
|
1068
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
1069
|
+
} else {
|
|
1070
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
1071
|
+
foundIndex = -1;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
} else {
|
|
1075
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
1076
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
1077
|
+
let found = true;
|
|
1078
|
+
for (let j = 0; j < valLength; j++) {
|
|
1079
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
1080
|
+
found = false;
|
|
1081
|
+
break
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (found) return i
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return -1
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
1092
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
1096
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1099
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
1100
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
function hexWrite (buf, string, offset, length) {
|
|
1104
|
+
offset = Number(offset) || 0;
|
|
1105
|
+
const remaining = buf.length - offset;
|
|
1106
|
+
if (!length) {
|
|
1107
|
+
length = remaining;
|
|
1108
|
+
} else {
|
|
1109
|
+
length = Number(length);
|
|
1110
|
+
if (length > remaining) {
|
|
1111
|
+
length = remaining;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
const strLen = string.length;
|
|
1116
|
+
|
|
1117
|
+
if (length > strLen / 2) {
|
|
1118
|
+
length = strLen / 2;
|
|
1119
|
+
}
|
|
1120
|
+
let i;
|
|
1121
|
+
for (i = 0; i < length; ++i) {
|
|
1122
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
1123
|
+
if (numberIsNaN(parsed)) return i
|
|
1124
|
+
buf[offset + i] = parsed;
|
|
1125
|
+
}
|
|
1126
|
+
return i
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
function utf8Write (buf, string, offset, length) {
|
|
1130
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
function asciiWrite (buf, string, offset, length) {
|
|
1134
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function base64Write (buf, string, offset, length) {
|
|
1138
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function ucs2Write (buf, string, offset, length) {
|
|
1142
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
1146
|
+
// Buffer#write(string)
|
|
1147
|
+
if (offset === undefined) {
|
|
1148
|
+
encoding = 'utf8';
|
|
1149
|
+
length = this.length;
|
|
1150
|
+
offset = 0;
|
|
1151
|
+
// Buffer#write(string, encoding)
|
|
1152
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
1153
|
+
encoding = offset;
|
|
1154
|
+
length = this.length;
|
|
1155
|
+
offset = 0;
|
|
1156
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
1157
|
+
} else if (isFinite(offset)) {
|
|
1158
|
+
offset = offset >>> 0;
|
|
1159
|
+
if (isFinite(length)) {
|
|
1160
|
+
length = length >>> 0;
|
|
1161
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
1162
|
+
} else {
|
|
1163
|
+
encoding = length;
|
|
1164
|
+
length = undefined;
|
|
1165
|
+
}
|
|
1166
|
+
} else {
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1169
|
+
)
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
const remaining = this.length - offset;
|
|
1173
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
1174
|
+
|
|
1175
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1176
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
if (!encoding) encoding = 'utf8';
|
|
1180
|
+
|
|
1181
|
+
let loweredCase = false;
|
|
1182
|
+
for (;;) {
|
|
1183
|
+
switch (encoding) {
|
|
1184
|
+
case 'hex':
|
|
1185
|
+
return hexWrite(this, string, offset, length)
|
|
1186
|
+
|
|
1187
|
+
case 'utf8':
|
|
1188
|
+
case 'utf-8':
|
|
1189
|
+
return utf8Write(this, string, offset, length)
|
|
1190
|
+
|
|
1191
|
+
case 'ascii':
|
|
1192
|
+
case 'latin1':
|
|
1193
|
+
case 'binary':
|
|
1194
|
+
return asciiWrite(this, string, offset, length)
|
|
1195
|
+
|
|
1196
|
+
case 'base64':
|
|
1197
|
+
// Warning: maxLength not taken into account in base64Write
|
|
1198
|
+
return base64Write(this, string, offset, length)
|
|
1199
|
+
|
|
1200
|
+
case 'ucs2':
|
|
1201
|
+
case 'ucs-2':
|
|
1202
|
+
case 'utf16le':
|
|
1203
|
+
case 'utf-16le':
|
|
1204
|
+
return ucs2Write(this, string, offset, length)
|
|
1205
|
+
|
|
1206
|
+
default:
|
|
1207
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1208
|
+
encoding = ('' + encoding).toLowerCase();
|
|
1209
|
+
loweredCase = true;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
1215
|
+
return {
|
|
1216
|
+
type: 'Buffer',
|
|
1217
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
function base64Slice (buf, start, end) {
|
|
1222
|
+
if (start === 0 && end === buf.length) {
|
|
1223
|
+
return base64.fromByteArray(buf)
|
|
1224
|
+
} else {
|
|
1225
|
+
return base64.fromByteArray(buf.slice(start, end))
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function utf8Slice (buf, start, end) {
|
|
1230
|
+
end = Math.min(buf.length, end);
|
|
1231
|
+
const res = [];
|
|
1232
|
+
|
|
1233
|
+
let i = start;
|
|
1234
|
+
while (i < end) {
|
|
1235
|
+
const firstByte = buf[i];
|
|
1236
|
+
let codePoint = null;
|
|
1237
|
+
let bytesPerSequence = (firstByte > 0xEF)
|
|
1238
|
+
? 4
|
|
1239
|
+
: (firstByte > 0xDF)
|
|
1240
|
+
? 3
|
|
1241
|
+
: (firstByte > 0xBF)
|
|
1242
|
+
? 2
|
|
1243
|
+
: 1;
|
|
1244
|
+
|
|
1245
|
+
if (i + bytesPerSequence <= end) {
|
|
1246
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1247
|
+
|
|
1248
|
+
switch (bytesPerSequence) {
|
|
1249
|
+
case 1:
|
|
1250
|
+
if (firstByte < 0x80) {
|
|
1251
|
+
codePoint = firstByte;
|
|
1252
|
+
}
|
|
1253
|
+
break
|
|
1254
|
+
case 2:
|
|
1255
|
+
secondByte = buf[i + 1];
|
|
1256
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
1257
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
1258
|
+
if (tempCodePoint > 0x7F) {
|
|
1259
|
+
codePoint = tempCodePoint;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
break
|
|
1263
|
+
case 3:
|
|
1264
|
+
secondByte = buf[i + 1];
|
|
1265
|
+
thirdByte = buf[i + 2];
|
|
1266
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1267
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
1268
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1269
|
+
codePoint = tempCodePoint;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
break
|
|
1273
|
+
case 4:
|
|
1274
|
+
secondByte = buf[i + 1];
|
|
1275
|
+
thirdByte = buf[i + 2];
|
|
1276
|
+
fourthByte = buf[i + 3];
|
|
1277
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1278
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
1279
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1280
|
+
codePoint = tempCodePoint;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
if (codePoint === null) {
|
|
1287
|
+
// we did not generate a valid codePoint so insert a
|
|
1288
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
1289
|
+
codePoint = 0xFFFD;
|
|
1290
|
+
bytesPerSequence = 1;
|
|
1291
|
+
} else if (codePoint > 0xFFFF) {
|
|
1292
|
+
// encode to utf16 (surrogate pair dance)
|
|
1293
|
+
codePoint -= 0x10000;
|
|
1294
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
1295
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
res.push(codePoint);
|
|
1299
|
+
i += bytesPerSequence;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
return decodeCodePointsArray(res)
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1306
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
1307
|
+
// We go 1 magnitude less, for safety
|
|
1308
|
+
const MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
1309
|
+
|
|
1310
|
+
function decodeCodePointsArray (codePoints) {
|
|
1311
|
+
const len = codePoints.length;
|
|
1312
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1313
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
1317
|
+
let res = '';
|
|
1318
|
+
let i = 0;
|
|
1319
|
+
while (i < len) {
|
|
1320
|
+
res += String.fromCharCode.apply(
|
|
1321
|
+
String,
|
|
1322
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
return res
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function asciiSlice (buf, start, end) {
|
|
1329
|
+
let ret = '';
|
|
1330
|
+
end = Math.min(buf.length, end);
|
|
1331
|
+
|
|
1332
|
+
for (let i = start; i < end; ++i) {
|
|
1333
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
1334
|
+
}
|
|
1335
|
+
return ret
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
function latin1Slice (buf, start, end) {
|
|
1339
|
+
let ret = '';
|
|
1340
|
+
end = Math.min(buf.length, end);
|
|
1341
|
+
|
|
1342
|
+
for (let i = start; i < end; ++i) {
|
|
1343
|
+
ret += String.fromCharCode(buf[i]);
|
|
1344
|
+
}
|
|
1345
|
+
return ret
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function hexSlice (buf, start, end) {
|
|
1349
|
+
const len = buf.length;
|
|
1350
|
+
|
|
1351
|
+
if (!start || start < 0) start = 0;
|
|
1352
|
+
if (!end || end < 0 || end > len) end = len;
|
|
1353
|
+
|
|
1354
|
+
let out = '';
|
|
1355
|
+
for (let i = start; i < end; ++i) {
|
|
1356
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1357
|
+
}
|
|
1358
|
+
return out
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
function utf16leSlice (buf, start, end) {
|
|
1362
|
+
const bytes = buf.slice(start, end);
|
|
1363
|
+
let res = '';
|
|
1364
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
1365
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1366
|
+
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
1367
|
+
}
|
|
1368
|
+
return res
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
1372
|
+
const len = this.length;
|
|
1373
|
+
start = ~~start;
|
|
1374
|
+
end = end === undefined ? len : ~~end;
|
|
1375
|
+
|
|
1376
|
+
if (start < 0) {
|
|
1377
|
+
start += len;
|
|
1378
|
+
if (start < 0) start = 0;
|
|
1379
|
+
} else if (start > len) {
|
|
1380
|
+
start = len;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
if (end < 0) {
|
|
1384
|
+
end += len;
|
|
1385
|
+
if (end < 0) end = 0;
|
|
1386
|
+
} else if (end > len) {
|
|
1387
|
+
end = len;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
if (end < start) end = start;
|
|
1391
|
+
|
|
1392
|
+
const newBuf = this.subarray(start, end);
|
|
1393
|
+
// Return an augmented `Uint8Array` instance
|
|
1394
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
1395
|
+
|
|
1396
|
+
return newBuf
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
/*
|
|
1400
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1401
|
+
*/
|
|
1402
|
+
function checkOffset (offset, ext, length) {
|
|
1403
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1404
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
Buffer.prototype.readUintLE =
|
|
1408
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1409
|
+
offset = offset >>> 0;
|
|
1410
|
+
byteLength = byteLength >>> 0;
|
|
1411
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1412
|
+
|
|
1413
|
+
let val = this[offset];
|
|
1414
|
+
let mul = 1;
|
|
1415
|
+
let i = 0;
|
|
1416
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1417
|
+
val += this[offset + i] * mul;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
return val
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
Buffer.prototype.readUintBE =
|
|
1424
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1425
|
+
offset = offset >>> 0;
|
|
1426
|
+
byteLength = byteLength >>> 0;
|
|
1427
|
+
if (!noAssert) {
|
|
1428
|
+
checkOffset(offset, byteLength, this.length);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
let val = this[offset + --byteLength];
|
|
1432
|
+
let mul = 1;
|
|
1433
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1434
|
+
val += this[offset + --byteLength] * mul;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
return val
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
Buffer.prototype.readUint8 =
|
|
1441
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1442
|
+
offset = offset >>> 0;
|
|
1443
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1444
|
+
return this[offset]
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
Buffer.prototype.readUint16LE =
|
|
1448
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1449
|
+
offset = offset >>> 0;
|
|
1450
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1451
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
Buffer.prototype.readUint16BE =
|
|
1455
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1456
|
+
offset = offset >>> 0;
|
|
1457
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1458
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1461
|
+
Buffer.prototype.readUint32LE =
|
|
1462
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1463
|
+
offset = offset >>> 0;
|
|
1464
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1465
|
+
|
|
1466
|
+
return ((this[offset]) |
|
|
1467
|
+
(this[offset + 1] << 8) |
|
|
1468
|
+
(this[offset + 2] << 16)) +
|
|
1469
|
+
(this[offset + 3] * 0x1000000)
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
Buffer.prototype.readUint32BE =
|
|
1473
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
1474
|
+
offset = offset >>> 0;
|
|
1475
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1476
|
+
|
|
1477
|
+
return (this[offset] * 0x1000000) +
|
|
1478
|
+
((this[offset + 1] << 16) |
|
|
1479
|
+
(this[offset + 2] << 8) |
|
|
1480
|
+
this[offset + 3])
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
|
|
1484
|
+
offset = offset >>> 0;
|
|
1485
|
+
validateNumber(offset, 'offset');
|
|
1486
|
+
const first = this[offset];
|
|
1487
|
+
const last = this[offset + 7];
|
|
1488
|
+
if (first === undefined || last === undefined) {
|
|
1489
|
+
boundsError(offset, this.length - 8);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
const lo = first +
|
|
1493
|
+
this[++offset] * 2 ** 8 +
|
|
1494
|
+
this[++offset] * 2 ** 16 +
|
|
1495
|
+
this[++offset] * 2 ** 24;
|
|
1496
|
+
|
|
1497
|
+
const hi = this[++offset] +
|
|
1498
|
+
this[++offset] * 2 ** 8 +
|
|
1499
|
+
this[++offset] * 2 ** 16 +
|
|
1500
|
+
last * 2 ** 24;
|
|
1501
|
+
|
|
1502
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32))
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
|
|
1506
|
+
offset = offset >>> 0;
|
|
1507
|
+
validateNumber(offset, 'offset');
|
|
1508
|
+
const first = this[offset];
|
|
1509
|
+
const last = this[offset + 7];
|
|
1510
|
+
if (first === undefined || last === undefined) {
|
|
1511
|
+
boundsError(offset, this.length - 8);
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
const hi = first * 2 ** 24 +
|
|
1515
|
+
this[++offset] * 2 ** 16 +
|
|
1516
|
+
this[++offset] * 2 ** 8 +
|
|
1517
|
+
this[++offset];
|
|
1518
|
+
|
|
1519
|
+
const lo = this[++offset] * 2 ** 24 +
|
|
1520
|
+
this[++offset] * 2 ** 16 +
|
|
1521
|
+
this[++offset] * 2 ** 8 +
|
|
1522
|
+
last;
|
|
1523
|
+
|
|
1524
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
|
|
1525
|
+
});
|
|
1526
|
+
|
|
1527
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
1528
|
+
offset = offset >>> 0;
|
|
1529
|
+
byteLength = byteLength >>> 0;
|
|
1530
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1531
|
+
|
|
1532
|
+
let val = this[offset];
|
|
1533
|
+
let mul = 1;
|
|
1534
|
+
let i = 0;
|
|
1535
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1536
|
+
val += this[offset + i] * mul;
|
|
1537
|
+
}
|
|
1538
|
+
mul *= 0x80;
|
|
1539
|
+
|
|
1540
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1541
|
+
|
|
1542
|
+
return val
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
1546
|
+
offset = offset >>> 0;
|
|
1547
|
+
byteLength = byteLength >>> 0;
|
|
1548
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
1549
|
+
|
|
1550
|
+
let i = byteLength;
|
|
1551
|
+
let mul = 1;
|
|
1552
|
+
let val = this[offset + --i];
|
|
1553
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
1554
|
+
val += this[offset + --i] * mul;
|
|
1555
|
+
}
|
|
1556
|
+
mul *= 0x80;
|
|
1557
|
+
|
|
1558
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
1559
|
+
|
|
1560
|
+
return val
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
1564
|
+
offset = offset >>> 0;
|
|
1565
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
1566
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1567
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1571
|
+
offset = offset >>> 0;
|
|
1572
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1573
|
+
const val = this[offset] | (this[offset + 1] << 8);
|
|
1574
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1578
|
+
offset = offset >>> 0;
|
|
1579
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
1580
|
+
const val = this[offset + 1] | (this[offset] << 8);
|
|
1581
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1585
|
+
offset = offset >>> 0;
|
|
1586
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1587
|
+
|
|
1588
|
+
return (this[offset]) |
|
|
1589
|
+
(this[offset + 1] << 8) |
|
|
1590
|
+
(this[offset + 2] << 16) |
|
|
1591
|
+
(this[offset + 3] << 24)
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1595
|
+
offset = offset >>> 0;
|
|
1596
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1597
|
+
|
|
1598
|
+
return (this[offset] << 24) |
|
|
1599
|
+
(this[offset + 1] << 16) |
|
|
1600
|
+
(this[offset + 2] << 8) |
|
|
1601
|
+
(this[offset + 3])
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1604
|
+
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
|
|
1605
|
+
offset = offset >>> 0;
|
|
1606
|
+
validateNumber(offset, 'offset');
|
|
1607
|
+
const first = this[offset];
|
|
1608
|
+
const last = this[offset + 7];
|
|
1609
|
+
if (first === undefined || last === undefined) {
|
|
1610
|
+
boundsError(offset, this.length - 8);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
const val = this[offset + 4] +
|
|
1614
|
+
this[offset + 5] * 2 ** 8 +
|
|
1615
|
+
this[offset + 6] * 2 ** 16 +
|
|
1616
|
+
(last << 24); // Overflow
|
|
1617
|
+
|
|
1618
|
+
return (BigInt(val) << BigInt(32)) +
|
|
1619
|
+
BigInt(first +
|
|
1620
|
+
this[++offset] * 2 ** 8 +
|
|
1621
|
+
this[++offset] * 2 ** 16 +
|
|
1622
|
+
this[++offset] * 2 ** 24)
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
|
|
1626
|
+
offset = offset >>> 0;
|
|
1627
|
+
validateNumber(offset, 'offset');
|
|
1628
|
+
const first = this[offset];
|
|
1629
|
+
const last = this[offset + 7];
|
|
1630
|
+
if (first === undefined || last === undefined) {
|
|
1631
|
+
boundsError(offset, this.length - 8);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
const val = (first << 24) + // Overflow
|
|
1635
|
+
this[++offset] * 2 ** 16 +
|
|
1636
|
+
this[++offset] * 2 ** 8 +
|
|
1637
|
+
this[++offset];
|
|
1638
|
+
|
|
1639
|
+
return (BigInt(val) << BigInt(32)) +
|
|
1640
|
+
BigInt(this[++offset] * 2 ** 24 +
|
|
1641
|
+
this[++offset] * 2 ** 16 +
|
|
1642
|
+
this[++offset] * 2 ** 8 +
|
|
1643
|
+
last)
|
|
1644
|
+
});
|
|
1645
|
+
|
|
1646
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1647
|
+
offset = offset >>> 0;
|
|
1648
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1649
|
+
return ieee754$1.read(this, offset, true, 23, 4)
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1653
|
+
offset = offset >>> 0;
|
|
1654
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
1655
|
+
return ieee754$1.read(this, offset, false, 23, 4)
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1659
|
+
offset = offset >>> 0;
|
|
1660
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1661
|
+
return ieee754$1.read(this, offset, true, 52, 8)
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1665
|
+
offset = offset >>> 0;
|
|
1666
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
1667
|
+
return ieee754$1.read(this, offset, false, 52, 8)
|
|
1668
|
+
};
|
|
1669
|
+
|
|
1670
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
1671
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1672
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1673
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
Buffer.prototype.writeUintLE =
|
|
1677
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1678
|
+
value = +value;
|
|
1679
|
+
offset = offset >>> 0;
|
|
1680
|
+
byteLength = byteLength >>> 0;
|
|
1681
|
+
if (!noAssert) {
|
|
1682
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1683
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
let mul = 1;
|
|
1687
|
+
let i = 0;
|
|
1688
|
+
this[offset] = value & 0xFF;
|
|
1689
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1690
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
return offset + byteLength
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
Buffer.prototype.writeUintBE =
|
|
1697
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1698
|
+
value = +value;
|
|
1699
|
+
offset = offset >>> 0;
|
|
1700
|
+
byteLength = byteLength >>> 0;
|
|
1701
|
+
if (!noAssert) {
|
|
1702
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
1703
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
let i = byteLength - 1;
|
|
1707
|
+
let mul = 1;
|
|
1708
|
+
this[offset + i] = value & 0xFF;
|
|
1709
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1710
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
return offset + byteLength
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
Buffer.prototype.writeUint8 =
|
|
1717
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1718
|
+
value = +value;
|
|
1719
|
+
offset = offset >>> 0;
|
|
1720
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
1721
|
+
this[offset] = (value & 0xff);
|
|
1722
|
+
return offset + 1
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
Buffer.prototype.writeUint16LE =
|
|
1726
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
1727
|
+
value = +value;
|
|
1728
|
+
offset = offset >>> 0;
|
|
1729
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1730
|
+
this[offset] = (value & 0xff);
|
|
1731
|
+
this[offset + 1] = (value >>> 8);
|
|
1732
|
+
return offset + 2
|
|
1733
|
+
};
|
|
1734
|
+
|
|
1735
|
+
Buffer.prototype.writeUint16BE =
|
|
1736
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1737
|
+
value = +value;
|
|
1738
|
+
offset = offset >>> 0;
|
|
1739
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
1740
|
+
this[offset] = (value >>> 8);
|
|
1741
|
+
this[offset + 1] = (value & 0xff);
|
|
1742
|
+
return offset + 2
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
Buffer.prototype.writeUint32LE =
|
|
1746
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1747
|
+
value = +value;
|
|
1748
|
+
offset = offset >>> 0;
|
|
1749
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1750
|
+
this[offset + 3] = (value >>> 24);
|
|
1751
|
+
this[offset + 2] = (value >>> 16);
|
|
1752
|
+
this[offset + 1] = (value >>> 8);
|
|
1753
|
+
this[offset] = (value & 0xff);
|
|
1754
|
+
return offset + 4
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1757
|
+
Buffer.prototype.writeUint32BE =
|
|
1758
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1759
|
+
value = +value;
|
|
1760
|
+
offset = offset >>> 0;
|
|
1761
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
1762
|
+
this[offset] = (value >>> 24);
|
|
1763
|
+
this[offset + 1] = (value >>> 16);
|
|
1764
|
+
this[offset + 2] = (value >>> 8);
|
|
1765
|
+
this[offset + 3] = (value & 0xff);
|
|
1766
|
+
return offset + 4
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
function wrtBigUInt64LE (buf, value, offset, min, max) {
|
|
1770
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1771
|
+
|
|
1772
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
1773
|
+
buf[offset++] = lo;
|
|
1774
|
+
lo = lo >> 8;
|
|
1775
|
+
buf[offset++] = lo;
|
|
1776
|
+
lo = lo >> 8;
|
|
1777
|
+
buf[offset++] = lo;
|
|
1778
|
+
lo = lo >> 8;
|
|
1779
|
+
buf[offset++] = lo;
|
|
1780
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
1781
|
+
buf[offset++] = hi;
|
|
1782
|
+
hi = hi >> 8;
|
|
1783
|
+
buf[offset++] = hi;
|
|
1784
|
+
hi = hi >> 8;
|
|
1785
|
+
buf[offset++] = hi;
|
|
1786
|
+
hi = hi >> 8;
|
|
1787
|
+
buf[offset++] = hi;
|
|
1788
|
+
return offset
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
function wrtBigUInt64BE (buf, value, offset, min, max) {
|
|
1792
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1793
|
+
|
|
1794
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
1795
|
+
buf[offset + 7] = lo;
|
|
1796
|
+
lo = lo >> 8;
|
|
1797
|
+
buf[offset + 6] = lo;
|
|
1798
|
+
lo = lo >> 8;
|
|
1799
|
+
buf[offset + 5] = lo;
|
|
1800
|
+
lo = lo >> 8;
|
|
1801
|
+
buf[offset + 4] = lo;
|
|
1802
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
1803
|
+
buf[offset + 3] = hi;
|
|
1804
|
+
hi = hi >> 8;
|
|
1805
|
+
buf[offset + 2] = hi;
|
|
1806
|
+
hi = hi >> 8;
|
|
1807
|
+
buf[offset + 1] = hi;
|
|
1808
|
+
hi = hi >> 8;
|
|
1809
|
+
buf[offset] = hi;
|
|
1810
|
+
return offset + 8
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
1814
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
1818
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
1819
|
+
});
|
|
1820
|
+
|
|
1821
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
1822
|
+
value = +value;
|
|
1823
|
+
offset = offset >>> 0;
|
|
1824
|
+
if (!noAssert) {
|
|
1825
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
1826
|
+
|
|
1827
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
let i = 0;
|
|
1831
|
+
let mul = 1;
|
|
1832
|
+
let sub = 0;
|
|
1833
|
+
this[offset] = value & 0xFF;
|
|
1834
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
1835
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1836
|
+
sub = 1;
|
|
1837
|
+
}
|
|
1838
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
return offset + byteLength
|
|
1842
|
+
};
|
|
1843
|
+
|
|
1844
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1845
|
+
value = +value;
|
|
1846
|
+
offset = offset >>> 0;
|
|
1847
|
+
if (!noAssert) {
|
|
1848
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
1849
|
+
|
|
1850
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
let i = byteLength - 1;
|
|
1854
|
+
let mul = 1;
|
|
1855
|
+
let sub = 0;
|
|
1856
|
+
this[offset + i] = value & 0xFF;
|
|
1857
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
1858
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1859
|
+
sub = 1;
|
|
1860
|
+
}
|
|
1861
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
return offset + byteLength
|
|
1865
|
+
};
|
|
1866
|
+
|
|
1867
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1868
|
+
value = +value;
|
|
1869
|
+
offset = offset >>> 0;
|
|
1870
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
1871
|
+
if (value < 0) value = 0xff + value + 1;
|
|
1872
|
+
this[offset] = (value & 0xff);
|
|
1873
|
+
return offset + 1
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1876
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1877
|
+
value = +value;
|
|
1878
|
+
offset = offset >>> 0;
|
|
1879
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1880
|
+
this[offset] = (value & 0xff);
|
|
1881
|
+
this[offset + 1] = (value >>> 8);
|
|
1882
|
+
return offset + 2
|
|
1883
|
+
};
|
|
1884
|
+
|
|
1885
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1886
|
+
value = +value;
|
|
1887
|
+
offset = offset >>> 0;
|
|
1888
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
1889
|
+
this[offset] = (value >>> 8);
|
|
1890
|
+
this[offset + 1] = (value & 0xff);
|
|
1891
|
+
return offset + 2
|
|
1892
|
+
};
|
|
1893
|
+
|
|
1894
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1895
|
+
value = +value;
|
|
1896
|
+
offset = offset >>> 0;
|
|
1897
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1898
|
+
this[offset] = (value & 0xff);
|
|
1899
|
+
this[offset + 1] = (value >>> 8);
|
|
1900
|
+
this[offset + 2] = (value >>> 16);
|
|
1901
|
+
this[offset + 3] = (value >>> 24);
|
|
1902
|
+
return offset + 4
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1906
|
+
value = +value;
|
|
1907
|
+
offset = offset >>> 0;
|
|
1908
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
1909
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
1910
|
+
this[offset] = (value >>> 24);
|
|
1911
|
+
this[offset + 1] = (value >>> 16);
|
|
1912
|
+
this[offset + 2] = (value >>> 8);
|
|
1913
|
+
this[offset + 3] = (value & 0xff);
|
|
1914
|
+
return offset + 4
|
|
1915
|
+
};
|
|
1916
|
+
|
|
1917
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
1918
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
1919
|
+
});
|
|
1920
|
+
|
|
1921
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
1922
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
1923
|
+
});
|
|
1924
|
+
|
|
1925
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1926
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1927
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1931
|
+
value = +value;
|
|
1932
|
+
offset = offset >>> 0;
|
|
1933
|
+
if (!noAssert) {
|
|
1934
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1935
|
+
}
|
|
1936
|
+
ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
|
|
1937
|
+
return offset + 4
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1941
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
1942
|
+
};
|
|
1943
|
+
|
|
1944
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1945
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
1946
|
+
};
|
|
1947
|
+
|
|
1948
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1949
|
+
value = +value;
|
|
1950
|
+
offset = offset >>> 0;
|
|
1951
|
+
if (!noAssert) {
|
|
1952
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1953
|
+
}
|
|
1954
|
+
ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
|
|
1955
|
+
return offset + 8
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1959
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1963
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1967
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1968
|
+
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
1969
|
+
if (!start) start = 0;
|
|
1970
|
+
if (!end && end !== 0) end = this.length;
|
|
1971
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
1972
|
+
if (!targetStart) targetStart = 0;
|
|
1973
|
+
if (end > 0 && end < start) end = start;
|
|
1974
|
+
|
|
1975
|
+
// Copy 0 bytes; we're done
|
|
1976
|
+
if (end === start) return 0
|
|
1977
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
1978
|
+
|
|
1979
|
+
// Fatal error conditions
|
|
1980
|
+
if (targetStart < 0) {
|
|
1981
|
+
throw new RangeError('targetStart out of bounds')
|
|
1982
|
+
}
|
|
1983
|
+
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
1984
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1985
|
+
|
|
1986
|
+
// Are we oob?
|
|
1987
|
+
if (end > this.length) end = this.length;
|
|
1988
|
+
if (target.length - targetStart < end - start) {
|
|
1989
|
+
end = target.length - targetStart + start;
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
const len = end - start;
|
|
1993
|
+
|
|
1994
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
1995
|
+
// Use built-in when available, missing from IE11
|
|
1996
|
+
this.copyWithin(targetStart, start, end);
|
|
1997
|
+
} else {
|
|
1998
|
+
Uint8Array.prototype.set.call(
|
|
1999
|
+
target,
|
|
2000
|
+
this.subarray(start, end),
|
|
2001
|
+
targetStart
|
|
2002
|
+
);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
return len
|
|
2006
|
+
};
|
|
2007
|
+
|
|
2008
|
+
// Usage:
|
|
2009
|
+
// buffer.fill(number[, offset[, end]])
|
|
2010
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
2011
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
2012
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
2013
|
+
// Handle string cases:
|
|
2014
|
+
if (typeof val === 'string') {
|
|
2015
|
+
if (typeof start === 'string') {
|
|
2016
|
+
encoding = start;
|
|
2017
|
+
start = 0;
|
|
2018
|
+
end = this.length;
|
|
2019
|
+
} else if (typeof end === 'string') {
|
|
2020
|
+
encoding = end;
|
|
2021
|
+
end = this.length;
|
|
2022
|
+
}
|
|
2023
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
2024
|
+
throw new TypeError('encoding must be a string')
|
|
2025
|
+
}
|
|
2026
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
2027
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
2028
|
+
}
|
|
2029
|
+
if (val.length === 1) {
|
|
2030
|
+
const code = val.charCodeAt(0);
|
|
2031
|
+
if ((encoding === 'utf8' && code < 128) ||
|
|
2032
|
+
encoding === 'latin1') {
|
|
2033
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
2034
|
+
val = code;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
} else if (typeof val === 'number') {
|
|
2038
|
+
val = val & 255;
|
|
2039
|
+
} else if (typeof val === 'boolean') {
|
|
2040
|
+
val = Number(val);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
2044
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
2045
|
+
throw new RangeError('Out of range index')
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
if (end <= start) {
|
|
2049
|
+
return this
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
start = start >>> 0;
|
|
2053
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
2054
|
+
|
|
2055
|
+
if (!val) val = 0;
|
|
2056
|
+
|
|
2057
|
+
let i;
|
|
2058
|
+
if (typeof val === 'number') {
|
|
2059
|
+
for (i = start; i < end; ++i) {
|
|
2060
|
+
this[i] = val;
|
|
2061
|
+
}
|
|
2062
|
+
} else {
|
|
2063
|
+
const bytes = Buffer.isBuffer(val)
|
|
2064
|
+
? val
|
|
2065
|
+
: Buffer.from(val, encoding);
|
|
2066
|
+
const len = bytes.length;
|
|
2067
|
+
if (len === 0) {
|
|
2068
|
+
throw new TypeError('The value "' + val +
|
|
2069
|
+
'" is invalid for argument "value"')
|
|
2070
|
+
}
|
|
2071
|
+
for (i = 0; i < end - start; ++i) {
|
|
2072
|
+
this[i + start] = bytes[i % len];
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
return this
|
|
2077
|
+
};
|
|
2078
|
+
|
|
2079
|
+
// CUSTOM ERRORS
|
|
2080
|
+
// =============
|
|
2081
|
+
|
|
2082
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
2083
|
+
const errors = {};
|
|
2084
|
+
function E (sym, getMessage, Base) {
|
|
2085
|
+
errors[sym] = class NodeError extends Base {
|
|
2086
|
+
constructor () {
|
|
2087
|
+
super();
|
|
2088
|
+
|
|
2089
|
+
Object.defineProperty(this, 'message', {
|
|
2090
|
+
value: getMessage.apply(this, arguments),
|
|
2091
|
+
writable: true,
|
|
2092
|
+
configurable: true
|
|
2093
|
+
});
|
|
2094
|
+
|
|
2095
|
+
// Add the error code to the name to include it in the stack trace.
|
|
2096
|
+
this.name = `${this.name} [${sym}]`;
|
|
2097
|
+
// Access the stack to generate the error message including the error code
|
|
2098
|
+
// from the name.
|
|
2099
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
2100
|
+
// Reset the name to the actual name.
|
|
2101
|
+
delete this.name;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
get code () {
|
|
2105
|
+
return sym
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
set code (value) {
|
|
2109
|
+
Object.defineProperty(this, 'code', {
|
|
2110
|
+
configurable: true,
|
|
2111
|
+
enumerable: true,
|
|
2112
|
+
value,
|
|
2113
|
+
writable: true
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
toString () {
|
|
2118
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
2124
|
+
function (name) {
|
|
2125
|
+
if (name) {
|
|
2126
|
+
return `${name} is outside of buffer bounds`
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
2130
|
+
}, RangeError);
|
|
2131
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
2132
|
+
function (name, actual) {
|
|
2133
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
2134
|
+
}, TypeError);
|
|
2135
|
+
E('ERR_OUT_OF_RANGE',
|
|
2136
|
+
function (str, range, input) {
|
|
2137
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
2138
|
+
let received = input;
|
|
2139
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
2140
|
+
received = addNumericalSeparator(String(input));
|
|
2141
|
+
} else if (typeof input === 'bigint') {
|
|
2142
|
+
received = String(input);
|
|
2143
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
2144
|
+
received = addNumericalSeparator(received);
|
|
2145
|
+
}
|
|
2146
|
+
received += 'n';
|
|
2147
|
+
}
|
|
2148
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
2149
|
+
return msg
|
|
2150
|
+
}, RangeError);
|
|
2151
|
+
|
|
2152
|
+
function addNumericalSeparator (val) {
|
|
2153
|
+
let res = '';
|
|
2154
|
+
let i = val.length;
|
|
2155
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
2156
|
+
for (; i >= start + 4; i -= 3) {
|
|
2157
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
2158
|
+
}
|
|
2159
|
+
return `${val.slice(0, i)}${res}`
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
// CHECK FUNCTIONS
|
|
2163
|
+
// ===============
|
|
2164
|
+
|
|
2165
|
+
function checkBounds (buf, offset, byteLength) {
|
|
2166
|
+
validateNumber(offset, 'offset');
|
|
2167
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
2168
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
2173
|
+
if (value > max || value < min) {
|
|
2174
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
2175
|
+
let range;
|
|
2176
|
+
if (byteLength > 3) {
|
|
2177
|
+
if (min === 0 || min === BigInt(0)) {
|
|
2178
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
2179
|
+
} else {
|
|
2180
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
2181
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
2182
|
+
}
|
|
2183
|
+
} else {
|
|
2184
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
2185
|
+
}
|
|
2186
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
2187
|
+
}
|
|
2188
|
+
checkBounds(buf, offset, byteLength);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
function validateNumber (value, name) {
|
|
2192
|
+
if (typeof value !== 'number') {
|
|
2193
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
function boundsError (value, length, type) {
|
|
2198
|
+
if (Math.floor(value) !== value) {
|
|
2199
|
+
validateNumber(value, type);
|
|
2200
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
if (length < 0) {
|
|
2204
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
|
|
2208
|
+
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
2209
|
+
value)
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// HELPER FUNCTIONS
|
|
2213
|
+
// ================
|
|
2214
|
+
|
|
2215
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
2216
|
+
|
|
2217
|
+
function base64clean (str) {
|
|
2218
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
2219
|
+
str = str.split('=')[0];
|
|
2220
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
2221
|
+
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
2222
|
+
// Node converts strings with length < 2 to ''
|
|
2223
|
+
if (str.length < 2) return ''
|
|
2224
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
2225
|
+
while (str.length % 4 !== 0) {
|
|
2226
|
+
str = str + '=';
|
|
2227
|
+
}
|
|
2228
|
+
return str
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
function utf8ToBytes (string, units) {
|
|
2232
|
+
units = units || Infinity;
|
|
2233
|
+
let codePoint;
|
|
2234
|
+
const length = string.length;
|
|
2235
|
+
let leadSurrogate = null;
|
|
2236
|
+
const bytes = [];
|
|
2237
|
+
|
|
2238
|
+
for (let i = 0; i < length; ++i) {
|
|
2239
|
+
codePoint = string.charCodeAt(i);
|
|
2240
|
+
|
|
2241
|
+
// is surrogate component
|
|
2242
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
2243
|
+
// last char was a lead
|
|
2244
|
+
if (!leadSurrogate) {
|
|
2245
|
+
// no lead yet
|
|
2246
|
+
if (codePoint > 0xDBFF) {
|
|
2247
|
+
// unexpected trail
|
|
2248
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2249
|
+
continue
|
|
2250
|
+
} else if (i + 1 === length) {
|
|
2251
|
+
// unpaired lead
|
|
2252
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2253
|
+
continue
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
// valid lead
|
|
2257
|
+
leadSurrogate = codePoint;
|
|
2258
|
+
|
|
2259
|
+
continue
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
// 2 leads in a row
|
|
2263
|
+
if (codePoint < 0xDC00) {
|
|
2264
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2265
|
+
leadSurrogate = codePoint;
|
|
2266
|
+
continue
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// valid surrogate pair
|
|
2270
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
2271
|
+
} else if (leadSurrogate) {
|
|
2272
|
+
// valid bmp char, but last char was a lead
|
|
2273
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
leadSurrogate = null;
|
|
2277
|
+
|
|
2278
|
+
// encode utf8
|
|
2279
|
+
if (codePoint < 0x80) {
|
|
2280
|
+
if ((units -= 1) < 0) break
|
|
2281
|
+
bytes.push(codePoint);
|
|
2282
|
+
} else if (codePoint < 0x800) {
|
|
2283
|
+
if ((units -= 2) < 0) break
|
|
2284
|
+
bytes.push(
|
|
2285
|
+
codePoint >> 0x6 | 0xC0,
|
|
2286
|
+
codePoint & 0x3F | 0x80
|
|
2287
|
+
);
|
|
2288
|
+
} else if (codePoint < 0x10000) {
|
|
2289
|
+
if ((units -= 3) < 0) break
|
|
2290
|
+
bytes.push(
|
|
2291
|
+
codePoint >> 0xC | 0xE0,
|
|
2292
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
2293
|
+
codePoint & 0x3F | 0x80
|
|
2294
|
+
);
|
|
2295
|
+
} else if (codePoint < 0x110000) {
|
|
2296
|
+
if ((units -= 4) < 0) break
|
|
2297
|
+
bytes.push(
|
|
2298
|
+
codePoint >> 0x12 | 0xF0,
|
|
2299
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
2300
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
2301
|
+
codePoint & 0x3F | 0x80
|
|
2302
|
+
);
|
|
2303
|
+
} else {
|
|
2304
|
+
throw new Error('Invalid code point')
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
return bytes
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
function asciiToBytes (str) {
|
|
2312
|
+
const byteArray = [];
|
|
2313
|
+
for (let i = 0; i < str.length; ++i) {
|
|
2314
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
2315
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
2316
|
+
}
|
|
2317
|
+
return byteArray
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
function utf16leToBytes (str, units) {
|
|
2321
|
+
let c, hi, lo;
|
|
2322
|
+
const byteArray = [];
|
|
2323
|
+
for (let i = 0; i < str.length; ++i) {
|
|
2324
|
+
if ((units -= 2) < 0) break
|
|
2325
|
+
|
|
2326
|
+
c = str.charCodeAt(i);
|
|
2327
|
+
hi = c >> 8;
|
|
2328
|
+
lo = c % 256;
|
|
2329
|
+
byteArray.push(lo);
|
|
2330
|
+
byteArray.push(hi);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
return byteArray
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
function base64ToBytes (str) {
|
|
2337
|
+
return base64.toByteArray(base64clean(str))
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
function blitBuffer (src, dst, offset, length) {
|
|
2341
|
+
let i;
|
|
2342
|
+
for (i = 0; i < length; ++i) {
|
|
2343
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
2344
|
+
dst[i + offset] = src[i];
|
|
2345
|
+
}
|
|
2346
|
+
return i
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
2350
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
2351
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
2352
|
+
function isInstance (obj, type) {
|
|
2353
|
+
return obj instanceof type ||
|
|
2354
|
+
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
2355
|
+
obj.constructor.name === type.name)
|
|
2356
|
+
}
|
|
2357
|
+
function numberIsNaN (obj) {
|
|
2358
|
+
// For IE11 support
|
|
2359
|
+
return obj !== obj // eslint-disable-line no-self-compare
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// Create lookup table for `toString('hex')`
|
|
2363
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
2364
|
+
const hexSliceLookupTable = (function () {
|
|
2365
|
+
const alphabet = '0123456789abcdef';
|
|
2366
|
+
const table = new Array(256);
|
|
2367
|
+
for (let i = 0; i < 16; ++i) {
|
|
2368
|
+
const i16 = i * 16;
|
|
2369
|
+
for (let j = 0; j < 16; ++j) {
|
|
2370
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
return table
|
|
2374
|
+
})();
|
|
2375
|
+
|
|
2376
|
+
// Return not function with Error if BigInt not supported
|
|
2377
|
+
function defineBigIntMethod (fn) {
|
|
2378
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
function BufferBigIntNotDefined () {
|
|
2382
|
+
throw new Error('BigInt not supported')
|
|
2383
|
+
}
|
|
2384
|
+
} (buffer$3));
|
|
2385
|
+
|
|
41
2386
|
var factory = {};
|
|
42
2387
|
|
|
43
2388
|
var types = {};
|
|
@@ -141,7 +2486,7 @@ function buildTree(value, merkleHashVersion) {
|
|
|
141
2486
|
if (Array.isArray(value)) {
|
|
142
2487
|
return handleArrayContainer(value, merkleHashVersion);
|
|
143
2488
|
}
|
|
144
|
-
if (typeof value === 'object' && value !== null && !
|
|
2489
|
+
if (typeof value === 'object' && value !== null && !buffer$3.Buffer.isBuffer(value)) {
|
|
145
2490
|
const entries = Object.entries(value);
|
|
146
2491
|
return handleDictContainer(entries, merkleHashVersion);
|
|
147
2492
|
}
|
|
@@ -3653,8 +5998,8 @@ var inherits_browserExports = inherits_browser.exports;
|
|
|
3653
5998
|
|
|
3654
5999
|
/* eslint-disable node/no-deprecated-api */
|
|
3655
6000
|
|
|
3656
|
-
var buffer$2 =
|
|
3657
|
-
var Buffer$
|
|
6001
|
+
var buffer$2 = buffer$3;
|
|
6002
|
+
var Buffer$G = buffer$2.Buffer;
|
|
3658
6003
|
|
|
3659
6004
|
var safer = {};
|
|
3660
6005
|
|
|
@@ -3667,13 +6012,13 @@ for (key$3 in buffer$2) {
|
|
|
3667
6012
|
}
|
|
3668
6013
|
|
|
3669
6014
|
var Safer = safer.Buffer = {};
|
|
3670
|
-
for (key$3 in Buffer$
|
|
3671
|
-
if (!Buffer$
|
|
6015
|
+
for (key$3 in Buffer$G) {
|
|
6016
|
+
if (!Buffer$G.hasOwnProperty(key$3)) continue
|
|
3672
6017
|
if (key$3 === 'allocUnsafe' || key$3 === 'allocUnsafeSlow') continue
|
|
3673
|
-
Safer[key$3] = Buffer$
|
|
6018
|
+
Safer[key$3] = Buffer$G[key$3];
|
|
3674
6019
|
}
|
|
3675
6020
|
|
|
3676
|
-
safer.Buffer.prototype = Buffer$
|
|
6021
|
+
safer.Buffer.prototype = Buffer$G.prototype;
|
|
3677
6022
|
|
|
3678
6023
|
if (!Safer.from || Safer.from === Uint8Array.from) {
|
|
3679
6024
|
Safer.from = function (value, encodingOrOffset, length) {
|
|
@@ -3683,7 +6028,7 @@ if (!Safer.from || Safer.from === Uint8Array.from) {
|
|
|
3683
6028
|
if (value && typeof value.length === 'undefined') {
|
|
3684
6029
|
throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value)
|
|
3685
6030
|
}
|
|
3686
|
-
return Buffer$
|
|
6031
|
+
return Buffer$G(value, encodingOrOffset, length)
|
|
3687
6032
|
};
|
|
3688
6033
|
}
|
|
3689
6034
|
|
|
@@ -3695,7 +6040,7 @@ if (!Safer.alloc) {
|
|
|
3695
6040
|
if (size < 0 || size >= 2 * (1 << 30)) {
|
|
3696
6041
|
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
3697
6042
|
}
|
|
3698
|
-
var buf = Buffer$
|
|
6043
|
+
var buf = Buffer$G(size);
|
|
3699
6044
|
if (!fill || fill.length === 0) {
|
|
3700
6045
|
buf.fill(0);
|
|
3701
6046
|
} else if (typeof encoding === 'string') {
|
|
@@ -3855,11 +6200,11 @@ var buffer$1 = {};
|
|
|
3855
6200
|
|
|
3856
6201
|
const inherits$y = inherits_browserExports;
|
|
3857
6202
|
const Reporter$4 = reporter$1.Reporter;
|
|
3858
|
-
const Buffer$
|
|
6203
|
+
const Buffer$F = safer_1.Buffer;
|
|
3859
6204
|
|
|
3860
6205
|
function DecoderBuffer$5(base, options) {
|
|
3861
6206
|
Reporter$4.call(this, options);
|
|
3862
|
-
if (!Buffer$
|
|
6207
|
+
if (!Buffer$F.isBuffer(base)) {
|
|
3863
6208
|
this.error('Input not Buffer');
|
|
3864
6209
|
return;
|
|
3865
6210
|
}
|
|
@@ -3878,7 +6223,7 @@ DecoderBuffer$5.isDecoderBuffer = function isDecoderBuffer(data) {
|
|
|
3878
6223
|
|
|
3879
6224
|
// Or accept compatible API
|
|
3880
6225
|
const isCompatible = typeof data === 'object' &&
|
|
3881
|
-
Buffer$
|
|
6226
|
+
Buffer$F.isBuffer(data.base) &&
|
|
3882
6227
|
data.constructor.name === 'DecoderBuffer' &&
|
|
3883
6228
|
typeof data.offset === 'number' &&
|
|
3884
6229
|
typeof data.length === 'number' &&
|
|
@@ -3954,8 +6299,8 @@ function EncoderBuffer$3(value, reporter) {
|
|
|
3954
6299
|
this.length = 1;
|
|
3955
6300
|
} else if (typeof value === 'string') {
|
|
3956
6301
|
this.value = value;
|
|
3957
|
-
this.length = Buffer$
|
|
3958
|
-
} else if (Buffer$
|
|
6302
|
+
this.length = Buffer$F.byteLength(value);
|
|
6303
|
+
} else if (Buffer$F.isBuffer(value)) {
|
|
3959
6304
|
this.value = value;
|
|
3960
6305
|
this.length = value.length;
|
|
3961
6306
|
} else {
|
|
@@ -3980,7 +6325,7 @@ EncoderBuffer$3.isEncoderBuffer = function isEncoderBuffer(data) {
|
|
|
3980
6325
|
|
|
3981
6326
|
EncoderBuffer$3.prototype.join = function join(out, offset) {
|
|
3982
6327
|
if (!out)
|
|
3983
|
-
out = Buffer$
|
|
6328
|
+
out = Buffer$F.alloc(this.length);
|
|
3984
6329
|
if (!offset)
|
|
3985
6330
|
offset = 0;
|
|
3986
6331
|
|
|
@@ -3997,7 +6342,7 @@ EncoderBuffer$3.prototype.join = function join(out, offset) {
|
|
|
3997
6342
|
out[offset] = this.value;
|
|
3998
6343
|
else if (typeof this.value === 'string')
|
|
3999
6344
|
out.write(this.value, offset);
|
|
4000
|
-
else if (Buffer$
|
|
6345
|
+
else if (Buffer$F.isBuffer(this.value))
|
|
4001
6346
|
this.value.copy(out, offset);
|
|
4002
6347
|
offset += this.length;
|
|
4003
6348
|
}
|
|
@@ -5422,7 +7767,7 @@ function derDecodeLen$1(buf, primitive, fail) {
|
|
|
5422
7767
|
}
|
|
5423
7768
|
|
|
5424
7769
|
const inherits$w = inherits_browserExports;
|
|
5425
|
-
const Buffer$
|
|
7770
|
+
const Buffer$E = safer_1.Buffer;
|
|
5426
7771
|
|
|
5427
7772
|
const DERDecoder$2 = der_1$2;
|
|
5428
7773
|
|
|
@@ -5467,7 +7812,7 @@ PEMDecoder$1.prototype.decode = function decode(data, options) {
|
|
|
5467
7812
|
// Remove excessive symbols
|
|
5468
7813
|
base64.replace(/[^a-z0-9+/=]+/gi, '');
|
|
5469
7814
|
|
|
5470
|
-
const input = Buffer$
|
|
7815
|
+
const input = Buffer$E.from(base64, 'base64');
|
|
5471
7816
|
return DERDecoder$2.prototype.decode.call(this, input, options);
|
|
5472
7817
|
};
|
|
5473
7818
|
|
|
@@ -5607,7 +7952,7 @@ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || func
|
|
|
5607
7952
|
};
|
|
5608
7953
|
Object.defineProperty(utils$o, "__esModule", { value: true });
|
|
5609
7954
|
utils$o.encode_value = encode_value;
|
|
5610
|
-
const buffer_1 =
|
|
7955
|
+
const buffer_1 = buffer$3;
|
|
5611
7956
|
const asn1_1 = __importDefault(requireAsn1());
|
|
5612
7957
|
const bn_js_1 = __importDefault(bnExports$2);
|
|
5613
7958
|
const ASNDictPair$1 = asn1_1.default.define("DictPair", function () {
|
|
@@ -5704,7 +8049,7 @@ var safeBuffer$1 = {exports: {}};
|
|
|
5704
8049
|
|
|
5705
8050
|
(function (module, exports) {
|
|
5706
8051
|
/* eslint-disable node/no-deprecated-api */
|
|
5707
|
-
var buffer =
|
|
8052
|
+
var buffer = buffer$3;
|
|
5708
8053
|
var Buffer = buffer.Buffer;
|
|
5709
8054
|
|
|
5710
8055
|
// alternative to using Object.keys for old browsers
|
|
@@ -5783,7 +8128,7 @@ function oldBrowser$1 () {
|
|
|
5783
8128
|
throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
|
|
5784
8129
|
}
|
|
5785
8130
|
|
|
5786
|
-
var Buffer$
|
|
8131
|
+
var Buffer$D = safeBufferExports.Buffer;
|
|
5787
8132
|
var crypto$1 = commonjsGlobal.crypto || commonjsGlobal.msCrypto;
|
|
5788
8133
|
|
|
5789
8134
|
if (crypto$1 && crypto$1.getRandomValues) {
|
|
@@ -5796,7 +8141,7 @@ function randomBytes$3 (size, cb) {
|
|
|
5796
8141
|
// phantomjs needs to throw
|
|
5797
8142
|
if (size > MAX_UINT32) throw new RangeError('requested too many random bytes')
|
|
5798
8143
|
|
|
5799
|
-
var bytes = Buffer$
|
|
8144
|
+
var bytes = Buffer$D.allocUnsafe(size);
|
|
5800
8145
|
|
|
5801
8146
|
if (size > 0) { // getRandomValues fails on IE if size == 0
|
|
5802
8147
|
if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues
|
|
@@ -5824,7 +8169,485 @@ var browserExports = browser$b.exports;
|
|
|
5824
8169
|
|
|
5825
8170
|
var readableBrowser = {exports: {}};
|
|
5826
8171
|
|
|
5827
|
-
var
|
|
8172
|
+
var events = {exports: {}};
|
|
8173
|
+
|
|
8174
|
+
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
8175
|
+
var ReflectApply = R && typeof R.apply === 'function'
|
|
8176
|
+
? R.apply
|
|
8177
|
+
: function ReflectApply(target, receiver, args) {
|
|
8178
|
+
return Function.prototype.apply.call(target, receiver, args);
|
|
8179
|
+
};
|
|
8180
|
+
|
|
8181
|
+
var ReflectOwnKeys;
|
|
8182
|
+
if (R && typeof R.ownKeys === 'function') {
|
|
8183
|
+
ReflectOwnKeys = R.ownKeys;
|
|
8184
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
8185
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
8186
|
+
return Object.getOwnPropertyNames(target)
|
|
8187
|
+
.concat(Object.getOwnPropertySymbols(target));
|
|
8188
|
+
};
|
|
8189
|
+
} else {
|
|
8190
|
+
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
8191
|
+
return Object.getOwnPropertyNames(target);
|
|
8192
|
+
};
|
|
8193
|
+
}
|
|
8194
|
+
|
|
8195
|
+
function ProcessEmitWarning(warning) {
|
|
8196
|
+
if (console && console.warn) console.warn(warning);
|
|
8197
|
+
}
|
|
8198
|
+
|
|
8199
|
+
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
|
8200
|
+
return value !== value;
|
|
8201
|
+
};
|
|
8202
|
+
|
|
8203
|
+
function EventEmitter() {
|
|
8204
|
+
EventEmitter.init.call(this);
|
|
8205
|
+
}
|
|
8206
|
+
events.exports = EventEmitter;
|
|
8207
|
+
events.exports.once = once$2;
|
|
8208
|
+
|
|
8209
|
+
// Backwards-compat with node 0.10.x
|
|
8210
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
8211
|
+
|
|
8212
|
+
EventEmitter.prototype._events = undefined;
|
|
8213
|
+
EventEmitter.prototype._eventsCount = 0;
|
|
8214
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
8215
|
+
|
|
8216
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
8217
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
8218
|
+
var defaultMaxListeners = 10;
|
|
8219
|
+
|
|
8220
|
+
function checkListener(listener) {
|
|
8221
|
+
if (typeof listener !== 'function') {
|
|
8222
|
+
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8225
|
+
|
|
8226
|
+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
|
8227
|
+
enumerable: true,
|
|
8228
|
+
get: function() {
|
|
8229
|
+
return defaultMaxListeners;
|
|
8230
|
+
},
|
|
8231
|
+
set: function(arg) {
|
|
8232
|
+
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
8233
|
+
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
8234
|
+
}
|
|
8235
|
+
defaultMaxListeners = arg;
|
|
8236
|
+
}
|
|
8237
|
+
});
|
|
8238
|
+
|
|
8239
|
+
EventEmitter.init = function() {
|
|
8240
|
+
|
|
8241
|
+
if (this._events === undefined ||
|
|
8242
|
+
this._events === Object.getPrototypeOf(this)._events) {
|
|
8243
|
+
this._events = Object.create(null);
|
|
8244
|
+
this._eventsCount = 0;
|
|
8245
|
+
}
|
|
8246
|
+
|
|
8247
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
8248
|
+
};
|
|
8249
|
+
|
|
8250
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
8251
|
+
// that to be increased. Set to zero for unlimited.
|
|
8252
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
8253
|
+
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
8254
|
+
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
8255
|
+
}
|
|
8256
|
+
this._maxListeners = n;
|
|
8257
|
+
return this;
|
|
8258
|
+
};
|
|
8259
|
+
|
|
8260
|
+
function _getMaxListeners(that) {
|
|
8261
|
+
if (that._maxListeners === undefined)
|
|
8262
|
+
return EventEmitter.defaultMaxListeners;
|
|
8263
|
+
return that._maxListeners;
|
|
8264
|
+
}
|
|
8265
|
+
|
|
8266
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
8267
|
+
return _getMaxListeners(this);
|
|
8268
|
+
};
|
|
8269
|
+
|
|
8270
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
8271
|
+
var args = [];
|
|
8272
|
+
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
|
8273
|
+
var doError = (type === 'error');
|
|
8274
|
+
|
|
8275
|
+
var events = this._events;
|
|
8276
|
+
if (events !== undefined)
|
|
8277
|
+
doError = (doError && events.error === undefined);
|
|
8278
|
+
else if (!doError)
|
|
8279
|
+
return false;
|
|
8280
|
+
|
|
8281
|
+
// If there is no 'error' event listener then throw.
|
|
8282
|
+
if (doError) {
|
|
8283
|
+
var er;
|
|
8284
|
+
if (args.length > 0)
|
|
8285
|
+
er = args[0];
|
|
8286
|
+
if (er instanceof Error) {
|
|
8287
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
8288
|
+
// up in Node's output if this results in an unhandled exception.
|
|
8289
|
+
throw er; // Unhandled 'error' event
|
|
8290
|
+
}
|
|
8291
|
+
// At least give some kind of context to the user
|
|
8292
|
+
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
|
8293
|
+
err.context = er;
|
|
8294
|
+
throw err; // Unhandled 'error' event
|
|
8295
|
+
}
|
|
8296
|
+
|
|
8297
|
+
var handler = events[type];
|
|
8298
|
+
|
|
8299
|
+
if (handler === undefined)
|
|
8300
|
+
return false;
|
|
8301
|
+
|
|
8302
|
+
if (typeof handler === 'function') {
|
|
8303
|
+
ReflectApply(handler, this, args);
|
|
8304
|
+
} else {
|
|
8305
|
+
var len = handler.length;
|
|
8306
|
+
var listeners = arrayClone(handler, len);
|
|
8307
|
+
for (var i = 0; i < len; ++i)
|
|
8308
|
+
ReflectApply(listeners[i], this, args);
|
|
8309
|
+
}
|
|
8310
|
+
|
|
8311
|
+
return true;
|
|
8312
|
+
};
|
|
8313
|
+
|
|
8314
|
+
function _addListener(target, type, listener, prepend) {
|
|
8315
|
+
var m;
|
|
8316
|
+
var events;
|
|
8317
|
+
var existing;
|
|
8318
|
+
|
|
8319
|
+
checkListener(listener);
|
|
8320
|
+
|
|
8321
|
+
events = target._events;
|
|
8322
|
+
if (events === undefined) {
|
|
8323
|
+
events = target._events = Object.create(null);
|
|
8324
|
+
target._eventsCount = 0;
|
|
8325
|
+
} else {
|
|
8326
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
8327
|
+
// adding it to the listeners, first emit "newListener".
|
|
8328
|
+
if (events.newListener !== undefined) {
|
|
8329
|
+
target.emit('newListener', type,
|
|
8330
|
+
listener.listener ? listener.listener : listener);
|
|
8331
|
+
|
|
8332
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
8333
|
+
// this._events to be assigned to a new object
|
|
8334
|
+
events = target._events;
|
|
8335
|
+
}
|
|
8336
|
+
existing = events[type];
|
|
8337
|
+
}
|
|
8338
|
+
|
|
8339
|
+
if (existing === undefined) {
|
|
8340
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
8341
|
+
existing = events[type] = listener;
|
|
8342
|
+
++target._eventsCount;
|
|
8343
|
+
} else {
|
|
8344
|
+
if (typeof existing === 'function') {
|
|
8345
|
+
// Adding the second element, need to change to array.
|
|
8346
|
+
existing = events[type] =
|
|
8347
|
+
prepend ? [listener, existing] : [existing, listener];
|
|
8348
|
+
// If we've already got an array, just append.
|
|
8349
|
+
} else if (prepend) {
|
|
8350
|
+
existing.unshift(listener);
|
|
8351
|
+
} else {
|
|
8352
|
+
existing.push(listener);
|
|
8353
|
+
}
|
|
8354
|
+
|
|
8355
|
+
// Check for listener leak
|
|
8356
|
+
m = _getMaxListeners(target);
|
|
8357
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
8358
|
+
existing.warned = true;
|
|
8359
|
+
// No error code for this since it is a Warning
|
|
8360
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
8361
|
+
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
|
8362
|
+
existing.length + ' ' + String(type) + ' listeners ' +
|
|
8363
|
+
'added. Use emitter.setMaxListeners() to ' +
|
|
8364
|
+
'increase limit');
|
|
8365
|
+
w.name = 'MaxListenersExceededWarning';
|
|
8366
|
+
w.emitter = target;
|
|
8367
|
+
w.type = type;
|
|
8368
|
+
w.count = existing.length;
|
|
8369
|
+
ProcessEmitWarning(w);
|
|
8370
|
+
}
|
|
8371
|
+
}
|
|
8372
|
+
|
|
8373
|
+
return target;
|
|
8374
|
+
}
|
|
8375
|
+
|
|
8376
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
8377
|
+
return _addListener(this, type, listener, false);
|
|
8378
|
+
};
|
|
8379
|
+
|
|
8380
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
8381
|
+
|
|
8382
|
+
EventEmitter.prototype.prependListener =
|
|
8383
|
+
function prependListener(type, listener) {
|
|
8384
|
+
return _addListener(this, type, listener, true);
|
|
8385
|
+
};
|
|
8386
|
+
|
|
8387
|
+
function onceWrapper() {
|
|
8388
|
+
if (!this.fired) {
|
|
8389
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
8390
|
+
this.fired = true;
|
|
8391
|
+
if (arguments.length === 0)
|
|
8392
|
+
return this.listener.call(this.target);
|
|
8393
|
+
return this.listener.apply(this.target, arguments);
|
|
8394
|
+
}
|
|
8395
|
+
}
|
|
8396
|
+
|
|
8397
|
+
function _onceWrap(target, type, listener) {
|
|
8398
|
+
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
|
8399
|
+
var wrapped = onceWrapper.bind(state);
|
|
8400
|
+
wrapped.listener = listener;
|
|
8401
|
+
state.wrapFn = wrapped;
|
|
8402
|
+
return wrapped;
|
|
8403
|
+
}
|
|
8404
|
+
|
|
8405
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
8406
|
+
checkListener(listener);
|
|
8407
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
8408
|
+
return this;
|
|
8409
|
+
};
|
|
8410
|
+
|
|
8411
|
+
EventEmitter.prototype.prependOnceListener =
|
|
8412
|
+
function prependOnceListener(type, listener) {
|
|
8413
|
+
checkListener(listener);
|
|
8414
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
8415
|
+
return this;
|
|
8416
|
+
};
|
|
8417
|
+
|
|
8418
|
+
// Emits a 'removeListener' event if and only if the listener was removed.
|
|
8419
|
+
EventEmitter.prototype.removeListener =
|
|
8420
|
+
function removeListener(type, listener) {
|
|
8421
|
+
var list, events, position, i, originalListener;
|
|
8422
|
+
|
|
8423
|
+
checkListener(listener);
|
|
8424
|
+
|
|
8425
|
+
events = this._events;
|
|
8426
|
+
if (events === undefined)
|
|
8427
|
+
return this;
|
|
8428
|
+
|
|
8429
|
+
list = events[type];
|
|
8430
|
+
if (list === undefined)
|
|
8431
|
+
return this;
|
|
8432
|
+
|
|
8433
|
+
if (list === listener || list.listener === listener) {
|
|
8434
|
+
if (--this._eventsCount === 0)
|
|
8435
|
+
this._events = Object.create(null);
|
|
8436
|
+
else {
|
|
8437
|
+
delete events[type];
|
|
8438
|
+
if (events.removeListener)
|
|
8439
|
+
this.emit('removeListener', type, list.listener || listener);
|
|
8440
|
+
}
|
|
8441
|
+
} else if (typeof list !== 'function') {
|
|
8442
|
+
position = -1;
|
|
8443
|
+
|
|
8444
|
+
for (i = list.length - 1; i >= 0; i--) {
|
|
8445
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
8446
|
+
originalListener = list[i].listener;
|
|
8447
|
+
position = i;
|
|
8448
|
+
break;
|
|
8449
|
+
}
|
|
8450
|
+
}
|
|
8451
|
+
|
|
8452
|
+
if (position < 0)
|
|
8453
|
+
return this;
|
|
8454
|
+
|
|
8455
|
+
if (position === 0)
|
|
8456
|
+
list.shift();
|
|
8457
|
+
else {
|
|
8458
|
+
spliceOne(list, position);
|
|
8459
|
+
}
|
|
8460
|
+
|
|
8461
|
+
if (list.length === 1)
|
|
8462
|
+
events[type] = list[0];
|
|
8463
|
+
|
|
8464
|
+
if (events.removeListener !== undefined)
|
|
8465
|
+
this.emit('removeListener', type, originalListener || listener);
|
|
8466
|
+
}
|
|
8467
|
+
|
|
8468
|
+
return this;
|
|
8469
|
+
};
|
|
8470
|
+
|
|
8471
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
8472
|
+
|
|
8473
|
+
EventEmitter.prototype.removeAllListeners =
|
|
8474
|
+
function removeAllListeners(type) {
|
|
8475
|
+
var listeners, events, i;
|
|
8476
|
+
|
|
8477
|
+
events = this._events;
|
|
8478
|
+
if (events === undefined)
|
|
8479
|
+
return this;
|
|
8480
|
+
|
|
8481
|
+
// not listening for removeListener, no need to emit
|
|
8482
|
+
if (events.removeListener === undefined) {
|
|
8483
|
+
if (arguments.length === 0) {
|
|
8484
|
+
this._events = Object.create(null);
|
|
8485
|
+
this._eventsCount = 0;
|
|
8486
|
+
} else if (events[type] !== undefined) {
|
|
8487
|
+
if (--this._eventsCount === 0)
|
|
8488
|
+
this._events = Object.create(null);
|
|
8489
|
+
else
|
|
8490
|
+
delete events[type];
|
|
8491
|
+
}
|
|
8492
|
+
return this;
|
|
8493
|
+
}
|
|
8494
|
+
|
|
8495
|
+
// emit removeListener for all listeners on all events
|
|
8496
|
+
if (arguments.length === 0) {
|
|
8497
|
+
var keys = Object.keys(events);
|
|
8498
|
+
var key;
|
|
8499
|
+
for (i = 0; i < keys.length; ++i) {
|
|
8500
|
+
key = keys[i];
|
|
8501
|
+
if (key === 'removeListener') continue;
|
|
8502
|
+
this.removeAllListeners(key);
|
|
8503
|
+
}
|
|
8504
|
+
this.removeAllListeners('removeListener');
|
|
8505
|
+
this._events = Object.create(null);
|
|
8506
|
+
this._eventsCount = 0;
|
|
8507
|
+
return this;
|
|
8508
|
+
}
|
|
8509
|
+
|
|
8510
|
+
listeners = events[type];
|
|
8511
|
+
|
|
8512
|
+
if (typeof listeners === 'function') {
|
|
8513
|
+
this.removeListener(type, listeners);
|
|
8514
|
+
} else if (listeners !== undefined) {
|
|
8515
|
+
// LIFO order
|
|
8516
|
+
for (i = listeners.length - 1; i >= 0; i--) {
|
|
8517
|
+
this.removeListener(type, listeners[i]);
|
|
8518
|
+
}
|
|
8519
|
+
}
|
|
8520
|
+
|
|
8521
|
+
return this;
|
|
8522
|
+
};
|
|
8523
|
+
|
|
8524
|
+
function _listeners(target, type, unwrap) {
|
|
8525
|
+
var events = target._events;
|
|
8526
|
+
|
|
8527
|
+
if (events === undefined)
|
|
8528
|
+
return [];
|
|
8529
|
+
|
|
8530
|
+
var evlistener = events[type];
|
|
8531
|
+
if (evlistener === undefined)
|
|
8532
|
+
return [];
|
|
8533
|
+
|
|
8534
|
+
if (typeof evlistener === 'function')
|
|
8535
|
+
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
8536
|
+
|
|
8537
|
+
return unwrap ?
|
|
8538
|
+
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
|
8539
|
+
}
|
|
8540
|
+
|
|
8541
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
8542
|
+
return _listeners(this, type, true);
|
|
8543
|
+
};
|
|
8544
|
+
|
|
8545
|
+
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
8546
|
+
return _listeners(this, type, false);
|
|
8547
|
+
};
|
|
8548
|
+
|
|
8549
|
+
EventEmitter.listenerCount = function(emitter, type) {
|
|
8550
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
8551
|
+
return emitter.listenerCount(type);
|
|
8552
|
+
} else {
|
|
8553
|
+
return listenerCount.call(emitter, type);
|
|
8554
|
+
}
|
|
8555
|
+
};
|
|
8556
|
+
|
|
8557
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
8558
|
+
function listenerCount(type) {
|
|
8559
|
+
var events = this._events;
|
|
8560
|
+
|
|
8561
|
+
if (events !== undefined) {
|
|
8562
|
+
var evlistener = events[type];
|
|
8563
|
+
|
|
8564
|
+
if (typeof evlistener === 'function') {
|
|
8565
|
+
return 1;
|
|
8566
|
+
} else if (evlistener !== undefined) {
|
|
8567
|
+
return evlistener.length;
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
|
|
8571
|
+
return 0;
|
|
8572
|
+
}
|
|
8573
|
+
|
|
8574
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
8575
|
+
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
8576
|
+
};
|
|
8577
|
+
|
|
8578
|
+
function arrayClone(arr, n) {
|
|
8579
|
+
var copy = new Array(n);
|
|
8580
|
+
for (var i = 0; i < n; ++i)
|
|
8581
|
+
copy[i] = arr[i];
|
|
8582
|
+
return copy;
|
|
8583
|
+
}
|
|
8584
|
+
|
|
8585
|
+
function spliceOne(list, index) {
|
|
8586
|
+
for (; index + 1 < list.length; index++)
|
|
8587
|
+
list[index] = list[index + 1];
|
|
8588
|
+
list.pop();
|
|
8589
|
+
}
|
|
8590
|
+
|
|
8591
|
+
function unwrapListeners(arr) {
|
|
8592
|
+
var ret = new Array(arr.length);
|
|
8593
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
8594
|
+
ret[i] = arr[i].listener || arr[i];
|
|
8595
|
+
}
|
|
8596
|
+
return ret;
|
|
8597
|
+
}
|
|
8598
|
+
|
|
8599
|
+
function once$2(emitter, name) {
|
|
8600
|
+
return new Promise(function (resolve, reject) {
|
|
8601
|
+
function errorListener(err) {
|
|
8602
|
+
emitter.removeListener(name, resolver);
|
|
8603
|
+
reject(err);
|
|
8604
|
+
}
|
|
8605
|
+
|
|
8606
|
+
function resolver() {
|
|
8607
|
+
if (typeof emitter.removeListener === 'function') {
|
|
8608
|
+
emitter.removeListener('error', errorListener);
|
|
8609
|
+
}
|
|
8610
|
+
resolve([].slice.call(arguments));
|
|
8611
|
+
}
|
|
8612
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
8613
|
+
if (name !== 'error') {
|
|
8614
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
8615
|
+
}
|
|
8616
|
+
});
|
|
8617
|
+
}
|
|
8618
|
+
|
|
8619
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
8620
|
+
if (typeof emitter.on === 'function') {
|
|
8621
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
8622
|
+
}
|
|
8623
|
+
}
|
|
8624
|
+
|
|
8625
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
8626
|
+
if (typeof emitter.on === 'function') {
|
|
8627
|
+
if (flags.once) {
|
|
8628
|
+
emitter.once(name, listener);
|
|
8629
|
+
} else {
|
|
8630
|
+
emitter.on(name, listener);
|
|
8631
|
+
}
|
|
8632
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
8633
|
+
// EventTarget does not have `error` event semantics like Node
|
|
8634
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
8635
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
8636
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
8637
|
+
// have to do it manually.
|
|
8638
|
+
if (flags.once) {
|
|
8639
|
+
emitter.removeEventListener(name, wrapListener);
|
|
8640
|
+
}
|
|
8641
|
+
listener(arg);
|
|
8642
|
+
});
|
|
8643
|
+
} else {
|
|
8644
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
8645
|
+
}
|
|
8646
|
+
}
|
|
8647
|
+
|
|
8648
|
+
var eventsExports = events.exports;
|
|
8649
|
+
|
|
8650
|
+
var streamBrowser = eventsExports.EventEmitter;
|
|
5828
8651
|
|
|
5829
8652
|
var buffer_list;
|
|
5830
8653
|
var hasRequiredBuffer_list;
|
|
@@ -5841,7 +8664,7 @@ function requireBuffer_list () {
|
|
|
5841
8664
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5842
8665
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5843
8666
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5844
|
-
var _require =
|
|
8667
|
+
var _require = buffer$3,
|
|
5845
8668
|
Buffer = _require.Buffer;
|
|
5846
8669
|
var _require2 = require$$0$1,
|
|
5847
8670
|
inspect = _require2.inspect;
|
|
@@ -6373,7 +9196,7 @@ function require_stream_writable () {
|
|
|
6373
9196
|
var Stream = streamBrowser;
|
|
6374
9197
|
/*</replacement>*/
|
|
6375
9198
|
|
|
6376
|
-
var Buffer =
|
|
9199
|
+
var Buffer = buffer$3.Buffer;
|
|
6377
9200
|
var OurUint8Array = (typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
|
6378
9201
|
function _uint8ArrayToBuffer(chunk) {
|
|
6379
9202
|
return Buffer.from(chunk);
|
|
@@ -7062,285 +9885,277 @@ function require_stream_duplex () {
|
|
|
7062
9885
|
|
|
7063
9886
|
var string_decoder = {};
|
|
7064
9887
|
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
function requireString_decoder () {
|
|
7068
|
-
if (hasRequiredString_decoder) return string_decoder;
|
|
7069
|
-
hasRequiredString_decoder = 1;
|
|
7070
|
-
|
|
7071
|
-
/*<replacement>*/
|
|
7072
|
-
|
|
7073
|
-
var Buffer = safeBufferExports.Buffer;
|
|
7074
|
-
/*</replacement>*/
|
|
9888
|
+
/*<replacement>*/
|
|
7075
9889
|
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
switch (encoding && encoding.toLowerCase()) {
|
|
7079
|
-
case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
|
|
7080
|
-
return true;
|
|
7081
|
-
default:
|
|
7082
|
-
return false;
|
|
7083
|
-
}
|
|
7084
|
-
};
|
|
7085
|
-
|
|
7086
|
-
function _normalizeEncoding(enc) {
|
|
7087
|
-
if (!enc) return 'utf8';
|
|
7088
|
-
var retried;
|
|
7089
|
-
while (true) {
|
|
7090
|
-
switch (enc) {
|
|
7091
|
-
case 'utf8':
|
|
7092
|
-
case 'utf-8':
|
|
7093
|
-
return 'utf8';
|
|
7094
|
-
case 'ucs2':
|
|
7095
|
-
case 'ucs-2':
|
|
7096
|
-
case 'utf16le':
|
|
7097
|
-
case 'utf-16le':
|
|
7098
|
-
return 'utf16le';
|
|
7099
|
-
case 'latin1':
|
|
7100
|
-
case 'binary':
|
|
7101
|
-
return 'latin1';
|
|
7102
|
-
case 'base64':
|
|
7103
|
-
case 'ascii':
|
|
7104
|
-
case 'hex':
|
|
7105
|
-
return enc;
|
|
7106
|
-
default:
|
|
7107
|
-
if (retried) return; // undefined
|
|
7108
|
-
enc = ('' + enc).toLowerCase();
|
|
7109
|
-
retried = true;
|
|
7110
|
-
}
|
|
7111
|
-
}
|
|
7112
|
-
}
|
|
7113
|
-
// Do not cache `Buffer.isEncoding` when checking encoding names as some
|
|
7114
|
-
// modules monkey-patch it to support additional encodings
|
|
7115
|
-
function normalizeEncoding(enc) {
|
|
7116
|
-
var nenc = _normalizeEncoding(enc);
|
|
7117
|
-
if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
|
7118
|
-
return nenc || enc;
|
|
7119
|
-
}
|
|
7120
|
-
|
|
7121
|
-
// StringDecoder provides an interface for efficiently splitting a series of
|
|
7122
|
-
// buffers into a series of JS strings without breaking apart multi-byte
|
|
7123
|
-
// characters.
|
|
7124
|
-
string_decoder.StringDecoder = StringDecoder;
|
|
7125
|
-
function StringDecoder(encoding) {
|
|
7126
|
-
this.encoding = normalizeEncoding(encoding);
|
|
7127
|
-
var nb;
|
|
7128
|
-
switch (this.encoding) {
|
|
7129
|
-
case 'utf16le':
|
|
7130
|
-
this.text = utf16Text;
|
|
7131
|
-
this.end = utf16End;
|
|
7132
|
-
nb = 4;
|
|
7133
|
-
break;
|
|
7134
|
-
case 'utf8':
|
|
7135
|
-
this.fillLast = utf8FillLast;
|
|
7136
|
-
nb = 4;
|
|
7137
|
-
break;
|
|
7138
|
-
case 'base64':
|
|
7139
|
-
this.text = base64Text;
|
|
7140
|
-
this.end = base64End;
|
|
7141
|
-
nb = 3;
|
|
7142
|
-
break;
|
|
7143
|
-
default:
|
|
7144
|
-
this.write = simpleWrite;
|
|
7145
|
-
this.end = simpleEnd;
|
|
7146
|
-
return;
|
|
7147
|
-
}
|
|
7148
|
-
this.lastNeed = 0;
|
|
7149
|
-
this.lastTotal = 0;
|
|
7150
|
-
this.lastChar = Buffer.allocUnsafe(nb);
|
|
7151
|
-
}
|
|
7152
|
-
|
|
7153
|
-
StringDecoder.prototype.write = function (buf) {
|
|
7154
|
-
if (buf.length === 0) return '';
|
|
7155
|
-
var r;
|
|
7156
|
-
var i;
|
|
7157
|
-
if (this.lastNeed) {
|
|
7158
|
-
r = this.fillLast(buf);
|
|
7159
|
-
if (r === undefined) return '';
|
|
7160
|
-
i = this.lastNeed;
|
|
7161
|
-
this.lastNeed = 0;
|
|
7162
|
-
} else {
|
|
7163
|
-
i = 0;
|
|
7164
|
-
}
|
|
7165
|
-
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
|
7166
|
-
return r || '';
|
|
7167
|
-
};
|
|
7168
|
-
|
|
7169
|
-
StringDecoder.prototype.end = utf8End;
|
|
7170
|
-
|
|
7171
|
-
// Returns only complete characters in a Buffer
|
|
7172
|
-
StringDecoder.prototype.text = utf8Text;
|
|
7173
|
-
|
|
7174
|
-
// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
|
|
7175
|
-
StringDecoder.prototype.fillLast = function (buf) {
|
|
7176
|
-
if (this.lastNeed <= buf.length) {
|
|
7177
|
-
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
|
7178
|
-
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
7179
|
-
}
|
|
7180
|
-
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
|
7181
|
-
this.lastNeed -= buf.length;
|
|
7182
|
-
};
|
|
9890
|
+
var Buffer$C = safeBufferExports.Buffer;
|
|
9891
|
+
/*</replacement>*/
|
|
7183
9892
|
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
9893
|
+
var isEncoding = Buffer$C.isEncoding || function (encoding) {
|
|
9894
|
+
encoding = '' + encoding;
|
|
9895
|
+
switch (encoding && encoding.toLowerCase()) {
|
|
9896
|
+
case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
|
|
9897
|
+
return true;
|
|
9898
|
+
default:
|
|
9899
|
+
return false;
|
|
9900
|
+
}
|
|
9901
|
+
};
|
|
7190
9902
|
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
9903
|
+
function _normalizeEncoding(enc) {
|
|
9904
|
+
if (!enc) return 'utf8';
|
|
9905
|
+
var retried;
|
|
9906
|
+
while (true) {
|
|
9907
|
+
switch (enc) {
|
|
9908
|
+
case 'utf8':
|
|
9909
|
+
case 'utf-8':
|
|
9910
|
+
return 'utf8';
|
|
9911
|
+
case 'ucs2':
|
|
9912
|
+
case 'ucs-2':
|
|
9913
|
+
case 'utf16le':
|
|
9914
|
+
case 'utf-16le':
|
|
9915
|
+
return 'utf16le';
|
|
9916
|
+
case 'latin1':
|
|
9917
|
+
case 'binary':
|
|
9918
|
+
return 'latin1';
|
|
9919
|
+
case 'base64':
|
|
9920
|
+
case 'ascii':
|
|
9921
|
+
case 'hex':
|
|
9922
|
+
return enc;
|
|
9923
|
+
default:
|
|
9924
|
+
if (retried) return; // undefined
|
|
9925
|
+
enc = ('' + enc).toLowerCase();
|
|
9926
|
+
retried = true;
|
|
9927
|
+
}
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9930
|
+
// Do not cache `Buffer.isEncoding` when checking encoding names as some
|
|
9931
|
+
// modules monkey-patch it to support additional encodings
|
|
9932
|
+
function normalizeEncoding(enc) {
|
|
9933
|
+
var nenc = _normalizeEncoding(enc);
|
|
9934
|
+
if (typeof nenc !== 'string' && (Buffer$C.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
|
9935
|
+
return nenc || enc;
|
|
9936
|
+
}
|
|
9937
|
+
|
|
9938
|
+
// StringDecoder provides an interface for efficiently splitting a series of
|
|
9939
|
+
// buffers into a series of JS strings without breaking apart multi-byte
|
|
9940
|
+
// characters.
|
|
9941
|
+
string_decoder.StringDecoder = StringDecoder$1;
|
|
9942
|
+
function StringDecoder$1(encoding) {
|
|
9943
|
+
this.encoding = normalizeEncoding(encoding);
|
|
9944
|
+
var nb;
|
|
9945
|
+
switch (this.encoding) {
|
|
9946
|
+
case 'utf16le':
|
|
9947
|
+
this.text = utf16Text;
|
|
9948
|
+
this.end = utf16End;
|
|
9949
|
+
nb = 4;
|
|
9950
|
+
break;
|
|
9951
|
+
case 'utf8':
|
|
9952
|
+
this.fillLast = utf8FillLast;
|
|
9953
|
+
nb = 4;
|
|
9954
|
+
break;
|
|
9955
|
+
case 'base64':
|
|
9956
|
+
this.text = base64Text;
|
|
9957
|
+
this.end = base64End;
|
|
9958
|
+
nb = 3;
|
|
9959
|
+
break;
|
|
9960
|
+
default:
|
|
9961
|
+
this.write = simpleWrite;
|
|
9962
|
+
this.end = simpleEnd;
|
|
9963
|
+
return;
|
|
9964
|
+
}
|
|
9965
|
+
this.lastNeed = 0;
|
|
9966
|
+
this.lastTotal = 0;
|
|
9967
|
+
this.lastChar = Buffer$C.allocUnsafe(nb);
|
|
9968
|
+
}
|
|
7218
9969
|
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
9970
|
+
StringDecoder$1.prototype.write = function (buf) {
|
|
9971
|
+
if (buf.length === 0) return '';
|
|
9972
|
+
var r;
|
|
9973
|
+
var i;
|
|
9974
|
+
if (this.lastNeed) {
|
|
9975
|
+
r = this.fillLast(buf);
|
|
9976
|
+
if (r === undefined) return '';
|
|
9977
|
+
i = this.lastNeed;
|
|
9978
|
+
this.lastNeed = 0;
|
|
9979
|
+
} else {
|
|
9980
|
+
i = 0;
|
|
9981
|
+
}
|
|
9982
|
+
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
|
9983
|
+
return r || '';
|
|
9984
|
+
};
|
|
9985
|
+
|
|
9986
|
+
StringDecoder$1.prototype.end = utf8End;
|
|
9987
|
+
|
|
9988
|
+
// Returns only complete characters in a Buffer
|
|
9989
|
+
StringDecoder$1.prototype.text = utf8Text;
|
|
9990
|
+
|
|
9991
|
+
// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
|
|
9992
|
+
StringDecoder$1.prototype.fillLast = function (buf) {
|
|
9993
|
+
if (this.lastNeed <= buf.length) {
|
|
9994
|
+
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
|
9995
|
+
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
9996
|
+
}
|
|
9997
|
+
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
|
9998
|
+
this.lastNeed -= buf.length;
|
|
9999
|
+
};
|
|
10000
|
+
|
|
10001
|
+
// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
|
|
10002
|
+
// continuation byte. If an invalid byte is detected, -2 is returned.
|
|
10003
|
+
function utf8CheckByte(byte) {
|
|
10004
|
+
if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
|
|
10005
|
+
return byte >> 6 === 0x02 ? -1 : -2;
|
|
10006
|
+
}
|
|
10007
|
+
|
|
10008
|
+
// Checks at most 3 bytes at the end of a Buffer in order to detect an
|
|
10009
|
+
// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
|
|
10010
|
+
// needed to complete the UTF-8 character (if applicable) are returned.
|
|
10011
|
+
function utf8CheckIncomplete(self, buf, i) {
|
|
10012
|
+
var j = buf.length - 1;
|
|
10013
|
+
if (j < i) return 0;
|
|
10014
|
+
var nb = utf8CheckByte(buf[j]);
|
|
10015
|
+
if (nb >= 0) {
|
|
10016
|
+
if (nb > 0) self.lastNeed = nb - 1;
|
|
10017
|
+
return nb;
|
|
10018
|
+
}
|
|
10019
|
+
if (--j < i || nb === -2) return 0;
|
|
10020
|
+
nb = utf8CheckByte(buf[j]);
|
|
10021
|
+
if (nb >= 0) {
|
|
10022
|
+
if (nb > 0) self.lastNeed = nb - 2;
|
|
10023
|
+
return nb;
|
|
10024
|
+
}
|
|
10025
|
+
if (--j < i || nb === -2) return 0;
|
|
10026
|
+
nb = utf8CheckByte(buf[j]);
|
|
10027
|
+
if (nb >= 0) {
|
|
10028
|
+
if (nb > 0) {
|
|
10029
|
+
if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
|
10030
|
+
}
|
|
10031
|
+
return nb;
|
|
10032
|
+
}
|
|
10033
|
+
return 0;
|
|
10034
|
+
}
|
|
10035
|
+
|
|
10036
|
+
// Validates as many continuation bytes for a multi-byte UTF-8 character as
|
|
10037
|
+
// needed or are available. If we see a non-continuation byte where we expect
|
|
10038
|
+
// one, we "replace" the validated continuation bytes we've seen so far with
|
|
10039
|
+
// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
|
|
10040
|
+
// behavior. The continuation byte check is included three times in the case
|
|
10041
|
+
// where all of the continuation bytes for a character exist in the same buffer.
|
|
10042
|
+
// It is also done this way as a slight performance increase instead of using a
|
|
10043
|
+
// loop.
|
|
10044
|
+
function utf8CheckExtraBytes(self, buf, p) {
|
|
10045
|
+
if ((buf[0] & 0xC0) !== 0x80) {
|
|
10046
|
+
self.lastNeed = 0;
|
|
10047
|
+
return '\ufffd';
|
|
10048
|
+
}
|
|
10049
|
+
if (self.lastNeed > 1 && buf.length > 1) {
|
|
10050
|
+
if ((buf[1] & 0xC0) !== 0x80) {
|
|
10051
|
+
self.lastNeed = 1;
|
|
10052
|
+
return '\ufffd';
|
|
10053
|
+
}
|
|
10054
|
+
if (self.lastNeed > 2 && buf.length > 2) {
|
|
10055
|
+
if ((buf[2] & 0xC0) !== 0x80) {
|
|
10056
|
+
self.lastNeed = 2;
|
|
10057
|
+
return '\ufffd';
|
|
10058
|
+
}
|
|
10059
|
+
}
|
|
10060
|
+
}
|
|
10061
|
+
}
|
|
7245
10062
|
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
10063
|
+
// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
|
|
10064
|
+
function utf8FillLast(buf) {
|
|
10065
|
+
var p = this.lastTotal - this.lastNeed;
|
|
10066
|
+
var r = utf8CheckExtraBytes(this, buf);
|
|
10067
|
+
if (r !== undefined) return r;
|
|
10068
|
+
if (this.lastNeed <= buf.length) {
|
|
10069
|
+
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
|
10070
|
+
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
10071
|
+
}
|
|
10072
|
+
buf.copy(this.lastChar, p, 0, buf.length);
|
|
10073
|
+
this.lastNeed -= buf.length;
|
|
10074
|
+
}
|
|
7258
10075
|
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
10076
|
+
// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
|
|
10077
|
+
// partial character, the character's bytes are buffered until the required
|
|
10078
|
+
// number of bytes are available.
|
|
10079
|
+
function utf8Text(buf, i) {
|
|
10080
|
+
var total = utf8CheckIncomplete(this, buf, i);
|
|
10081
|
+
if (!this.lastNeed) return buf.toString('utf8', i);
|
|
10082
|
+
this.lastTotal = total;
|
|
10083
|
+
var end = buf.length - (total - this.lastNeed);
|
|
10084
|
+
buf.copy(this.lastChar, 0, end);
|
|
10085
|
+
return buf.toString('utf8', i, end);
|
|
10086
|
+
}
|
|
7270
10087
|
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
10088
|
+
// For UTF-8, a replacement character is added when ending on a partial
|
|
10089
|
+
// character.
|
|
10090
|
+
function utf8End(buf) {
|
|
10091
|
+
var r = buf && buf.length ? this.write(buf) : '';
|
|
10092
|
+
if (this.lastNeed) return r + '\ufffd';
|
|
10093
|
+
return r;
|
|
10094
|
+
}
|
|
7278
10095
|
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
10096
|
+
// UTF-16LE typically needs two bytes per character, but even if we have an even
|
|
10097
|
+
// number of bytes available, we need to check if we end on a leading/high
|
|
10098
|
+
// surrogate. In that case, we need to wait for the next two bytes in order to
|
|
10099
|
+
// decode the last character properly.
|
|
10100
|
+
function utf16Text(buf, i) {
|
|
10101
|
+
if ((buf.length - i) % 2 === 0) {
|
|
10102
|
+
var r = buf.toString('utf16le', i);
|
|
10103
|
+
if (r) {
|
|
10104
|
+
var c = r.charCodeAt(r.length - 1);
|
|
10105
|
+
if (c >= 0xD800 && c <= 0xDBFF) {
|
|
10106
|
+
this.lastNeed = 2;
|
|
10107
|
+
this.lastTotal = 4;
|
|
10108
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
10109
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
10110
|
+
return r.slice(0, -1);
|
|
10111
|
+
}
|
|
10112
|
+
}
|
|
10113
|
+
return r;
|
|
10114
|
+
}
|
|
10115
|
+
this.lastNeed = 1;
|
|
10116
|
+
this.lastTotal = 2;
|
|
10117
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
10118
|
+
return buf.toString('utf16le', i, buf.length - 1);
|
|
10119
|
+
}
|
|
7303
10120
|
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
10121
|
+
// For UTF-16LE we do not explicitly append special replacement characters if we
|
|
10122
|
+
// end on a partial character, we simply let v8 handle that.
|
|
10123
|
+
function utf16End(buf) {
|
|
10124
|
+
var r = buf && buf.length ? this.write(buf) : '';
|
|
10125
|
+
if (this.lastNeed) {
|
|
10126
|
+
var end = this.lastTotal - this.lastNeed;
|
|
10127
|
+
return r + this.lastChar.toString('utf16le', 0, end);
|
|
10128
|
+
}
|
|
10129
|
+
return r;
|
|
10130
|
+
}
|
|
7314
10131
|
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
10132
|
+
function base64Text(buf, i) {
|
|
10133
|
+
var n = (buf.length - i) % 3;
|
|
10134
|
+
if (n === 0) return buf.toString('base64', i);
|
|
10135
|
+
this.lastNeed = 3 - n;
|
|
10136
|
+
this.lastTotal = 3;
|
|
10137
|
+
if (n === 1) {
|
|
10138
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
10139
|
+
} else {
|
|
10140
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
10141
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
10142
|
+
}
|
|
10143
|
+
return buf.toString('base64', i, buf.length - n);
|
|
10144
|
+
}
|
|
7328
10145
|
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
10146
|
+
function base64End(buf) {
|
|
10147
|
+
var r = buf && buf.length ? this.write(buf) : '';
|
|
10148
|
+
if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
|
10149
|
+
return r;
|
|
10150
|
+
}
|
|
7334
10151
|
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
10152
|
+
// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
|
|
10153
|
+
function simpleWrite(buf) {
|
|
10154
|
+
return buf.toString(this.encoding);
|
|
10155
|
+
}
|
|
7339
10156
|
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
}
|
|
7343
|
-
return string_decoder;
|
|
10157
|
+
function simpleEnd(buf) {
|
|
10158
|
+
return buf && buf.length ? this.write(buf) : '';
|
|
7344
10159
|
}
|
|
7345
10160
|
|
|
7346
10161
|
var ERR_STREAM_PREMATURE_CLOSE = errorsBrowser.codes.ERR_STREAM_PREMATURE_CLOSE;
|
|
@@ -7641,7 +10456,7 @@ function require_stream_readable () {
|
|
|
7641
10456
|
Readable.ReadableState = ReadableState;
|
|
7642
10457
|
|
|
7643
10458
|
/*<replacement>*/
|
|
7644
|
-
|
|
10459
|
+
eventsExports.EventEmitter;
|
|
7645
10460
|
var EElistenerCount = function EElistenerCount(emitter, type) {
|
|
7646
10461
|
return emitter.listeners(type).length;
|
|
7647
10462
|
};
|
|
@@ -7651,7 +10466,7 @@ function require_stream_readable () {
|
|
|
7651
10466
|
var Stream = streamBrowser;
|
|
7652
10467
|
/*</replacement>*/
|
|
7653
10468
|
|
|
7654
|
-
var Buffer =
|
|
10469
|
+
var Buffer = buffer$3.Buffer;
|
|
7655
10470
|
var OurUint8Array = (typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
|
7656
10471
|
function _uint8ArrayToBuffer(chunk) {
|
|
7657
10472
|
return Buffer.from(chunk);
|
|
@@ -7766,7 +10581,7 @@ function require_stream_readable () {
|
|
|
7766
10581
|
this.decoder = null;
|
|
7767
10582
|
this.encoding = null;
|
|
7768
10583
|
if (options.encoding) {
|
|
7769
|
-
if (!StringDecoder) StringDecoder =
|
|
10584
|
+
if (!StringDecoder) StringDecoder = string_decoder.StringDecoder;
|
|
7770
10585
|
this.decoder = new StringDecoder(options.encoding);
|
|
7771
10586
|
this.encoding = options.encoding;
|
|
7772
10587
|
}
|
|
@@ -7909,7 +10724,7 @@ function require_stream_readable () {
|
|
|
7909
10724
|
|
|
7910
10725
|
// backwards compatibility.
|
|
7911
10726
|
Readable.prototype.setEncoding = function (enc) {
|
|
7912
|
-
if (!StringDecoder) StringDecoder =
|
|
10727
|
+
if (!StringDecoder) StringDecoder = string_decoder.StringDecoder;
|
|
7913
10728
|
var decoder = new StringDecoder(enc);
|
|
7914
10729
|
this._readableState.decoder = decoder;
|
|
7915
10730
|
// If setEncoding(null), decoder.encoding equals utf8
|
|
@@ -9113,7 +11928,7 @@ function fnI (a, b, c, d, m, k, s) {
|
|
|
9113
11928
|
|
|
9114
11929
|
var md5_js = MD5$3;
|
|
9115
11930
|
|
|
9116
|
-
var Buffer$z =
|
|
11931
|
+
var Buffer$z = buffer$3.Buffer;
|
|
9117
11932
|
var inherits$t = inherits_browserExports;
|
|
9118
11933
|
var HashBase = hashBase;
|
|
9119
11934
|
|
|
@@ -10105,7 +12920,7 @@ var sha_jsExports = sha_js.exports;
|
|
|
10105
12920
|
|
|
10106
12921
|
var streamBrowserify = Stream;
|
|
10107
12922
|
|
|
10108
|
-
var EE =
|
|
12923
|
+
var EE = eventsExports.EventEmitter;
|
|
10109
12924
|
var inherits$m = inherits_browserExports;
|
|
10110
12925
|
|
|
10111
12926
|
inherits$m(Stream, EE);
|
|
@@ -10214,7 +13029,7 @@ Stream.prototype.pipe = function(dest, options) {
|
|
|
10214
13029
|
|
|
10215
13030
|
var Buffer$r = safeBufferExports.Buffer;
|
|
10216
13031
|
var Transform$4 = streamBrowserify.Transform;
|
|
10217
|
-
var StringDecoder =
|
|
13032
|
+
var StringDecoder = string_decoder.StringDecoder;
|
|
10218
13033
|
var inherits$l = inherits_browserExports;
|
|
10219
13034
|
|
|
10220
13035
|
function CipherBase$1 (hashMode) {
|
|
@@ -11644,7 +14459,7 @@ var cbc = {};
|
|
|
11644
14459
|
|
|
11645
14460
|
var bufferXor = function xor (a, b) {
|
|
11646
14461
|
var length = Math.min(a.length, b.length);
|
|
11647
|
-
var buffer = new Buffer
|
|
14462
|
+
var buffer = new buffer$3.Buffer(length);
|
|
11648
14463
|
|
|
11649
14464
|
for (var i = 0; i < length; ++i) {
|
|
11650
14465
|
buffer[i] = a[i] ^ b[i];
|
|
@@ -11791,7 +14606,7 @@ function getBlock$1 (self) {
|
|
|
11791
14606
|
|
|
11792
14607
|
ofb.encrypt = function (self, chunk) {
|
|
11793
14608
|
while (self._cache.length < chunk.length) {
|
|
11794
|
-
self._cache =
|
|
14609
|
+
self._cache = buffer$3.Buffer.concat([self._cache, getBlock$1(self)]);
|
|
11795
14610
|
}
|
|
11796
14611
|
|
|
11797
14612
|
var pad = self._cache.slice(0, chunk.length);
|
|
@@ -13306,8 +16121,8 @@ function requireDh () {
|
|
|
13306
16121
|
|
|
13307
16122
|
function setPublicKey(pub, enc) {
|
|
13308
16123
|
enc = enc || 'utf8';
|
|
13309
|
-
if (!
|
|
13310
|
-
pub = new Buffer
|
|
16124
|
+
if (!buffer$3.Buffer.isBuffer(pub)) {
|
|
16125
|
+
pub = new buffer$3.Buffer(pub, enc);
|
|
13311
16126
|
}
|
|
13312
16127
|
this._pub = new BN(pub);
|
|
13313
16128
|
return this;
|
|
@@ -13315,8 +16130,8 @@ function requireDh () {
|
|
|
13315
16130
|
|
|
13316
16131
|
function setPrivateKey(priv, enc) {
|
|
13317
16132
|
enc = enc || 'utf8';
|
|
13318
|
-
if (!
|
|
13319
|
-
priv = new Buffer
|
|
16133
|
+
if (!buffer$3.Buffer.isBuffer(priv)) {
|
|
16134
|
+
priv = new buffer$3.Buffer(priv, enc);
|
|
13320
16135
|
}
|
|
13321
16136
|
this._priv = new BN(priv);
|
|
13322
16137
|
return this;
|
|
@@ -13412,12 +16227,12 @@ function requireDh () {
|
|
|
13412
16227
|
other = new BN(other);
|
|
13413
16228
|
other = other.toRed(this._prime);
|
|
13414
16229
|
var secret = other.redPow(this._priv).fromRed();
|
|
13415
|
-
var out = new Buffer
|
|
16230
|
+
var out = new buffer$3.Buffer(secret.toArray());
|
|
13416
16231
|
var prime = this.getPrime();
|
|
13417
16232
|
if (out.length < prime.length) {
|
|
13418
|
-
var front = new Buffer
|
|
16233
|
+
var front = new buffer$3.Buffer(prime.length - out.length);
|
|
13419
16234
|
front.fill(0);
|
|
13420
|
-
out =
|
|
16235
|
+
out = buffer$3.Buffer.concat([front, out]);
|
|
13421
16236
|
}
|
|
13422
16237
|
return out;
|
|
13423
16238
|
};
|
|
@@ -13440,8 +16255,8 @@ function requireDh () {
|
|
|
13440
16255
|
|
|
13441
16256
|
DH.prototype.setGenerator = function (gen, enc) {
|
|
13442
16257
|
enc = enc || 'utf8';
|
|
13443
|
-
if (!
|
|
13444
|
-
gen = new Buffer
|
|
16258
|
+
if (!buffer$3.Buffer.isBuffer(gen)) {
|
|
16259
|
+
gen = new buffer$3.Buffer(gen, enc);
|
|
13445
16260
|
}
|
|
13446
16261
|
this.__gen = gen;
|
|
13447
16262
|
this._gen = new BN(gen);
|
|
@@ -13449,7 +16264,7 @@ function requireDh () {
|
|
|
13449
16264
|
};
|
|
13450
16265
|
|
|
13451
16266
|
function formatReturnValue(bn, enc) {
|
|
13452
|
-
var buf = new Buffer
|
|
16267
|
+
var buf = new buffer$3.Buffer(bn.toArray());
|
|
13453
16268
|
if (!enc) {
|
|
13454
16269
|
return buf;
|
|
13455
16270
|
} else {
|
|
@@ -13470,8 +16285,8 @@ function requireBrowser$2 () {
|
|
|
13470
16285
|
var DH = requireDh();
|
|
13471
16286
|
|
|
13472
16287
|
function getDiffieHellman (mod) {
|
|
13473
|
-
var prime = new Buffer
|
|
13474
|
-
var gen = new Buffer
|
|
16288
|
+
var prime = new buffer$3.Buffer(primes[mod].prime, 'hex');
|
|
16289
|
+
var gen = new buffer$3.Buffer(primes[mod].gen, 'hex');
|
|
13475
16290
|
|
|
13476
16291
|
return new DH(prime, gen)
|
|
13477
16292
|
}
|
|
@@ -13481,24 +16296,24 @@ function requireBrowser$2 () {
|
|
|
13481
16296
|
};
|
|
13482
16297
|
|
|
13483
16298
|
function createDiffieHellman (prime, enc, generator, genc) {
|
|
13484
|
-
if (
|
|
16299
|
+
if (buffer$3.Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
|
|
13485
16300
|
return createDiffieHellman(prime, 'binary', enc, generator)
|
|
13486
16301
|
}
|
|
13487
16302
|
|
|
13488
16303
|
enc = enc || 'binary';
|
|
13489
16304
|
genc = genc || 'binary';
|
|
13490
|
-
generator = generator || new Buffer
|
|
16305
|
+
generator = generator || new buffer$3.Buffer([2]);
|
|
13491
16306
|
|
|
13492
|
-
if (!
|
|
13493
|
-
generator = new Buffer
|
|
16307
|
+
if (!buffer$3.Buffer.isBuffer(generator)) {
|
|
16308
|
+
generator = new buffer$3.Buffer(generator, genc);
|
|
13494
16309
|
}
|
|
13495
16310
|
|
|
13496
16311
|
if (typeof prime === 'number') {
|
|
13497
16312
|
return new DH(generatePrime(prime, generator), generator, true)
|
|
13498
16313
|
}
|
|
13499
16314
|
|
|
13500
|
-
if (!
|
|
13501
|
-
prime = new Buffer
|
|
16315
|
+
if (!buffer$3.Buffer.isBuffer(prime)) {
|
|
16316
|
+
prime = new buffer$3.Buffer(prime, enc);
|
|
13502
16317
|
}
|
|
13503
16318
|
|
|
13504
16319
|
return new DH(prime, generator, true)
|
|
@@ -16898,7 +19713,7 @@ function crt$2 (msg, priv) {
|
|
|
16898
19713
|
var m1 = c1.redPow(priv.exponent1).fromRed();
|
|
16899
19714
|
var m2 = c2.redPow(priv.exponent2).fromRed();
|
|
16900
19715
|
var h = m1.isub(m2).imul(qinv).umod(p).imul(q);
|
|
16901
|
-
return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer
|
|
19716
|
+
return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(buffer$3.Buffer, 'be', len)
|
|
16902
19717
|
}
|
|
16903
19718
|
crt$2.getr = getr;
|
|
16904
19719
|
|
|
@@ -28248,8 +31063,8 @@ function requireBrowser () {
|
|
|
28248
31063
|
|
|
28249
31064
|
ECDH.prototype.computeSecret = function (other, inenc, enc) {
|
|
28250
31065
|
inenc = inenc || 'utf8';
|
|
28251
|
-
if (!
|
|
28252
|
-
other = new Buffer
|
|
31066
|
+
if (!buffer$3.Buffer.isBuffer(other)) {
|
|
31067
|
+
other = new buffer$3.Buffer(other, inenc);
|
|
28253
31068
|
}
|
|
28254
31069
|
var otherPub = this.curve.keyFromPublic(other).getPublic();
|
|
28255
31070
|
var out = otherPub.mul(this.keys.getPrivate()).getX();
|
|
@@ -28274,8 +31089,8 @@ function requireBrowser () {
|
|
|
28274
31089
|
|
|
28275
31090
|
ECDH.prototype.setPublicKey = function (pub, enc) {
|
|
28276
31091
|
enc = enc || 'utf8';
|
|
28277
|
-
if (!
|
|
28278
|
-
pub = new Buffer
|
|
31092
|
+
if (!buffer$3.Buffer.isBuffer(pub)) {
|
|
31093
|
+
pub = new buffer$3.Buffer(pub, enc);
|
|
28279
31094
|
}
|
|
28280
31095
|
this.keys._importPublic(pub);
|
|
28281
31096
|
return this
|
|
@@ -28283,8 +31098,8 @@ function requireBrowser () {
|
|
|
28283
31098
|
|
|
28284
31099
|
ECDH.prototype.setPrivateKey = function (priv, enc) {
|
|
28285
31100
|
enc = enc || 'utf8';
|
|
28286
|
-
if (!
|
|
28287
|
-
priv = new Buffer
|
|
31101
|
+
if (!buffer$3.Buffer.isBuffer(priv)) {
|
|
31102
|
+
priv = new buffer$3.Buffer(priv, enc);
|
|
28288
31103
|
}
|
|
28289
31104
|
|
|
28290
31105
|
var _priv = new BN(priv);
|
|
@@ -28298,11 +31113,11 @@ function requireBrowser () {
|
|
|
28298
31113
|
if (!Array.isArray(bn)) {
|
|
28299
31114
|
bn = bn.toArray();
|
|
28300
31115
|
}
|
|
28301
|
-
var buf = new Buffer
|
|
31116
|
+
var buf = new buffer$3.Buffer(bn);
|
|
28302
31117
|
if (len && buf.length < len) {
|
|
28303
|
-
var zeros = new Buffer
|
|
31118
|
+
var zeros = new buffer$3.Buffer(len - buf.length);
|
|
28304
31119
|
zeros.fill(0);
|
|
28305
|
-
buf =
|
|
31120
|
+
buf = buffer$3.Buffer.concat([zeros, buf]);
|
|
28306
31121
|
}
|
|
28307
31122
|
if (!enc) {
|
|
28308
31123
|
return buf
|
|
@@ -28800,15 +31615,15 @@ const utils_1 = utils$o;
|
|
|
28800
31615
|
const crypto_1 = crypto$2;
|
|
28801
31616
|
const constants_1 = constants;
|
|
28802
31617
|
function calculateNodeHash(prefix, leftHash, rightHash) {
|
|
28803
|
-
return (0, crypto_1.sha256)(
|
|
31618
|
+
return (0, crypto_1.sha256)(buffer$3.Buffer.concat([buffer$3.Buffer.from([prefix]), leftHash, rightHash]));
|
|
28804
31619
|
}
|
|
28805
31620
|
function calculateLeafHash(gtv) {
|
|
28806
|
-
const ret = (0, crypto_1.sha256)(
|
|
31621
|
+
const ret = (0, crypto_1.sha256)(buffer$3.Buffer.concat([buffer$3.Buffer.from([constants_1.HASH_PREFIX_LEAF]), buffer$3.Buffer.from((0, utils_1.encode_value)(gtv))]));
|
|
28807
31622
|
return ret;
|
|
28808
31623
|
}
|
|
28809
31624
|
function calculateMerkleHash(element) {
|
|
28810
31625
|
if (element.type === 'empty')
|
|
28811
|
-
return
|
|
31626
|
+
return buffer$3.Buffer.alloc(32);
|
|
28812
31627
|
if (element.type === 'leaf')
|
|
28813
31628
|
return calculateLeafHash(element.content);
|
|
28814
31629
|
const prefix = 'kind' in element
|
|
@@ -32899,7 +35714,7 @@ var z = /*#__PURE__*/Object.freeze({
|
|
|
32899
35714
|
ZodError: ZodError
|
|
32900
35715
|
});
|
|
32901
35716
|
|
|
32902
|
-
const bufferSchema = z.custom(val =>
|
|
35717
|
+
const bufferSchema = z.custom(val => buffer$3.Buffer.isBuffer(val), {
|
|
32903
35718
|
message: "Expected Buffer",
|
|
32904
35719
|
});
|
|
32905
35720
|
const rawGtvSchema = z.lazy(() => z.union([
|
|
@@ -32921,7 +35736,7 @@ function isRawGtx(value) {
|
|
|
32921
35736
|
}
|
|
32922
35737
|
|
|
32923
35738
|
function pgBytes(buffer) {
|
|
32924
|
-
if (!
|
|
35739
|
+
if (!buffer$3.Buffer.isBuffer(buffer)) {
|
|
32925
35740
|
throw new PgBytesInputException(buffer);
|
|
32926
35741
|
}
|
|
32927
35742
|
return `\\x${buffer.toString("hex")}`;
|
|
@@ -32932,7 +35747,7 @@ function pgBytes(buffer) {
|
|
|
32932
35747
|
* @returns {Buffer}
|
|
32933
35748
|
*/
|
|
32934
35749
|
function toBuffer(key) {
|
|
32935
|
-
return
|
|
35750
|
+
return buffer$3.Buffer.from(key, "hex");
|
|
32936
35751
|
}
|
|
32937
35752
|
/**
|
|
32938
35753
|
* Converts Buffer to hex string
|
|
@@ -32957,7 +35772,7 @@ class PgBytesInputException extends Error {
|
|
|
32957
35772
|
}
|
|
32958
35773
|
}
|
|
32959
35774
|
function ensureBuffer(value) {
|
|
32960
|
-
if (value instanceof Buffer
|
|
35775
|
+
if (value instanceof buffer$3.Buffer) {
|
|
32961
35776
|
return value;
|
|
32962
35777
|
}
|
|
32963
35778
|
else {
|
|
@@ -32977,7 +35792,7 @@ function checkGtvType(value) {
|
|
|
32977
35792
|
if (value == null) {
|
|
32978
35793
|
return true;
|
|
32979
35794
|
}
|
|
32980
|
-
if (
|
|
35795
|
+
if (buffer$3.Buffer.isBuffer(value)) {
|
|
32981
35796
|
return true;
|
|
32982
35797
|
}
|
|
32983
35798
|
if (typeof value === "string" || typeof value === "bigint") {
|
|
@@ -33043,7 +35858,7 @@ function removeDuplicateSigners(signers) {
|
|
|
33043
35858
|
});
|
|
33044
35859
|
const result = [];
|
|
33045
35860
|
signersAsString.forEach(item => {
|
|
33046
|
-
result.push(
|
|
35861
|
+
result.push(buffer$3.Buffer.from(item, "hex"));
|
|
33047
35862
|
});
|
|
33048
35863
|
return result;
|
|
33049
35864
|
}
|
|
@@ -33132,7 +35947,7 @@ function createTypedArg(value) {
|
|
|
33132
35947
|
if (value == null) {
|
|
33133
35948
|
return { type: "null", value: null };
|
|
33134
35949
|
}
|
|
33135
|
-
if (
|
|
35950
|
+
if (buffer$3.Buffer.isBuffer(value)) {
|
|
33136
35951
|
return { type: "byteArray", value: value };
|
|
33137
35952
|
}
|
|
33138
35953
|
if (typeof value === "boolean") {
|
|
@@ -33200,7 +36015,19 @@ function sortDictPairByKey(dict) {
|
|
|
33200
36015
|
return sortedDict;
|
|
33201
36016
|
}
|
|
33202
36017
|
|
|
36018
|
+
const MERKLE_HASH_VERSIONS = {
|
|
36019
|
+
ONE: 1,
|
|
36020
|
+
TWO: 2,
|
|
36021
|
+
UNSET: NaN,
|
|
36022
|
+
};
|
|
36023
|
+
|
|
33203
36024
|
const gtvHash2 = (obj, merkleHashVersion) => {
|
|
36025
|
+
if (!Object.values(MERKLE_HASH_VERSIONS).includes(merkleHashVersion)) {
|
|
36026
|
+
throw new Error("Merkle hash version is not valid");
|
|
36027
|
+
}
|
|
36028
|
+
if (isNaN(merkleHashVersion)) {
|
|
36029
|
+
throw new Error("Merkle hash version is not set");
|
|
36030
|
+
}
|
|
33204
36031
|
return gtvHash_1(obj, merkleHashVersion);
|
|
33205
36032
|
};
|
|
33206
36033
|
const encode$1 = encodeValue;
|
|
@@ -33974,7 +36801,7 @@ class MissingPrivKeyArgumentException extends Error {
|
|
|
33974
36801
|
|
|
33975
36802
|
function createPublicKey(privKey) {
|
|
33976
36803
|
validatePrivKeyFormat(privKey);
|
|
33977
|
-
return
|
|
36804
|
+
return buffer$3.Buffer.from(elliptic.publicKeyCreate(privKey, true).buffer);
|
|
33978
36805
|
}
|
|
33979
36806
|
function randomBytes(size) {
|
|
33980
36807
|
return cryptoBrowserifyExports.randomBytes(size);
|
|
@@ -33984,7 +36811,7 @@ function sha256(buffer) {
|
|
|
33984
36811
|
}
|
|
33985
36812
|
const hash256 = sha256;
|
|
33986
36813
|
function hashConcat(items) {
|
|
33987
|
-
return hash256(
|
|
36814
|
+
return hash256(buffer$3.Buffer.concat(items));
|
|
33988
36815
|
}
|
|
33989
36816
|
/**
|
|
33990
36817
|
* @param content the content that the signature signs. It will be digested before validating.
|
|
@@ -34025,7 +36852,7 @@ function sign$1(content, privKey) {
|
|
|
34025
36852
|
* @return the signature
|
|
34026
36853
|
*/
|
|
34027
36854
|
function signDigest(digestBuffer, privKey) {
|
|
34028
|
-
return
|
|
36855
|
+
return buffer$3.Buffer.from(elliptic.ecdsaSign(digestBuffer, privKey).signature);
|
|
34029
36856
|
}
|
|
34030
36857
|
/**
|
|
34031
36858
|
* Creates a key pair (which usually represents one user)
|
|
@@ -34042,7 +36869,7 @@ function makeKeyPair(privKey) {
|
|
|
34042
36869
|
do {
|
|
34043
36870
|
privKey = randomBytes(32);
|
|
34044
36871
|
} while (!elliptic.privateKeyVerify(privKey));
|
|
34045
|
-
pubKey =
|
|
36872
|
+
pubKey = buffer$3.Buffer.from(elliptic.publicKeyCreate(privKey).buffer);
|
|
34046
36873
|
}
|
|
34047
36874
|
return { pubKey, privKey };
|
|
34048
36875
|
}
|
|
@@ -34060,14 +36887,14 @@ function makeTuid() {
|
|
|
34060
36887
|
*/
|
|
34061
36888
|
function verifyKeyPair(privKey) {
|
|
34062
36889
|
validatePrivKeyFormat(privKey);
|
|
34063
|
-
const pubKey =
|
|
36890
|
+
const pubKey = buffer$3.Buffer.from(elliptic.publicKeyCreate(privKey).buffer);
|
|
34064
36891
|
return { pubKey, privKey };
|
|
34065
36892
|
}
|
|
34066
36893
|
function validatePrivKeyFormat(privKey) {
|
|
34067
36894
|
if (!privKey) {
|
|
34068
36895
|
throw new MissingPrivKeyArgumentException();
|
|
34069
36896
|
}
|
|
34070
|
-
if (!
|
|
36897
|
+
if (!buffer$3.Buffer.isBuffer(privKey) || privKey.length !== 32) {
|
|
34071
36898
|
throw new PrivKeyFormatException(privKey);
|
|
34072
36899
|
}
|
|
34073
36900
|
}
|
|
@@ -34165,7 +36992,7 @@ function gtxToRawGtx(gtx) {
|
|
|
34165
36992
|
}
|
|
34166
36993
|
function sign(gtx, privOrSigProv, merkleHashVersion, pubKey) {
|
|
34167
36994
|
return __awaiter$9(this, void 0, void 0, function* () {
|
|
34168
|
-
if (privOrSigProv instanceof Buffer
|
|
36995
|
+
if (privOrSigProv instanceof buffer$3.Buffer) {
|
|
34169
36996
|
const digestToSign = getDigestToSign(gtx, merkleHashVersion);
|
|
34170
36997
|
const signature = signDigest(digestToSign, privOrSigProv);
|
|
34171
36998
|
return addSignature(pubKey || makeKeyPair(privOrSigProv).pubKey, signature, gtx);
|
|
@@ -34173,7 +37000,7 @@ function sign(gtx, privOrSigProv, merkleHashVersion, pubKey) {
|
|
|
34173
37000
|
else {
|
|
34174
37001
|
// Removes signatures and extract the rawgtxBody
|
|
34175
37002
|
const rawGtxBody = gtxToRawGtxBody(gtx);
|
|
34176
|
-
const signature = yield privOrSigProv.sign(rawGtxBody);
|
|
37003
|
+
const signature = yield privOrSigProv.sign(rawGtxBody, merkleHashVersion);
|
|
34177
37004
|
return addSignature(privOrSigProv.pubKey, signature, gtx);
|
|
34178
37005
|
}
|
|
34179
37006
|
});
|
|
@@ -34243,7 +37070,7 @@ function checkExistingGTXSignatures(txHash, gtx) {
|
|
|
34243
37070
|
}
|
|
34244
37071
|
return true;
|
|
34245
37072
|
}
|
|
34246
|
-
function newSignatureProvider(
|
|
37073
|
+
function newSignatureProvider(keyPair) {
|
|
34247
37074
|
let pub, priv;
|
|
34248
37075
|
if (keyPair) {
|
|
34249
37076
|
priv = ensureBuffer(keyPair.privKey);
|
|
@@ -34254,7 +37081,7 @@ function newSignatureProvider(merkleHashVersion, keyPair) {
|
|
|
34254
37081
|
}
|
|
34255
37082
|
return {
|
|
34256
37083
|
pubKey: pub,
|
|
34257
|
-
sign: (gtx) => __awaiter$9(this, void 0, void 0, function* () {
|
|
37084
|
+
sign: (gtx, merkleHashVersion) => __awaiter$9(this, void 0, void 0, function* () {
|
|
34258
37085
|
const signature = getDigestToSignFromRawGtxBody(gtx, merkleHashVersion);
|
|
34259
37086
|
return signDigest(signature, priv);
|
|
34260
37087
|
}),
|
|
@@ -34272,7 +37099,7 @@ function rawGtvToGtx(gtv) {
|
|
|
34272
37099
|
throw new Error("Second element must be an array");
|
|
34273
37100
|
}
|
|
34274
37101
|
gtvArray[1].forEach(element => {
|
|
34275
|
-
if (!
|
|
37102
|
+
if (!buffer$3.Buffer.isBuffer(element)) {
|
|
34276
37103
|
throw new Error("Element must be a buffer");
|
|
34277
37104
|
}
|
|
34278
37105
|
});
|
|
@@ -34284,7 +37111,7 @@ function rawGtvToGtxBody(gtv) {
|
|
|
34284
37111
|
throw new Error("Gtv must be an array of size 3");
|
|
34285
37112
|
}
|
|
34286
37113
|
const array = gtv;
|
|
34287
|
-
if (!
|
|
37114
|
+
if (!buffer$3.Buffer.isBuffer(array[0])) {
|
|
34288
37115
|
throw new Error("First element must be a byte array");
|
|
34289
37116
|
}
|
|
34290
37117
|
if (!Array.isArray(array[1])) {
|
|
@@ -34294,7 +37121,7 @@ function rawGtvToGtxBody(gtv) {
|
|
|
34294
37121
|
throw new Error("Third element must be an array");
|
|
34295
37122
|
}
|
|
34296
37123
|
array[2].forEach(element => {
|
|
34297
|
-
if (!
|
|
37124
|
+
if (!buffer$3.Buffer.isBuffer(element)) {
|
|
34298
37125
|
throw new Error("Element must be a buffer");
|
|
34299
37126
|
}
|
|
34300
37127
|
});
|
|
@@ -37347,6 +40174,7 @@ var TransactionEvent;
|
|
|
37347
40174
|
TransactionEvent["DappConfirmed"] = "dappConfirmed";
|
|
37348
40175
|
TransactionEvent["DappReceived"] = "dappReceived";
|
|
37349
40176
|
TransactionEvent["Signed"] = "signed";
|
|
40177
|
+
TransactionEvent["Rejected"] = "rejected";
|
|
37350
40178
|
})(TransactionEvent || (TransactionEvent = {}));
|
|
37351
40179
|
var AnchoringStatus;
|
|
37352
40180
|
(function (AnchoringStatus) {
|
|
@@ -37441,7 +40269,7 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
|
|
|
37441
40269
|
};
|
|
37442
40270
|
};
|
|
37443
40271
|
|
|
37444
|
-
const BufferSchema = z.union([z.instanceof(Uint8Array), z.instanceof(Buffer
|
|
40272
|
+
const BufferSchema = z.union([z.instanceof(Uint8Array), z.instanceof(buffer$3.Buffer)]);
|
|
37445
40273
|
|
|
37446
40274
|
const TxRidSchema = BufferSchema.refine(x => x.length === 32, "Rid must be 32 bytes long");
|
|
37447
40275
|
const isTxRidValid = (rid, options) => {
|
|
@@ -37463,12 +40291,12 @@ const isTxRidValid = (rid, options) => {
|
|
|
37463
40291
|
};
|
|
37464
40292
|
|
|
37465
40293
|
const AnchoringTransactionSchema = z.object({
|
|
37466
|
-
txRid: z.instanceof(Buffer
|
|
40294
|
+
txRid: z.instanceof(buffer$3.Buffer).superRefine((rid, refCtx) => {
|
|
37467
40295
|
const txRidValidation = TxRidSchema.safeParse(rid);
|
|
37468
40296
|
if (!txRidValidation.success)
|
|
37469
40297
|
txRidValidation.error.issues.forEach(issue => refCtx.addIssue(issue));
|
|
37470
40298
|
}),
|
|
37471
|
-
txData: z.instanceof(Buffer
|
|
40299
|
+
txData: z.instanceof(buffer$3.Buffer).refine(data => data.length > 0, {
|
|
37472
40300
|
message: "txData must be a non-empty Buffer",
|
|
37473
40301
|
}),
|
|
37474
40302
|
txOpIndex: z.number().int().nonnegative({ message: "txOpIndex must be a non-negative integer" }),
|
|
@@ -37515,7 +40343,7 @@ const RawGtvSchema = z.union([
|
|
|
37515
40343
|
z.string(),
|
|
37516
40344
|
z.number(),
|
|
37517
40345
|
z.bigint(),
|
|
37518
|
-
z.instanceof(Buffer
|
|
40346
|
+
z.instanceof(buffer$3.Buffer),
|
|
37519
40347
|
z.array(z.unknown()),
|
|
37520
40348
|
z.record(z.unknown()),
|
|
37521
40349
|
]);
|
|
@@ -37545,9 +40373,9 @@ const TransactionConfirmationProofSchema = z.object({
|
|
|
37545
40373
|
proof: z.string(),
|
|
37546
40374
|
});
|
|
37547
40375
|
const ConfirmationProofSchema = z.object({
|
|
37548
|
-
hash: z.instanceof(Buffer
|
|
37549
|
-
blockHeader: z.instanceof(Buffer
|
|
37550
|
-
witness: z.instanceof(Buffer
|
|
40376
|
+
hash: z.instanceof(buffer$3.Buffer),
|
|
40377
|
+
blockHeader: z.instanceof(buffer$3.Buffer),
|
|
40378
|
+
witness: z.instanceof(buffer$3.Buffer),
|
|
37551
40379
|
merkleProofTree: RawGtvSchema,
|
|
37552
40380
|
txIndex: z.number(),
|
|
37553
40381
|
});
|
|
@@ -37562,17 +40390,17 @@ const TransactionInfoResponseSchema = z.object({
|
|
|
37562
40390
|
txData: z.string(),
|
|
37563
40391
|
});
|
|
37564
40392
|
const TransactionInfoSchema = z.object({
|
|
37565
|
-
blockRid: z.instanceof(Buffer
|
|
40393
|
+
blockRid: z.instanceof(buffer$3.Buffer),
|
|
37566
40394
|
blockHeight: z.number(),
|
|
37567
|
-
blockHeader: z.instanceof(Buffer
|
|
37568
|
-
witness: z.instanceof(Buffer
|
|
40395
|
+
blockHeader: z.instanceof(buffer$3.Buffer),
|
|
40396
|
+
witness: z.instanceof(buffer$3.Buffer),
|
|
37569
40397
|
timestamp: z.number(),
|
|
37570
|
-
txRid: z.instanceof(Buffer
|
|
37571
|
-
txHash: z.instanceof(Buffer
|
|
37572
|
-
txData: z.instanceof(Buffer
|
|
40398
|
+
txRid: z.instanceof(buffer$3.Buffer),
|
|
40399
|
+
txHash: z.instanceof(buffer$3.Buffer),
|
|
40400
|
+
txData: z.instanceof(buffer$3.Buffer),
|
|
37573
40401
|
});
|
|
37574
40402
|
z.object({
|
|
37575
|
-
txRid: z.instanceof(Buffer
|
|
40403
|
+
txRid: z.instanceof(buffer$3.Buffer),
|
|
37576
40404
|
rejectReason: z.string(),
|
|
37577
40405
|
rejectTimestamp: z.number(),
|
|
37578
40406
|
});
|
|
@@ -37655,18 +40483,12 @@ function encodeTransaction(gtx) {
|
|
|
37655
40483
|
return serialize(gtx);
|
|
37656
40484
|
}
|
|
37657
40485
|
|
|
37658
|
-
const MERKLE_HASH_VERSIONS = {
|
|
37659
|
-
ONE: 1,
|
|
37660
|
-
TWO: 2,
|
|
37661
|
-
};
|
|
37662
|
-
|
|
37663
40486
|
const MerkleHashSchema = z.object({
|
|
37664
40487
|
merkle_hash_version: z.number().int().positive(),
|
|
37665
40488
|
});
|
|
37666
40489
|
const validateMerkleHash = (data) => {
|
|
37667
40490
|
const result = MerkleHashSchema.safeParse(data);
|
|
37668
40491
|
if (!result.success) {
|
|
37669
|
-
console.warn("MERKLE_HASH_WARNING: version not found or endpoint unreachable");
|
|
37670
40492
|
return { merkle_hash_version: MERKLE_HASH_VERSIONS.ONE };
|
|
37671
40493
|
}
|
|
37672
40494
|
return result.data;
|
|
@@ -37732,7 +40554,7 @@ function post(path, endpoint, requestBody) {
|
|
|
37732
40554
|
return __awaiter$8(this, void 0, void 0, function* () {
|
|
37733
40555
|
debug(`POST URL ${new URL(path, endpoint).href}`);
|
|
37734
40556
|
debug(`POST body ${JSON.stringify(requestBody)}`);
|
|
37735
|
-
if (
|
|
40557
|
+
if (buffer$3.Buffer.isBuffer(requestBody)) {
|
|
37736
40558
|
try {
|
|
37737
40559
|
const requestOptions = {
|
|
37738
40560
|
method: "post",
|
|
@@ -37774,7 +40596,7 @@ function constructBufferResponseBody(response) {
|
|
|
37774
40596
|
const contentType = response.headers.get("content-type");
|
|
37775
40597
|
if (contentType === "application/octet-stream") {
|
|
37776
40598
|
const responseBuffer = yield response.arrayBuffer();
|
|
37777
|
-
const buffer =
|
|
40599
|
+
const buffer = buffer$3.Buffer.from(responseBuffer);
|
|
37778
40600
|
return decodeValue(buffer);
|
|
37779
40601
|
}
|
|
37780
40602
|
if (contentType === "application/json") {
|
|
@@ -37942,7 +40764,8 @@ function retryRequest({ method, path, config, postObject, validateStatusCode, })
|
|
|
37942
40764
|
let error = null;
|
|
37943
40765
|
let transactionTimestamp = undefined;
|
|
37944
40766
|
const { nodeManager } = config;
|
|
37945
|
-
|
|
40767
|
+
const availableNodes = nodeManager.getAvailableNodes();
|
|
40768
|
+
for (const endpoint of availableNodes) {
|
|
37946
40769
|
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
37947
40770
|
const response = yield handleRequest(method, path, endpoint.url, postObject);
|
|
37948
40771
|
error = (_a = response === null || response === void 0 ? void 0 : response.error) !== null && _a !== void 0 ? _a : null;
|
|
@@ -37953,6 +40776,7 @@ function retryRequest({ method, path, config, postObject, validateStatusCode, })
|
|
|
37953
40776
|
const isServerError = statusCode ? hasServerError(statusCode) : false;
|
|
37954
40777
|
if (isStatusCodeValid && !error) {
|
|
37955
40778
|
// Find a way to have this handled more elegantly in the node manager.
|
|
40779
|
+
nodeManager.lastUsedNode = endpoint;
|
|
37956
40780
|
if (nodeManager.stickedNode !== endpoint) {
|
|
37957
40781
|
nodeManager.setStickyNode(endpoint);
|
|
37958
40782
|
}
|
|
@@ -38103,7 +40927,7 @@ function getClientConfigFromSettings(settings) {
|
|
|
38103
40927
|
nodeManager,
|
|
38104
40928
|
endpointPool,
|
|
38105
40929
|
chainId: settings.blockchainIid,
|
|
38106
|
-
merkleHashVersion: (_k = settings.merkleHashVersion) !== null && _k !== void 0 ? _k :
|
|
40930
|
+
merkleHashVersion: (_k = settings.merkleHashVersion) !== null && _k !== void 0 ? _k : MERKLE_HASH_VERSIONS.UNSET,
|
|
38107
40931
|
});
|
|
38108
40932
|
}
|
|
38109
40933
|
throw new MissingBlockchainIdentifierError();
|
|
@@ -38118,17 +40942,18 @@ function getClientConfigFromSettings(settings) {
|
|
|
38118
40942
|
nodeManager,
|
|
38119
40943
|
endpointPool,
|
|
38120
40944
|
chainId: directoryChainIid,
|
|
38121
|
-
merkleHashVersion: (_l = settings.merkleHashVersion) !== null && _l !== void 0 ? _l :
|
|
40945
|
+
merkleHashVersion: (_l = settings.merkleHashVersion) !== null && _l !== void 0 ? _l : MERKLE_HASH_VERSIONS.UNSET,
|
|
38122
40946
|
});
|
|
38123
40947
|
}))();
|
|
38124
40948
|
return {
|
|
38125
40949
|
endpointPool,
|
|
38126
40950
|
nodeManager: nodeManager,
|
|
38127
40951
|
blockchainRid: blockchainRidToUse,
|
|
38128
|
-
merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e :
|
|
40952
|
+
merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : MERKLE_HASH_VERSIONS.UNSET,
|
|
38129
40953
|
dappStatusPolling: setStatusPolling(settings.dappStatusPolling),
|
|
38130
40954
|
clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling),
|
|
38131
40955
|
systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling),
|
|
40956
|
+
retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling),
|
|
38132
40957
|
failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || defaultFailoverConfig.strategy,
|
|
38133
40958
|
attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || defaultFailoverConfig.attemptsPerEndpoint,
|
|
38134
40959
|
attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || defaultFailoverConfig.attemptInterval,
|
|
@@ -38164,7 +40989,6 @@ function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blo
|
|
|
38164
40989
|
endpointPool: directoryEndpointPool,
|
|
38165
40990
|
chainId: directoryIid,
|
|
38166
40991
|
failOverConfig,
|
|
38167
|
-
merkleHashVersion: 0,
|
|
38168
40992
|
});
|
|
38169
40993
|
const blockchainRidToUse = yield (() => __awaiter$5(this, void 0, void 0, function* () {
|
|
38170
40994
|
if (blockchainRid) {
|
|
@@ -38176,7 +41000,6 @@ function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blo
|
|
|
38176
41000
|
endpointPool: directoryEndpointPool,
|
|
38177
41001
|
chainId: blockchainIid,
|
|
38178
41002
|
failOverConfig,
|
|
38179
|
-
merkleHashVersion: 0,
|
|
38180
41003
|
});
|
|
38181
41004
|
}
|
|
38182
41005
|
throw new MissingBlockchainIdentifierError();
|
|
@@ -38184,7 +41007,6 @@ function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blo
|
|
|
38184
41007
|
const D1Client = yield createClient({
|
|
38185
41008
|
nodeUrlPool: getUrlsFromEndpoints(directoryEndpointPool),
|
|
38186
41009
|
blockchainRid: directoryBRID,
|
|
38187
|
-
merkleHashVersion: 0,
|
|
38188
41010
|
});
|
|
38189
41011
|
return yield getBlockchainApiUrls(D1Client, ensureBuffer(blockchainRidToUse));
|
|
38190
41012
|
});
|
|
@@ -38209,13 +41031,13 @@ function convertToRellOperation(operations) {
|
|
|
38209
41031
|
}
|
|
38210
41032
|
function getSerializedGTX(gtx) {
|
|
38211
41033
|
const gtxBytes = encodeTransaction(gtx);
|
|
38212
|
-
if (!
|
|
41034
|
+
if (!buffer$3.Buffer.isBuffer(gtxBytes)) {
|
|
38213
41035
|
throw new SerializedTransactionFormatException();
|
|
38214
41036
|
}
|
|
38215
41037
|
return gtxBytes;
|
|
38216
41038
|
}
|
|
38217
41039
|
function getGTXFromBufferOrTransactionOrOperation(transaction, blockchainRid) {
|
|
38218
|
-
if (
|
|
41040
|
+
if (buffer$3.Buffer.isBuffer(transaction)) {
|
|
38219
41041
|
return deserialize(transaction);
|
|
38220
41042
|
}
|
|
38221
41043
|
else if ("operations" in transaction) {
|
|
@@ -38317,8 +41139,8 @@ const isKeyPair = (keypair) => {
|
|
|
38317
41139
|
keypair !== null &&
|
|
38318
41140
|
"privKey" in keypair &&
|
|
38319
41141
|
"pubKey" in keypair &&
|
|
38320
|
-
keypair.privKey instanceof Buffer
|
|
38321
|
-
keypair.pubKey instanceof Buffer
|
|
41142
|
+
keypair.privKey instanceof buffer$3.Buffer &&
|
|
41143
|
+
keypair.pubKey instanceof buffer$3.Buffer);
|
|
38322
41144
|
};
|
|
38323
41145
|
function getNodeUrlsFromSettings(settings) {
|
|
38324
41146
|
var _a;
|
|
@@ -38357,7 +41179,6 @@ function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
|
|
|
38357
41179
|
return yield createClient({
|
|
38358
41180
|
directoryNodeUrlPool,
|
|
38359
41181
|
blockchainRid: directoryChainRid,
|
|
38360
|
-
merkleHashVersion: 0,
|
|
38361
41182
|
});
|
|
38362
41183
|
});
|
|
38363
41184
|
}
|
|
@@ -38396,7 +41217,7 @@ const getUrlsFromEndpoints = (endpointPool) => {
|
|
|
38396
41217
|
function awaitDappConfirmation(txRID, dappStatusPolling, getTransactionStatus) {
|
|
38397
41218
|
var _a;
|
|
38398
41219
|
return __awaiter$5(this, void 0, void 0, function* () {
|
|
38399
|
-
let lastKnownResult;
|
|
41220
|
+
let lastKnownResult = null;
|
|
38400
41221
|
for (let i = 0; i < dappStatusPolling.count; i++) {
|
|
38401
41222
|
lastKnownResult = yield getTransactionStatus(txRID);
|
|
38402
41223
|
if (lastKnownResult.status === ResponseStatus.Confirmed) {
|
|
@@ -38407,10 +41228,7 @@ function awaitDappConfirmation(txRID, dappStatusPolling, getTransactionStatus) {
|
|
|
38407
41228
|
}
|
|
38408
41229
|
yield sleep(dappStatusPolling.interval);
|
|
38409
41230
|
}
|
|
38410
|
-
|
|
38411
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38412
|
-
//@ts-expect-error
|
|
38413
|
-
return lastKnownResult;
|
|
41231
|
+
throw new Error(`Retry count exceeded. Confirmation not received. Last transaction status: ${lastKnownResult === null || lastKnownResult === void 0 ? void 0 : lastKnownResult.status}`);
|
|
38414
41232
|
});
|
|
38415
41233
|
}
|
|
38416
41234
|
function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringStatusPolling, getClusterAnchoringTransactionConfirmation) {
|
|
@@ -38524,6 +41342,13 @@ function setStatusPolling(statusPolling) {
|
|
|
38524
41342
|
count: (_b = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.count) !== null && _b !== void 0 ? _b : 20,
|
|
38525
41343
|
};
|
|
38526
41344
|
}
|
|
41345
|
+
function setRetryTransactionPolling(statusPolling) {
|
|
41346
|
+
var _a, _b;
|
|
41347
|
+
return {
|
|
41348
|
+
interval: (_a = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.interval) !== null && _a !== void 0 ? _a : 500,
|
|
41349
|
+
count: (_b = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.count) !== null && _b !== void 0 ? _b : 3,
|
|
41350
|
+
};
|
|
41351
|
+
}
|
|
38527
41352
|
function linkPromiEvents(event1, event2) {
|
|
38528
41353
|
const transactionEvents = Object.values(TransactionEvent).filter((event) => typeof event === "string");
|
|
38529
41354
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -38595,11 +41420,12 @@ function getBlockchainRidFromIid({ endpointPool, chainId, failOverConfig = {}, n
|
|
|
38595
41420
|
dappStatusPolling: setStatusPolling(),
|
|
38596
41421
|
clusterAnchoringStatusPolling: setStatusPolling(),
|
|
38597
41422
|
systemAnchoringStatusPolling: setStatusPolling(),
|
|
41423
|
+
retryTransactionPolling: setRetryTransactionPolling(),
|
|
38598
41424
|
failoverStrategy: mergedFailOverConfig.strategy,
|
|
38599
41425
|
attemptsPerEndpoint: mergedFailOverConfig.attemptsPerEndpoint,
|
|
38600
41426
|
attemptInterval: mergedFailOverConfig.attemptInterval,
|
|
38601
41427
|
unreachableDuration: mergedFailOverConfig.unreachableDuration,
|
|
38602
|
-
merkleHashVersion:
|
|
41428
|
+
merkleHashVersion: MERKLE_HASH_VERSIONS.UNSET,
|
|
38603
41429
|
};
|
|
38604
41430
|
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/brid/iid_${chainId}`, config);
|
|
38605
41431
|
const blockchainRid = isString(rspBody);
|
|
@@ -38723,7 +41549,7 @@ function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToPr
|
|
|
38723
41549
|
const rawTx = yield sourceClient.getTransaction(txToProveRID);
|
|
38724
41550
|
const txGtv = decodeValue(rawTx);
|
|
38725
41551
|
const fetchedTxHash = gtvHash2(txGtv, sourceClient.config.merkleHashVersion);
|
|
38726
|
-
if (
|
|
41552
|
+
if (buffer$3.Buffer.compare(fetchedTxHash, proofHash)) {
|
|
38727
41553
|
// We received another hash for tx RID than what was included in proof
|
|
38728
41554
|
// Possibly rouge or faulty node(s). Anyway, we need to give up.
|
|
38729
41555
|
throw new MissingTransactionProof(proofHash, fetchedTxHash);
|
|
@@ -38733,7 +41559,7 @@ function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToPr
|
|
|
38733
41559
|
throw new DifferentNumberOfSignersException((_c = (_b = fetchedTx.signatures) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0, txToProveSigners.length);
|
|
38734
41560
|
}
|
|
38735
41561
|
const txRID = getDigestToSign(fetchedTx, sourceClient.config.merkleHashVersion);
|
|
38736
|
-
if (
|
|
41562
|
+
if (buffer$3.Buffer.compare(txRID, ensureBuffer(txToProveRID))) {
|
|
38737
41563
|
throw new ProofRidException();
|
|
38738
41564
|
}
|
|
38739
41565
|
for (const signer of txToProveSigners) {
|
|
@@ -38907,7 +41733,7 @@ function getAnchoringClient(client, dappBlockchainRid, cluster) {
|
|
|
38907
41733
|
if (!sourceClusterInfo || !sourceClusterInfo.anchoring_chain) {
|
|
38908
41734
|
throw Error("Cluster info could not be found");
|
|
38909
41735
|
}
|
|
38910
|
-
const networkSettings = Object.assign(Object.assign({}, client.config), { directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool), blockchainRid: toString(sourceClusterInfo.anchoring_chain)
|
|
41736
|
+
const networkSettings = Object.assign(Object.assign({}, client.config), { directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool), blockchainRid: toString(sourceClusterInfo.anchoring_chain) });
|
|
38911
41737
|
const clientConfiguredToAnchoringchain = yield createClient(networkSettings);
|
|
38912
41738
|
return clientConfiguredToAnchoringchain;
|
|
38913
41739
|
});
|
|
@@ -38931,7 +41757,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
|
38931
41757
|
*/
|
|
38932
41758
|
class Web3EventEmitter {
|
|
38933
41759
|
constructor() {
|
|
38934
|
-
this._emitter = new EventEmitter();
|
|
41760
|
+
this._emitter = new eventsExports.EventEmitter();
|
|
38935
41761
|
}
|
|
38936
41762
|
on(eventName, fn) {
|
|
38937
41763
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
@@ -39265,6 +42091,48 @@ function createClient(settings) {
|
|
|
39265
42091
|
}
|
|
39266
42092
|
});
|
|
39267
42093
|
},
|
|
42094
|
+
sendTransactionWithRetries(transaction, callback, confirmationLevel = ChainConfirmationLevel.Dapp) {
|
|
42095
|
+
const client = this;
|
|
42096
|
+
function sendOnce() {
|
|
42097
|
+
return client.sendTransaction(transaction, true, callback, confirmationLevel);
|
|
42098
|
+
}
|
|
42099
|
+
const promiEvent = new Web3PromiEvent((resolve, reject) => __awaiter$1(this, void 0, void 0, function* () {
|
|
42100
|
+
let error = null;
|
|
42101
|
+
// await sleep(1000);
|
|
42102
|
+
for (let i = 0; i < config.retryTransactionPolling.count; i++) {
|
|
42103
|
+
info(`sendTransactionWithRetries attempt ${i + 1} of ${config.retryTransactionPolling.count}`);
|
|
42104
|
+
const tmpPromiEvent = sendOnce()
|
|
42105
|
+
.on(TransactionEvent.ClusterAnchoringConfirmation, receipt => {
|
|
42106
|
+
promiEvent.emit(TransactionEvent.ClusterAnchoringConfirmation, receipt);
|
|
42107
|
+
})
|
|
42108
|
+
.on(TransactionEvent.SystemAnchoringConfirmation, receipt => {
|
|
42109
|
+
promiEvent.emit(TransactionEvent.SystemAnchoringConfirmation, receipt);
|
|
42110
|
+
})
|
|
42111
|
+
.on(TransactionEvent.DappReceived, receipt => {
|
|
42112
|
+
promiEvent.emit(TransactionEvent.DappReceived, receipt);
|
|
42113
|
+
})
|
|
42114
|
+
.on(TransactionEvent.Signed, receipt => {
|
|
42115
|
+
promiEvent.emit(TransactionEvent.Signed, receipt);
|
|
42116
|
+
})
|
|
42117
|
+
.on(TransactionEvent.DappConfirmed, receipt => {
|
|
42118
|
+
promiEvent.emit(TransactionEvent.DappConfirmed, receipt);
|
|
42119
|
+
})
|
|
42120
|
+
.catch(tmpError => {
|
|
42121
|
+
warning(`sendTransactionWithRetries error on attempt ${i + 1} of ${config.retryTransactionPolling.count}: ${tmpError}`);
|
|
42122
|
+
promiEvent.emit(TransactionEvent.Rejected, tmpError);
|
|
42123
|
+
error = tmpError;
|
|
42124
|
+
});
|
|
42125
|
+
const tmpReceipt = yield tmpPromiEvent;
|
|
42126
|
+
if (tmpReceipt) {
|
|
42127
|
+
resolve(tmpReceipt);
|
|
42128
|
+
return;
|
|
42129
|
+
}
|
|
42130
|
+
yield sleep(config.retryTransactionPolling.interval);
|
|
42131
|
+
}
|
|
42132
|
+
reject(error);
|
|
42133
|
+
}));
|
|
42134
|
+
return promiEvent;
|
|
42135
|
+
},
|
|
39268
42136
|
sendTransaction(transaction, doStatusPolling = true, callback, confirmationLevel = ChainConfirmationLevel.Dapp) {
|
|
39269
42137
|
const promiEvent = new Web3PromiEvent((resolve, reject) => __awaiter$1(this, void 0, void 0, function* () {
|
|
39270
42138
|
var _a, _b;
|
|
@@ -39299,14 +42167,15 @@ function createClient(settings) {
|
|
|
39299
42167
|
clusterAnchoringStatusPolling: client.config.clusterAnchoringStatusPolling,
|
|
39300
42168
|
systemAnchoringStatusPolling: client.config.systemAnchoringStatusPolling,
|
|
39301
42169
|
};
|
|
39302
|
-
|
|
42170
|
+
const stickyNodeClient = yield createStickyNodeClient(client); //to avoid false rejections by oblivious nodes
|
|
42171
|
+
let transactionReceipt = yield handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, statusPollingConfig.dappStatusPolling, () => stickyNodeClient.getTransactionStatus(transactionRid, callback), stickyNodeClient);
|
|
39303
42172
|
if (confirmationLevel === ChainConfirmationLevel.None ||
|
|
39304
42173
|
confirmationLevel === ChainConfirmationLevel.Dapp) {
|
|
39305
42174
|
resolve(transactionReceipt);
|
|
39306
42175
|
return;
|
|
39307
42176
|
}
|
|
39308
42177
|
const { anchoringClient, systemAnchoringChainBridString } = yield getAnchoringClientAndSystemChainRid(client);
|
|
39309
|
-
transactionReceipt = yield handleSystemConfirmations(transactionReceipt, confirmationLevel, promiEvent, statusPollingConfig, anchoringClient, systemAnchoringChainBridString, () =>
|
|
42178
|
+
transactionReceipt = yield handleSystemConfirmations(transactionReceipt, confirmationLevel, promiEvent, statusPollingConfig, anchoringClient, systemAnchoringChainBridString, () => stickyNodeClient.getClusterAnchoringTransactionConfirmation(transactionRid, anchoringClient, callback), anchoredTxRid => stickyNodeClient.getSystemAnchoringTransactionConfirmation(anchoredTxRid, anchoringClient, systemAnchoringChainBridString, callback));
|
|
39310
42179
|
resolve(transactionReceipt);
|
|
39311
42180
|
}
|
|
39312
42181
|
catch (error) {
|
|
@@ -39726,6 +42595,21 @@ function createClient(settings) {
|
|
|
39726
42595
|
return merkleHashVersion;
|
|
39727
42596
|
});
|
|
39728
42597
|
}
|
|
42598
|
+
function createStickyNodeClient(client) {
|
|
42599
|
+
var _a;
|
|
42600
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
42601
|
+
if (!client.config.nodeManager.lastUsedNode) {
|
|
42602
|
+
throw new Error("No last used node found; cannot create sticky node client");
|
|
42603
|
+
}
|
|
42604
|
+
const stickyNodeClient = yield createClient({
|
|
42605
|
+
nodeUrlPool: (_a = client.config.nodeManager.lastUsedNode) === null || _a === void 0 ? void 0 : _a.url,
|
|
42606
|
+
blockchainRid: client.config.blockchainRid,
|
|
42607
|
+
merkleHashVersion: client.config.merkleHashVersion,
|
|
42608
|
+
useStickyNode: true,
|
|
42609
|
+
});
|
|
42610
|
+
return stickyNodeClient;
|
|
42611
|
+
});
|
|
42612
|
+
}
|
|
39729
42613
|
});
|
|
39730
42614
|
}
|
|
39731
42615
|
|
|
@@ -39751,6 +42635,7 @@ function createStubClient() {
|
|
|
39751
42635
|
dappStatusPolling: setStatusPolling({ interval: 5000, count: 5 }),
|
|
39752
42636
|
clusterAnchoringStatusPolling: setStatusPolling(),
|
|
39753
42637
|
systemAnchoringStatusPolling: setStatusPolling(),
|
|
42638
|
+
retryTransactionPolling: setRetryTransactionPolling(),
|
|
39754
42639
|
failoverStrategy: FailoverStrategy.AbortOnError,
|
|
39755
42640
|
attemptsPerEndpoint: 3,
|
|
39756
42641
|
attemptInterval: 5000,
|
|
@@ -39770,6 +42655,9 @@ function createStubClient() {
|
|
|
39770
42655
|
sendTransaction() {
|
|
39771
42656
|
return new Web3PromiEvent((_resolve, reject) => reject("sendTransaction rejected"));
|
|
39772
42657
|
},
|
|
42658
|
+
sendTransactionWithRetries() {
|
|
42659
|
+
return new Web3PromiEvent((_resolve, reject) => reject("sendTransactionWithRetries rejected"));
|
|
42660
|
+
},
|
|
39773
42661
|
signAndSendUniqueTransaction() {
|
|
39774
42662
|
return new Web3PromiEvent((_resolve, reject) => reject("signAndSendUniqueTransaction rejected"));
|
|
39775
42663
|
},
|
|
@@ -39895,7 +42783,7 @@ function dumpGtv(rawGtv) {
|
|
|
39895
42783
|
if (typeof value === "bigint") {
|
|
39896
42784
|
return `${value.toString()}L`;
|
|
39897
42785
|
}
|
|
39898
|
-
if (
|
|
42786
|
+
if (buffer$3.Buffer.isBuffer(value)) {
|
|
39899
42787
|
return toString(value);
|
|
39900
42788
|
}
|
|
39901
42789
|
if (typeof value === "object" &&
|