@taquito/sapling 24.3.0-beta.4 → 24.3.0-beta.7

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 (29) hide show
  1. package/dist/lib/constants.js +2 -1
  2. package/dist/lib/sapling-forger/sapling-forger.js +12 -11
  3. package/dist/lib/sapling-keys/in-memory-proving-key.js +3 -2
  4. package/dist/lib/sapling-keys/in-memory-spending-key.js +3 -2
  5. package/dist/lib/sapling-keys/in-memory-viewing-key.js +3 -2
  6. package/dist/lib/sapling-module-wrapper.js +6 -7
  7. package/dist/lib/sapling-output-params.js +12 -0
  8. package/dist/lib/sapling-state/sapling-state.js +8 -7
  9. package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +10 -9
  10. package/dist/lib/sapling-tx-viewer/helpers.js +3 -2
  11. package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +5 -4
  12. package/dist/lib/sapling-wasm.js +22 -0
  13. package/dist/lib/taquito-sapling.js +2 -1
  14. package/dist/lib/version.js +2 -2
  15. package/dist/taquito-sapling.es6.js +2454 -71
  16. package/dist/taquito-sapling.es6.js.map +1 -1
  17. package/dist/taquito-sapling.umd.js +2457 -94
  18. package/dist/taquito-sapling.umd.js.map +1 -1
  19. package/dist/types/constants.d.ts +1 -0
  20. package/dist/types/sapling-forger/sapling-forger.d.ts +1 -0
  21. package/dist/types/sapling-keys/in-memory-viewing-key.d.ts +1 -0
  22. package/dist/types/sapling-module-wrapper.d.ts +1 -0
  23. package/dist/types/sapling-output-params.d.ts +6 -0
  24. package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +1 -0
  25. package/dist/types/sapling-tx-viewer/helpers.d.ts +1 -0
  26. package/dist/types/sapling-wasm.d.ts +1 -0
  27. package/package.json +8 -6
  28. package/saplingOutputParams.d.ts +5 -0
  29. package/saplingOutputParams.js +8 -5
@@ -2,10 +2,11 @@ import BigNumberJs from 'bignumber.js';
2
2
  import { MichelCodecPacker } from '@taquito/taquito';
3
3
  import { b58Encode, PrefixV2, bytesToString, toHexBuf, stringToBytes, hex2buf, mergebuf, hex2Bytes, num2PaddedHex, b58DecodeAndCheckPrefix, format, b58DecodePublicKeyHash, validateKeyHash, ValidationResult } from '@taquito/utils';
4
4
  import { ParameterValidationError, TaquitoError, InvalidKeyHashError, InvalidAddressError } from '@taquito/core';
5
- import * as sapling from '@taquito/sapling-wasm';
6
- import { merkleHash } from '@taquito/sapling-wasm';
5
+ import { keyAgreement, getRawPaymentAddressFromIncomingViewingKey, verifyCommitment, computeNullifier, merkleHash, withProvingContext, randR, getOutgoingViewingKey, preparePartialOutputDescription, getDiversifiedFromRawPaymentAddress, deriveEphemeralPublicKey, getPkdFromRawPaymentAddress, createBindingSignature, initParameters, getExtendedFullViewingKeyFromSpendingKey, getIncomingViewingKey, getPaymentAddressFromViewingKey, getExtendedSpendingKey, prepareSpendDescriptionWithSpendingKey, signSpendDescription, getProofAuthorizingKey, prepareSpendDescriptionWithAuthorizingKey } from '@taquito/sapling-wasm';
7
6
  import blake from 'blakejs';
8
7
  import { openSecretBox, secretBox } from '@stablelib/nacl';
8
+ import '../saplingOutputParams.js';
9
+ import saplingSpendParams from '@taquito/sapling-spend-params';
9
10
  import toBuffer from 'typedarray-to-buffer';
10
11
 
11
12
  /******************************************************************************
@@ -43,6 +44,2377 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
43
44
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
45
  };
45
46
 
47
+ var buffer = {};
48
+
49
+ var base64Js = {};
50
+
51
+ var hasRequiredBase64Js;
52
+
53
+ function requireBase64Js () {
54
+ if (hasRequiredBase64Js) return base64Js;
55
+ hasRequiredBase64Js = 1;
56
+
57
+ base64Js.byteLength = byteLength;
58
+ base64Js.toByteArray = toByteArray;
59
+ base64Js.fromByteArray = fromByteArray;
60
+
61
+ var lookup = [];
62
+ var revLookup = [];
63
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
64
+
65
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
66
+ for (var i = 0, len = code.length; i < len; ++i) {
67
+ lookup[i] = code[i];
68
+ revLookup[code.charCodeAt(i)] = i;
69
+ }
70
+
71
+ // Support decoding URL-safe base64 strings, as Node.js does.
72
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
73
+ revLookup['-'.charCodeAt(0)] = 62;
74
+ revLookup['_'.charCodeAt(0)] = 63;
75
+
76
+ function getLens (b64) {
77
+ var len = b64.length;
78
+
79
+ if (len % 4 > 0) {
80
+ throw new Error('Invalid string. Length must be a multiple of 4')
81
+ }
82
+
83
+ // Trim off extra bytes after placeholder bytes are found
84
+ // See: https://github.com/beatgammit/base64-js/issues/42
85
+ var validLen = b64.indexOf('=');
86
+ if (validLen === -1) validLen = len;
87
+
88
+ var placeHoldersLen = validLen === len
89
+ ? 0
90
+ : 4 - (validLen % 4);
91
+
92
+ return [validLen, placeHoldersLen]
93
+ }
94
+
95
+ // base64 is 4/3 + up to two characters of the original data
96
+ function byteLength (b64) {
97
+ var lens = getLens(b64);
98
+ var validLen = lens[0];
99
+ var placeHoldersLen = lens[1];
100
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
101
+ }
102
+
103
+ function _byteLength (b64, validLen, placeHoldersLen) {
104
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
105
+ }
106
+
107
+ function toByteArray (b64) {
108
+ var tmp;
109
+ var lens = getLens(b64);
110
+ var validLen = lens[0];
111
+ var placeHoldersLen = lens[1];
112
+
113
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
114
+
115
+ var curByte = 0;
116
+
117
+ // if there are placeholders, only get up to the last complete 4 chars
118
+ var len = placeHoldersLen > 0
119
+ ? validLen - 4
120
+ : validLen;
121
+
122
+ var i;
123
+ for (i = 0; i < len; i += 4) {
124
+ tmp =
125
+ (revLookup[b64.charCodeAt(i)] << 18) |
126
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
127
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
128
+ revLookup[b64.charCodeAt(i + 3)];
129
+ arr[curByte++] = (tmp >> 16) & 0xFF;
130
+ arr[curByte++] = (tmp >> 8) & 0xFF;
131
+ arr[curByte++] = tmp & 0xFF;
132
+ }
133
+
134
+ if (placeHoldersLen === 2) {
135
+ tmp =
136
+ (revLookup[b64.charCodeAt(i)] << 2) |
137
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
138
+ arr[curByte++] = tmp & 0xFF;
139
+ }
140
+
141
+ if (placeHoldersLen === 1) {
142
+ tmp =
143
+ (revLookup[b64.charCodeAt(i)] << 10) |
144
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
145
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
146
+ arr[curByte++] = (tmp >> 8) & 0xFF;
147
+ arr[curByte++] = tmp & 0xFF;
148
+ }
149
+
150
+ return arr
151
+ }
152
+
153
+ function tripletToBase64 (num) {
154
+ return lookup[num >> 18 & 0x3F] +
155
+ lookup[num >> 12 & 0x3F] +
156
+ lookup[num >> 6 & 0x3F] +
157
+ lookup[num & 0x3F]
158
+ }
159
+
160
+ function encodeChunk (uint8, start, end) {
161
+ var tmp;
162
+ var output = [];
163
+ for (var i = start; i < end; i += 3) {
164
+ tmp =
165
+ ((uint8[i] << 16) & 0xFF0000) +
166
+ ((uint8[i + 1] << 8) & 0xFF00) +
167
+ (uint8[i + 2] & 0xFF);
168
+ output.push(tripletToBase64(tmp));
169
+ }
170
+ return output.join('')
171
+ }
172
+
173
+ function fromByteArray (uint8) {
174
+ var tmp;
175
+ var len = uint8.length;
176
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
177
+ var parts = [];
178
+ var maxChunkLength = 16383; // must be multiple of 3
179
+
180
+ // go through the array every three bytes, we'll deal with trailing stuff later
181
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
182
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
183
+ }
184
+
185
+ // pad the end with zeros, but make sure to not forget the extra bytes
186
+ if (extraBytes === 1) {
187
+ tmp = uint8[len - 1];
188
+ parts.push(
189
+ lookup[tmp >> 2] +
190
+ lookup[(tmp << 4) & 0x3F] +
191
+ '=='
192
+ );
193
+ } else if (extraBytes === 2) {
194
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
195
+ parts.push(
196
+ lookup[tmp >> 10] +
197
+ lookup[(tmp >> 4) & 0x3F] +
198
+ lookup[(tmp << 2) & 0x3F] +
199
+ '='
200
+ );
201
+ }
202
+
203
+ return parts.join('')
204
+ }
205
+ return base64Js;
206
+ }
207
+
208
+ var ieee754 = {};
209
+
210
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
211
+
212
+ var hasRequiredIeee754;
213
+
214
+ function requireIeee754 () {
215
+ if (hasRequiredIeee754) return ieee754;
216
+ hasRequiredIeee754 = 1;
217
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
218
+ var e, m;
219
+ var eLen = (nBytes * 8) - mLen - 1;
220
+ var eMax = (1 << eLen) - 1;
221
+ var eBias = eMax >> 1;
222
+ var nBits = -7;
223
+ var i = isLE ? (nBytes - 1) : 0;
224
+ var d = isLE ? -1 : 1;
225
+ var s = buffer[offset + i];
226
+
227
+ i += d;
228
+
229
+ e = s & ((1 << (-nBits)) - 1);
230
+ s >>= (-nBits);
231
+ nBits += eLen;
232
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
233
+
234
+ m = e & ((1 << (-nBits)) - 1);
235
+ e >>= (-nBits);
236
+ nBits += mLen;
237
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
238
+
239
+ if (e === 0) {
240
+ e = 1 - eBias;
241
+ } else if (e === eMax) {
242
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
243
+ } else {
244
+ m = m + Math.pow(2, mLen);
245
+ e = e - eBias;
246
+ }
247
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
248
+ };
249
+
250
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
251
+ var e, m, c;
252
+ var eLen = (nBytes * 8) - mLen - 1;
253
+ var eMax = (1 << eLen) - 1;
254
+ var eBias = eMax >> 1;
255
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
256
+ var i = isLE ? 0 : (nBytes - 1);
257
+ var d = isLE ? 1 : -1;
258
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
259
+
260
+ value = Math.abs(value);
261
+
262
+ if (isNaN(value) || value === Infinity) {
263
+ m = isNaN(value) ? 1 : 0;
264
+ e = eMax;
265
+ } else {
266
+ e = Math.floor(Math.log(value) / Math.LN2);
267
+ if (value * (c = Math.pow(2, -e)) < 1) {
268
+ e--;
269
+ c *= 2;
270
+ }
271
+ if (e + eBias >= 1) {
272
+ value += rt / c;
273
+ } else {
274
+ value += rt * Math.pow(2, 1 - eBias);
275
+ }
276
+ if (value * c >= 2) {
277
+ e++;
278
+ c /= 2;
279
+ }
280
+
281
+ if (e + eBias >= eMax) {
282
+ m = 0;
283
+ e = eMax;
284
+ } else if (e + eBias >= 1) {
285
+ m = ((value * c) - 1) * Math.pow(2, mLen);
286
+ e = e + eBias;
287
+ } else {
288
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
289
+ e = 0;
290
+ }
291
+ }
292
+
293
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
294
+
295
+ e = (e << mLen) | m;
296
+ eLen += mLen;
297
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
298
+
299
+ buffer[offset + i - d] |= s * 128;
300
+ };
301
+ return ieee754;
302
+ }
303
+
304
+ /*!
305
+ * The buffer module from node.js, for the browser.
306
+ *
307
+ * @author Feross Aboukhadijeh <https://feross.org>
308
+ * @license MIT
309
+ */
310
+
311
+ var hasRequiredBuffer;
312
+
313
+ function requireBuffer () {
314
+ if (hasRequiredBuffer) return buffer;
315
+ hasRequiredBuffer = 1;
316
+ (function (exports$1) {
317
+
318
+ const base64 = requireBase64Js();
319
+ const ieee754 = requireIeee754();
320
+ const customInspectSymbol =
321
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
322
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
323
+ : null;
324
+
325
+ exports$1.Buffer = Buffer;
326
+ exports$1.SlowBuffer = SlowBuffer;
327
+ exports$1.INSPECT_MAX_BYTES = 50;
328
+
329
+ const K_MAX_LENGTH = 0x7fffffff;
330
+ exports$1.kMaxLength = K_MAX_LENGTH;
331
+
332
+ /**
333
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
334
+ * === true Use Uint8Array implementation (fastest)
335
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
336
+ * implementation (most compatible, even IE6)
337
+ *
338
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
339
+ * Opera 11.6+, iOS 4.2+.
340
+ *
341
+ * We report that the browser does not support typed arrays if the are not subclassable
342
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
343
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
344
+ * for __proto__ and has a buggy typed array implementation.
345
+ */
346
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
347
+
348
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
349
+ typeof console.error === 'function') {
350
+ console.error(
351
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
352
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
353
+ );
354
+ }
355
+
356
+ function typedArraySupport () {
357
+ // Can typed array instances can be augmented?
358
+ try {
359
+ const arr = new Uint8Array(1);
360
+ const proto = { foo: function () { return 42 } };
361
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
362
+ Object.setPrototypeOf(arr, proto);
363
+ return arr.foo() === 42
364
+ } catch (e) {
365
+ return false
366
+ }
367
+ }
368
+
369
+ Object.defineProperty(Buffer.prototype, 'parent', {
370
+ enumerable: true,
371
+ get: function () {
372
+ if (!Buffer.isBuffer(this)) return undefined
373
+ return this.buffer
374
+ }
375
+ });
376
+
377
+ Object.defineProperty(Buffer.prototype, 'offset', {
378
+ enumerable: true,
379
+ get: function () {
380
+ if (!Buffer.isBuffer(this)) return undefined
381
+ return this.byteOffset
382
+ }
383
+ });
384
+
385
+ function createBuffer (length) {
386
+ if (length > K_MAX_LENGTH) {
387
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
388
+ }
389
+ // Return an augmented `Uint8Array` instance
390
+ const buf = new Uint8Array(length);
391
+ Object.setPrototypeOf(buf, Buffer.prototype);
392
+ return buf
393
+ }
394
+
395
+ /**
396
+ * The Buffer constructor returns instances of `Uint8Array` that have their
397
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
398
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
399
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
400
+ * returns a single octet.
401
+ *
402
+ * The `Uint8Array` prototype remains unmodified.
403
+ */
404
+
405
+ function Buffer (arg, encodingOrOffset, length) {
406
+ // Common case.
407
+ if (typeof arg === 'number') {
408
+ if (typeof encodingOrOffset === 'string') {
409
+ throw new TypeError(
410
+ 'The "string" argument must be of type string. Received type number'
411
+ )
412
+ }
413
+ return allocUnsafe(arg)
414
+ }
415
+ return from(arg, encodingOrOffset, length)
416
+ }
417
+
418
+ Buffer.poolSize = 8192; // not used by this implementation
419
+
420
+ function from (value, encodingOrOffset, length) {
421
+ if (typeof value === 'string') {
422
+ return fromString(value, encodingOrOffset)
423
+ }
424
+
425
+ if (ArrayBuffer.isView(value)) {
426
+ return fromArrayView(value)
427
+ }
428
+
429
+ if (value == null) {
430
+ throw new TypeError(
431
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
432
+ 'or Array-like Object. Received type ' + (typeof value)
433
+ )
434
+ }
435
+
436
+ if (isInstance(value, ArrayBuffer) ||
437
+ (value && isInstance(value.buffer, ArrayBuffer))) {
438
+ return fromArrayBuffer(value, encodingOrOffset, length)
439
+ }
440
+
441
+ if (typeof SharedArrayBuffer !== 'undefined' &&
442
+ (isInstance(value, SharedArrayBuffer) ||
443
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
444
+ return fromArrayBuffer(value, encodingOrOffset, length)
445
+ }
446
+
447
+ if (typeof value === 'number') {
448
+ throw new TypeError(
449
+ 'The "value" argument must not be of type number. Received type number'
450
+ )
451
+ }
452
+
453
+ const valueOf = value.valueOf && value.valueOf();
454
+ if (valueOf != null && valueOf !== value) {
455
+ return Buffer.from(valueOf, encodingOrOffset, length)
456
+ }
457
+
458
+ const b = fromObject(value);
459
+ if (b) return b
460
+
461
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
462
+ typeof value[Symbol.toPrimitive] === 'function') {
463
+ return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
464
+ }
465
+
466
+ throw new TypeError(
467
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
468
+ 'or Array-like Object. Received type ' + (typeof value)
469
+ )
470
+ }
471
+
472
+ /**
473
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
474
+ * if value is a number.
475
+ * Buffer.from(str[, encoding])
476
+ * Buffer.from(array)
477
+ * Buffer.from(buffer)
478
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
479
+ **/
480
+ Buffer.from = function (value, encodingOrOffset, length) {
481
+ return from(value, encodingOrOffset, length)
482
+ };
483
+
484
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
485
+ // https://github.com/feross/buffer/pull/148
486
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
487
+ Object.setPrototypeOf(Buffer, Uint8Array);
488
+
489
+ function assertSize (size) {
490
+ if (typeof size !== 'number') {
491
+ throw new TypeError('"size" argument must be of type number')
492
+ } else if (size < 0) {
493
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
494
+ }
495
+ }
496
+
497
+ function alloc (size, fill, encoding) {
498
+ assertSize(size);
499
+ if (size <= 0) {
500
+ return createBuffer(size)
501
+ }
502
+ if (fill !== undefined) {
503
+ // Only pay attention to encoding if it's a string. This
504
+ // prevents accidentally sending in a number that would
505
+ // be interpreted as a start offset.
506
+ return typeof encoding === 'string'
507
+ ? createBuffer(size).fill(fill, encoding)
508
+ : createBuffer(size).fill(fill)
509
+ }
510
+ return createBuffer(size)
511
+ }
512
+
513
+ /**
514
+ * Creates a new filled Buffer instance.
515
+ * alloc(size[, fill[, encoding]])
516
+ **/
517
+ Buffer.alloc = function (size, fill, encoding) {
518
+ return alloc(size, fill, encoding)
519
+ };
520
+
521
+ function allocUnsafe (size) {
522
+ assertSize(size);
523
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
524
+ }
525
+
526
+ /**
527
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
528
+ * */
529
+ Buffer.allocUnsafe = function (size) {
530
+ return allocUnsafe(size)
531
+ };
532
+ /**
533
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
534
+ */
535
+ Buffer.allocUnsafeSlow = function (size) {
536
+ return allocUnsafe(size)
537
+ };
538
+
539
+ function fromString (string, encoding) {
540
+ if (typeof encoding !== 'string' || encoding === '') {
541
+ encoding = 'utf8';
542
+ }
543
+
544
+ if (!Buffer.isEncoding(encoding)) {
545
+ throw new TypeError('Unknown encoding: ' + encoding)
546
+ }
547
+
548
+ const length = byteLength(string, encoding) | 0;
549
+ let buf = createBuffer(length);
550
+
551
+ const actual = buf.write(string, encoding);
552
+
553
+ if (actual !== length) {
554
+ // Writing a hex string, for example, that contains invalid characters will
555
+ // cause everything after the first invalid character to be ignored. (e.g.
556
+ // 'abxxcd' will be treated as 'ab')
557
+ buf = buf.slice(0, actual);
558
+ }
559
+
560
+ return buf
561
+ }
562
+
563
+ function fromArrayLike (array) {
564
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
565
+ const buf = createBuffer(length);
566
+ for (let i = 0; i < length; i += 1) {
567
+ buf[i] = array[i] & 255;
568
+ }
569
+ return buf
570
+ }
571
+
572
+ function fromArrayView (arrayView) {
573
+ if (isInstance(arrayView, Uint8Array)) {
574
+ const copy = new Uint8Array(arrayView);
575
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
576
+ }
577
+ return fromArrayLike(arrayView)
578
+ }
579
+
580
+ function fromArrayBuffer (array, byteOffset, length) {
581
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
582
+ throw new RangeError('"offset" is outside of buffer bounds')
583
+ }
584
+
585
+ if (array.byteLength < byteOffset + (length || 0)) {
586
+ throw new RangeError('"length" is outside of buffer bounds')
587
+ }
588
+
589
+ let buf;
590
+ if (byteOffset === undefined && length === undefined) {
591
+ buf = new Uint8Array(array);
592
+ } else if (length === undefined) {
593
+ buf = new Uint8Array(array, byteOffset);
594
+ } else {
595
+ buf = new Uint8Array(array, byteOffset, length);
596
+ }
597
+
598
+ // Return an augmented `Uint8Array` instance
599
+ Object.setPrototypeOf(buf, Buffer.prototype);
600
+
601
+ return buf
602
+ }
603
+
604
+ function fromObject (obj) {
605
+ if (Buffer.isBuffer(obj)) {
606
+ const len = checked(obj.length) | 0;
607
+ const buf = createBuffer(len);
608
+
609
+ if (buf.length === 0) {
610
+ return buf
611
+ }
612
+
613
+ obj.copy(buf, 0, 0, len);
614
+ return buf
615
+ }
616
+
617
+ if (obj.length !== undefined) {
618
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
619
+ return createBuffer(0)
620
+ }
621
+ return fromArrayLike(obj)
622
+ }
623
+
624
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
625
+ return fromArrayLike(obj.data)
626
+ }
627
+ }
628
+
629
+ function checked (length) {
630
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
631
+ // length is NaN (which is otherwise coerced to zero.)
632
+ if (length >= K_MAX_LENGTH) {
633
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
634
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
635
+ }
636
+ return length | 0
637
+ }
638
+
639
+ function SlowBuffer (length) {
640
+ if (+length != length) { // eslint-disable-line eqeqeq
641
+ length = 0;
642
+ }
643
+ return Buffer.alloc(+length)
644
+ }
645
+
646
+ Buffer.isBuffer = function isBuffer (b) {
647
+ return b != null && b._isBuffer === true &&
648
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
649
+ };
650
+
651
+ Buffer.compare = function compare (a, b) {
652
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
653
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
654
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
655
+ throw new TypeError(
656
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
657
+ )
658
+ }
659
+
660
+ if (a === b) return 0
661
+
662
+ let x = a.length;
663
+ let y = b.length;
664
+
665
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
666
+ if (a[i] !== b[i]) {
667
+ x = a[i];
668
+ y = b[i];
669
+ break
670
+ }
671
+ }
672
+
673
+ if (x < y) return -1
674
+ if (y < x) return 1
675
+ return 0
676
+ };
677
+
678
+ Buffer.isEncoding = function isEncoding (encoding) {
679
+ switch (String(encoding).toLowerCase()) {
680
+ case 'hex':
681
+ case 'utf8':
682
+ case 'utf-8':
683
+ case 'ascii':
684
+ case 'latin1':
685
+ case 'binary':
686
+ case 'base64':
687
+ case 'ucs2':
688
+ case 'ucs-2':
689
+ case 'utf16le':
690
+ case 'utf-16le':
691
+ return true
692
+ default:
693
+ return false
694
+ }
695
+ };
696
+
697
+ Buffer.concat = function concat (list, length) {
698
+ if (!Array.isArray(list)) {
699
+ throw new TypeError('"list" argument must be an Array of Buffers')
700
+ }
701
+
702
+ if (list.length === 0) {
703
+ return Buffer.alloc(0)
704
+ }
705
+
706
+ let i;
707
+ if (length === undefined) {
708
+ length = 0;
709
+ for (i = 0; i < list.length; ++i) {
710
+ length += list[i].length;
711
+ }
712
+ }
713
+
714
+ const buffer = Buffer.allocUnsafe(length);
715
+ let pos = 0;
716
+ for (i = 0; i < list.length; ++i) {
717
+ let buf = list[i];
718
+ if (isInstance(buf, Uint8Array)) {
719
+ if (pos + buf.length > buffer.length) {
720
+ if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
721
+ buf.copy(buffer, pos);
722
+ } else {
723
+ Uint8Array.prototype.set.call(
724
+ buffer,
725
+ buf,
726
+ pos
727
+ );
728
+ }
729
+ } else if (!Buffer.isBuffer(buf)) {
730
+ throw new TypeError('"list" argument must be an Array of Buffers')
731
+ } else {
732
+ buf.copy(buffer, pos);
733
+ }
734
+ pos += buf.length;
735
+ }
736
+ return buffer
737
+ };
738
+
739
+ function byteLength (string, encoding) {
740
+ if (Buffer.isBuffer(string)) {
741
+ return string.length
742
+ }
743
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
744
+ return string.byteLength
745
+ }
746
+ if (typeof string !== 'string') {
747
+ throw new TypeError(
748
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
749
+ 'Received type ' + typeof string
750
+ )
751
+ }
752
+
753
+ const len = string.length;
754
+ const mustMatch = (arguments.length > 2 && arguments[2] === true);
755
+ if (!mustMatch && len === 0) return 0
756
+
757
+ // Use a for loop to avoid recursion
758
+ let loweredCase = false;
759
+ for (;;) {
760
+ switch (encoding) {
761
+ case 'ascii':
762
+ case 'latin1':
763
+ case 'binary':
764
+ return len
765
+ case 'utf8':
766
+ case 'utf-8':
767
+ return utf8ToBytes(string).length
768
+ case 'ucs2':
769
+ case 'ucs-2':
770
+ case 'utf16le':
771
+ case 'utf-16le':
772
+ return len * 2
773
+ case 'hex':
774
+ return len >>> 1
775
+ case 'base64':
776
+ return base64ToBytes(string).length
777
+ default:
778
+ if (loweredCase) {
779
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
780
+ }
781
+ encoding = ('' + encoding).toLowerCase();
782
+ loweredCase = true;
783
+ }
784
+ }
785
+ }
786
+ Buffer.byteLength = byteLength;
787
+
788
+ function slowToString (encoding, start, end) {
789
+ let loweredCase = false;
790
+
791
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
792
+ // property of a typed array.
793
+
794
+ // This behaves neither like String nor Uint8Array in that we set start/end
795
+ // to their upper/lower bounds if the value passed is out of range.
796
+ // undefined is handled specially as per ECMA-262 6th Edition,
797
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
798
+ if (start === undefined || start < 0) {
799
+ start = 0;
800
+ }
801
+ // Return early if start > this.length. Done here to prevent potential uint32
802
+ // coercion fail below.
803
+ if (start > this.length) {
804
+ return ''
805
+ }
806
+
807
+ if (end === undefined || end > this.length) {
808
+ end = this.length;
809
+ }
810
+
811
+ if (end <= 0) {
812
+ return ''
813
+ }
814
+
815
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
816
+ end >>>= 0;
817
+ start >>>= 0;
818
+
819
+ if (end <= start) {
820
+ return ''
821
+ }
822
+
823
+ if (!encoding) encoding = 'utf8';
824
+
825
+ while (true) {
826
+ switch (encoding) {
827
+ case 'hex':
828
+ return hexSlice(this, start, end)
829
+
830
+ case 'utf8':
831
+ case 'utf-8':
832
+ return utf8Slice(this, start, end)
833
+
834
+ case 'ascii':
835
+ return asciiSlice(this, start, end)
836
+
837
+ case 'latin1':
838
+ case 'binary':
839
+ return latin1Slice(this, start, end)
840
+
841
+ case 'base64':
842
+ return base64Slice(this, start, end)
843
+
844
+ case 'ucs2':
845
+ case 'ucs-2':
846
+ case 'utf16le':
847
+ case 'utf-16le':
848
+ return utf16leSlice(this, start, end)
849
+
850
+ default:
851
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
852
+ encoding = (encoding + '').toLowerCase();
853
+ loweredCase = true;
854
+ }
855
+ }
856
+ }
857
+
858
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
859
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
860
+ // reliably in a browserify context because there could be multiple different
861
+ // copies of the 'buffer' package in use. This method works even for Buffer
862
+ // instances that were created from another copy of the `buffer` package.
863
+ // See: https://github.com/feross/buffer/issues/154
864
+ Buffer.prototype._isBuffer = true;
865
+
866
+ function swap (b, n, m) {
867
+ const i = b[n];
868
+ b[n] = b[m];
869
+ b[m] = i;
870
+ }
871
+
872
+ Buffer.prototype.swap16 = function swap16 () {
873
+ const len = this.length;
874
+ if (len % 2 !== 0) {
875
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
876
+ }
877
+ for (let i = 0; i < len; i += 2) {
878
+ swap(this, i, i + 1);
879
+ }
880
+ return this
881
+ };
882
+
883
+ Buffer.prototype.swap32 = function swap32 () {
884
+ const len = this.length;
885
+ if (len % 4 !== 0) {
886
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
887
+ }
888
+ for (let i = 0; i < len; i += 4) {
889
+ swap(this, i, i + 3);
890
+ swap(this, i + 1, i + 2);
891
+ }
892
+ return this
893
+ };
894
+
895
+ Buffer.prototype.swap64 = function swap64 () {
896
+ const len = this.length;
897
+ if (len % 8 !== 0) {
898
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
899
+ }
900
+ for (let i = 0; i < len; i += 8) {
901
+ swap(this, i, i + 7);
902
+ swap(this, i + 1, i + 6);
903
+ swap(this, i + 2, i + 5);
904
+ swap(this, i + 3, i + 4);
905
+ }
906
+ return this
907
+ };
908
+
909
+ Buffer.prototype.toString = function toString () {
910
+ const length = this.length;
911
+ if (length === 0) return ''
912
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
913
+ return slowToString.apply(this, arguments)
914
+ };
915
+
916
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
917
+
918
+ Buffer.prototype.equals = function equals (b) {
919
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
920
+ if (this === b) return true
921
+ return Buffer.compare(this, b) === 0
922
+ };
923
+
924
+ Buffer.prototype.inspect = function inspect () {
925
+ let str = '';
926
+ const max = exports$1.INSPECT_MAX_BYTES;
927
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
928
+ if (this.length > max) str += ' ... ';
929
+ return '<Buffer ' + str + '>'
930
+ };
931
+ if (customInspectSymbol) {
932
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
933
+ }
934
+
935
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
936
+ if (isInstance(target, Uint8Array)) {
937
+ target = Buffer.from(target, target.offset, target.byteLength);
938
+ }
939
+ if (!Buffer.isBuffer(target)) {
940
+ throw new TypeError(
941
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
942
+ 'Received type ' + (typeof target)
943
+ )
944
+ }
945
+
946
+ if (start === undefined) {
947
+ start = 0;
948
+ }
949
+ if (end === undefined) {
950
+ end = target ? target.length : 0;
951
+ }
952
+ if (thisStart === undefined) {
953
+ thisStart = 0;
954
+ }
955
+ if (thisEnd === undefined) {
956
+ thisEnd = this.length;
957
+ }
958
+
959
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
960
+ throw new RangeError('out of range index')
961
+ }
962
+
963
+ if (thisStart >= thisEnd && start >= end) {
964
+ return 0
965
+ }
966
+ if (thisStart >= thisEnd) {
967
+ return -1
968
+ }
969
+ if (start >= end) {
970
+ return 1
971
+ }
972
+
973
+ start >>>= 0;
974
+ end >>>= 0;
975
+ thisStart >>>= 0;
976
+ thisEnd >>>= 0;
977
+
978
+ if (this === target) return 0
979
+
980
+ let x = thisEnd - thisStart;
981
+ let y = end - start;
982
+ const len = Math.min(x, y);
983
+
984
+ const thisCopy = this.slice(thisStart, thisEnd);
985
+ const targetCopy = target.slice(start, end);
986
+
987
+ for (let i = 0; i < len; ++i) {
988
+ if (thisCopy[i] !== targetCopy[i]) {
989
+ x = thisCopy[i];
990
+ y = targetCopy[i];
991
+ break
992
+ }
993
+ }
994
+
995
+ if (x < y) return -1
996
+ if (y < x) return 1
997
+ return 0
998
+ };
999
+
1000
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
1001
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
1002
+ //
1003
+ // Arguments:
1004
+ // - buffer - a Buffer to search
1005
+ // - val - a string, Buffer, or number
1006
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
1007
+ // - encoding - an optional encoding, relevant is val is a string
1008
+ // - dir - true for indexOf, false for lastIndexOf
1009
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
1010
+ // Empty buffer means no match
1011
+ if (buffer.length === 0) return -1
1012
+
1013
+ // Normalize byteOffset
1014
+ if (typeof byteOffset === 'string') {
1015
+ encoding = byteOffset;
1016
+ byteOffset = 0;
1017
+ } else if (byteOffset > 0x7fffffff) {
1018
+ byteOffset = 0x7fffffff;
1019
+ } else if (byteOffset < -2147483648) {
1020
+ byteOffset = -2147483648;
1021
+ }
1022
+ byteOffset = +byteOffset; // Coerce to Number.
1023
+ if (numberIsNaN(byteOffset)) {
1024
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1025
+ byteOffset = dir ? 0 : (buffer.length - 1);
1026
+ }
1027
+
1028
+ // Normalize byteOffset: negative offsets start from the end of the buffer
1029
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
1030
+ if (byteOffset >= buffer.length) {
1031
+ if (dir) return -1
1032
+ else byteOffset = buffer.length - 1;
1033
+ } else if (byteOffset < 0) {
1034
+ if (dir) byteOffset = 0;
1035
+ else return -1
1036
+ }
1037
+
1038
+ // Normalize val
1039
+ if (typeof val === 'string') {
1040
+ val = Buffer.from(val, encoding);
1041
+ }
1042
+
1043
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
1044
+ if (Buffer.isBuffer(val)) {
1045
+ // Special case: looking for empty string/buffer always fails
1046
+ if (val.length === 0) {
1047
+ return -1
1048
+ }
1049
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
1050
+ } else if (typeof val === 'number') {
1051
+ val = val & 0xFF; // Search for a byte value [0-255]
1052
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
1053
+ if (dir) {
1054
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
1055
+ } else {
1056
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
1057
+ }
1058
+ }
1059
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
1060
+ }
1061
+
1062
+ throw new TypeError('val must be string, number or Buffer')
1063
+ }
1064
+
1065
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
1066
+ let indexSize = 1;
1067
+ let arrLength = arr.length;
1068
+ let valLength = val.length;
1069
+
1070
+ if (encoding !== undefined) {
1071
+ encoding = String(encoding).toLowerCase();
1072
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
1073
+ encoding === 'utf16le' || encoding === 'utf-16le') {
1074
+ if (arr.length < 2 || val.length < 2) {
1075
+ return -1
1076
+ }
1077
+ indexSize = 2;
1078
+ arrLength /= 2;
1079
+ valLength /= 2;
1080
+ byteOffset /= 2;
1081
+ }
1082
+ }
1083
+
1084
+ function read (buf, i) {
1085
+ if (indexSize === 1) {
1086
+ return buf[i]
1087
+ } else {
1088
+ return buf.readUInt16BE(i * indexSize)
1089
+ }
1090
+ }
1091
+
1092
+ let i;
1093
+ if (dir) {
1094
+ let foundIndex = -1;
1095
+ for (i = byteOffset; i < arrLength; i++) {
1096
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1097
+ if (foundIndex === -1) foundIndex = i;
1098
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
1099
+ } else {
1100
+ if (foundIndex !== -1) i -= i - foundIndex;
1101
+ foundIndex = -1;
1102
+ }
1103
+ }
1104
+ } else {
1105
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
1106
+ for (i = byteOffset; i >= 0; i--) {
1107
+ let found = true;
1108
+ for (let j = 0; j < valLength; j++) {
1109
+ if (read(arr, i + j) !== read(val, j)) {
1110
+ found = false;
1111
+ break
1112
+ }
1113
+ }
1114
+ if (found) return i
1115
+ }
1116
+ }
1117
+
1118
+ return -1
1119
+ }
1120
+
1121
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1122
+ return this.indexOf(val, byteOffset, encoding) !== -1
1123
+ };
1124
+
1125
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1126
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1127
+ };
1128
+
1129
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1130
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1131
+ };
1132
+
1133
+ function hexWrite (buf, string, offset, length) {
1134
+ offset = Number(offset) || 0;
1135
+ const remaining = buf.length - offset;
1136
+ if (!length) {
1137
+ length = remaining;
1138
+ } else {
1139
+ length = Number(length);
1140
+ if (length > remaining) {
1141
+ length = remaining;
1142
+ }
1143
+ }
1144
+
1145
+ const strLen = string.length;
1146
+
1147
+ if (length > strLen / 2) {
1148
+ length = strLen / 2;
1149
+ }
1150
+ let i;
1151
+ for (i = 0; i < length; ++i) {
1152
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
1153
+ if (numberIsNaN(parsed)) return i
1154
+ buf[offset + i] = parsed;
1155
+ }
1156
+ return i
1157
+ }
1158
+
1159
+ function utf8Write (buf, string, offset, length) {
1160
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1161
+ }
1162
+
1163
+ function asciiWrite (buf, string, offset, length) {
1164
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
1165
+ }
1166
+
1167
+ function base64Write (buf, string, offset, length) {
1168
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
1169
+ }
1170
+
1171
+ function ucs2Write (buf, string, offset, length) {
1172
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1173
+ }
1174
+
1175
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
1176
+ // Buffer#write(string)
1177
+ if (offset === undefined) {
1178
+ encoding = 'utf8';
1179
+ length = this.length;
1180
+ offset = 0;
1181
+ // Buffer#write(string, encoding)
1182
+ } else if (length === undefined && typeof offset === 'string') {
1183
+ encoding = offset;
1184
+ length = this.length;
1185
+ offset = 0;
1186
+ // Buffer#write(string, offset[, length][, encoding])
1187
+ } else if (isFinite(offset)) {
1188
+ offset = offset >>> 0;
1189
+ if (isFinite(length)) {
1190
+ length = length >>> 0;
1191
+ if (encoding === undefined) encoding = 'utf8';
1192
+ } else {
1193
+ encoding = length;
1194
+ length = undefined;
1195
+ }
1196
+ } else {
1197
+ throw new Error(
1198
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1199
+ )
1200
+ }
1201
+
1202
+ const remaining = this.length - offset;
1203
+ if (length === undefined || length > remaining) length = remaining;
1204
+
1205
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1206
+ throw new RangeError('Attempt to write outside buffer bounds')
1207
+ }
1208
+
1209
+ if (!encoding) encoding = 'utf8';
1210
+
1211
+ let loweredCase = false;
1212
+ for (;;) {
1213
+ switch (encoding) {
1214
+ case 'hex':
1215
+ return hexWrite(this, string, offset, length)
1216
+
1217
+ case 'utf8':
1218
+ case 'utf-8':
1219
+ return utf8Write(this, string, offset, length)
1220
+
1221
+ case 'ascii':
1222
+ case 'latin1':
1223
+ case 'binary':
1224
+ return asciiWrite(this, string, offset, length)
1225
+
1226
+ case 'base64':
1227
+ // Warning: maxLength not taken into account in base64Write
1228
+ return base64Write(this, string, offset, length)
1229
+
1230
+ case 'ucs2':
1231
+ case 'ucs-2':
1232
+ case 'utf16le':
1233
+ case 'utf-16le':
1234
+ return ucs2Write(this, string, offset, length)
1235
+
1236
+ default:
1237
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1238
+ encoding = ('' + encoding).toLowerCase();
1239
+ loweredCase = true;
1240
+ }
1241
+ }
1242
+ };
1243
+
1244
+ Buffer.prototype.toJSON = function toJSON () {
1245
+ return {
1246
+ type: 'Buffer',
1247
+ data: Array.prototype.slice.call(this._arr || this, 0)
1248
+ }
1249
+ };
1250
+
1251
+ function base64Slice (buf, start, end) {
1252
+ if (start === 0 && end === buf.length) {
1253
+ return base64.fromByteArray(buf)
1254
+ } else {
1255
+ return base64.fromByteArray(buf.slice(start, end))
1256
+ }
1257
+ }
1258
+
1259
+ function utf8Slice (buf, start, end) {
1260
+ end = Math.min(buf.length, end);
1261
+ const res = [];
1262
+
1263
+ let i = start;
1264
+ while (i < end) {
1265
+ const firstByte = buf[i];
1266
+ let codePoint = null;
1267
+ let bytesPerSequence = (firstByte > 0xEF)
1268
+ ? 4
1269
+ : (firstByte > 0xDF)
1270
+ ? 3
1271
+ : (firstByte > 0xBF)
1272
+ ? 2
1273
+ : 1;
1274
+
1275
+ if (i + bytesPerSequence <= end) {
1276
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
1277
+
1278
+ switch (bytesPerSequence) {
1279
+ case 1:
1280
+ if (firstByte < 0x80) {
1281
+ codePoint = firstByte;
1282
+ }
1283
+ break
1284
+ case 2:
1285
+ secondByte = buf[i + 1];
1286
+ if ((secondByte & 0xC0) === 0x80) {
1287
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1288
+ if (tempCodePoint > 0x7F) {
1289
+ codePoint = tempCodePoint;
1290
+ }
1291
+ }
1292
+ break
1293
+ case 3:
1294
+ secondByte = buf[i + 1];
1295
+ thirdByte = buf[i + 2];
1296
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1297
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1298
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1299
+ codePoint = tempCodePoint;
1300
+ }
1301
+ }
1302
+ break
1303
+ case 4:
1304
+ secondByte = buf[i + 1];
1305
+ thirdByte = buf[i + 2];
1306
+ fourthByte = buf[i + 3];
1307
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1308
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1309
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1310
+ codePoint = tempCodePoint;
1311
+ }
1312
+ }
1313
+ }
1314
+ }
1315
+
1316
+ if (codePoint === null) {
1317
+ // we did not generate a valid codePoint so insert a
1318
+ // replacement char (U+FFFD) and advance only 1 byte
1319
+ codePoint = 0xFFFD;
1320
+ bytesPerSequence = 1;
1321
+ } else if (codePoint > 0xFFFF) {
1322
+ // encode to utf16 (surrogate pair dance)
1323
+ codePoint -= 0x10000;
1324
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1325
+ codePoint = 0xDC00 | codePoint & 0x3FF;
1326
+ }
1327
+
1328
+ res.push(codePoint);
1329
+ i += bytesPerSequence;
1330
+ }
1331
+
1332
+ return decodeCodePointsArray(res)
1333
+ }
1334
+
1335
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1336
+ // the lowest limit is Chrome, with 0x10000 args.
1337
+ // We go 1 magnitude less, for safety
1338
+ const MAX_ARGUMENTS_LENGTH = 0x1000;
1339
+
1340
+ function decodeCodePointsArray (codePoints) {
1341
+ const len = codePoints.length;
1342
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1343
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1344
+ }
1345
+
1346
+ // Decode in chunks to avoid "call stack size exceeded".
1347
+ let res = '';
1348
+ let i = 0;
1349
+ while (i < len) {
1350
+ res += String.fromCharCode.apply(
1351
+ String,
1352
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1353
+ );
1354
+ }
1355
+ return res
1356
+ }
1357
+
1358
+ function asciiSlice (buf, start, end) {
1359
+ let ret = '';
1360
+ end = Math.min(buf.length, end);
1361
+
1362
+ for (let i = start; i < end; ++i) {
1363
+ ret += String.fromCharCode(buf[i] & 0x7F);
1364
+ }
1365
+ return ret
1366
+ }
1367
+
1368
+ function latin1Slice (buf, start, end) {
1369
+ let ret = '';
1370
+ end = Math.min(buf.length, end);
1371
+
1372
+ for (let i = start; i < end; ++i) {
1373
+ ret += String.fromCharCode(buf[i]);
1374
+ }
1375
+ return ret
1376
+ }
1377
+
1378
+ function hexSlice (buf, start, end) {
1379
+ const len = buf.length;
1380
+
1381
+ if (!start || start < 0) start = 0;
1382
+ if (!end || end < 0 || end > len) end = len;
1383
+
1384
+ let out = '';
1385
+ for (let i = start; i < end; ++i) {
1386
+ out += hexSliceLookupTable[buf[i]];
1387
+ }
1388
+ return out
1389
+ }
1390
+
1391
+ function utf16leSlice (buf, start, end) {
1392
+ const bytes = buf.slice(start, end);
1393
+ let res = '';
1394
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
1395
+ for (let i = 0; i < bytes.length - 1; i += 2) {
1396
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
1397
+ }
1398
+ return res
1399
+ }
1400
+
1401
+ Buffer.prototype.slice = function slice (start, end) {
1402
+ const len = this.length;
1403
+ start = ~~start;
1404
+ end = end === undefined ? len : ~~end;
1405
+
1406
+ if (start < 0) {
1407
+ start += len;
1408
+ if (start < 0) start = 0;
1409
+ } else if (start > len) {
1410
+ start = len;
1411
+ }
1412
+
1413
+ if (end < 0) {
1414
+ end += len;
1415
+ if (end < 0) end = 0;
1416
+ } else if (end > len) {
1417
+ end = len;
1418
+ }
1419
+
1420
+ if (end < start) end = start;
1421
+
1422
+ const newBuf = this.subarray(start, end);
1423
+ // Return an augmented `Uint8Array` instance
1424
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
1425
+
1426
+ return newBuf
1427
+ };
1428
+
1429
+ /*
1430
+ * Need to make sure that buffer isn't trying to write out of bounds.
1431
+ */
1432
+ function checkOffset (offset, ext, length) {
1433
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1434
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1435
+ }
1436
+
1437
+ Buffer.prototype.readUintLE =
1438
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1439
+ offset = offset >>> 0;
1440
+ byteLength = byteLength >>> 0;
1441
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1442
+
1443
+ let val = this[offset];
1444
+ let mul = 1;
1445
+ let i = 0;
1446
+ while (++i < byteLength && (mul *= 0x100)) {
1447
+ val += this[offset + i] * mul;
1448
+ }
1449
+
1450
+ return val
1451
+ };
1452
+
1453
+ Buffer.prototype.readUintBE =
1454
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1455
+ offset = offset >>> 0;
1456
+ byteLength = byteLength >>> 0;
1457
+ if (!noAssert) {
1458
+ checkOffset(offset, byteLength, this.length);
1459
+ }
1460
+
1461
+ let val = this[offset + --byteLength];
1462
+ let mul = 1;
1463
+ while (byteLength > 0 && (mul *= 0x100)) {
1464
+ val += this[offset + --byteLength] * mul;
1465
+ }
1466
+
1467
+ return val
1468
+ };
1469
+
1470
+ Buffer.prototype.readUint8 =
1471
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1472
+ offset = offset >>> 0;
1473
+ if (!noAssert) checkOffset(offset, 1, this.length);
1474
+ return this[offset]
1475
+ };
1476
+
1477
+ Buffer.prototype.readUint16LE =
1478
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1479
+ offset = offset >>> 0;
1480
+ if (!noAssert) checkOffset(offset, 2, this.length);
1481
+ return this[offset] | (this[offset + 1] << 8)
1482
+ };
1483
+
1484
+ Buffer.prototype.readUint16BE =
1485
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1486
+ offset = offset >>> 0;
1487
+ if (!noAssert) checkOffset(offset, 2, this.length);
1488
+ return (this[offset] << 8) | this[offset + 1]
1489
+ };
1490
+
1491
+ Buffer.prototype.readUint32LE =
1492
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1493
+ offset = offset >>> 0;
1494
+ if (!noAssert) checkOffset(offset, 4, this.length);
1495
+
1496
+ return ((this[offset]) |
1497
+ (this[offset + 1] << 8) |
1498
+ (this[offset + 2] << 16)) +
1499
+ (this[offset + 3] * 0x1000000)
1500
+ };
1501
+
1502
+ Buffer.prototype.readUint32BE =
1503
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1504
+ offset = offset >>> 0;
1505
+ if (!noAssert) checkOffset(offset, 4, this.length);
1506
+
1507
+ return (this[offset] * 0x1000000) +
1508
+ ((this[offset + 1] << 16) |
1509
+ (this[offset + 2] << 8) |
1510
+ this[offset + 3])
1511
+ };
1512
+
1513
+ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
1514
+ offset = offset >>> 0;
1515
+ validateNumber(offset, 'offset');
1516
+ const first = this[offset];
1517
+ const last = this[offset + 7];
1518
+ if (first === undefined || last === undefined) {
1519
+ boundsError(offset, this.length - 8);
1520
+ }
1521
+
1522
+ const lo = first +
1523
+ this[++offset] * 2 ** 8 +
1524
+ this[++offset] * 2 ** 16 +
1525
+ this[++offset] * 2 ** 24;
1526
+
1527
+ const hi = this[++offset] +
1528
+ this[++offset] * 2 ** 8 +
1529
+ this[++offset] * 2 ** 16 +
1530
+ last * 2 ** 24;
1531
+
1532
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
1533
+ });
1534
+
1535
+ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
1536
+ offset = offset >>> 0;
1537
+ validateNumber(offset, 'offset');
1538
+ const first = this[offset];
1539
+ const last = this[offset + 7];
1540
+ if (first === undefined || last === undefined) {
1541
+ boundsError(offset, this.length - 8);
1542
+ }
1543
+
1544
+ const hi = first * 2 ** 24 +
1545
+ this[++offset] * 2 ** 16 +
1546
+ this[++offset] * 2 ** 8 +
1547
+ this[++offset];
1548
+
1549
+ const lo = this[++offset] * 2 ** 24 +
1550
+ this[++offset] * 2 ** 16 +
1551
+ this[++offset] * 2 ** 8 +
1552
+ last;
1553
+
1554
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
1555
+ });
1556
+
1557
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1558
+ offset = offset >>> 0;
1559
+ byteLength = byteLength >>> 0;
1560
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1561
+
1562
+ let val = this[offset];
1563
+ let mul = 1;
1564
+ let i = 0;
1565
+ while (++i < byteLength && (mul *= 0x100)) {
1566
+ val += this[offset + i] * mul;
1567
+ }
1568
+ mul *= 0x80;
1569
+
1570
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1571
+
1572
+ return val
1573
+ };
1574
+
1575
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1576
+ offset = offset >>> 0;
1577
+ byteLength = byteLength >>> 0;
1578
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1579
+
1580
+ let i = byteLength;
1581
+ let mul = 1;
1582
+ let val = this[offset + --i];
1583
+ while (i > 0 && (mul *= 0x100)) {
1584
+ val += this[offset + --i] * mul;
1585
+ }
1586
+ mul *= 0x80;
1587
+
1588
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1589
+
1590
+ return val
1591
+ };
1592
+
1593
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1594
+ offset = offset >>> 0;
1595
+ if (!noAssert) checkOffset(offset, 1, this.length);
1596
+ if (!(this[offset] & 0x80)) return (this[offset])
1597
+ return ((0xff - this[offset] + 1) * -1)
1598
+ };
1599
+
1600
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1601
+ offset = offset >>> 0;
1602
+ if (!noAssert) checkOffset(offset, 2, this.length);
1603
+ const val = this[offset] | (this[offset + 1] << 8);
1604
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1605
+ };
1606
+
1607
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1608
+ offset = offset >>> 0;
1609
+ if (!noAssert) checkOffset(offset, 2, this.length);
1610
+ const val = this[offset + 1] | (this[offset] << 8);
1611
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1612
+ };
1613
+
1614
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1615
+ offset = offset >>> 0;
1616
+ if (!noAssert) checkOffset(offset, 4, this.length);
1617
+
1618
+ return (this[offset]) |
1619
+ (this[offset + 1] << 8) |
1620
+ (this[offset + 2] << 16) |
1621
+ (this[offset + 3] << 24)
1622
+ };
1623
+
1624
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1625
+ offset = offset >>> 0;
1626
+ if (!noAssert) checkOffset(offset, 4, this.length);
1627
+
1628
+ return (this[offset] << 24) |
1629
+ (this[offset + 1] << 16) |
1630
+ (this[offset + 2] << 8) |
1631
+ (this[offset + 3])
1632
+ };
1633
+
1634
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
1635
+ offset = offset >>> 0;
1636
+ validateNumber(offset, 'offset');
1637
+ const first = this[offset];
1638
+ const last = this[offset + 7];
1639
+ if (first === undefined || last === undefined) {
1640
+ boundsError(offset, this.length - 8);
1641
+ }
1642
+
1643
+ const val = this[offset + 4] +
1644
+ this[offset + 5] * 2 ** 8 +
1645
+ this[offset + 6] * 2 ** 16 +
1646
+ (last << 24); // Overflow
1647
+
1648
+ return (BigInt(val) << BigInt(32)) +
1649
+ BigInt(first +
1650
+ this[++offset] * 2 ** 8 +
1651
+ this[++offset] * 2 ** 16 +
1652
+ this[++offset] * 2 ** 24)
1653
+ });
1654
+
1655
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
1656
+ offset = offset >>> 0;
1657
+ validateNumber(offset, 'offset');
1658
+ const first = this[offset];
1659
+ const last = this[offset + 7];
1660
+ if (first === undefined || last === undefined) {
1661
+ boundsError(offset, this.length - 8);
1662
+ }
1663
+
1664
+ const val = (first << 24) + // Overflow
1665
+ this[++offset] * 2 ** 16 +
1666
+ this[++offset] * 2 ** 8 +
1667
+ this[++offset];
1668
+
1669
+ return (BigInt(val) << BigInt(32)) +
1670
+ BigInt(this[++offset] * 2 ** 24 +
1671
+ this[++offset] * 2 ** 16 +
1672
+ this[++offset] * 2 ** 8 +
1673
+ last)
1674
+ });
1675
+
1676
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1677
+ offset = offset >>> 0;
1678
+ if (!noAssert) checkOffset(offset, 4, this.length);
1679
+ return ieee754.read(this, offset, true, 23, 4)
1680
+ };
1681
+
1682
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1683
+ offset = offset >>> 0;
1684
+ if (!noAssert) checkOffset(offset, 4, this.length);
1685
+ return ieee754.read(this, offset, false, 23, 4)
1686
+ };
1687
+
1688
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1689
+ offset = offset >>> 0;
1690
+ if (!noAssert) checkOffset(offset, 8, this.length);
1691
+ return ieee754.read(this, offset, true, 52, 8)
1692
+ };
1693
+
1694
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1695
+ offset = offset >>> 0;
1696
+ if (!noAssert) checkOffset(offset, 8, this.length);
1697
+ return ieee754.read(this, offset, false, 52, 8)
1698
+ };
1699
+
1700
+ function checkInt (buf, value, offset, ext, max, min) {
1701
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1702
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1703
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1704
+ }
1705
+
1706
+ Buffer.prototype.writeUintLE =
1707
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1708
+ value = +value;
1709
+ offset = offset >>> 0;
1710
+ byteLength = byteLength >>> 0;
1711
+ if (!noAssert) {
1712
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1713
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1714
+ }
1715
+
1716
+ let mul = 1;
1717
+ let i = 0;
1718
+ this[offset] = value & 0xFF;
1719
+ while (++i < byteLength && (mul *= 0x100)) {
1720
+ this[offset + i] = (value / mul) & 0xFF;
1721
+ }
1722
+
1723
+ return offset + byteLength
1724
+ };
1725
+
1726
+ Buffer.prototype.writeUintBE =
1727
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1728
+ value = +value;
1729
+ offset = offset >>> 0;
1730
+ byteLength = byteLength >>> 0;
1731
+ if (!noAssert) {
1732
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
1733
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1734
+ }
1735
+
1736
+ let i = byteLength - 1;
1737
+ let mul = 1;
1738
+ this[offset + i] = value & 0xFF;
1739
+ while (--i >= 0 && (mul *= 0x100)) {
1740
+ this[offset + i] = (value / mul) & 0xFF;
1741
+ }
1742
+
1743
+ return offset + byteLength
1744
+ };
1745
+
1746
+ Buffer.prototype.writeUint8 =
1747
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1748
+ value = +value;
1749
+ offset = offset >>> 0;
1750
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1751
+ this[offset] = (value & 0xff);
1752
+ return offset + 1
1753
+ };
1754
+
1755
+ Buffer.prototype.writeUint16LE =
1756
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1757
+ value = +value;
1758
+ offset = offset >>> 0;
1759
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1760
+ this[offset] = (value & 0xff);
1761
+ this[offset + 1] = (value >>> 8);
1762
+ return offset + 2
1763
+ };
1764
+
1765
+ Buffer.prototype.writeUint16BE =
1766
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1767
+ value = +value;
1768
+ offset = offset >>> 0;
1769
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1770
+ this[offset] = (value >>> 8);
1771
+ this[offset + 1] = (value & 0xff);
1772
+ return offset + 2
1773
+ };
1774
+
1775
+ Buffer.prototype.writeUint32LE =
1776
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1777
+ value = +value;
1778
+ offset = offset >>> 0;
1779
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1780
+ this[offset + 3] = (value >>> 24);
1781
+ this[offset + 2] = (value >>> 16);
1782
+ this[offset + 1] = (value >>> 8);
1783
+ this[offset] = (value & 0xff);
1784
+ return offset + 4
1785
+ };
1786
+
1787
+ Buffer.prototype.writeUint32BE =
1788
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1789
+ value = +value;
1790
+ offset = offset >>> 0;
1791
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1792
+ this[offset] = (value >>> 24);
1793
+ this[offset + 1] = (value >>> 16);
1794
+ this[offset + 2] = (value >>> 8);
1795
+ this[offset + 3] = (value & 0xff);
1796
+ return offset + 4
1797
+ };
1798
+
1799
+ function wrtBigUInt64LE (buf, value, offset, min, max) {
1800
+ checkIntBI(value, min, max, buf, offset, 7);
1801
+
1802
+ let lo = Number(value & BigInt(0xffffffff));
1803
+ buf[offset++] = lo;
1804
+ lo = lo >> 8;
1805
+ buf[offset++] = lo;
1806
+ lo = lo >> 8;
1807
+ buf[offset++] = lo;
1808
+ lo = lo >> 8;
1809
+ buf[offset++] = lo;
1810
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1811
+ buf[offset++] = hi;
1812
+ hi = hi >> 8;
1813
+ buf[offset++] = hi;
1814
+ hi = hi >> 8;
1815
+ buf[offset++] = hi;
1816
+ hi = hi >> 8;
1817
+ buf[offset++] = hi;
1818
+ return offset
1819
+ }
1820
+
1821
+ function wrtBigUInt64BE (buf, value, offset, min, max) {
1822
+ checkIntBI(value, min, max, buf, offset, 7);
1823
+
1824
+ let lo = Number(value & BigInt(0xffffffff));
1825
+ buf[offset + 7] = lo;
1826
+ lo = lo >> 8;
1827
+ buf[offset + 6] = lo;
1828
+ lo = lo >> 8;
1829
+ buf[offset + 5] = lo;
1830
+ lo = lo >> 8;
1831
+ buf[offset + 4] = lo;
1832
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
1833
+ buf[offset + 3] = hi;
1834
+ hi = hi >> 8;
1835
+ buf[offset + 2] = hi;
1836
+ hi = hi >> 8;
1837
+ buf[offset + 1] = hi;
1838
+ hi = hi >> 8;
1839
+ buf[offset] = hi;
1840
+ return offset + 8
1841
+ }
1842
+
1843
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
1844
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1845
+ });
1846
+
1847
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
1848
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
1849
+ });
1850
+
1851
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1852
+ value = +value;
1853
+ offset = offset >>> 0;
1854
+ if (!noAssert) {
1855
+ const limit = Math.pow(2, (8 * byteLength) - 1);
1856
+
1857
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1858
+ }
1859
+
1860
+ let i = 0;
1861
+ let mul = 1;
1862
+ let sub = 0;
1863
+ this[offset] = value & 0xFF;
1864
+ while (++i < byteLength && (mul *= 0x100)) {
1865
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1866
+ sub = 1;
1867
+ }
1868
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1869
+ }
1870
+
1871
+ return offset + byteLength
1872
+ };
1873
+
1874
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1875
+ value = +value;
1876
+ offset = offset >>> 0;
1877
+ if (!noAssert) {
1878
+ const limit = Math.pow(2, (8 * byteLength) - 1);
1879
+
1880
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1881
+ }
1882
+
1883
+ let i = byteLength - 1;
1884
+ let mul = 1;
1885
+ let sub = 0;
1886
+ this[offset + i] = value & 0xFF;
1887
+ while (--i >= 0 && (mul *= 0x100)) {
1888
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1889
+ sub = 1;
1890
+ }
1891
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1892
+ }
1893
+
1894
+ return offset + byteLength
1895
+ };
1896
+
1897
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1898
+ value = +value;
1899
+ offset = offset >>> 0;
1900
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
1901
+ if (value < 0) value = 0xff + value + 1;
1902
+ this[offset] = (value & 0xff);
1903
+ return offset + 1
1904
+ };
1905
+
1906
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1907
+ value = +value;
1908
+ offset = offset >>> 0;
1909
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1910
+ this[offset] = (value & 0xff);
1911
+ this[offset + 1] = (value >>> 8);
1912
+ return offset + 2
1913
+ };
1914
+
1915
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1916
+ value = +value;
1917
+ offset = offset >>> 0;
1918
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1919
+ this[offset] = (value >>> 8);
1920
+ this[offset + 1] = (value & 0xff);
1921
+ return offset + 2
1922
+ };
1923
+
1924
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1925
+ value = +value;
1926
+ offset = offset >>> 0;
1927
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1928
+ this[offset] = (value & 0xff);
1929
+ this[offset + 1] = (value >>> 8);
1930
+ this[offset + 2] = (value >>> 16);
1931
+ this[offset + 3] = (value >>> 24);
1932
+ return offset + 4
1933
+ };
1934
+
1935
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1936
+ value = +value;
1937
+ offset = offset >>> 0;
1938
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1939
+ if (value < 0) value = 0xffffffff + value + 1;
1940
+ this[offset] = (value >>> 24);
1941
+ this[offset + 1] = (value >>> 16);
1942
+ this[offset + 2] = (value >>> 8);
1943
+ this[offset + 3] = (value & 0xff);
1944
+ return offset + 4
1945
+ };
1946
+
1947
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
1948
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1949
+ });
1950
+
1951
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
1952
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
1953
+ });
1954
+
1955
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
1956
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1957
+ if (offset < 0) throw new RangeError('Index out of range')
1958
+ }
1959
+
1960
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
1961
+ value = +value;
1962
+ offset = offset >>> 0;
1963
+ if (!noAssert) {
1964
+ checkIEEE754(buf, value, offset, 4);
1965
+ }
1966
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
1967
+ return offset + 4
1968
+ }
1969
+
1970
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1971
+ return writeFloat(this, value, offset, true, noAssert)
1972
+ };
1973
+
1974
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1975
+ return writeFloat(this, value, offset, false, noAssert)
1976
+ };
1977
+
1978
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
1979
+ value = +value;
1980
+ offset = offset >>> 0;
1981
+ if (!noAssert) {
1982
+ checkIEEE754(buf, value, offset, 8);
1983
+ }
1984
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
1985
+ return offset + 8
1986
+ }
1987
+
1988
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1989
+ return writeDouble(this, value, offset, true, noAssert)
1990
+ };
1991
+
1992
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1993
+ return writeDouble(this, value, offset, false, noAssert)
1994
+ };
1995
+
1996
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1997
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1998
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
1999
+ if (!start) start = 0;
2000
+ if (!end && end !== 0) end = this.length;
2001
+ if (targetStart >= target.length) targetStart = target.length;
2002
+ if (!targetStart) targetStart = 0;
2003
+ if (end > 0 && end < start) end = start;
2004
+
2005
+ // Copy 0 bytes; we're done
2006
+ if (end === start) return 0
2007
+ if (target.length === 0 || this.length === 0) return 0
2008
+
2009
+ // Fatal error conditions
2010
+ if (targetStart < 0) {
2011
+ throw new RangeError('targetStart out of bounds')
2012
+ }
2013
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
2014
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
2015
+
2016
+ // Are we oob?
2017
+ if (end > this.length) end = this.length;
2018
+ if (target.length - targetStart < end - start) {
2019
+ end = target.length - targetStart + start;
2020
+ }
2021
+
2022
+ const len = end - start;
2023
+
2024
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
2025
+ // Use built-in when available, missing from IE11
2026
+ this.copyWithin(targetStart, start, end);
2027
+ } else {
2028
+ Uint8Array.prototype.set.call(
2029
+ target,
2030
+ this.subarray(start, end),
2031
+ targetStart
2032
+ );
2033
+ }
2034
+
2035
+ return len
2036
+ };
2037
+
2038
+ // Usage:
2039
+ // buffer.fill(number[, offset[, end]])
2040
+ // buffer.fill(buffer[, offset[, end]])
2041
+ // buffer.fill(string[, offset[, end]][, encoding])
2042
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
2043
+ // Handle string cases:
2044
+ if (typeof val === 'string') {
2045
+ if (typeof start === 'string') {
2046
+ encoding = start;
2047
+ start = 0;
2048
+ end = this.length;
2049
+ } else if (typeof end === 'string') {
2050
+ encoding = end;
2051
+ end = this.length;
2052
+ }
2053
+ if (encoding !== undefined && typeof encoding !== 'string') {
2054
+ throw new TypeError('encoding must be a string')
2055
+ }
2056
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
2057
+ throw new TypeError('Unknown encoding: ' + encoding)
2058
+ }
2059
+ if (val.length === 1) {
2060
+ const code = val.charCodeAt(0);
2061
+ if ((encoding === 'utf8' && code < 128) ||
2062
+ encoding === 'latin1') {
2063
+ // Fast path: If `val` fits into a single byte, use that numeric value.
2064
+ val = code;
2065
+ }
2066
+ }
2067
+ } else if (typeof val === 'number') {
2068
+ val = val & 255;
2069
+ } else if (typeof val === 'boolean') {
2070
+ val = Number(val);
2071
+ }
2072
+
2073
+ // Invalid ranges are not set to a default, so can range check early.
2074
+ if (start < 0 || this.length < start || this.length < end) {
2075
+ throw new RangeError('Out of range index')
2076
+ }
2077
+
2078
+ if (end <= start) {
2079
+ return this
2080
+ }
2081
+
2082
+ start = start >>> 0;
2083
+ end = end === undefined ? this.length : end >>> 0;
2084
+
2085
+ if (!val) val = 0;
2086
+
2087
+ let i;
2088
+ if (typeof val === 'number') {
2089
+ for (i = start; i < end; ++i) {
2090
+ this[i] = val;
2091
+ }
2092
+ } else {
2093
+ const bytes = Buffer.isBuffer(val)
2094
+ ? val
2095
+ : Buffer.from(val, encoding);
2096
+ const len = bytes.length;
2097
+ if (len === 0) {
2098
+ throw new TypeError('The value "' + val +
2099
+ '" is invalid for argument "value"')
2100
+ }
2101
+ for (i = 0; i < end - start; ++i) {
2102
+ this[i + start] = bytes[i % len];
2103
+ }
2104
+ }
2105
+
2106
+ return this
2107
+ };
2108
+
2109
+ // CUSTOM ERRORS
2110
+ // =============
2111
+
2112
+ // Simplified versions from Node, changed for Buffer-only usage
2113
+ const errors = {};
2114
+ function E (sym, getMessage, Base) {
2115
+ errors[sym] = class NodeError extends Base {
2116
+ constructor () {
2117
+ super();
2118
+
2119
+ Object.defineProperty(this, 'message', {
2120
+ value: getMessage.apply(this, arguments),
2121
+ writable: true,
2122
+ configurable: true
2123
+ });
2124
+
2125
+ // Add the error code to the name to include it in the stack trace.
2126
+ this.name = `${this.name} [${sym}]`;
2127
+ // Access the stack to generate the error message including the error code
2128
+ // from the name.
2129
+ this.stack; // eslint-disable-line no-unused-expressions
2130
+ // Reset the name to the actual name.
2131
+ delete this.name;
2132
+ }
2133
+
2134
+ get code () {
2135
+ return sym
2136
+ }
2137
+
2138
+ set code (value) {
2139
+ Object.defineProperty(this, 'code', {
2140
+ configurable: true,
2141
+ enumerable: true,
2142
+ value,
2143
+ writable: true
2144
+ });
2145
+ }
2146
+
2147
+ toString () {
2148
+ return `${this.name} [${sym}]: ${this.message}`
2149
+ }
2150
+ };
2151
+ }
2152
+
2153
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
2154
+ function (name) {
2155
+ if (name) {
2156
+ return `${name} is outside of buffer bounds`
2157
+ }
2158
+
2159
+ return 'Attempt to access memory outside buffer bounds'
2160
+ }, RangeError);
2161
+ E('ERR_INVALID_ARG_TYPE',
2162
+ function (name, actual) {
2163
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
2164
+ }, TypeError);
2165
+ E('ERR_OUT_OF_RANGE',
2166
+ function (str, range, input) {
2167
+ let msg = `The value of "${str}" is out of range.`;
2168
+ let received = input;
2169
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
2170
+ received = addNumericalSeparator(String(input));
2171
+ } else if (typeof input === 'bigint') {
2172
+ received = String(input);
2173
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
2174
+ received = addNumericalSeparator(received);
2175
+ }
2176
+ received += 'n';
2177
+ }
2178
+ msg += ` It must be ${range}. Received ${received}`;
2179
+ return msg
2180
+ }, RangeError);
2181
+
2182
+ function addNumericalSeparator (val) {
2183
+ let res = '';
2184
+ let i = val.length;
2185
+ const start = val[0] === '-' ? 1 : 0;
2186
+ for (; i >= start + 4; i -= 3) {
2187
+ res = `_${val.slice(i - 3, i)}${res}`;
2188
+ }
2189
+ return `${val.slice(0, i)}${res}`
2190
+ }
2191
+
2192
+ // CHECK FUNCTIONS
2193
+ // ===============
2194
+
2195
+ function checkBounds (buf, offset, byteLength) {
2196
+ validateNumber(offset, 'offset');
2197
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
2198
+ boundsError(offset, buf.length - (byteLength + 1));
2199
+ }
2200
+ }
2201
+
2202
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
2203
+ if (value > max || value < min) {
2204
+ const n = typeof min === 'bigint' ? 'n' : '';
2205
+ let range;
2206
+ {
2207
+ if (min === 0 || min === BigInt(0)) {
2208
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
2209
+ } else {
2210
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
2211
+ `${(byteLength + 1) * 8 - 1}${n}`;
2212
+ }
2213
+ }
2214
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
2215
+ }
2216
+ checkBounds(buf, offset, byteLength);
2217
+ }
2218
+
2219
+ function validateNumber (value, name) {
2220
+ if (typeof value !== 'number') {
2221
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
2222
+ }
2223
+ }
2224
+
2225
+ function boundsError (value, length, type) {
2226
+ if (Math.floor(value) !== value) {
2227
+ validateNumber(value, type);
2228
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
2229
+ }
2230
+
2231
+ if (length < 0) {
2232
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
2233
+ }
2234
+
2235
+ throw new errors.ERR_OUT_OF_RANGE('offset',
2236
+ `>= ${0} and <= ${length}`,
2237
+ value)
2238
+ }
2239
+
2240
+ // HELPER FUNCTIONS
2241
+ // ================
2242
+
2243
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
2244
+
2245
+ function base64clean (str) {
2246
+ // Node takes equal signs as end of the Base64 encoding
2247
+ str = str.split('=')[0];
2248
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
2249
+ str = str.trim().replace(INVALID_BASE64_RE, '');
2250
+ // Node converts strings with length < 2 to ''
2251
+ if (str.length < 2) return ''
2252
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
2253
+ while (str.length % 4 !== 0) {
2254
+ str = str + '=';
2255
+ }
2256
+ return str
2257
+ }
2258
+
2259
+ function utf8ToBytes (string, units) {
2260
+ units = units || Infinity;
2261
+ let codePoint;
2262
+ const length = string.length;
2263
+ let leadSurrogate = null;
2264
+ const bytes = [];
2265
+
2266
+ for (let i = 0; i < length; ++i) {
2267
+ codePoint = string.charCodeAt(i);
2268
+
2269
+ // is surrogate component
2270
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
2271
+ // last char was a lead
2272
+ if (!leadSurrogate) {
2273
+ // no lead yet
2274
+ if (codePoint > 0xDBFF) {
2275
+ // unexpected trail
2276
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2277
+ continue
2278
+ } else if (i + 1 === length) {
2279
+ // unpaired lead
2280
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2281
+ continue
2282
+ }
2283
+
2284
+ // valid lead
2285
+ leadSurrogate = codePoint;
2286
+
2287
+ continue
2288
+ }
2289
+
2290
+ // 2 leads in a row
2291
+ if (codePoint < 0xDC00) {
2292
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2293
+ leadSurrogate = codePoint;
2294
+ continue
2295
+ }
2296
+
2297
+ // valid surrogate pair
2298
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
2299
+ } else if (leadSurrogate) {
2300
+ // valid bmp char, but last char was a lead
2301
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2302
+ }
2303
+
2304
+ leadSurrogate = null;
2305
+
2306
+ // encode utf8
2307
+ if (codePoint < 0x80) {
2308
+ if ((units -= 1) < 0) break
2309
+ bytes.push(codePoint);
2310
+ } else if (codePoint < 0x800) {
2311
+ if ((units -= 2) < 0) break
2312
+ bytes.push(
2313
+ codePoint >> 0x6 | 0xC0,
2314
+ codePoint & 0x3F | 0x80
2315
+ );
2316
+ } else if (codePoint < 0x10000) {
2317
+ if ((units -= 3) < 0) break
2318
+ bytes.push(
2319
+ codePoint >> 0xC | 0xE0,
2320
+ codePoint >> 0x6 & 0x3F | 0x80,
2321
+ codePoint & 0x3F | 0x80
2322
+ );
2323
+ } else if (codePoint < 0x110000) {
2324
+ if ((units -= 4) < 0) break
2325
+ bytes.push(
2326
+ codePoint >> 0x12 | 0xF0,
2327
+ codePoint >> 0xC & 0x3F | 0x80,
2328
+ codePoint >> 0x6 & 0x3F | 0x80,
2329
+ codePoint & 0x3F | 0x80
2330
+ );
2331
+ } else {
2332
+ throw new Error('Invalid code point')
2333
+ }
2334
+ }
2335
+
2336
+ return bytes
2337
+ }
2338
+
2339
+ function asciiToBytes (str) {
2340
+ const byteArray = [];
2341
+ for (let i = 0; i < str.length; ++i) {
2342
+ // Node's code seems to be doing this and not & 0x7F..
2343
+ byteArray.push(str.charCodeAt(i) & 0xFF);
2344
+ }
2345
+ return byteArray
2346
+ }
2347
+
2348
+ function utf16leToBytes (str, units) {
2349
+ let c, hi, lo;
2350
+ const byteArray = [];
2351
+ for (let i = 0; i < str.length; ++i) {
2352
+ if ((units -= 2) < 0) break
2353
+
2354
+ c = str.charCodeAt(i);
2355
+ hi = c >> 8;
2356
+ lo = c % 256;
2357
+ byteArray.push(lo);
2358
+ byteArray.push(hi);
2359
+ }
2360
+
2361
+ return byteArray
2362
+ }
2363
+
2364
+ function base64ToBytes (str) {
2365
+ return base64.toByteArray(base64clean(str))
2366
+ }
2367
+
2368
+ function blitBuffer (src, dst, offset, length) {
2369
+ let i;
2370
+ for (i = 0; i < length; ++i) {
2371
+ if ((i + offset >= dst.length) || (i >= src.length)) break
2372
+ dst[i + offset] = src[i];
2373
+ }
2374
+ return i
2375
+ }
2376
+
2377
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2378
+ // the `instanceof` check but they should be treated as of that type.
2379
+ // See: https://github.com/feross/buffer/issues/166
2380
+ function isInstance (obj, type) {
2381
+ return obj instanceof type ||
2382
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
2383
+ obj.constructor.name === type.name)
2384
+ }
2385
+ function numberIsNaN (obj) {
2386
+ // For IE11 support
2387
+ return obj !== obj // eslint-disable-line no-self-compare
2388
+ }
2389
+
2390
+ // Create lookup table for `toString('hex')`
2391
+ // See: https://github.com/feross/buffer/issues/219
2392
+ const hexSliceLookupTable = (function () {
2393
+ const alphabet = '0123456789abcdef';
2394
+ const table = new Array(256);
2395
+ for (let i = 0; i < 16; ++i) {
2396
+ const i16 = i * 16;
2397
+ for (let j = 0; j < 16; ++j) {
2398
+ table[i16 + j] = alphabet[i] + alphabet[j];
2399
+ }
2400
+ }
2401
+ return table
2402
+ })();
2403
+
2404
+ // Return not function with Error if BigInt not supported
2405
+ function defineBigIntMethod (fn) {
2406
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
2407
+ }
2408
+
2409
+ function BufferBigIntNotDefined () {
2410
+ throw new Error('BigInt not supported')
2411
+ }
2412
+ } (buffer));
2413
+ return buffer;
2414
+ }
2415
+
2416
+ var bufferExports = requireBuffer();
2417
+
46
2418
  /**
47
2419
  * @category Error
48
2420
  * Error indicates the spending key is invalid
@@ -128,12 +2500,12 @@ function removeZeroPaddedBytesRight(memo) {
128
2500
  function readableFormat(saplingTransactionProperties) {
129
2501
  return {
130
2502
  value: convertValueToBigNumber(saplingTransactionProperties.value),
131
- memo: memoHexToUtf8(Buffer.from(saplingTransactionProperties.memo).toString('hex')),
2503
+ memo: memoHexToUtf8(bufferExports.Buffer.from(saplingTransactionProperties.memo).toString('hex')),
132
2504
  paymentAddress: b58Encode(saplingTransactionProperties.paymentAddress, PrefixV2.SaplingAddress),
133
2505
  };
134
2506
  }
135
2507
  function convertValueToBigNumber(value) {
136
- return new BigNumberJs(Buffer.from(value).toString('hex'), 16);
2508
+ return new BigNumberJs(bufferExports.Buffer.from(value).toString('hex'), 16);
137
2509
  }
138
2510
  function bufToUint8Array(buffer) {
139
2511
  return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / Uint8Array.BYTES_PER_ELEMENT);
@@ -151,11 +2523,11 @@ class SaplingForger {
151
2523
  */
152
2524
  forgeSaplingTransaction(tx) {
153
2525
  const spendBuf = this.forgeSpendDescriptions(tx.inputs);
154
- const spend = Buffer.concat([toHexBuf(spendBuf.length, 32), spendBuf]);
2526
+ const spend = bufferExports.Buffer.concat([toHexBuf(spendBuf.length, 32), spendBuf]);
155
2527
  const outputBuf = this.forgeOutputDescriptions(tx.outputs);
156
- const output = Buffer.concat([toHexBuf(outputBuf.length, 32), outputBuf]);
157
- const root = Buffer.from(tx.root, 'hex');
158
- return Buffer.concat([
2528
+ const output = bufferExports.Buffer.concat([toHexBuf(outputBuf.length, 32), outputBuf]);
2529
+ const root = bufferExports.Buffer.from(tx.root, 'hex');
2530
+ return bufferExports.Buffer.concat([
159
2531
  spend,
160
2532
  output,
161
2533
  tx.signature,
@@ -176,10 +2548,10 @@ class SaplingForger {
176
2548
  const buff = this.forgeSpendDescription(i);
177
2549
  descriptions.push(buff);
178
2550
  }
179
- return Buffer.concat(descriptions);
2551
+ return bufferExports.Buffer.concat(descriptions);
180
2552
  }
181
2553
  forgeSpendDescription(desc) {
182
- return Buffer.concat([
2554
+ return bufferExports.Buffer.concat([
183
2555
  desc.commitmentValue,
184
2556
  desc.nullifier,
185
2557
  desc.publicKeyReRandomization,
@@ -198,11 +2570,11 @@ class SaplingForger {
198
2570
  const buff = this.forgeOutputDescription(i);
199
2571
  descriptions.push(buff);
200
2572
  }
201
- return Buffer.concat(descriptions);
2573
+ return bufferExports.Buffer.concat(descriptions);
202
2574
  }
203
2575
  forgeOutputDescription(desc) {
204
2576
  const ct = desc.ciphertext;
205
- return Buffer.concat([
2577
+ return bufferExports.Buffer.concat([
206
2578
  desc.commitment,
207
2579
  desc.proof,
208
2580
  ct.commitmentValue,
@@ -215,7 +2587,7 @@ class SaplingForger {
215
2587
  ]);
216
2588
  }
217
2589
  forgeUnsignedTxInput(unsignedSpendDescription) {
218
- return Buffer.concat([
2590
+ return bufferExports.Buffer.concat([
219
2591
  unsignedSpendDescription.commitmentValue,
220
2592
  unsignedSpendDescription.nullifier,
221
2593
  unsignedSpendDescription.publicKeyReRandomization,
@@ -223,8 +2595,8 @@ class SaplingForger {
223
2595
  ]);
224
2596
  }
225
2597
  forgeTransactionPlaintext(txPlainText) {
226
- const encodedMemo = Buffer.from(stringToBytes(txPlainText.memo).padEnd(txPlainText.memoSize, '0'), 'hex');
227
- return Buffer.concat([
2598
+ const encodedMemo = bufferExports.Buffer.from(stringToBytes(txPlainText.memo).padEnd(txPlainText.memoSize, '0'), 'hex');
2599
+ return bufferExports.Buffer.concat([
228
2600
  txPlainText.diversifier,
229
2601
  toHexBuf(new BigNumberJs(txPlainText.amount), 64),
230
2602
  txPlainText.randomCommitmentTrapdoor,
@@ -234,10 +2606,15 @@ class SaplingForger {
234
2606
  }
235
2607
  }
236
2608
 
2609
+ const globalWithBuffer = globalThis;
2610
+ if (typeof globalWithBuffer.Buffer === 'undefined') {
2611
+ globalWithBuffer.Buffer = bufferExports.Buffer;
2612
+ }
2613
+
237
2614
  const KDF_KEY = 'KDFSaplingForTezosV1';
238
2615
  const OCK_KEY = 'OCK_keystringderivation_TEZOS';
239
2616
  const DEFAULT_MEMO = '';
240
- const DEFAULT_BOUND_DATA = Buffer.from('', 'hex');
2617
+ const DEFAULT_BOUND_DATA = bufferExports.Buffer.from('', 'hex');
241
2618
 
242
2619
  var _SaplingTransactionViewer_viewingKeyProvider, _SaplingTransactionViewer_readProvider, _SaplingTransactionViewer_saplingContractId;
243
2620
  const BigNumber$3 = BigNumberJs;
@@ -335,14 +2712,14 @@ class SaplingTransactionViewer {
335
2712
  const commitment = commitmentsAndCiphertexts[0];
336
2713
  const { epk, payload_enc, nonce_enc } = commitmentsAndCiphertexts[1];
337
2714
  const incomingViewingKey = await __classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getIncomingViewingKey();
338
- const keyAgreement = await sapling.keyAgreement(epk, incomingViewingKey);
339
- const keyAgreementHash = blake.blake2b(keyAgreement, Buffer.from(KDF_KEY), 32);
2715
+ const keyAgreement$1 = await keyAgreement(epk, incomingViewingKey);
2716
+ const keyAgreementHash = blake.blake2b(keyAgreement$1, bufferExports.Buffer.from(KDF_KEY), 32);
340
2717
  const decrypted = await this.decryptCiphertext(keyAgreementHash, hex2buf(nonce_enc), hex2buf(payload_enc));
341
2718
  if (decrypted) {
342
2719
  const { diversifier, value, randomCommitmentTrapdoor: rcm, memo, } = this.extractTransactionProperties(decrypted);
343
- const paymentAddress = bufToUint8Array(await sapling.getRawPaymentAddressFromIncomingViewingKey(incomingViewingKey, diversifier));
2720
+ const paymentAddress = bufToUint8Array(await getRawPaymentAddressFromIncomingViewingKey(incomingViewingKey, diversifier));
344
2721
  try {
345
- const valid = await sapling.verifyCommitment(commitment, paymentAddress, convertValueToBigNumber(value).toString(), rcm);
2722
+ const valid = await verifyCommitment(commitment, paymentAddress, convertValueToBigNumber(value).toString(), rcm);
346
2723
  if (valid) {
347
2724
  return { value, memo, paymentAddress, randomCommitmentTrapdoor: rcm };
348
2725
  }
@@ -359,18 +2736,18 @@ class SaplingTransactionViewer {
359
2736
  const { epk, payload_enc, nonce_enc, payload_out, nonce_out, cv } = commitmentsAndCiphertexts[1];
360
2737
  const outgoingViewingKey = await __classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getOutgoingViewingKey();
361
2738
  const concat = cv.concat(commitment, epk, outgoingViewingKey.toString('hex'));
362
- const outgoingCipherKey = blake.blake2b(Buffer.from(concat, 'hex'), Buffer.from(OCK_KEY), 32);
2739
+ const outgoingCipherKey = blake.blake2b(bufferExports.Buffer.from(concat, 'hex'), bufferExports.Buffer.from(OCK_KEY), 32);
363
2740
  const decryptedOut = await this.decryptCiphertext(outgoingCipherKey, hex2buf(nonce_out), hex2buf(payload_out));
364
2741
  if (decryptedOut) {
365
2742
  const { recipientDiversifiedTransmissionKey: pkd, ephemeralPrivateKey: esk } = this.extractPkdAndEsk(decryptedOut);
366
- const keyAgreement = await sapling.keyAgreement(pkd, esk);
367
- const keyAgreementHash = blake.blake2b(keyAgreement, Buffer.from(KDF_KEY), 32);
2743
+ const keyAgreement$1 = await keyAgreement(pkd, esk);
2744
+ const keyAgreementHash = blake.blake2b(keyAgreement$1, bufferExports.Buffer.from(KDF_KEY), 32);
368
2745
  const decryptedEnc = await this.decryptCiphertext(keyAgreementHash, hex2buf(nonce_enc), hex2buf(payload_enc));
369
2746
  if (decryptedEnc) {
370
2747
  const { diversifier, value, randomCommitmentTrapdoor: rcm, memo, } = this.extractTransactionProperties(decryptedEnc);
371
2748
  const paymentAddress = mergebuf(diversifier, pkd);
372
2749
  try {
373
- const isValid = await sapling.verifyCommitment(commitment, paymentAddress, convertValueToBigNumber(value).toString(), rcm);
2750
+ const isValid = await verifyCommitment(commitment, paymentAddress, convertValueToBigNumber(value).toString(), rcm);
374
2751
  if (isValid) {
375
2752
  return { value, memo, paymentAddress, randomCommitmentTrapdoor: rcm };
376
2753
  }
@@ -402,7 +2779,7 @@ class SaplingTransactionViewer {
402
2779
  };
403
2780
  }
404
2781
  async isSpent(address, value, randomCommitmentTrapdoor, position, nullifiers) {
405
- const computedNullifier = await sapling.computeNullifier(__classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getFullViewingKey(), address, value, randomCommitmentTrapdoor, position);
2782
+ const computedNullifier = await computeNullifier(__classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getFullViewingKey(), address, value, randomCommitmentTrapdoor, position);
406
2783
  return nullifiers.includes(computedNullifier.toString('hex'));
407
2784
  }
408
2785
  }
@@ -496,10 +2873,10 @@ class SaplingState {
496
2873
  const posBuffer = hex2Bytes(changeEndianness(num2PaddedHex(position, 64)));
497
2874
  const neighbouringHashes = await this.getNeighbouringHashes([], stateTree.height, position, stateTree.tree);
498
2875
  const witness = neighbouringHashes
499
- .map((hash) => Buffer.concat([hex2Bytes(changeEndianness(num2PaddedHex(hash.length))), hash]))
2876
+ .map((hash) => bufferExports.Buffer.concat([hex2Bytes(changeEndianness(num2PaddedHex(hash.length))), hash]))
500
2877
  .reverse()
501
- .reduce((acc, next) => Buffer.concat([acc, next]));
502
- return Buffer.concat([heightBuffer, witness, posBuffer]).toString('hex');
2878
+ .reduce((acc, next) => bufferExports.Buffer.concat([acc, next]));
2879
+ return bufferExports.Buffer.concat([heightBuffer, witness, posBuffer]).toString('hex');
503
2880
  }
504
2881
  /**
505
2882
  *
@@ -528,10 +2905,10 @@ class SaplingState {
528
2905
  return (await this.uncommittedMerkleHashes.get())[height];
529
2906
  }
530
2907
  else if (typeof tree === 'string') {
531
- return Buffer.from(tree, 'hex');
2908
+ return bufferExports.Buffer.from(tree, 'hex');
532
2909
  }
533
2910
  else {
534
- return Buffer.from(tree[0], 'hex');
2911
+ return bufferExports.Buffer.from(tree[0], 'hex');
535
2912
  }
536
2913
  }
537
2914
  /**
@@ -540,7 +2917,7 @@ class SaplingState {
540
2917
  */
541
2918
  async createUncommittedMerkleHashes() {
542
2919
  const res = new Array(this.height);
543
- res[0] = Buffer.from(this.uncommittedMerkleHash, 'hex');
2920
+ res[0] = bufferExports.Buffer.from(this.uncommittedMerkleHash, 'hex');
544
2921
  for (let i = 0; i < this.height; i++) {
545
2922
  const hash = res[i];
546
2923
  res[i + 1] = await merkleHash(i, hash, hash);
@@ -592,10 +2969,16 @@ class SaplingState {
592
2969
  }
593
2970
  }
594
2971
 
595
- // eslint-disable-next-line @typescript-eslint/no-var-requires
596
- const saplingOutputParams = require('../saplingOutputParams');
597
- // eslint-disable-next-line @typescript-eslint/no-var-requires
598
- const saplingSpendParams = require('@taquito/sapling-spend-params');
2972
+ const loadSaplingOutputParams = () => {
2973
+ const saplingOutputParams = globalThis.__taquitoVendoredParams
2974
+ ?.saplingOutputParams;
2975
+ if (!saplingOutputParams) {
2976
+ throw new Error('Vendored sapling output params failed to load');
2977
+ }
2978
+ return saplingOutputParams;
2979
+ };
2980
+ var saplingOutputParams = loadSaplingOutputParams();
2981
+
599
2982
  let cachedParams;
600
2983
  const getRandomValueSource = () => {
601
2984
  const crypto = globalThis.crypto;
@@ -607,7 +2990,7 @@ const getRandomValueSource = () => {
607
2990
  class SaplingWrapper {
608
2991
  async withProvingContext(action) {
609
2992
  await this.initSaplingParameters();
610
- return sapling.withProvingContext(action);
2993
+ return withProvingContext(action);
611
2994
  }
612
2995
  getRandomBytes(length) {
613
2996
  const bytes = new Uint8Array(length);
@@ -615,13 +2998,13 @@ class SaplingWrapper {
615
2998
  return bytes;
616
2999
  }
617
3000
  async randR() {
618
- return sapling.randR();
3001
+ return randR();
619
3002
  }
620
3003
  async getOutgoingViewingKey(vk) {
621
- return sapling.getOutgoingViewingKey(vk);
3004
+ return getOutgoingViewingKey(vk);
622
3005
  }
623
3006
  async preparePartialOutputDescription(parametersOutputProof) {
624
- const partialOutputDesc = await sapling.preparePartialOutputDescription(parametersOutputProof.saplingContext, parametersOutputProof.address, parametersOutputProof.randomCommitmentTrapdoor, parametersOutputProof.ephemeralPrivateKey, parametersOutputProof.amount);
3007
+ const partialOutputDesc = await preparePartialOutputDescription(parametersOutputProof.saplingContext, parametersOutputProof.address, parametersOutputProof.randomCommitmentTrapdoor, parametersOutputProof.ephemeralPrivateKey, parametersOutputProof.amount);
625
3008
  return {
626
3009
  commitmentValue: partialOutputDesc.cv,
627
3010
  commitment: partialOutputDesc.cm,
@@ -629,28 +3012,28 @@ class SaplingWrapper {
629
3012
  };
630
3013
  }
631
3014
  async getDiversifiedFromRawPaymentAddress(decodedDestination) {
632
- return sapling.getDiversifiedFromRawPaymentAddress(decodedDestination);
3015
+ return getDiversifiedFromRawPaymentAddress(decodedDestination);
633
3016
  }
634
3017
  async deriveEphemeralPublicKey(diversifier, esk) {
635
- return sapling.deriveEphemeralPublicKey(diversifier, esk);
3018
+ return deriveEphemeralPublicKey(diversifier, esk);
636
3019
  }
637
3020
  async getPkdFromRawPaymentAddress(destination) {
638
- return sapling.getPkdFromRawPaymentAddress(destination);
3021
+ return getPkdFromRawPaymentAddress(destination);
639
3022
  }
640
3023
  async keyAgreement(p, sk) {
641
- return sapling.keyAgreement(p, sk);
3024
+ return keyAgreement(p, sk);
642
3025
  }
643
3026
  async createBindingSignature(saplingContext, balance, transactionSigHash) {
644
- return sapling.createBindingSignature(saplingContext, balance, transactionSigHash);
3027
+ return createBindingSignature(saplingContext, balance, transactionSigHash);
645
3028
  }
646
3029
  async initSaplingParameters() {
647
3030
  if (!cachedParams) {
648
3031
  cachedParams = {
649
- spend: Buffer.from(saplingSpendParams.saplingSpendParams, 'base64'),
650
- output: Buffer.from(saplingOutputParams.saplingOutputParams, 'base64'),
3032
+ spend: bufferExports.Buffer.from(saplingSpendParams.saplingSpendParams, 'base64'),
3033
+ output: bufferExports.Buffer.from(saplingOutputParams.saplingOutputParams, 'base64'),
651
3034
  };
652
3035
  }
653
- return sapling.initParameters(cachedParams.spend, cachedParams.output);
3036
+ return initParameters(cachedParams.spend, cachedParams.output);
654
3037
  }
655
3038
  }
656
3039
 
@@ -782,12 +3165,12 @@ class SaplingTransactionBuilder {
782
3165
  const diversifier = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getDiversifiedFromRawPaymentAddress(parametersOutputDescription.address);
783
3166
  const ephemeralPublicKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").deriveEphemeralPublicKey(diversifier, ephemeralPrivateKey);
784
3167
  const outgoingCipherKey = parametersOutputDescription.outgoingViewingKey
785
- ? blake.blake2b(Buffer.concat([
3168
+ ? blake.blake2b(bufferExports.Buffer.concat([
786
3169
  commitmentValue,
787
3170
  commitment,
788
3171
  ephemeralPublicKey,
789
3172
  parametersOutputDescription.outgoingViewingKey,
790
- ]), Buffer.from(OCK_KEY), 32)
3173
+ ]), bufferExports.Buffer.from(OCK_KEY), 32)
791
3174
  : __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(32);
792
3175
  const ciphertext = await this.encryptCiphertext({
793
3176
  address: parametersOutputDescription.address,
@@ -858,8 +3241,8 @@ class SaplingTransactionBuilder {
858
3241
  async encryptCiphertext(parametersCiphertext) {
859
3242
  const recipientDiversifiedTransmissionKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getPkdFromRawPaymentAddress(parametersCiphertext.address);
860
3243
  const keyAgreement = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").keyAgreement(recipientDiversifiedTransmissionKey, parametersCiphertext.ephemeralPrivateKey);
861
- const keyAgreementHash = blake.blake2b(keyAgreement, Buffer.from(KDF_KEY), 32);
862
- const nonceEnc = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
3244
+ const keyAgreementHash = blake.blake2b(keyAgreement, bufferExports.Buffer.from(KDF_KEY), 32);
3245
+ const nonceEnc = bufferExports.Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
863
3246
  const transactionPlaintext = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeTransactionPlaintext({
864
3247
  diversifier: parametersCiphertext.diversifier,
865
3248
  amount: parametersCiphertext.amount,
@@ -867,9 +3250,9 @@ class SaplingTransactionBuilder {
867
3250
  memoSize: __classPrivateFieldGet(this, _SaplingTransactionBuilder_memoSize, "f") * 2,
868
3251
  memo: parametersCiphertext.memo,
869
3252
  });
870
- const nonceOut = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
871
- const payloadEnc = Buffer.from(secretBox(keyAgreementHash, nonceEnc, transactionPlaintext));
872
- const payloadOut = Buffer.from(secretBox(parametersCiphertext.outgoingCipherKey, nonceOut, Buffer.concat([
3253
+ const nonceOut = bufferExports.Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
3254
+ const payloadEnc = bufferExports.Buffer.from(secretBox(keyAgreementHash, nonceEnc, transactionPlaintext));
3255
+ const payloadOut = bufferExports.Buffer.from(secretBox(parametersCiphertext.outgoingCipherKey, nonceOut, bufferExports.Buffer.concat([
873
3256
  recipientDiversifiedTransmissionKey,
874
3257
  parametersCiphertext.ephemeralPrivateKey,
875
3258
  ])));
@@ -890,7 +3273,7 @@ class SaplingTransactionBuilder {
890
3273
  async createBindingSignature(parametersBindingSig) {
891
3274
  const outputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeOutputDescriptions(parametersBindingSig.outputs);
892
3275
  const inputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeSpendDescriptions(parametersBindingSig.inputs);
893
- const transactionSigHash = blake.blake2b(Buffer.concat([inputs, outputs, parametersBindingSig.boundData]), await this.getAntiReplay(), 32);
3276
+ const transactionSigHash = blake.blake2b(bufferExports.Buffer.concat([inputs, outputs, parametersBindingSig.boundData]), await this.getAntiReplay(), 32);
894
3277
  return __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").createBindingSignature(parametersBindingSig.saplingContext, parametersBindingSig.balance.toFixed(), transactionSigHash);
895
3278
  }
896
3279
  async getAntiReplay() {
@@ -899,7 +3282,7 @@ class SaplingTransactionBuilder {
899
3282
  chainId = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getChainId();
900
3283
  __classPrivateFieldSet(this, _SaplingTransactionBuilder_chainId, chainId, "f");
901
3284
  }
902
- return Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
3285
+ return bufferExports.Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
903
3286
  }
904
3287
  }
905
3288
  _SaplingTransactionBuilder_inMemorySpendingKey = new WeakMap(), _SaplingTransactionBuilder_inMemoryProvingKey = new WeakMap(), _SaplingTransactionBuilder_saplingForger = new WeakMap(), _SaplingTransactionBuilder_contractAddress = new WeakMap(), _SaplingTransactionBuilder_saplingId = new WeakMap(), _SaplingTransactionBuilder_memoSize = new WeakMap(), _SaplingTransactionBuilder_readProvider = new WeakMap(), _SaplingTransactionBuilder_saplingWrapper = new WeakMap(), _SaplingTransactionBuilder_chainId = new WeakMap(), _SaplingTransactionBuilder_saplingState = new WeakMap();
@@ -1590,7 +3973,7 @@ var _InMemoryViewingKey_fullViewingKey;
1590
3973
  class InMemoryViewingKey {
1591
3974
  constructor(fullViewingKey) {
1592
3975
  _InMemoryViewingKey_fullViewingKey.set(this, void 0);
1593
- __classPrivateFieldSet(this, _InMemoryViewingKey_fullViewingKey, Buffer.from(fullViewingKey, 'hex'), "f");
3976
+ __classPrivateFieldSet(this, _InMemoryViewingKey_fullViewingKey, bufferExports.Buffer.from(fullViewingKey, 'hex'), "f");
1594
3977
  }
1595
3978
  /**
1596
3979
  * Allows to instantiate the InMemoryViewingKey from an encrypted/unencrypted spending key
@@ -1605,7 +3988,7 @@ class InMemoryViewingKey {
1605
3988
  */
1606
3989
  static async fromSpendingKey(spendingKey, password) {
1607
3990
  const spendingKeyBuf = decryptKey(spendingKey, password);
1608
- const viewingKey = await sapling.getExtendedFullViewingKeyFromSpendingKey(spendingKeyBuf);
3991
+ const viewingKey = await getExtendedFullViewingKeyFromSpendingKey(spendingKeyBuf);
1609
3992
  return new InMemoryViewingKey(viewingKey.toString('hex'));
1610
3993
  }
1611
3994
  /**
@@ -1622,7 +4005,7 @@ class InMemoryViewingKey {
1622
4005
  *
1623
4006
  */
1624
4007
  async getOutgoingViewingKey() {
1625
- return sapling.getOutgoingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
4008
+ return getOutgoingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
1626
4009
  }
1627
4010
  /**
1628
4011
  * Retrieve the incoming viewing key
@@ -1630,7 +4013,7 @@ class InMemoryViewingKey {
1630
4013
  *
1631
4014
  */
1632
4015
  async getIncomingViewingKey() {
1633
- return sapling.getIncomingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
4016
+ return getIncomingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
1634
4017
  }
1635
4018
  /**
1636
4019
  * Retrieve a payment address
@@ -1639,7 +4022,7 @@ class InMemoryViewingKey {
1639
4022
  *
1640
4023
  */
1641
4024
  async getAddress(addressIndex) {
1642
- const { index, raw } = await sapling.getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
4025
+ const { index, raw } = await getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
1643
4026
  return {
1644
4027
  address: b58Encode(raw, PrefixV2.SaplingAddress),
1645
4028
  addressIndex: index.readInt32LE(),
@@ -1709,8 +4092,8 @@ class InMemorySpendingKey {
1709
4092
  const first32 = fullSeed.slice(0, 32);
1710
4093
  const second32 = fullSeed.slice(32);
1711
4094
  // reduce seed bytes must be 32 bytes reflecting both halves
1712
- const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
1713
- const spendingKeyArr = new Uint8Array(await sapling.getExtendedSpendingKey(seed, derivationPath));
4095
+ const seed = bufferExports.Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
4096
+ const spendingKeyArr = new Uint8Array(await getExtendedSpendingKey(seed, derivationPath));
1714
4097
  const spendingKey = b58Encode(spendingKeyArr, PrefixV2.SaplingSpendingKey);
1715
4098
  return new InMemorySpendingKey(spendingKey);
1716
4099
  }
@@ -1721,7 +4104,7 @@ class InMemorySpendingKey {
1721
4104
  async getSaplingViewingKeyProvider() {
1722
4105
  let viewingKey;
1723
4106
  if (!__classPrivateFieldGet(this, _InMemorySpendingKey_saplingViewingKey, "f")) {
1724
- viewingKey = await sapling.getExtendedFullViewingKeyFromSpendingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
4107
+ viewingKey = await getExtendedFullViewingKeyFromSpendingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
1725
4108
  __classPrivateFieldSet(this, _InMemorySpendingKey_saplingViewingKey, new InMemoryViewingKey(viewingKey.toString('hex')), "f");
1726
4109
  }
1727
4110
  return __classPrivateFieldGet(this, _InMemorySpendingKey_saplingViewingKey, "f");
@@ -1738,7 +4121,7 @@ class InMemorySpendingKey {
1738
4121
  * @returns The unsigned spend description
1739
4122
  */
1740
4123
  async prepareSpendDescription(parametersSpendProof) {
1741
- const spendDescription = await sapling.prepareSpendDescriptionWithSpendingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
4124
+ const spendDescription = await prepareSpendDescriptionWithSpendingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
1742
4125
  return {
1743
4126
  commitmentValue: spendDescription.cv,
1744
4127
  nullifier: spendDescription.nf,
@@ -1755,7 +4138,7 @@ class InMemorySpendingKey {
1755
4138
  * @returns The signed spend description
1756
4139
  */
1757
4140
  async signSpendDescription(parametersSpendSig) {
1758
- const signedSpendDescription = await sapling.signSpendDescription({
4141
+ const signedSpendDescription = await signSpendDescription({
1759
4142
  cv: parametersSpendSig.unsignedSpendDescription.commitmentValue,
1760
4143
  rt: parametersSpendSig.unsignedSpendDescription.rtAnchor,
1761
4144
  nf: parametersSpendSig.unsignedSpendDescription.nullifier,
@@ -1774,7 +4157,7 @@ class InMemorySpendingKey {
1774
4157
  * Return a proof authorizing key from the configured spending key
1775
4158
  */
1776
4159
  async getProvingKey() {
1777
- const provingKey = await sapling.getProofAuthorizingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
4160
+ const provingKey = await getProofAuthorizingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
1778
4161
  return provingKey.toString('hex');
1779
4162
  }
1780
4163
  }
@@ -1788,7 +4171,7 @@ var _InMemoryProvingKey_provingKey;
1788
4171
  class InMemoryProvingKey {
1789
4172
  constructor(provingKey) {
1790
4173
  _InMemoryProvingKey_provingKey.set(this, void 0);
1791
- __classPrivateFieldSet(this, _InMemoryProvingKey_provingKey, Buffer.from(provingKey, 'hex'), "f");
4174
+ __classPrivateFieldSet(this, _InMemoryProvingKey_provingKey, bufferExports.Buffer.from(provingKey, 'hex'), "f");
1792
4175
  }
1793
4176
  /**
1794
4177
  * Allows to instantiate the InMemoryProvingKey from an encrypted/unencrypted spending key
@@ -1803,7 +4186,7 @@ class InMemoryProvingKey {
1803
4186
  */
1804
4187
  static async fromSpendingKey(spendingKey, password) {
1805
4188
  const decodedSpendingKey = decryptKey(spendingKey, password);
1806
- const provingKey = await sapling.getProofAuthorizingKey(decodedSpendingKey);
4189
+ const provingKey = await getProofAuthorizingKey(decodedSpendingKey);
1807
4190
  return new InMemoryProvingKey(provingKey.toString('hex'));
1808
4191
  }
1809
4192
  /**
@@ -1819,7 +4202,7 @@ class InMemoryProvingKey {
1819
4202
  * @returns The unsinged spend description
1820
4203
  */
1821
4204
  async prepareSpendDescription(parametersSpendProof) {
1822
- const spendDescription = await sapling.prepareSpendDescriptionWithAuthorizingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemoryProvingKey_provingKey, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
4205
+ const spendDescription = await prepareSpendDescriptionWithAuthorizingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemoryProvingKey_provingKey, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
1823
4206
  return {
1824
4207
  commitmentValue: spendDescription.cv,
1825
4208
  nullifier: spendDescription.nf,
@@ -1992,7 +4375,7 @@ class SaplingToolkit {
1992
4375
  data: { bytes },
1993
4376
  type: { prim: 'bytes' },
1994
4377
  });
1995
- return Buffer.from(packedDestination.packed, 'hex');
4378
+ return bufferExports.Buffer.from(packedDestination.packed, 'hex');
1996
4379
  }
1997
4380
  validateDestinationImplicitAddress(to) {
1998
4381
  const toValidation = validateKeyHash(to);