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