@semaphore-protocol/identity 4.3.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +9 -2226
  2. package/dist/index.js +5 -2222
  3. package/package.json +5 -7
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/identity
3
- * @version 4.3.0
3
+ * @version 4.3.1
4
4
  * @file A library to create Semaphore identities.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -9,2226 +9,9 @@
9
9
  'use strict';
10
10
 
11
11
  var eddsaPoseidon = require('@zk-kit/eddsa-poseidon');
12
-
13
- function getDefaultExportFromCjs (x) {
14
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
15
- }
16
-
17
- var buffer = {};
18
-
19
- var base64Js = {};
20
-
21
- base64Js.byteLength = byteLength;
22
- base64Js.toByteArray = toByteArray;
23
- base64Js.fromByteArray = fromByteArray;
24
- var lookup = [];
25
- var revLookup = [];
26
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
27
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
28
- for (var i = 0, len = code.length; i < len; ++i) {
29
- lookup[i] = code[i];
30
- revLookup[code.charCodeAt(i)] = i;
31
- }
32
- revLookup['-'.charCodeAt(0)] = 62;
33
- revLookup['_'.charCodeAt(0)] = 63;
34
- function getLens (b64) {
35
- var len = b64.length;
36
- if (len % 4 > 0) {
37
- throw new Error('Invalid string. Length must be a multiple of 4')
38
- }
39
- var validLen = b64.indexOf('=');
40
- if (validLen === -1) validLen = len;
41
- var placeHoldersLen = validLen === len
42
- ? 0
43
- : 4 - (validLen % 4);
44
- return [validLen, placeHoldersLen]
45
- }
46
- function byteLength (b64) {
47
- var lens = getLens(b64);
48
- var validLen = lens[0];
49
- var placeHoldersLen = lens[1];
50
- return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
51
- }
52
- function _byteLength (b64, validLen, placeHoldersLen) {
53
- return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
54
- }
55
- function toByteArray (b64) {
56
- var tmp;
57
- var lens = getLens(b64);
58
- var validLen = lens[0];
59
- var placeHoldersLen = lens[1];
60
- var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
61
- var curByte = 0;
62
- var len = placeHoldersLen > 0
63
- ? validLen - 4
64
- : validLen;
65
- var i;
66
- for (i = 0; i < len; i += 4) {
67
- tmp =
68
- (revLookup[b64.charCodeAt(i)] << 18) |
69
- (revLookup[b64.charCodeAt(i + 1)] << 12) |
70
- (revLookup[b64.charCodeAt(i + 2)] << 6) |
71
- revLookup[b64.charCodeAt(i + 3)];
72
- arr[curByte++] = (tmp >> 16) & 0xFF;
73
- arr[curByte++] = (tmp >> 8) & 0xFF;
74
- arr[curByte++] = tmp & 0xFF;
75
- }
76
- if (placeHoldersLen === 2) {
77
- tmp =
78
- (revLookup[b64.charCodeAt(i)] << 2) |
79
- (revLookup[b64.charCodeAt(i + 1)] >> 4);
80
- arr[curByte++] = tmp & 0xFF;
81
- }
82
- if (placeHoldersLen === 1) {
83
- tmp =
84
- (revLookup[b64.charCodeAt(i)] << 10) |
85
- (revLookup[b64.charCodeAt(i + 1)] << 4) |
86
- (revLookup[b64.charCodeAt(i + 2)] >> 2);
87
- arr[curByte++] = (tmp >> 8) & 0xFF;
88
- arr[curByte++] = tmp & 0xFF;
89
- }
90
- return arr
91
- }
92
- function tripletToBase64 (num) {
93
- return lookup[num >> 18 & 0x3F] +
94
- lookup[num >> 12 & 0x3F] +
95
- lookup[num >> 6 & 0x3F] +
96
- lookup[num & 0x3F]
97
- }
98
- function encodeChunk (uint8, start, end) {
99
- var tmp;
100
- var output = [];
101
- for (var i = start; i < end; i += 3) {
102
- tmp =
103
- ((uint8[i] << 16) & 0xFF0000) +
104
- ((uint8[i + 1] << 8) & 0xFF00) +
105
- (uint8[i + 2] & 0xFF);
106
- output.push(tripletToBase64(tmp));
107
- }
108
- return output.join('')
109
- }
110
- function fromByteArray (uint8) {
111
- var tmp;
112
- var len = uint8.length;
113
- var extraBytes = len % 3;
114
- var parts = [];
115
- var maxChunkLength = 16383;
116
- for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
117
- parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
118
- }
119
- if (extraBytes === 1) {
120
- tmp = uint8[len - 1];
121
- parts.push(
122
- lookup[tmp >> 2] +
123
- lookup[(tmp << 4) & 0x3F] +
124
- '=='
125
- );
126
- } else if (extraBytes === 2) {
127
- tmp = (uint8[len - 2] << 8) + uint8[len - 1];
128
- parts.push(
129
- lookup[tmp >> 10] +
130
- lookup[(tmp >> 4) & 0x3F] +
131
- lookup[(tmp << 2) & 0x3F] +
132
- '='
133
- );
134
- }
135
- return parts.join('')
136
- }
137
-
138
- var ieee754 = {};
139
-
140
- ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
141
- var e, m;
142
- var eLen = (nBytes * 8) - mLen - 1;
143
- var eMax = (1 << eLen) - 1;
144
- var eBias = eMax >> 1;
145
- var nBits = -7;
146
- var i = isLE ? (nBytes - 1) : 0;
147
- var d = isLE ? -1 : 1;
148
- var s = buffer[offset + i];
149
- i += d;
150
- e = s & ((1 << (-nBits)) - 1);
151
- s >>= (-nBits);
152
- nBits += eLen;
153
- for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
154
- m = e & ((1 << (-nBits)) - 1);
155
- e >>= (-nBits);
156
- nBits += mLen;
157
- for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
158
- if (e === 0) {
159
- e = 1 - eBias;
160
- } else if (e === eMax) {
161
- return m ? NaN : ((s ? -1 : 1) * Infinity)
162
- } else {
163
- m = m + Math.pow(2, mLen);
164
- e = e - eBias;
165
- }
166
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
167
- };
168
- ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
169
- var e, m, c;
170
- var eLen = (nBytes * 8) - mLen - 1;
171
- var eMax = (1 << eLen) - 1;
172
- var eBias = eMax >> 1;
173
- var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
174
- var i = isLE ? 0 : (nBytes - 1);
175
- var d = isLE ? 1 : -1;
176
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
177
- value = Math.abs(value);
178
- if (isNaN(value) || value === Infinity) {
179
- m = isNaN(value) ? 1 : 0;
180
- e = eMax;
181
- } else {
182
- e = Math.floor(Math.log(value) / Math.LN2);
183
- if (value * (c = Math.pow(2, -e)) < 1) {
184
- e--;
185
- c *= 2;
186
- }
187
- if (e + eBias >= 1) {
188
- value += rt / c;
189
- } else {
190
- value += rt * Math.pow(2, 1 - eBias);
191
- }
192
- if (value * c >= 2) {
193
- e++;
194
- c /= 2;
195
- }
196
- if (e + eBias >= eMax) {
197
- m = 0;
198
- e = eMax;
199
- } else if (e + eBias >= 1) {
200
- m = ((value * c) - 1) * Math.pow(2, mLen);
201
- e = e + eBias;
202
- } else {
203
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
204
- e = 0;
205
- }
206
- }
207
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
208
- e = (e << mLen) | m;
209
- eLen += mLen;
210
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
211
- buffer[offset + i - d] |= s * 128;
212
- };
213
-
214
- (function (exports) {
215
- const base64 = base64Js;
216
- const ieee754$1 = ieee754;
217
- const customInspectSymbol =
218
- (typeof Symbol === 'function' && typeof Symbol['for'] === 'function')
219
- ? Symbol['for']('nodejs.util.inspect.custom')
220
- : null;
221
- exports.Buffer = Buffer;
222
- exports.SlowBuffer = SlowBuffer;
223
- exports.INSPECT_MAX_BYTES = 50;
224
- const K_MAX_LENGTH = 0x7fffffff;
225
- exports.kMaxLength = K_MAX_LENGTH;
226
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
227
- if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
228
- typeof console.error === 'function') {
229
- console.error(
230
- 'This browser lacks typed array (Uint8Array) support which is required by ' +
231
- '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
232
- );
233
- }
234
- function typedArraySupport () {
235
- try {
236
- const arr = new Uint8Array(1);
237
- const proto = { foo: function () { return 42 } };
238
- Object.setPrototypeOf(proto, Uint8Array.prototype);
239
- Object.setPrototypeOf(arr, proto);
240
- return arr.foo() === 42
241
- } catch (e) {
242
- return false
243
- }
244
- }
245
- Object.defineProperty(Buffer.prototype, 'parent', {
246
- enumerable: true,
247
- get: function () {
248
- if (!Buffer.isBuffer(this)) return undefined
249
- return this.buffer
250
- }
251
- });
252
- Object.defineProperty(Buffer.prototype, 'offset', {
253
- enumerable: true,
254
- get: function () {
255
- if (!Buffer.isBuffer(this)) return undefined
256
- return this.byteOffset
257
- }
258
- });
259
- function createBuffer (length) {
260
- if (length > K_MAX_LENGTH) {
261
- throw new RangeError('The value "' + length + '" is invalid for option "size"')
262
- }
263
- const buf = new Uint8Array(length);
264
- Object.setPrototypeOf(buf, Buffer.prototype);
265
- return buf
266
- }
267
- function Buffer (arg, encodingOrOffset, length) {
268
- if (typeof arg === 'number') {
269
- if (typeof encodingOrOffset === 'string') {
270
- throw new TypeError(
271
- 'The "string" argument must be of type string. Received type number'
272
- )
273
- }
274
- return allocUnsafe(arg)
275
- }
276
- return from(arg, encodingOrOffset, length)
277
- }
278
- Buffer.poolSize = 8192;
279
- function from (value, encodingOrOffset, length) {
280
- if (typeof value === 'string') {
281
- return fromString(value, encodingOrOffset)
282
- }
283
- if (ArrayBuffer.isView(value)) {
284
- return fromArrayView(value)
285
- }
286
- if (value == null) {
287
- throw new TypeError(
288
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
289
- 'or Array-like Object. Received type ' + (typeof value)
290
- )
291
- }
292
- if (isInstance(value, ArrayBuffer) ||
293
- (value && isInstance(value.buffer, ArrayBuffer))) {
294
- return fromArrayBuffer(value, encodingOrOffset, length)
295
- }
296
- if (typeof SharedArrayBuffer !== 'undefined' &&
297
- (isInstance(value, SharedArrayBuffer) ||
298
- (value && isInstance(value.buffer, SharedArrayBuffer)))) {
299
- return fromArrayBuffer(value, encodingOrOffset, length)
300
- }
301
- if (typeof value === 'number') {
302
- throw new TypeError(
303
- 'The "value" argument must not be of type number. Received type number'
304
- )
305
- }
306
- const valueOf = value.valueOf && value.valueOf();
307
- if (valueOf != null && valueOf !== value) {
308
- return Buffer.from(valueOf, encodingOrOffset, length)
309
- }
310
- const b = fromObject(value);
311
- if (b) return b
312
- if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
313
- typeof value[Symbol.toPrimitive] === 'function') {
314
- return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
315
- }
316
- throw new TypeError(
317
- 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
318
- 'or Array-like Object. Received type ' + (typeof value)
319
- )
320
- }
321
- Buffer.from = function (value, encodingOrOffset, length) {
322
- return from(value, encodingOrOffset, length)
323
- };
324
- Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
325
- Object.setPrototypeOf(Buffer, Uint8Array);
326
- function assertSize (size) {
327
- if (typeof size !== 'number') {
328
- throw new TypeError('"size" argument must be of type number')
329
- } else if (size < 0) {
330
- throw new RangeError('The value "' + size + '" is invalid for option "size"')
331
- }
332
- }
333
- function alloc (size, fill, encoding) {
334
- assertSize(size);
335
- if (size <= 0) {
336
- return createBuffer(size)
337
- }
338
- if (fill !== undefined) {
339
- return typeof encoding === 'string'
340
- ? createBuffer(size).fill(fill, encoding)
341
- : createBuffer(size).fill(fill)
342
- }
343
- return createBuffer(size)
344
- }
345
- Buffer.alloc = function (size, fill, encoding) {
346
- return alloc(size, fill, encoding)
347
- };
348
- function allocUnsafe (size) {
349
- assertSize(size);
350
- return createBuffer(size < 0 ? 0 : checked(size) | 0)
351
- }
352
- Buffer.allocUnsafe = function (size) {
353
- return allocUnsafe(size)
354
- };
355
- Buffer.allocUnsafeSlow = function (size) {
356
- return allocUnsafe(size)
357
- };
358
- function fromString (string, encoding) {
359
- if (typeof encoding !== 'string' || encoding === '') {
360
- encoding = 'utf8';
361
- }
362
- if (!Buffer.isEncoding(encoding)) {
363
- throw new TypeError('Unknown encoding: ' + encoding)
364
- }
365
- const length = byteLength(string, encoding) | 0;
366
- let buf = createBuffer(length);
367
- const actual = buf.write(string, encoding);
368
- if (actual !== length) {
369
- buf = buf.slice(0, actual);
370
- }
371
- return buf
372
- }
373
- function fromArrayLike (array) {
374
- const length = array.length < 0 ? 0 : checked(array.length) | 0;
375
- const buf = createBuffer(length);
376
- for (let i = 0; i < length; i += 1) {
377
- buf[i] = array[i] & 255;
378
- }
379
- return buf
380
- }
381
- function fromArrayView (arrayView) {
382
- if (isInstance(arrayView, Uint8Array)) {
383
- const copy = new Uint8Array(arrayView);
384
- return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
385
- }
386
- return fromArrayLike(arrayView)
387
- }
388
- function fromArrayBuffer (array, byteOffset, length) {
389
- if (byteOffset < 0 || array.byteLength < byteOffset) {
390
- throw new RangeError('"offset" is outside of buffer bounds')
391
- }
392
- if (array.byteLength < byteOffset + (length || 0)) {
393
- throw new RangeError('"length" is outside of buffer bounds')
394
- }
395
- let buf;
396
- if (byteOffset === undefined && length === undefined) {
397
- buf = new Uint8Array(array);
398
- } else if (length === undefined) {
399
- buf = new Uint8Array(array, byteOffset);
400
- } else {
401
- buf = new Uint8Array(array, byteOffset, length);
402
- }
403
- Object.setPrototypeOf(buf, Buffer.prototype);
404
- return buf
405
- }
406
- function fromObject (obj) {
407
- if (Buffer.isBuffer(obj)) {
408
- const len = checked(obj.length) | 0;
409
- const buf = createBuffer(len);
410
- if (buf.length === 0) {
411
- return buf
412
- }
413
- obj.copy(buf, 0, 0, len);
414
- return buf
415
- }
416
- if (obj.length !== undefined) {
417
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
418
- return createBuffer(0)
419
- }
420
- return fromArrayLike(obj)
421
- }
422
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
423
- return fromArrayLike(obj.data)
424
- }
425
- }
426
- function checked (length) {
427
- if (length >= K_MAX_LENGTH) {
428
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
429
- 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
430
- }
431
- return length | 0
432
- }
433
- function SlowBuffer (length) {
434
- if (+length != length) {
435
- length = 0;
436
- }
437
- return Buffer.alloc(+length)
438
- }
439
- Buffer.isBuffer = function isBuffer (b) {
440
- return b != null && b._isBuffer === true &&
441
- b !== Buffer.prototype
442
- };
443
- Buffer.compare = function compare (a, b) {
444
- if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
445
- if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
446
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
447
- throw new TypeError(
448
- 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
449
- )
450
- }
451
- if (a === b) return 0
452
- let x = a.length;
453
- let y = b.length;
454
- for (let i = 0, len = Math.min(x, y); i < len; ++i) {
455
- if (a[i] !== b[i]) {
456
- x = a[i];
457
- y = b[i];
458
- break
459
- }
460
- }
461
- if (x < y) return -1
462
- if (y < x) return 1
463
- return 0
464
- };
465
- Buffer.isEncoding = function isEncoding (encoding) {
466
- switch (String(encoding).toLowerCase()) {
467
- case 'hex':
468
- case 'utf8':
469
- case 'utf-8':
470
- case 'ascii':
471
- case 'latin1':
472
- case 'binary':
473
- case 'base64':
474
- case 'ucs2':
475
- case 'ucs-2':
476
- case 'utf16le':
477
- case 'utf-16le':
478
- return true
479
- default:
480
- return false
481
- }
482
- };
483
- Buffer.concat = function concat (list, length) {
484
- if (!Array.isArray(list)) {
485
- throw new TypeError('"list" argument must be an Array of Buffers')
486
- }
487
- if (list.length === 0) {
488
- return Buffer.alloc(0)
489
- }
490
- let i;
491
- if (length === undefined) {
492
- length = 0;
493
- for (i = 0; i < list.length; ++i) {
494
- length += list[i].length;
495
- }
496
- }
497
- const buffer = Buffer.allocUnsafe(length);
498
- let pos = 0;
499
- for (i = 0; i < list.length; ++i) {
500
- let buf = list[i];
501
- if (isInstance(buf, Uint8Array)) {
502
- if (pos + buf.length > buffer.length) {
503
- if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
504
- buf.copy(buffer, pos);
505
- } else {
506
- Uint8Array.prototype.set.call(
507
- buffer,
508
- buf,
509
- pos
510
- );
511
- }
512
- } else if (!Buffer.isBuffer(buf)) {
513
- throw new TypeError('"list" argument must be an Array of Buffers')
514
- } else {
515
- buf.copy(buffer, pos);
516
- }
517
- pos += buf.length;
518
- }
519
- return buffer
520
- };
521
- function byteLength (string, encoding) {
522
- if (Buffer.isBuffer(string)) {
523
- return string.length
524
- }
525
- if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
526
- return string.byteLength
527
- }
528
- if (typeof string !== 'string') {
529
- throw new TypeError(
530
- 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
531
- 'Received type ' + typeof string
532
- )
533
- }
534
- const len = string.length;
535
- const mustMatch = (arguments.length > 2 && arguments[2] === true);
536
- if (!mustMatch && len === 0) return 0
537
- let loweredCase = false;
538
- for (;;) {
539
- switch (encoding) {
540
- case 'ascii':
541
- case 'latin1':
542
- case 'binary':
543
- return len
544
- case 'utf8':
545
- case 'utf-8':
546
- return utf8ToBytes(string).length
547
- case 'ucs2':
548
- case 'ucs-2':
549
- case 'utf16le':
550
- case 'utf-16le':
551
- return len * 2
552
- case 'hex':
553
- return len >>> 1
554
- case 'base64':
555
- return base64ToBytes(string).length
556
- default:
557
- if (loweredCase) {
558
- return mustMatch ? -1 : utf8ToBytes(string).length
559
- }
560
- encoding = ('' + encoding).toLowerCase();
561
- loweredCase = true;
562
- }
563
- }
564
- }
565
- Buffer.byteLength = byteLength;
566
- function slowToString (encoding, start, end) {
567
- let loweredCase = false;
568
- if (start === undefined || start < 0) {
569
- start = 0;
570
- }
571
- if (start > this.length) {
572
- return ''
573
- }
574
- if (end === undefined || end > this.length) {
575
- end = this.length;
576
- }
577
- if (end <= 0) {
578
- return ''
579
- }
580
- end >>>= 0;
581
- start >>>= 0;
582
- if (end <= start) {
583
- return ''
584
- }
585
- if (!encoding) encoding = 'utf8';
586
- while (true) {
587
- switch (encoding) {
588
- case 'hex':
589
- return hexSlice(this, start, end)
590
- case 'utf8':
591
- case 'utf-8':
592
- return utf8Slice(this, start, end)
593
- case 'ascii':
594
- return asciiSlice(this, start, end)
595
- case 'latin1':
596
- case 'binary':
597
- return latin1Slice(this, start, end)
598
- case 'base64':
599
- return base64Slice(this, start, end)
600
- case 'ucs2':
601
- case 'ucs-2':
602
- case 'utf16le':
603
- case 'utf-16le':
604
- return utf16leSlice(this, start, end)
605
- default:
606
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
607
- encoding = (encoding + '').toLowerCase();
608
- loweredCase = true;
609
- }
610
- }
611
- }
612
- Buffer.prototype._isBuffer = true;
613
- function swap (b, n, m) {
614
- const i = b[n];
615
- b[n] = b[m];
616
- b[m] = i;
617
- }
618
- Buffer.prototype.swap16 = function swap16 () {
619
- const len = this.length;
620
- if (len % 2 !== 0) {
621
- throw new RangeError('Buffer size must be a multiple of 16-bits')
622
- }
623
- for (let i = 0; i < len; i += 2) {
624
- swap(this, i, i + 1);
625
- }
626
- return this
627
- };
628
- Buffer.prototype.swap32 = function swap32 () {
629
- const len = this.length;
630
- if (len % 4 !== 0) {
631
- throw new RangeError('Buffer size must be a multiple of 32-bits')
632
- }
633
- for (let i = 0; i < len; i += 4) {
634
- swap(this, i, i + 3);
635
- swap(this, i + 1, i + 2);
636
- }
637
- return this
638
- };
639
- Buffer.prototype.swap64 = function swap64 () {
640
- const len = this.length;
641
- if (len % 8 !== 0) {
642
- throw new RangeError('Buffer size must be a multiple of 64-bits')
643
- }
644
- for (let i = 0; i < len; i += 8) {
645
- swap(this, i, i + 7);
646
- swap(this, i + 1, i + 6);
647
- swap(this, i + 2, i + 5);
648
- swap(this, i + 3, i + 4);
649
- }
650
- return this
651
- };
652
- Buffer.prototype.toString = function toString () {
653
- const length = this.length;
654
- if (length === 0) return ''
655
- if (arguments.length === 0) return utf8Slice(this, 0, length)
656
- return slowToString.apply(this, arguments)
657
- };
658
- Buffer.prototype.toLocaleString = Buffer.prototype.toString;
659
- Buffer.prototype.equals = function equals (b) {
660
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
661
- if (this === b) return true
662
- return Buffer.compare(this, b) === 0
663
- };
664
- Buffer.prototype.inspect = function inspect () {
665
- let str = '';
666
- const max = exports.INSPECT_MAX_BYTES;
667
- str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
668
- if (this.length > max) str += ' ... ';
669
- return '<Buffer ' + str + '>'
670
- };
671
- if (customInspectSymbol) {
672
- Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
673
- }
674
- Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
675
- if (isInstance(target, Uint8Array)) {
676
- target = Buffer.from(target, target.offset, target.byteLength);
677
- }
678
- if (!Buffer.isBuffer(target)) {
679
- throw new TypeError(
680
- 'The "target" argument must be one of type Buffer or Uint8Array. ' +
681
- 'Received type ' + (typeof target)
682
- )
683
- }
684
- if (start === undefined) {
685
- start = 0;
686
- }
687
- if (end === undefined) {
688
- end = target ? target.length : 0;
689
- }
690
- if (thisStart === undefined) {
691
- thisStart = 0;
692
- }
693
- if (thisEnd === undefined) {
694
- thisEnd = this.length;
695
- }
696
- if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
697
- throw new RangeError('out of range index')
698
- }
699
- if (thisStart >= thisEnd && start >= end) {
700
- return 0
701
- }
702
- if (thisStart >= thisEnd) {
703
- return -1
704
- }
705
- if (start >= end) {
706
- return 1
707
- }
708
- start >>>= 0;
709
- end >>>= 0;
710
- thisStart >>>= 0;
711
- thisEnd >>>= 0;
712
- if (this === target) return 0
713
- let x = thisEnd - thisStart;
714
- let y = end - start;
715
- const len = Math.min(x, y);
716
- const thisCopy = this.slice(thisStart, thisEnd);
717
- const targetCopy = target.slice(start, end);
718
- for (let i = 0; i < len; ++i) {
719
- if (thisCopy[i] !== targetCopy[i]) {
720
- x = thisCopy[i];
721
- y = targetCopy[i];
722
- break
723
- }
724
- }
725
- if (x < y) return -1
726
- if (y < x) return 1
727
- return 0
728
- };
729
- function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
730
- if (buffer.length === 0) return -1
731
- if (typeof byteOffset === 'string') {
732
- encoding = byteOffset;
733
- byteOffset = 0;
734
- } else if (byteOffset > 0x7fffffff) {
735
- byteOffset = 0x7fffffff;
736
- } else if (byteOffset < -0x80000000) {
737
- byteOffset = -0x80000000;
738
- }
739
- byteOffset = +byteOffset;
740
- if (numberIsNaN(byteOffset)) {
741
- byteOffset = dir ? 0 : (buffer.length - 1);
742
- }
743
- if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
744
- if (byteOffset >= buffer.length) {
745
- if (dir) return -1
746
- else byteOffset = buffer.length - 1;
747
- } else if (byteOffset < 0) {
748
- if (dir) byteOffset = 0;
749
- else return -1
750
- }
751
- if (typeof val === 'string') {
752
- val = Buffer.from(val, encoding);
753
- }
754
- if (Buffer.isBuffer(val)) {
755
- if (val.length === 0) {
756
- return -1
757
- }
758
- return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
759
- } else if (typeof val === 'number') {
760
- val = val & 0xFF;
761
- if (typeof Uint8Array.prototype.indexOf === 'function') {
762
- if (dir) {
763
- return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
764
- } else {
765
- return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
766
- }
767
- }
768
- return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
769
- }
770
- throw new TypeError('val must be string, number or Buffer')
771
- }
772
- function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
773
- let indexSize = 1;
774
- let arrLength = arr.length;
775
- let valLength = val.length;
776
- if (encoding !== undefined) {
777
- encoding = String(encoding).toLowerCase();
778
- if (encoding === 'ucs2' || encoding === 'ucs-2' ||
779
- encoding === 'utf16le' || encoding === 'utf-16le') {
780
- if (arr.length < 2 || val.length < 2) {
781
- return -1
782
- }
783
- indexSize = 2;
784
- arrLength /= 2;
785
- valLength /= 2;
786
- byteOffset /= 2;
787
- }
788
- }
789
- function read (buf, i) {
790
- if (indexSize === 1) {
791
- return buf[i]
792
- } else {
793
- return buf.readUInt16BE(i * indexSize)
794
- }
795
- }
796
- let i;
797
- if (dir) {
798
- let foundIndex = -1;
799
- for (i = byteOffset; i < arrLength; i++) {
800
- if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
801
- if (foundIndex === -1) foundIndex = i;
802
- if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
803
- } else {
804
- if (foundIndex !== -1) i -= i - foundIndex;
805
- foundIndex = -1;
806
- }
807
- }
808
- } else {
809
- if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
810
- for (i = byteOffset; i >= 0; i--) {
811
- let found = true;
812
- for (let j = 0; j < valLength; j++) {
813
- if (read(arr, i + j) !== read(val, j)) {
814
- found = false;
815
- break
816
- }
817
- }
818
- if (found) return i
819
- }
820
- }
821
- return -1
822
- }
823
- Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
824
- return this.indexOf(val, byteOffset, encoding) !== -1
825
- };
826
- Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
827
- return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
828
- };
829
- Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
830
- return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
831
- };
832
- function hexWrite (buf, string, offset, length) {
833
- offset = Number(offset) || 0;
834
- const remaining = buf.length - offset;
835
- if (!length) {
836
- length = remaining;
837
- } else {
838
- length = Number(length);
839
- if (length > remaining) {
840
- length = remaining;
841
- }
842
- }
843
- const strLen = string.length;
844
- if (length > strLen / 2) {
845
- length = strLen / 2;
846
- }
847
- let i;
848
- for (i = 0; i < length; ++i) {
849
- const parsed = parseInt(string.substr(i * 2, 2), 16);
850
- if (numberIsNaN(parsed)) return i
851
- buf[offset + i] = parsed;
852
- }
853
- return i
854
- }
855
- function utf8Write (buf, string, offset, length) {
856
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
857
- }
858
- function asciiWrite (buf, string, offset, length) {
859
- return blitBuffer(asciiToBytes(string), buf, offset, length)
860
- }
861
- function base64Write (buf, string, offset, length) {
862
- return blitBuffer(base64ToBytes(string), buf, offset, length)
863
- }
864
- function ucs2Write (buf, string, offset, length) {
865
- return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
866
- }
867
- Buffer.prototype.write = function write (string, offset, length, encoding) {
868
- if (offset === undefined) {
869
- encoding = 'utf8';
870
- length = this.length;
871
- offset = 0;
872
- } else if (length === undefined && typeof offset === 'string') {
873
- encoding = offset;
874
- length = this.length;
875
- offset = 0;
876
- } else if (isFinite(offset)) {
877
- offset = offset >>> 0;
878
- if (isFinite(length)) {
879
- length = length >>> 0;
880
- if (encoding === undefined) encoding = 'utf8';
881
- } else {
882
- encoding = length;
883
- length = undefined;
884
- }
885
- } else {
886
- throw new Error(
887
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
888
- )
889
- }
890
- const remaining = this.length - offset;
891
- if (length === undefined || length > remaining) length = remaining;
892
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
893
- throw new RangeError('Attempt to write outside buffer bounds')
894
- }
895
- if (!encoding) encoding = 'utf8';
896
- let loweredCase = false;
897
- for (;;) {
898
- switch (encoding) {
899
- case 'hex':
900
- return hexWrite(this, string, offset, length)
901
- case 'utf8':
902
- case 'utf-8':
903
- return utf8Write(this, string, offset, length)
904
- case 'ascii':
905
- case 'latin1':
906
- case 'binary':
907
- return asciiWrite(this, string, offset, length)
908
- case 'base64':
909
- return base64Write(this, string, offset, length)
910
- case 'ucs2':
911
- case 'ucs-2':
912
- case 'utf16le':
913
- case 'utf-16le':
914
- return ucs2Write(this, string, offset, length)
915
- default:
916
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
917
- encoding = ('' + encoding).toLowerCase();
918
- loweredCase = true;
919
- }
920
- }
921
- };
922
- Buffer.prototype.toJSON = function toJSON () {
923
- return {
924
- type: 'Buffer',
925
- data: Array.prototype.slice.call(this._arr || this, 0)
926
- }
927
- };
928
- function base64Slice (buf, start, end) {
929
- if (start === 0 && end === buf.length) {
930
- return base64.fromByteArray(buf)
931
- } else {
932
- return base64.fromByteArray(buf.slice(start, end))
933
- }
934
- }
935
- function utf8Slice (buf, start, end) {
936
- end = Math.min(buf.length, end);
937
- const res = [];
938
- let i = start;
939
- while (i < end) {
940
- const firstByte = buf[i];
941
- let codePoint = null;
942
- let bytesPerSequence = (firstByte > 0xEF)
943
- ? 4
944
- : (firstByte > 0xDF)
945
- ? 3
946
- : (firstByte > 0xBF)
947
- ? 2
948
- : 1;
949
- if (i + bytesPerSequence <= end) {
950
- let secondByte, thirdByte, fourthByte, tempCodePoint;
951
- switch (bytesPerSequence) {
952
- case 1:
953
- if (firstByte < 0x80) {
954
- codePoint = firstByte;
955
- }
956
- break
957
- case 2:
958
- secondByte = buf[i + 1];
959
- if ((secondByte & 0xC0) === 0x80) {
960
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
961
- if (tempCodePoint > 0x7F) {
962
- codePoint = tempCodePoint;
963
- }
964
- }
965
- break
966
- case 3:
967
- secondByte = buf[i + 1];
968
- thirdByte = buf[i + 2];
969
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
970
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
971
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
972
- codePoint = tempCodePoint;
973
- }
974
- }
975
- break
976
- case 4:
977
- secondByte = buf[i + 1];
978
- thirdByte = buf[i + 2];
979
- fourthByte = buf[i + 3];
980
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
981
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
982
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
983
- codePoint = tempCodePoint;
984
- }
985
- }
986
- }
987
- }
988
- if (codePoint === null) {
989
- codePoint = 0xFFFD;
990
- bytesPerSequence = 1;
991
- } else if (codePoint > 0xFFFF) {
992
- codePoint -= 0x10000;
993
- res.push(codePoint >>> 10 & 0x3FF | 0xD800);
994
- codePoint = 0xDC00 | codePoint & 0x3FF;
995
- }
996
- res.push(codePoint);
997
- i += bytesPerSequence;
998
- }
999
- return decodeCodePointsArray(res)
1000
- }
1001
- const MAX_ARGUMENTS_LENGTH = 0x1000;
1002
- function decodeCodePointsArray (codePoints) {
1003
- const len = codePoints.length;
1004
- if (len <= MAX_ARGUMENTS_LENGTH) {
1005
- return String.fromCharCode.apply(String, codePoints)
1006
- }
1007
- let res = '';
1008
- let i = 0;
1009
- while (i < len) {
1010
- res += String.fromCharCode.apply(
1011
- String,
1012
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1013
- );
1014
- }
1015
- return res
1016
- }
1017
- function asciiSlice (buf, start, end) {
1018
- let ret = '';
1019
- end = Math.min(buf.length, end);
1020
- for (let i = start; i < end; ++i) {
1021
- ret += String.fromCharCode(buf[i] & 0x7F);
1022
- }
1023
- return ret
1024
- }
1025
- function latin1Slice (buf, start, end) {
1026
- let ret = '';
1027
- end = Math.min(buf.length, end);
1028
- for (let i = start; i < end; ++i) {
1029
- ret += String.fromCharCode(buf[i]);
1030
- }
1031
- return ret
1032
- }
1033
- function hexSlice (buf, start, end) {
1034
- const len = buf.length;
1035
- if (!start || start < 0) start = 0;
1036
- if (!end || end < 0 || end > len) end = len;
1037
- let out = '';
1038
- for (let i = start; i < end; ++i) {
1039
- out += hexSliceLookupTable[buf[i]];
1040
- }
1041
- return out
1042
- }
1043
- function utf16leSlice (buf, start, end) {
1044
- const bytes = buf.slice(start, end);
1045
- let res = '';
1046
- for (let i = 0; i < bytes.length - 1; i += 2) {
1047
- res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
1048
- }
1049
- return res
1050
- }
1051
- Buffer.prototype.slice = function slice (start, end) {
1052
- const len = this.length;
1053
- start = ~~start;
1054
- end = end === undefined ? len : ~~end;
1055
- if (start < 0) {
1056
- start += len;
1057
- if (start < 0) start = 0;
1058
- } else if (start > len) {
1059
- start = len;
1060
- }
1061
- if (end < 0) {
1062
- end += len;
1063
- if (end < 0) end = 0;
1064
- } else if (end > len) {
1065
- end = len;
1066
- }
1067
- if (end < start) end = start;
1068
- const newBuf = this.subarray(start, end);
1069
- Object.setPrototypeOf(newBuf, Buffer.prototype);
1070
- return newBuf
1071
- };
1072
- function checkOffset (offset, ext, length) {
1073
- if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1074
- if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1075
- }
1076
- Buffer.prototype.readUintLE =
1077
- Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1078
- offset = offset >>> 0;
1079
- byteLength = byteLength >>> 0;
1080
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1081
- let val = this[offset];
1082
- let mul = 1;
1083
- let i = 0;
1084
- while (++i < byteLength && (mul *= 0x100)) {
1085
- val += this[offset + i] * mul;
1086
- }
1087
- return val
1088
- };
1089
- Buffer.prototype.readUintBE =
1090
- Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1091
- offset = offset >>> 0;
1092
- byteLength = byteLength >>> 0;
1093
- if (!noAssert) {
1094
- checkOffset(offset, byteLength, this.length);
1095
- }
1096
- let val = this[offset + --byteLength];
1097
- let mul = 1;
1098
- while (byteLength > 0 && (mul *= 0x100)) {
1099
- val += this[offset + --byteLength] * mul;
1100
- }
1101
- return val
1102
- };
1103
- Buffer.prototype.readUint8 =
1104
- Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1105
- offset = offset >>> 0;
1106
- if (!noAssert) checkOffset(offset, 1, this.length);
1107
- return this[offset]
1108
- };
1109
- Buffer.prototype.readUint16LE =
1110
- Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1111
- offset = offset >>> 0;
1112
- if (!noAssert) checkOffset(offset, 2, this.length);
1113
- return this[offset] | (this[offset + 1] << 8)
1114
- };
1115
- Buffer.prototype.readUint16BE =
1116
- Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1117
- offset = offset >>> 0;
1118
- if (!noAssert) checkOffset(offset, 2, this.length);
1119
- return (this[offset] << 8) | this[offset + 1]
1120
- };
1121
- Buffer.prototype.readUint32LE =
1122
- Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1123
- offset = offset >>> 0;
1124
- if (!noAssert) checkOffset(offset, 4, this.length);
1125
- return ((this[offset]) |
1126
- (this[offset + 1] << 8) |
1127
- (this[offset + 2] << 16)) +
1128
- (this[offset + 3] * 0x1000000)
1129
- };
1130
- Buffer.prototype.readUint32BE =
1131
- Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1132
- offset = offset >>> 0;
1133
- if (!noAssert) checkOffset(offset, 4, this.length);
1134
- return (this[offset] * 0x1000000) +
1135
- ((this[offset + 1] << 16) |
1136
- (this[offset + 2] << 8) |
1137
- this[offset + 3])
1138
- };
1139
- Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
1140
- offset = offset >>> 0;
1141
- validateNumber(offset, 'offset');
1142
- const first = this[offset];
1143
- const last = this[offset + 7];
1144
- if (first === undefined || last === undefined) {
1145
- boundsError(offset, this.length - 8);
1146
- }
1147
- const lo = first +
1148
- this[++offset] * 2 ** 8 +
1149
- this[++offset] * 2 ** 16 +
1150
- this[++offset] * 2 ** 24;
1151
- const hi = this[++offset] +
1152
- this[++offset] * 2 ** 8 +
1153
- this[++offset] * 2 ** 16 +
1154
- last * 2 ** 24;
1155
- return BigInt(lo) + (BigInt(hi) << BigInt(32))
1156
- });
1157
- Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
1158
- offset = offset >>> 0;
1159
- validateNumber(offset, 'offset');
1160
- const first = this[offset];
1161
- const last = this[offset + 7];
1162
- if (first === undefined || last === undefined) {
1163
- boundsError(offset, this.length - 8);
1164
- }
1165
- const hi = first * 2 ** 24 +
1166
- this[++offset] * 2 ** 16 +
1167
- this[++offset] * 2 ** 8 +
1168
- this[++offset];
1169
- const lo = this[++offset] * 2 ** 24 +
1170
- this[++offset] * 2 ** 16 +
1171
- this[++offset] * 2 ** 8 +
1172
- last;
1173
- return (BigInt(hi) << BigInt(32)) + BigInt(lo)
1174
- });
1175
- Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1176
- offset = offset >>> 0;
1177
- byteLength = byteLength >>> 0;
1178
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1179
- let val = this[offset];
1180
- let mul = 1;
1181
- let i = 0;
1182
- while (++i < byteLength && (mul *= 0x100)) {
1183
- val += this[offset + i] * mul;
1184
- }
1185
- mul *= 0x80;
1186
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1187
- return val
1188
- };
1189
- Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1190
- offset = offset >>> 0;
1191
- byteLength = byteLength >>> 0;
1192
- if (!noAssert) checkOffset(offset, byteLength, this.length);
1193
- let i = byteLength;
1194
- let mul = 1;
1195
- let val = this[offset + --i];
1196
- while (i > 0 && (mul *= 0x100)) {
1197
- val += this[offset + --i] * mul;
1198
- }
1199
- mul *= 0x80;
1200
- if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1201
- return val
1202
- };
1203
- Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1204
- offset = offset >>> 0;
1205
- if (!noAssert) checkOffset(offset, 1, this.length);
1206
- if (!(this[offset] & 0x80)) return (this[offset])
1207
- return ((0xff - this[offset] + 1) * -1)
1208
- };
1209
- Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1210
- offset = offset >>> 0;
1211
- if (!noAssert) checkOffset(offset, 2, this.length);
1212
- const val = this[offset] | (this[offset + 1] << 8);
1213
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1214
- };
1215
- Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1216
- offset = offset >>> 0;
1217
- if (!noAssert) checkOffset(offset, 2, this.length);
1218
- const val = this[offset + 1] | (this[offset] << 8);
1219
- return (val & 0x8000) ? val | 0xFFFF0000 : val
1220
- };
1221
- Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1222
- offset = offset >>> 0;
1223
- if (!noAssert) checkOffset(offset, 4, this.length);
1224
- return (this[offset]) |
1225
- (this[offset + 1] << 8) |
1226
- (this[offset + 2] << 16) |
1227
- (this[offset + 3] << 24)
1228
- };
1229
- Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1230
- offset = offset >>> 0;
1231
- if (!noAssert) checkOffset(offset, 4, this.length);
1232
- return (this[offset] << 24) |
1233
- (this[offset + 1] << 16) |
1234
- (this[offset + 2] << 8) |
1235
- (this[offset + 3])
1236
- };
1237
- Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
1238
- offset = offset >>> 0;
1239
- validateNumber(offset, 'offset');
1240
- const first = this[offset];
1241
- const last = this[offset + 7];
1242
- if (first === undefined || last === undefined) {
1243
- boundsError(offset, this.length - 8);
1244
- }
1245
- const val = this[offset + 4] +
1246
- this[offset + 5] * 2 ** 8 +
1247
- this[offset + 6] * 2 ** 16 +
1248
- (last << 24);
1249
- return (BigInt(val) << BigInt(32)) +
1250
- BigInt(first +
1251
- this[++offset] * 2 ** 8 +
1252
- this[++offset] * 2 ** 16 +
1253
- this[++offset] * 2 ** 24)
1254
- });
1255
- Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
1256
- offset = offset >>> 0;
1257
- validateNumber(offset, 'offset');
1258
- const first = this[offset];
1259
- const last = this[offset + 7];
1260
- if (first === undefined || last === undefined) {
1261
- boundsError(offset, this.length - 8);
1262
- }
1263
- const val = (first << 24) +
1264
- this[++offset] * 2 ** 16 +
1265
- this[++offset] * 2 ** 8 +
1266
- this[++offset];
1267
- return (BigInt(val) << BigInt(32)) +
1268
- BigInt(this[++offset] * 2 ** 24 +
1269
- this[++offset] * 2 ** 16 +
1270
- this[++offset] * 2 ** 8 +
1271
- last)
1272
- });
1273
- Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1274
- offset = offset >>> 0;
1275
- if (!noAssert) checkOffset(offset, 4, this.length);
1276
- return ieee754$1.read(this, offset, true, 23, 4)
1277
- };
1278
- Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1279
- offset = offset >>> 0;
1280
- if (!noAssert) checkOffset(offset, 4, this.length);
1281
- return ieee754$1.read(this, offset, false, 23, 4)
1282
- };
1283
- Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1284
- offset = offset >>> 0;
1285
- if (!noAssert) checkOffset(offset, 8, this.length);
1286
- return ieee754$1.read(this, offset, true, 52, 8)
1287
- };
1288
- Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1289
- offset = offset >>> 0;
1290
- if (!noAssert) checkOffset(offset, 8, this.length);
1291
- return ieee754$1.read(this, offset, false, 52, 8)
1292
- };
1293
- function checkInt (buf, value, offset, ext, max, min) {
1294
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1295
- if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1296
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1297
- }
1298
- Buffer.prototype.writeUintLE =
1299
- Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1300
- value = +value;
1301
- offset = offset >>> 0;
1302
- byteLength = byteLength >>> 0;
1303
- if (!noAssert) {
1304
- const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1305
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1306
- }
1307
- let mul = 1;
1308
- let i = 0;
1309
- this[offset] = value & 0xFF;
1310
- while (++i < byteLength && (mul *= 0x100)) {
1311
- this[offset + i] = (value / mul) & 0xFF;
1312
- }
1313
- return offset + byteLength
1314
- };
1315
- Buffer.prototype.writeUintBE =
1316
- Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1317
- value = +value;
1318
- offset = offset >>> 0;
1319
- byteLength = byteLength >>> 0;
1320
- if (!noAssert) {
1321
- const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1322
- checkInt(this, value, offset, byteLength, maxBytes, 0);
1323
- }
1324
- let i = byteLength - 1;
1325
- let mul = 1;
1326
- this[offset + i] = value & 0xFF;
1327
- while (--i >= 0 && (mul *= 0x100)) {
1328
- this[offset + i] = (value / mul) & 0xFF;
1329
- }
1330
- return offset + byteLength
1331
- };
1332
- Buffer.prototype.writeUint8 =
1333
- Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1334
- value = +value;
1335
- offset = offset >>> 0;
1336
- if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1337
- this[offset] = (value & 0xff);
1338
- return offset + 1
1339
- };
1340
- Buffer.prototype.writeUint16LE =
1341
- Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1342
- value = +value;
1343
- offset = offset >>> 0;
1344
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1345
- this[offset] = (value & 0xff);
1346
- this[offset + 1] = (value >>> 8);
1347
- return offset + 2
1348
- };
1349
- Buffer.prototype.writeUint16BE =
1350
- Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1351
- value = +value;
1352
- offset = offset >>> 0;
1353
- if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1354
- this[offset] = (value >>> 8);
1355
- this[offset + 1] = (value & 0xff);
1356
- return offset + 2
1357
- };
1358
- Buffer.prototype.writeUint32LE =
1359
- Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1360
- value = +value;
1361
- offset = offset >>> 0;
1362
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1363
- this[offset + 3] = (value >>> 24);
1364
- this[offset + 2] = (value >>> 16);
1365
- this[offset + 1] = (value >>> 8);
1366
- this[offset] = (value & 0xff);
1367
- return offset + 4
1368
- };
1369
- Buffer.prototype.writeUint32BE =
1370
- Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1371
- value = +value;
1372
- offset = offset >>> 0;
1373
- if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1374
- this[offset] = (value >>> 24);
1375
- this[offset + 1] = (value >>> 16);
1376
- this[offset + 2] = (value >>> 8);
1377
- this[offset + 3] = (value & 0xff);
1378
- return offset + 4
1379
- };
1380
- function wrtBigUInt64LE (buf, value, offset, min, max) {
1381
- checkIntBI(value, min, max, buf, offset, 7);
1382
- let lo = Number(value & BigInt(0xffffffff));
1383
- buf[offset++] = lo;
1384
- lo = lo >> 8;
1385
- buf[offset++] = lo;
1386
- lo = lo >> 8;
1387
- buf[offset++] = lo;
1388
- lo = lo >> 8;
1389
- buf[offset++] = lo;
1390
- let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1391
- buf[offset++] = hi;
1392
- hi = hi >> 8;
1393
- buf[offset++] = hi;
1394
- hi = hi >> 8;
1395
- buf[offset++] = hi;
1396
- hi = hi >> 8;
1397
- buf[offset++] = hi;
1398
- return offset
1399
- }
1400
- function wrtBigUInt64BE (buf, value, offset, min, max) {
1401
- checkIntBI(value, min, max, buf, offset, 7);
1402
- let lo = Number(value & BigInt(0xffffffff));
1403
- buf[offset + 7] = lo;
1404
- lo = lo >> 8;
1405
- buf[offset + 6] = lo;
1406
- lo = lo >> 8;
1407
- buf[offset + 5] = lo;
1408
- lo = lo >> 8;
1409
- buf[offset + 4] = lo;
1410
- let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1411
- buf[offset + 3] = hi;
1412
- hi = hi >> 8;
1413
- buf[offset + 2] = hi;
1414
- hi = hi >> 8;
1415
- buf[offset + 1] = hi;
1416
- hi = hi >> 8;
1417
- buf[offset] = hi;
1418
- return offset + 8
1419
- }
1420
- Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
1421
- return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1422
- });
1423
- Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
1424
- return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1425
- });
1426
- Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1427
- value = +value;
1428
- offset = offset >>> 0;
1429
- if (!noAssert) {
1430
- const limit = Math.pow(2, (8 * byteLength) - 1);
1431
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1432
- }
1433
- let i = 0;
1434
- let mul = 1;
1435
- let sub = 0;
1436
- this[offset] = value & 0xFF;
1437
- while (++i < byteLength && (mul *= 0x100)) {
1438
- if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1439
- sub = 1;
1440
- }
1441
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1442
- }
1443
- return offset + byteLength
1444
- };
1445
- Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1446
- value = +value;
1447
- offset = offset >>> 0;
1448
- if (!noAssert) {
1449
- const limit = Math.pow(2, (8 * byteLength) - 1);
1450
- checkInt(this, value, offset, byteLength, limit - 1, -limit);
1451
- }
1452
- let i = byteLength - 1;
1453
- let mul = 1;
1454
- let sub = 0;
1455
- this[offset + i] = value & 0xFF;
1456
- while (--i >= 0 && (mul *= 0x100)) {
1457
- if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1458
- sub = 1;
1459
- }
1460
- this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1461
- }
1462
- return offset + byteLength
1463
- };
1464
- Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1465
- value = +value;
1466
- offset = offset >>> 0;
1467
- if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
1468
- if (value < 0) value = 0xff + value + 1;
1469
- this[offset] = (value & 0xff);
1470
- return offset + 1
1471
- };
1472
- Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1473
- value = +value;
1474
- offset = offset >>> 0;
1475
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1476
- this[offset] = (value & 0xff);
1477
- this[offset + 1] = (value >>> 8);
1478
- return offset + 2
1479
- };
1480
- Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1481
- value = +value;
1482
- offset = offset >>> 0;
1483
- if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1484
- this[offset] = (value >>> 8);
1485
- this[offset + 1] = (value & 0xff);
1486
- return offset + 2
1487
- };
1488
- Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1489
- value = +value;
1490
- offset = offset >>> 0;
1491
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1492
- this[offset] = (value & 0xff);
1493
- this[offset + 1] = (value >>> 8);
1494
- this[offset + 2] = (value >>> 16);
1495
- this[offset + 3] = (value >>> 24);
1496
- return offset + 4
1497
- };
1498
- Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1499
- value = +value;
1500
- offset = offset >>> 0;
1501
- if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1502
- if (value < 0) value = 0xffffffff + value + 1;
1503
- this[offset] = (value >>> 24);
1504
- this[offset + 1] = (value >>> 16);
1505
- this[offset + 2] = (value >>> 8);
1506
- this[offset + 3] = (value & 0xff);
1507
- return offset + 4
1508
- };
1509
- Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
1510
- return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1511
- });
1512
- Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
1513
- return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1514
- });
1515
- function checkIEEE754 (buf, value, offset, ext, max, min) {
1516
- if (offset + ext > buf.length) throw new RangeError('Index out of range')
1517
- if (offset < 0) throw new RangeError('Index out of range')
1518
- }
1519
- function writeFloat (buf, value, offset, littleEndian, noAssert) {
1520
- value = +value;
1521
- offset = offset >>> 0;
1522
- if (!noAssert) {
1523
- checkIEEE754(buf, value, offset, 4);
1524
- }
1525
- ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
1526
- return offset + 4
1527
- }
1528
- Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1529
- return writeFloat(this, value, offset, true, noAssert)
1530
- };
1531
- Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1532
- return writeFloat(this, value, offset, false, noAssert)
1533
- };
1534
- function writeDouble (buf, value, offset, littleEndian, noAssert) {
1535
- value = +value;
1536
- offset = offset >>> 0;
1537
- if (!noAssert) {
1538
- checkIEEE754(buf, value, offset, 8);
1539
- }
1540
- ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
1541
- return offset + 8
1542
- }
1543
- Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1544
- return writeDouble(this, value, offset, true, noAssert)
1545
- };
1546
- Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1547
- return writeDouble(this, value, offset, false, noAssert)
1548
- };
1549
- Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1550
- if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
1551
- if (!start) start = 0;
1552
- if (!end && end !== 0) end = this.length;
1553
- if (targetStart >= target.length) targetStart = target.length;
1554
- if (!targetStart) targetStart = 0;
1555
- if (end > 0 && end < start) end = start;
1556
- if (end === start) return 0
1557
- if (target.length === 0 || this.length === 0) return 0
1558
- if (targetStart < 0) {
1559
- throw new RangeError('targetStart out of bounds')
1560
- }
1561
- if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
1562
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
1563
- if (end > this.length) end = this.length;
1564
- if (target.length - targetStart < end - start) {
1565
- end = target.length - targetStart + start;
1566
- }
1567
- const len = end - start;
1568
- if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
1569
- this.copyWithin(targetStart, start, end);
1570
- } else {
1571
- Uint8Array.prototype.set.call(
1572
- target,
1573
- this.subarray(start, end),
1574
- targetStart
1575
- );
1576
- }
1577
- return len
1578
- };
1579
- Buffer.prototype.fill = function fill (val, start, end, encoding) {
1580
- if (typeof val === 'string') {
1581
- if (typeof start === 'string') {
1582
- encoding = start;
1583
- start = 0;
1584
- end = this.length;
1585
- } else if (typeof end === 'string') {
1586
- encoding = end;
1587
- end = this.length;
1588
- }
1589
- if (encoding !== undefined && typeof encoding !== 'string') {
1590
- throw new TypeError('encoding must be a string')
1591
- }
1592
- if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1593
- throw new TypeError('Unknown encoding: ' + encoding)
1594
- }
1595
- if (val.length === 1) {
1596
- const code = val.charCodeAt(0);
1597
- if ((encoding === 'utf8' && code < 128) ||
1598
- encoding === 'latin1') {
1599
- val = code;
1600
- }
1601
- }
1602
- } else if (typeof val === 'number') {
1603
- val = val & 255;
1604
- } else if (typeof val === 'boolean') {
1605
- val = Number(val);
1606
- }
1607
- if (start < 0 || this.length < start || this.length < end) {
1608
- throw new RangeError('Out of range index')
1609
- }
1610
- if (end <= start) {
1611
- return this
1612
- }
1613
- start = start >>> 0;
1614
- end = end === undefined ? this.length : end >>> 0;
1615
- if (!val) val = 0;
1616
- let i;
1617
- if (typeof val === 'number') {
1618
- for (i = start; i < end; ++i) {
1619
- this[i] = val;
1620
- }
1621
- } else {
1622
- const bytes = Buffer.isBuffer(val)
1623
- ? val
1624
- : Buffer.from(val, encoding);
1625
- const len = bytes.length;
1626
- if (len === 0) {
1627
- throw new TypeError('The value "' + val +
1628
- '" is invalid for argument "value"')
1629
- }
1630
- for (i = 0; i < end - start; ++i) {
1631
- this[i + start] = bytes[i % len];
1632
- }
1633
- }
1634
- return this
1635
- };
1636
- const errors = {};
1637
- function E (sym, getMessage, Base) {
1638
- errors[sym] = class NodeError extends Base {
1639
- constructor () {
1640
- super();
1641
- Object.defineProperty(this, 'message', {
1642
- value: getMessage.apply(this, arguments),
1643
- writable: true,
1644
- configurable: true
1645
- });
1646
- this.name = `${this.name} [${sym}]`;
1647
- this.stack;
1648
- delete this.name;
1649
- }
1650
- get code () {
1651
- return sym
1652
- }
1653
- set code (value) {
1654
- Object.defineProperty(this, 'code', {
1655
- configurable: true,
1656
- enumerable: true,
1657
- value,
1658
- writable: true
1659
- });
1660
- }
1661
- toString () {
1662
- return `${this.name} [${sym}]: ${this.message}`
1663
- }
1664
- };
1665
- }
1666
- E('ERR_BUFFER_OUT_OF_BOUNDS',
1667
- function (name) {
1668
- if (name) {
1669
- return `${name} is outside of buffer bounds`
1670
- }
1671
- return 'Attempt to access memory outside buffer bounds'
1672
- }, RangeError);
1673
- E('ERR_INVALID_ARG_TYPE',
1674
- function (name, actual) {
1675
- return `The "${name}" argument must be of type number. Received type ${typeof actual}`
1676
- }, TypeError);
1677
- E('ERR_OUT_OF_RANGE',
1678
- function (str, range, input) {
1679
- let msg = `The value of "${str}" is out of range.`;
1680
- let received = input;
1681
- if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
1682
- received = addNumericalSeparator(String(input));
1683
- } else if (typeof input === 'bigint') {
1684
- received = String(input);
1685
- if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
1686
- received = addNumericalSeparator(received);
1687
- }
1688
- received += 'n';
1689
- }
1690
- msg += ` It must be ${range}. Received ${received}`;
1691
- return msg
1692
- }, RangeError);
1693
- function addNumericalSeparator (val) {
1694
- let res = '';
1695
- let i = val.length;
1696
- const start = val[0] === '-' ? 1 : 0;
1697
- for (; i >= start + 4; i -= 3) {
1698
- res = `_${val.slice(i - 3, i)}${res}`;
1699
- }
1700
- return `${val.slice(0, i)}${res}`
1701
- }
1702
- function checkBounds (buf, offset, byteLength) {
1703
- validateNumber(offset, 'offset');
1704
- if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
1705
- boundsError(offset, buf.length - (byteLength + 1));
1706
- }
1707
- }
1708
- function checkIntBI (value, min, max, buf, offset, byteLength) {
1709
- if (value > max || value < min) {
1710
- const n = typeof min === 'bigint' ? 'n' : '';
1711
- let range;
1712
- {
1713
- if (min === 0 || min === BigInt(0)) {
1714
- range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
1715
- } else {
1716
- range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
1717
- `${(byteLength + 1) * 8 - 1}${n}`;
1718
- }
1719
- }
1720
- throw new errors.ERR_OUT_OF_RANGE('value', range, value)
1721
- }
1722
- checkBounds(buf, offset, byteLength);
1723
- }
1724
- function validateNumber (value, name) {
1725
- if (typeof value !== 'number') {
1726
- throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
1727
- }
1728
- }
1729
- function boundsError (value, length, type) {
1730
- if (Math.floor(value) !== value) {
1731
- validateNumber(value, type);
1732
- throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
1733
- }
1734
- if (length < 0) {
1735
- throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
1736
- }
1737
- throw new errors.ERR_OUT_OF_RANGE('offset',
1738
- `>= ${0} and <= ${length}`,
1739
- value)
1740
- }
1741
- const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
1742
- function base64clean (str) {
1743
- str = str.split('=')[0];
1744
- str = str.trim().replace(INVALID_BASE64_RE, '');
1745
- if (str.length < 2) return ''
1746
- while (str.length % 4 !== 0) {
1747
- str = str + '=';
1748
- }
1749
- return str
1750
- }
1751
- function utf8ToBytes (string, units) {
1752
- units = units || Infinity;
1753
- let codePoint;
1754
- const length = string.length;
1755
- let leadSurrogate = null;
1756
- const bytes = [];
1757
- for (let i = 0; i < length; ++i) {
1758
- codePoint = string.charCodeAt(i);
1759
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
1760
- if (!leadSurrogate) {
1761
- if (codePoint > 0xDBFF) {
1762
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1763
- continue
1764
- } else if (i + 1 === length) {
1765
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1766
- continue
1767
- }
1768
- leadSurrogate = codePoint;
1769
- continue
1770
- }
1771
- if (codePoint < 0xDC00) {
1772
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1773
- leadSurrogate = codePoint;
1774
- continue
1775
- }
1776
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
1777
- } else if (leadSurrogate) {
1778
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1779
- }
1780
- leadSurrogate = null;
1781
- if (codePoint < 0x80) {
1782
- if ((units -= 1) < 0) break
1783
- bytes.push(codePoint);
1784
- } else if (codePoint < 0x800) {
1785
- if ((units -= 2) < 0) break
1786
- bytes.push(
1787
- codePoint >> 0x6 | 0xC0,
1788
- codePoint & 0x3F | 0x80
1789
- );
1790
- } else if (codePoint < 0x10000) {
1791
- if ((units -= 3) < 0) break
1792
- bytes.push(
1793
- codePoint >> 0xC | 0xE0,
1794
- codePoint >> 0x6 & 0x3F | 0x80,
1795
- codePoint & 0x3F | 0x80
1796
- );
1797
- } else if (codePoint < 0x110000) {
1798
- if ((units -= 4) < 0) break
1799
- bytes.push(
1800
- codePoint >> 0x12 | 0xF0,
1801
- codePoint >> 0xC & 0x3F | 0x80,
1802
- codePoint >> 0x6 & 0x3F | 0x80,
1803
- codePoint & 0x3F | 0x80
1804
- );
1805
- } else {
1806
- throw new Error('Invalid code point')
1807
- }
1808
- }
1809
- return bytes
1810
- }
1811
- function asciiToBytes (str) {
1812
- const byteArray = [];
1813
- for (let i = 0; i < str.length; ++i) {
1814
- byteArray.push(str.charCodeAt(i) & 0xFF);
1815
- }
1816
- return byteArray
1817
- }
1818
- function utf16leToBytes (str, units) {
1819
- let c, hi, lo;
1820
- const byteArray = [];
1821
- for (let i = 0; i < str.length; ++i) {
1822
- if ((units -= 2) < 0) break
1823
- c = str.charCodeAt(i);
1824
- hi = c >> 8;
1825
- lo = c % 256;
1826
- byteArray.push(lo);
1827
- byteArray.push(hi);
1828
- }
1829
- return byteArray
1830
- }
1831
- function base64ToBytes (str) {
1832
- return base64.toByteArray(base64clean(str))
1833
- }
1834
- function blitBuffer (src, dst, offset, length) {
1835
- let i;
1836
- for (i = 0; i < length; ++i) {
1837
- if ((i + offset >= dst.length) || (i >= src.length)) break
1838
- dst[i + offset] = src[i];
1839
- }
1840
- return i
1841
- }
1842
- function isInstance (obj, type) {
1843
- return obj instanceof type ||
1844
- (obj != null && obj.constructor != null && obj.constructor.name != null &&
1845
- obj.constructor.name === type.name)
1846
- }
1847
- function numberIsNaN (obj) {
1848
- return obj !== obj
1849
- }
1850
- const hexSliceLookupTable = (function () {
1851
- const alphabet = '0123456789abcdef';
1852
- const table = new Array(256);
1853
- for (let i = 0; i < 16; ++i) {
1854
- const i16 = i * 16;
1855
- for (let j = 0; j < 16; ++j) {
1856
- table[i16 + j] = alphabet[i] + alphabet[j];
1857
- }
1858
- }
1859
- return table
1860
- })();
1861
- function defineBigIntMethod (fn) {
1862
- return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
1863
- }
1864
- function BufferBigIntNotDefined () {
1865
- throw new Error('BigInt not supported')
1866
- }
1867
- } (buffer));
1868
- getDefaultExportFromCjs(buffer);
1869
-
1870
- /**
1871
- * @module @zk-kit/utils
1872
- * @version 1.2.0
1873
- * @file Essential zero-knowledge utility library for JavaScript developers.
1874
- * @copyright Ethereum Foundation 2024
1875
- * @license MIT
1876
- * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
1877
- */
1878
- /**
1879
- * @module TypeChecks
1880
- * This module provides utility functions to check data types.
1881
- * It defines a set of supported types and includes functions to check if
1882
- * a value is defined and if it matches a supported type. These functions
1883
- * are useful for type checking and validation in the other libraries,
1884
- * enhancing code robustness and reliability.
1885
- */
1886
- /** @internal */
1887
- const supportedTypes = [
1888
- "number",
1889
- "string",
1890
- "function",
1891
- "Array",
1892
- "Uint8Array",
1893
- "Buffer",
1894
- "object",
1895
- "bigint",
1896
- "stringified-bigint",
1897
- "hexadecimal",
1898
- "bignumber",
1899
- "bignumberish"
1900
- ];
1901
- /**
1902
- * Returns true if the value is a number, false otherwise.
1903
- * @param value The value to be checked.
1904
- */
1905
- function isNumber(value) {
1906
- return typeof value === "number";
1907
- }
1908
- /**
1909
- * Returns true if the value is a string, false otherwise.
1910
- * @param value The value to be checked.
1911
- */
1912
- function isString(value) {
1913
- return typeof value === "string";
1914
- }
1915
- /**
1916
- * Returns true if the value is a function, false otherwise.
1917
- * @param value The value to be checked.
1918
- */
1919
- function isFunction(value) {
1920
- return typeof value === "function";
1921
- }
1922
- /**
1923
- * Returns true if the value is an object, false otherwise.
1924
- * Please, note that arrays are also objects in JavaScript.
1925
- * @param value The value to be checked.
1926
- */
1927
- function isObject(value) {
1928
- return typeof value === "object";
1929
- }
1930
- /**
1931
- * Returns true if the value is an Array instance, false otherwise.
1932
- * @param value The value to be checked.
1933
- */
1934
- function isArray(value) {
1935
- return isObject(value) && Array.isArray(value);
1936
- }
1937
- /**
1938
- * Returns true if the value is a Uint8Array instance, false otherwise.
1939
- * @param value The value to be checked.
1940
- */
1941
- function isUint8Array(value) {
1942
- return value instanceof Uint8Array;
1943
- }
1944
- /**
1945
- * Returns true if the value is a Buffer instance, false otherwise.
1946
- * @param value The value to be checked.
1947
- */
1948
- function isBuffer(value) {
1949
- return buffer.Buffer.isBuffer(value);
1950
- }
1951
- /**
1952
- * Returns true if the value is a bigint, false otherwise.
1953
- * @param value The value to be checked.
1954
- */
1955
- function isBigInt(value) {
1956
- return typeof value === "bigint";
1957
- }
1958
- /**
1959
- * Checks if the given value is a string that represents a valid bigint.
1960
- * @param value The value to be checked if it's a stringified bigint.
1961
- */
1962
- function isStringifiedBigInt(value) {
1963
- if (!isString(value)) {
1964
- return false;
1965
- }
1966
- try {
1967
- BigInt(value);
1968
- return true;
1969
- }
1970
- catch {
1971
- return false;
1972
- }
1973
- }
1974
- /**
1975
- * Checks if a string is a valid hexadecimal string representation.
1976
- * If 'prefix' is 'true', the string must start with '0x' or '0X' followed by one or more
1977
- * hexadecimal digits (0-9, a-f, A-F), otherwise no prefix is expected. 'prefix' is optional and
1978
- * if its value it is not explicitly defined it will be set to 'true' by default.
1979
- * @param value The string to be tested.
1980
- * @param prefix A boolean to include or not a '0x' or '0X' prefix.
1981
- */
1982
- function isHexadecimal(value, prefix = true) {
1983
- if (!isString(value)) {
1984
- return false;
1985
- }
1986
- if (prefix) {
1987
- return /^(0x|0X)[0-9a-fA-F]+$/.test(value);
1988
- }
1989
- return /^[0-9a-fA-F]+$/.test(value);
1990
- }
1991
- /**
1992
- * Checks if the given value can be considered as BigNumber.
1993
- * A value is considered a BigNumber if it is a bigint or a string
1994
- * that can be converted to a bigint (via `Bigint(s)`).
1995
- * @param value The value to check.
1996
- */
1997
- function isBigNumber(value) {
1998
- return isBigInt(value) || isStringifiedBigInt(value);
1999
- }
2000
- /**
2001
- * Checks if the given value can be considered as BigNumberish.
2002
- * A value is considered BigNumberish if it meets
2003
- * any of the following conditions: it's a number, a bigint, a string
2004
- * that can be converted to a bigint, a hexadecimal
2005
- * string, or a Buffer object.
2006
- * @param value The value to check.
2007
- */
2008
- function isBigNumberish(value) {
2009
- return (isNumber(value) ||
2010
- isBigInt(value) ||
2011
- isStringifiedBigInt(value) ||
2012
- isHexadecimal(value) ||
2013
- isBuffer(value) ||
2014
- isUint8Array(value));
2015
- }
2016
- /**
2017
- * Returns true if the value type is the same as the type passed
2018
- * as the second parameter, false otherwise.
2019
- * @param value
2020
- * @param type The expected type.
2021
- */
2022
- function isType(value, type) {
2023
- switch (type) {
2024
- case "number":
2025
- return isNumber(value);
2026
- case "string":
2027
- return isString(value);
2028
- case "function":
2029
- return isFunction(value);
2030
- case "Array":
2031
- return isArray(value);
2032
- case "Uint8Array":
2033
- return isUint8Array(value);
2034
- case "Buffer":
2035
- return isBuffer(value);
2036
- case "object":
2037
- return isObject(value);
2038
- case "bigint":
2039
- return isBigInt(value);
2040
- case "stringified-bigint":
2041
- return isStringifiedBigInt(value);
2042
- case "hexadecimal":
2043
- return isHexadecimal(value);
2044
- case "bignumber":
2045
- return isBigNumber(value);
2046
- case "bignumberish":
2047
- return isBigNumberish(value);
2048
- default:
2049
- return false;
2050
- }
2051
- }
2052
- /**
2053
- * Returns true if the type is being supported by this utility
2054
- * functions, false otherwise.
2055
- * @param type The type to be checked.
2056
- */
2057
- function isSupportedType(type) {
2058
- return supportedTypes.includes(type);
2059
- }
2060
-
2061
- /**
2062
- * @module @zk-kit/utils
2063
- * @version 1.2.0
2064
- * @file Essential zero-knowledge utility library for JavaScript developers.
2065
- * @copyright Ethereum Foundation 2024
2066
- * @license MIT
2067
- * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
2068
- */
2069
- /**
2070
- * @throws Throws a type error if the parameter value is not a string.
2071
- * @param parameterValue The parameter value.
2072
- * @param parameterName The parameter name.
2073
- */
2074
- function requireString(parameterValue, parameterName) {
2075
- if (!isString(parameterValue)) {
2076
- throw new TypeError(`Parameter '${parameterName}' is not a string, received type: ${typeof parameterValue}`);
2077
- }
2078
- }
2079
- /**
2080
- * @throws Throws a type error if the parameter value type is not part of the list of types.
2081
- * @param parameterValue The parameter value.
2082
- * @param parameterName The parameter name.
2083
- */
2084
- function requireTypes(parameterValue, parameterName, types) {
2085
- for (const type of types) {
2086
- if (!isSupportedType(type)) {
2087
- throw new Error(`Type '${type}' is not supported`);
2088
- }
2089
- }
2090
- for (const type of types) {
2091
- if (isType(parameterValue, type)) {
2092
- return;
2093
- }
2094
- }
2095
- throw new TypeError(`Parameter '${parameterName}' is none of the following types: ${types.join(", ")}`);
2096
- }
2097
-
2098
- /**
2099
- * @module @zk-kit/utils
2100
- * @version 1.2.0
2101
- * @file Essential zero-knowledge utility library for JavaScript developers.
2102
- * @copyright Ethereum Foundation 2024
2103
- * @license MIT
2104
- * @see [Github]{@link https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils}
2105
- */
2106
- /**
2107
- * Converts bytes to a base64 string. It accepts 'Buffer' or 'Uint8Array'.
2108
- * @param value The bytes to convert.
2109
- * @returns The converted base64 string.
2110
- */
2111
- function bufferToBase64(value) {
2112
- requireTypes(value, "value", ["Buffer", "Uint8Array"]);
2113
- return buffer.Buffer.from(value).toString("base64");
2114
- }
2115
- /**
2116
- * Converts a base64 string to bytes (i.e. a buffer). This function does not check
2117
- * if the input value is a valid base64 string. If there are unsupported characters
2118
- * they will be ignored.
2119
- * @param value The base64 string to convert.
2120
- * @returns The converted buffer.
2121
- */
2122
- function base64ToBuffer(value) {
2123
- requireString(value, "value");
2124
- return buffer.Buffer.from(value, "base64");
2125
- }
2126
- /**
2127
- * Converts text (utf8) to a base64 string.
2128
- * @param value The text to convert.
2129
- * @returns The converted base64 string.
2130
- */
2131
- function textToBase64(value) {
2132
- requireString(value, "value");
2133
- return buffer.Buffer.from(value, "utf8").toString("base64");
2134
- }
2135
-
2136
- var poseidon2$1 = {};
2137
-
2138
- const F = BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617');
2139
- const N_ROUNDS_F = 8;
2140
- const N_ROUNDS_P = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68];
2141
- const pow5 = v => {
2142
- let o = v * v;
2143
- return v * o * o % F;
2144
- };
2145
- function mix(state, M) {
2146
- const out = [];
2147
- for (let x = 0; x < state.length; x++) {
2148
- let o = 0n;
2149
- for (let y = 0; y < state.length; y++) {
2150
- o = o + M[x][y] * state[y];
2151
- }
2152
- out.push(o % F);
2153
- }
2154
- return out;
2155
- }
2156
- function poseidon(_inputs, opt) {
2157
- const inputs = _inputs.map(i => BigInt(i));
2158
- if (inputs.length <= 0) {
2159
- throw new Error('poseidon-lite: Not enough inputs');
2160
- }
2161
- if (inputs.length > N_ROUNDS_P.length) {
2162
- throw new Error('poseidon-lite: Too many inputs');
2163
- }
2164
- const t = inputs.length + 1;
2165
- const nRoundsF = N_ROUNDS_F;
2166
- const nRoundsP = N_ROUNDS_P[t - 2];
2167
- const {
2168
- C,
2169
- M
2170
- } = opt;
2171
- if (M.length !== t) {
2172
- throw new Error(`poseidon-lite: Incorrect M length, expected ${t} got ${M.length}`);
2173
- }
2174
- let state = [0n, ...inputs];
2175
- for (let x = 0; x < nRoundsF + nRoundsP; x++) {
2176
- for (let y = 0; y < state.length; y++) {
2177
- state[y] = state[y] + C[x * t + y];
2178
- if (x < nRoundsF / 2 || x >= nRoundsF / 2 + nRoundsP) state[y] = pow5(state[y]);else if (y === 0) state[y] = pow5(state[y]);
2179
- }
2180
- state = mix(state, M);
2181
- }
2182
- return state[0];
2183
- }
2184
- var poseidon_1 = poseidon;
2185
- getDefaultExportFromCjs(poseidon_1);
2186
-
2187
- var unstringify = {};
2188
-
2189
- Object.defineProperty(unstringify, "__esModule", {
2190
- value: true
2191
- });
2192
- unstringify.default = unstringifyBigInts;
2193
- function unstringifyBigInts(o) {
2194
- if (Array.isArray(o)) {
2195
- return o.map(unstringifyBigInts);
2196
- } else if (typeof o == 'object') {
2197
- const res = {};
2198
- for (const [key, val] of Object.entries(o)) {
2199
- res[key] = unstringifyBigInts(val);
2200
- }
2201
- return res;
2202
- }
2203
- const byteArray = Uint8Array.from(atob(o), c => c.charCodeAt(0));
2204
- const hex = [...byteArray].map(x => x.toString(16).padStart(2, '0')).join('');
2205
- return BigInt(`0x${hex}`);
2206
- }
2207
-
2208
- var _2 = {};
2209
-
2210
- Object.defineProperty(_2, "__esModule", {
2211
- value: true
2212
- });
2213
- _2.default = void 0;
2214
- var _default = {
2215
- C: ['DumlkrqalRjQWYbWVvQMIRTEmTwRuymTjSHUcwTNjm4=', 'APFEUjXyFIxZhlhxafwbzYh7CNTQCGjfVpb/9AlW6GQ=', 'CN/zSH6KyZ4fKaBY0PqAuTDHKHMLerNs6HnziQ7Pc/U=', 'Lye+aQ/a7kbDzij3UysTyFbDU0LIS9puIJZjEPrcAdA=', 'KyrhrPaLe40kFr6/PU9iNLdj/gS4BD7ki4MnvryhbPI=', 'AxnQYgcr737MperAb5fU1VlSwXWrawPq5ktEx9vxHPo=', 'KIE9yuuuqoKKN234evSmO8i3vyetScYpjvezh78oUm0=', 'JydnOyzLyQPxgb844cHUDSAzhlIAw1K8FQkord35y3g=', 'I07EXKJ3J8LnSr0rKhSUzW771D40BYfWuPueMeZcxjI=', 'FbUlNAMa4Y9/hiyyz3z3YKsQqBUKM3sczZn/boeX1Cg=', 'Dcj61tnks19e2aPRhrec444Oio0bWLEy1wHU7s9o0fY=', 'G82V/8IR+8pgD3B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F7vH3tsIU2oiIIQ/Ti2l8dqp69796KXqc0R5jSI=', 'HaVcyQDw0h9KPmlDkZGKGzwjsqx3PGs++I4uQigyUWE='],
2216
- M: [['EJt/QRug5MmytwyvXDansZS+fBGtJDeL/ttoWSuoEYs=', 'Fu1B4Tu5wMZq4RlCT928vJMU3J/b3upV1sZFQ9xJA+A=', 'K5C7oA/KBYn2F+fcv+guDfcGq2QM6yR7eRqTt042c20='], ['KWnyfu0xpIC5w2x2Q3nbyizI/dFBXD3e1ilAvN4L13E=', 'LiQZ+ewC7DlMmHHIMpY9wbiddDyMe5ZAKbIxFoex/iM=', 'EBBx8AMjebaXMVh2aQ8FPRSNThCfX7BlyKrMVaD4m/o='], ['FDAh7GhqPzMNX55lRjgGXObNeeKMWzdTMmJE7mWhsac=', 'F2zAKWla0CWCpw7/CKb9mdBX4S5Y59e2sWzfq8juKRE=', 'GaP8ClZwK/QXun/uOAJZP6ZERwMHBD93cyec1x0l1eA=']]
2217
- };
2218
- _2.default = _default;
2219
-
2220
- Object.defineProperty(poseidon2$1, "__esModule", {
2221
- value: true
2222
- });
2223
- var poseidon2_2 = poseidon2$1.poseidon2 = poseidon2;
2224
- var _poseidon = _interopRequireDefault(poseidon_1);
2225
- var _unstringify = _interopRequireDefault(unstringify);
2226
- var _ = _interopRequireDefault(_2);
2227
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2228
- const c = (0, _unstringify.default)(_.default);
2229
- function poseidon2(inputs) {
2230
- return (0, _poseidon.default)(inputs, c);
2231
- }
12
+ var conversions = require('@zk-kit/utils/conversions');
13
+ var typeChecks = require('@zk-kit/utils/type-checks');
14
+ var poseidon2 = require('poseidon-lite/poseidon2');
2232
15
 
2233
16
  /**
2234
17
  * The Semaphore identity is essentially an {@link https://www.rfc-editor.org/rfc/rfc8032 | EdDSA}
@@ -2260,7 +43,7 @@ class Identity {
2260
43
  this._privateKey = eddsa.privateKey;
2261
44
  this._secretScalar = eddsa.secretScalar;
2262
45
  this._publicKey = eddsa.publicKey;
2263
- this._commitment = poseidon2_2(this._publicKey);
46
+ this._commitment = poseidon2.poseidon2(this._publicKey);
2264
47
  }
2265
48
  /**
2266
49
  * Returns the private key.
@@ -2295,10 +78,10 @@ class Identity {
2295
78
  * @returns The private key as a base64 string.
2296
79
  */
2297
80
  export() {
2298
- if (isString(this._privateKey)) {
2299
- return textToBase64(this._privateKey);
81
+ if (typeChecks.isString(this._privateKey)) {
82
+ return conversions.textToBase64(this._privateKey);
2300
83
  }
2301
- return bufferToBase64(this.privateKey);
84
+ return conversions.bufferToBase64(this.privateKey);
2302
85
  }
2303
86
  /**
2304
87
  * Returns a Semaphore identity based on a private key encoded as a base64 string.
@@ -2307,7 +90,7 @@ class Identity {
2307
90
  * @returns The Semaphore identity.
2308
91
  */
2309
92
  static import(privateKey) {
2310
- return new Identity(base64ToBuffer(privateKey));
93
+ return new Identity(conversions.base64ToBuffer(privateKey));
2311
94
  }
2312
95
  /**
2313
96
  * Generates a signature for a given message using the private key.