@pooflabs/web 0.0.75 → 0.0.77

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 (83) hide show
  1. package/README.md +32 -0
  2. package/dist/auth/providers/sol/sol-utils.d.ts +2 -0
  3. package/dist/{index-BcDe_euX.js → index-Bfk81d8_.js} +883 -25
  4. package/dist/index-Bfk81d8_.js.map +1 -0
  5. package/dist/{index-Dho2J3X6.esm.js → index-CFh1x-M0.esm.js} +368 -162
  6. package/dist/index-CFh1x-M0.esm.js.map +1 -0
  7. package/dist/index-CdOv7Nw2.esm.js +6 -0
  8. package/dist/index-CdOv7Nw2.esm.js.map +1 -0
  9. package/dist/{index-_vhjpl1l.esm.js → index-CeQ8hE3s.esm.js} +881 -24
  10. package/dist/index-CeQ8hE3s.esm.js.map +1 -0
  11. package/dist/index-DDXzCx2W.js +8 -0
  12. package/dist/index-DDXzCx2W.js.map +1 -0
  13. package/dist/{index-CMeewi-G.js → index-DQVpAl5t.js} +368 -161
  14. package/dist/index-DQVpAl5t.js.map +1 -0
  15. package/dist/{index-BHYrnHi6.js → index-KUU0aVzP.js} +882 -24
  16. package/dist/index-KUU0aVzP.js.map +1 -0
  17. package/dist/{index-BqDvUK9s.esm.js → index-R7t9pRt_.esm.js} +882 -23
  18. package/dist/index-R7t9pRt_.esm.js.map +1 -0
  19. package/dist/{index.browser-Br0p4bjw.esm.js → index.browser-BE44CEaJ.esm.js} +3 -3
  20. package/dist/{index.browser-Br0p4bjw.esm.js.map → index.browser-BE44CEaJ.esm.js.map} +1 -1
  21. package/dist/{index.browser-DZjyUgtx.esm.js → index.browser-C-_FEr5M.esm.js} +449 -479
  22. package/dist/index.browser-C-_FEr5M.esm.js.map +1 -0
  23. package/dist/index.browser-C9bFQZyQ.esm.js +1373 -0
  24. package/dist/index.browser-C9bFQZyQ.esm.js.map +1 -0
  25. package/dist/index.browser-Dbq5Qf1G.esm.js +242 -0
  26. package/dist/index.browser-Dbq5Qf1G.esm.js.map +1 -0
  27. package/dist/index.browser-Df7yN8D5.js +245 -0
  28. package/dist/index.browser-Df7yN8D5.js.map +1 -0
  29. package/dist/{index.browser-BzHjnrpD.js → index.browser-Di1_YZpi.js} +3 -3
  30. package/dist/{index.browser-BzHjnrpD.js.map → index.browser-Di1_YZpi.js.map} +1 -1
  31. package/dist/{index.browser-BOJRGZWX.js → index.browser-DjEZSiqI.js} +449 -479
  32. package/dist/index.browser-DjEZSiqI.js.map +1 -0
  33. package/dist/index.browser-dszs5oe5.js +1376 -0
  34. package/dist/index.browser-dszs5oe5.js.map +1 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.esm.js +1 -1
  37. package/dist/index.js +3 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/{index.native-DcKDTqvq.js → index.native-CKd2b3_F.js} +2767 -188
  40. package/dist/index.native-CKd2b3_F.js.map +1 -0
  41. package/dist/{index.native-BB7er4-z.esm.js → index.native-DAyMVhFq.esm.js} +2766 -190
  42. package/dist/index.native-DAyMVhFq.esm.js.map +1 -0
  43. package/dist/index.native.d.ts +1 -0
  44. package/dist/index.native.esm.js +1 -1
  45. package/dist/index.native.js +3 -1
  46. package/dist/index.native.js.map +1 -1
  47. package/dist/{phantom-wallet-provider-DMxFAUC4.js → phantom-wallet-provider-DJ6qf2VB.js} +4 -4
  48. package/dist/{phantom-wallet-provider-DMxFAUC4.js.map → phantom-wallet-provider-DJ6qf2VB.js.map} +1 -1
  49. package/dist/{phantom-wallet-provider-DHok8ui3.esm.js → phantom-wallet-provider-DQ0uhl2v.esm.js} +4 -4
  50. package/dist/{phantom-wallet-provider-DHok8ui3.esm.js.map → phantom-wallet-provider-DQ0uhl2v.esm.js.map} +1 -1
  51. package/dist/{privy-wallet-provider-CFuoQYuv.esm.js → privy-wallet-provider-BhiHnphv.esm.js} +7 -8
  52. package/dist/privy-wallet-provider-BhiHnphv.esm.js.map +1 -0
  53. package/dist/{privy-wallet-provider-Bhvw0t1d.js → privy-wallet-provider-CMCv5g3O.js} +7 -8
  54. package/dist/privy-wallet-provider-CMCv5g3O.js.map +1 -0
  55. package/dist/{solana-mobile-wallet-provider-BpQghAgC.esm.js → solana-mobile-wallet-provider-DSSk_6CR.esm.js} +4 -4
  56. package/dist/{solana-mobile-wallet-provider-BpQghAgC.esm.js.map → solana-mobile-wallet-provider-DSSk_6CR.esm.js.map} +1 -1
  57. package/dist/{solana-mobile-wallet-provider-D8b5y-By.js → solana-mobile-wallet-provider-DaFNesCe.js} +4 -4
  58. package/dist/{solana-mobile-wallet-provider-D8b5y-By.js.map → solana-mobile-wallet-provider-DaFNesCe.js.map} +1 -1
  59. package/package.json +2 -2
  60. package/dist/index-BHYrnHi6.js.map +0 -1
  61. package/dist/index-BcDe_euX.js.map +0 -1
  62. package/dist/index-Bdcc5821.js +0 -2375
  63. package/dist/index-Bdcc5821.js.map +0 -1
  64. package/dist/index-BqDvUK9s.esm.js.map +0 -1
  65. package/dist/index-CMeewi-G.js.map +0 -1
  66. package/dist/index-CrOVJFX9.esm.js +0 -2373
  67. package/dist/index-CrOVJFX9.esm.js.map +0 -1
  68. package/dist/index-Dho2J3X6.esm.js.map +0 -1
  69. package/dist/index-_vhjpl1l.esm.js.map +0 -1
  70. package/dist/index.browser-BOJRGZWX.js.map +0 -1
  71. package/dist/index.browser-Btm3sRKb.esm.js +0 -307
  72. package/dist/index.browser-Btm3sRKb.esm.js.map +0 -1
  73. package/dist/index.browser-CGfjPfzM.esm.js +0 -1468
  74. package/dist/index.browser-CGfjPfzM.esm.js.map +0 -1
  75. package/dist/index.browser-DZjyUgtx.esm.js.map +0 -1
  76. package/dist/index.browser-Dapjfbl6.js +0 -310
  77. package/dist/index.browser-Dapjfbl6.js.map +0 -1
  78. package/dist/index.browser-JX3F6oPV.js +0 -1471
  79. package/dist/index.browser-JX3F6oPV.js.map +0 -1
  80. package/dist/index.native-BB7er4-z.esm.js.map +0 -1
  81. package/dist/index.native-DcKDTqvq.js.map +0 -1
  82. package/dist/privy-wallet-provider-Bhvw0t1d.js.map +0 -1
  83. package/dist/privy-wallet-provider-CFuoQYuv.esm.js.map +0 -1
@@ -1,9 +1,24 @@
1
1
  import globalAxios from 'axios';
2
- import { PublicKey, SystemProgram, TransactionInstruction, ComputeBudgetProgram, Keypair, VersionedTransaction, TransactionMessage, Connection, Transaction } from '@solana/web3.js';
2
+ import { PublicKey, SystemProgram, TransactionInstruction, ComputeBudgetProgram, Keypair, VersionedTransaction, TransactionMessage, Transaction, Connection } from '@solana/web3.js';
3
3
  import * as anchor from '@coral-xyz/anchor';
4
4
  import { Program } from '@coral-xyz/anchor';
5
5
  import * as React from 'react';
6
6
 
7
+ function _mergeNamespaces(n, m) {
8
+ m.forEach(function (e) {
9
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default' && !(k in n)) {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ });
19
+ return Object.freeze(n);
20
+ }
21
+
7
22
  function getDefaultExportFromCjs$1 (x) {
8
23
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
24
  }
@@ -6588,19 +6603,19 @@ function getDefaultExportFromCjs (x) {
6588
6603
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6589
6604
  }
6590
6605
 
6591
- var buffer = {};
6606
+ var buffer$1 = {};
6592
6607
 
6593
- var base64Js = {};
6608
+ var base64Js$1 = {};
6594
6609
 
6595
- var hasRequiredBase64Js;
6610
+ var hasRequiredBase64Js$1;
6596
6611
 
6597
- function requireBase64Js () {
6598
- if (hasRequiredBase64Js) return base64Js;
6599
- hasRequiredBase64Js = 1;
6612
+ function requireBase64Js$1 () {
6613
+ if (hasRequiredBase64Js$1) return base64Js$1;
6614
+ hasRequiredBase64Js$1 = 1;
6600
6615
 
6601
- base64Js.byteLength = byteLength;
6602
- base64Js.toByteArray = toByteArray;
6603
- base64Js.fromByteArray = fromByteArray;
6616
+ base64Js$1.byteLength = byteLength;
6617
+ base64Js$1.toByteArray = toByteArray;
6618
+ base64Js$1.fromByteArray = fromByteArray;
6604
6619
 
6605
6620
  var lookup = [];
6606
6621
  var revLookup = [];
@@ -6746,19 +6761,19 @@ function requireBase64Js () {
6746
6761
 
6747
6762
  return parts.join('')
6748
6763
  }
6749
- return base64Js;
6764
+ return base64Js$1;
6750
6765
  }
6751
6766
 
6752
- var ieee754 = {};
6767
+ var ieee754$1 = {};
6753
6768
 
6754
6769
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
6755
6770
 
6756
- var hasRequiredIeee754;
6771
+ var hasRequiredIeee754$1;
6757
6772
 
6758
- function requireIeee754 () {
6759
- if (hasRequiredIeee754) return ieee754;
6760
- hasRequiredIeee754 = 1;
6761
- ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
6773
+ function requireIeee754$1 () {
6774
+ if (hasRequiredIeee754$1) return ieee754$1;
6775
+ hasRequiredIeee754$1 = 1;
6776
+ ieee754$1.read = function (buffer, offset, isLE, mLen, nBytes) {
6762
6777
  var e, m;
6763
6778
  var eLen = (nBytes * 8) - mLen - 1;
6764
6779
  var eMax = (1 << eLen) - 1;
@@ -6791,7 +6806,7 @@ function requireIeee754 () {
6791
6806
  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
6792
6807
  };
6793
6808
 
6794
- ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
6809
+ ieee754$1.write = function (buffer, value, offset, isLE, mLen, nBytes) {
6795
6810
  var e, m, c;
6796
6811
  var eLen = (nBytes * 8) - mLen - 1;
6797
6812
  var eMax = (1 << eLen) - 1;
@@ -6842,7 +6857,7 @@ function requireIeee754 () {
6842
6857
 
6843
6858
  buffer[offset + i - d] |= s * 128;
6844
6859
  };
6845
- return ieee754;
6860
+ return ieee754$1;
6846
6861
  }
6847
6862
 
6848
6863
  /*!
@@ -6852,15 +6867,15 @@ function requireIeee754 () {
6852
6867
  * @license MIT
6853
6868
  */
6854
6869
 
6855
- var hasRequiredBuffer;
6870
+ var hasRequiredBuffer$1;
6856
6871
 
6857
- function requireBuffer () {
6858
- if (hasRequiredBuffer) return buffer;
6859
- hasRequiredBuffer = 1;
6872
+ function requireBuffer$1 () {
6873
+ if (hasRequiredBuffer$1) return buffer$1;
6874
+ hasRequiredBuffer$1 = 1;
6860
6875
  (function (exports$1) {
6861
6876
 
6862
- const base64 = requireBase64Js();
6863
- const ieee754 = requireIeee754();
6877
+ const base64 = requireBase64Js$1();
6878
+ const ieee754 = requireIeee754$1();
6864
6879
  const customInspectSymbol =
6865
6880
  (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
6866
6881
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
@@ -8953,24 +8968,24 @@ function requireBuffer () {
8953
8968
  function BufferBigIntNotDefined () {
8954
8969
  throw new Error('BigInt not supported')
8955
8970
  }
8956
- } (buffer));
8957
- return buffer;
8971
+ } (buffer$1));
8972
+ return buffer$1;
8958
8973
  }
8959
8974
 
8960
- var bufferExports = requireBuffer();
8975
+ var bufferExports = requireBuffer$1();
8961
8976
 
8962
- var safeBuffer = {exports: {}};
8977
+ var safeBuffer$1 = {exports: {}};
8963
8978
 
8964
8979
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
8965
8980
 
8966
- var hasRequiredSafeBuffer;
8981
+ var hasRequiredSafeBuffer$1;
8967
8982
 
8968
- function requireSafeBuffer () {
8969
- if (hasRequiredSafeBuffer) return safeBuffer.exports;
8970
- hasRequiredSafeBuffer = 1;
8983
+ function requireSafeBuffer$1 () {
8984
+ if (hasRequiredSafeBuffer$1) return safeBuffer$1.exports;
8985
+ hasRequiredSafeBuffer$1 = 1;
8971
8986
  (function (module, exports$1) {
8972
8987
  /* eslint-disable node/no-deprecated-api */
8973
- var buffer = requireBuffer();
8988
+ var buffer = requireBuffer$1();
8974
8989
  var Buffer = buffer.Buffer;
8975
8990
 
8976
8991
  // alternative to using Object.keys for old browsers
@@ -9033,23 +9048,23 @@ function requireSafeBuffer () {
9033
9048
  }
9034
9049
  return buffer.SlowBuffer(size)
9035
9050
  };
9036
- } (safeBuffer, safeBuffer.exports));
9037
- return safeBuffer.exports;
9051
+ } (safeBuffer$1, safeBuffer$1.exports));
9052
+ return safeBuffer$1.exports;
9038
9053
  }
9039
9054
 
9040
- var src;
9041
- var hasRequiredSrc;
9055
+ var src$1;
9056
+ var hasRequiredSrc$1;
9042
9057
 
9043
- function requireSrc () {
9044
- if (hasRequiredSrc) return src;
9045
- hasRequiredSrc = 1;
9058
+ function requireSrc$1 () {
9059
+ if (hasRequiredSrc$1) return src$1;
9060
+ hasRequiredSrc$1 = 1;
9046
9061
  // base-x encoding / decoding
9047
9062
  // Copyright (c) 2018 base-x contributors
9048
9063
  // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
9049
9064
  // Distributed under the MIT software license, see the accompanying
9050
9065
  // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
9051
9066
  // @ts-ignore
9052
- var _Buffer = requireSafeBuffer().Buffer;
9067
+ var _Buffer = requireSafeBuffer$1().Buffer;
9053
9068
  function base (ALPHABET) {
9054
9069
  if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
9055
9070
  var BASE_MAP = new Uint8Array(256);
@@ -9164,25 +9179,25 @@ function requireSrc () {
9164
9179
  decode: decode
9165
9180
  }
9166
9181
  }
9167
- src = base;
9168
- return src;
9182
+ src$1 = base;
9183
+ return src$1;
9169
9184
  }
9170
9185
 
9171
- var bs58$1;
9172
- var hasRequiredBs58;
9186
+ var bs58$1$1;
9187
+ var hasRequiredBs58$1;
9173
9188
 
9174
- function requireBs58 () {
9175
- if (hasRequiredBs58) return bs58$1;
9176
- hasRequiredBs58 = 1;
9177
- var basex = requireSrc();
9189
+ function requireBs58$1 () {
9190
+ if (hasRequiredBs58$1) return bs58$1$1;
9191
+ hasRequiredBs58$1 = 1;
9192
+ var basex = requireSrc$1();
9178
9193
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
9179
9194
 
9180
- bs58$1 = basex(ALPHABET);
9181
- return bs58$1;
9195
+ bs58$1$1 = basex(ALPHABET);
9196
+ return bs58$1$1;
9182
9197
  }
9183
9198
 
9184
- var bs58Exports = requireBs58();
9185
- var bs58$2 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
9199
+ var bs58Exports$1 = requireBs58$1();
9200
+ var bs58$2 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports$1);
9186
9201
 
9187
9202
  // ─────────────────────────────────────────────────────────────
9188
9203
  // Local implementation of getSimulationComputeUnits
@@ -10101,6 +10116,90 @@ function cleanupExpiredCache() {
10101
10116
  });
10102
10117
  lastCacheCleanup = now;
10103
10118
  }
10119
+ async function getMany(paths, opts = {}) {
10120
+ if (paths.length === 0) {
10121
+ return [];
10122
+ }
10123
+ if (paths.length > 30) {
10124
+ throw new Error('Cannot fetch more than 30 documents at once');
10125
+ }
10126
+ const normalizedPaths = [];
10127
+ for (const path of paths) {
10128
+ let normalizedPath = path.startsWith("/") ? path.slice(1) : path;
10129
+ if (normalizedPath.endsWith("*") && normalizedPath.length > 1) {
10130
+ normalizedPath = normalizedPath.slice(0, -1);
10131
+ }
10132
+ if (!normalizedPath || normalizedPath.length === 0) {
10133
+ throw new Error(`Invalid path provided: ${path}`);
10134
+ }
10135
+ const pathIsDocument = normalizedPath.split("/").length % 2 === 0;
10136
+ if (!pathIsDocument) {
10137
+ throw new Error(`Path must point to a document (even number of segments): ${path}`);
10138
+ }
10139
+ normalizedPaths.push(normalizedPath);
10140
+ }
10141
+ const now = Date.now();
10142
+ const results = new Array(paths.length);
10143
+ const uncachedIndices = [];
10144
+ const uncachedPaths = [];
10145
+ for (let i = 0; i < normalizedPaths.length; i++) {
10146
+ const normalizedPath = normalizedPaths[i];
10147
+ const cacheKey = `${normalizedPath}:`;
10148
+ if (!opts.bypassCache && getCache[cacheKey] && now < getCache[cacheKey].expiresAt) {
10149
+ results[i] = { path: normalizedPath, data: getCache[cacheKey].data };
10150
+ }
10151
+ else {
10152
+ uncachedIndices.push(i);
10153
+ uncachedPaths.push(normalizedPath);
10154
+ }
10155
+ }
10156
+ if (uncachedPaths.length > 0) {
10157
+ try {
10158
+ const response = await makeApiRequest('POST', 'items/batch', { paths: uncachedPaths }, opts._overrides);
10159
+ const serverResults = response.data.results;
10160
+ const serverResultsMap = new Map();
10161
+ for (const result of serverResults) {
10162
+ serverResultsMap.set(result.path, result);
10163
+ }
10164
+ for (let i = 0; i < uncachedIndices.length; i++) {
10165
+ const originalIndex = uncachedIndices[i];
10166
+ const normalizedPath = uncachedPaths[i];
10167
+ const serverResult = serverResultsMap.get(normalizedPath);
10168
+ if (serverResult) {
10169
+ results[originalIndex] = serverResult;
10170
+ if (!serverResult.error && !opts.bypassCache) {
10171
+ const cacheKey = `${normalizedPath}:`;
10172
+ getCache[cacheKey] = {
10173
+ data: serverResult.data,
10174
+ expiresAt: now + GET_CACHE_TTL
10175
+ };
10176
+ }
10177
+ }
10178
+ else {
10179
+ results[originalIndex] = {
10180
+ path: normalizedPath,
10181
+ data: null,
10182
+ error: { code: 'NOT_FOUND', message: `No result returned for path ${normalizedPath}` }
10183
+ };
10184
+ }
10185
+ }
10186
+ if (now - lastCacheCleanup > 5000) {
10187
+ cleanupExpiredCache();
10188
+ lastCacheCleanup = now;
10189
+ }
10190
+ }
10191
+ catch (error) {
10192
+ for (const originalIndex of uncachedIndices) {
10193
+ results[originalIndex] = {
10194
+ path: normalizedPaths[originalIndex],
10195
+ data: null,
10196
+ error: { code: 'NOT_FOUND', message: error instanceof Error ? error.message : 'Unknown error' }
10197
+ };
10198
+ }
10199
+ }
10200
+ }
10201
+ return results;
10202
+ }
10104
10203
  async function runQuery(absolutePath, queryName, queryArgs, opts) {
10105
10204
  const result = await runQueryMany([{ absolutePath, queryName, queryArgs }], opts);
10106
10205
  return result[0];
@@ -12386,15 +12485,15 @@ function clearIncompatibleSession() {
12386
12485
  // Lazy loaders for web-only providers.
12387
12486
  // Using dynamic import() ensures Metro (RN) never resolves these modules.
12388
12487
  async function loadPrivyWalletProvider() {
12389
- const mod = await import('./privy-wallet-provider-CFuoQYuv.esm.js');
12488
+ const mod = await import('./privy-wallet-provider-BhiHnphv.esm.js');
12390
12489
  return mod.PrivyWalletProvider;
12391
12490
  }
12392
12491
  async function loadPhantomWalletProvider() {
12393
- const mod = await import('./phantom-wallet-provider-DHok8ui3.esm.js');
12492
+ const mod = await import('./phantom-wallet-provider-DQ0uhl2v.esm.js');
12394
12493
  return { PhantomWalletProvider: mod.PhantomWalletProvider };
12395
12494
  }
12396
12495
  async function loadSolanaMobileWalletProvider() {
12397
- const mod = await import('./solana-mobile-wallet-provider-BpQghAgC.esm.js');
12496
+ const mod = await import('./solana-mobile-wallet-provider-DSSk_6CR.esm.js');
12398
12497
  return mod.SolanaMobileWalletProvider;
12399
12498
  }
12400
12499
  async function hotSwapToPrivyProvider(config) {
@@ -12741,6 +12840,16 @@ function useAuth() {
12741
12840
  };
12742
12841
  }
12743
12842
 
12843
+ async function deserializeTransaction(tx) {
12844
+ const buf = Buffer.isBuffer(tx) ? tx : Buffer.from(tx, 'base64');
12845
+ if ((buf[0] & 0x80) !== 0) {
12846
+ return VersionedTransaction.deserialize(buf);
12847
+ }
12848
+ else {
12849
+ return Transaction.from(buf);
12850
+ }
12851
+ }
12852
+
12744
12853
  // Wrapper for getIdToken - passes isServer=false for client-side usage
12745
12854
  async function getIdToken() {
12746
12855
  return getIdToken$1(false);
@@ -12794,137 +12903,2604 @@ async function confirmAndCheckTransaction(connection, signature) {
12794
12903
  throw new Error('Transaction confirmation timeout');
12795
12904
  }
12796
12905
 
12797
- // base-x encoding / decoding
12798
- // Copyright (c) 2018 base-x contributors
12799
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
12800
- // Distributed under the MIT software license, see the accompanying
12801
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
12802
- function base (ALPHABET) {
12803
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
12804
- const BASE_MAP = new Uint8Array(256);
12805
- for (let j = 0; j < BASE_MAP.length; j++) {
12806
- BASE_MAP[j] = 255;
12807
- }
12808
- for (let i = 0; i < ALPHABET.length; i++) {
12809
- const x = ALPHABET.charAt(i);
12810
- const xc = x.charCodeAt(0);
12811
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
12812
- BASE_MAP[xc] = i;
12813
- }
12814
- const BASE = ALPHABET.length;
12815
- const LEADER = ALPHABET.charAt(0);
12816
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
12817
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
12818
- function encode (source) {
12819
- // eslint-disable-next-line no-empty
12820
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
12821
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
12822
- } else if (Array.isArray(source)) {
12823
- source = Uint8Array.from(source);
12824
- }
12825
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
12826
- if (source.length === 0) { return '' }
12827
- // Skip & count leading zeroes.
12828
- let zeroes = 0;
12829
- let length = 0;
12830
- let pbegin = 0;
12831
- const pend = source.length;
12832
- while (pbegin !== pend && source[pbegin] === 0) {
12833
- pbegin++;
12834
- zeroes++;
12835
- }
12836
- // Allocate enough space in big-endian base58 representation.
12837
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
12838
- const b58 = new Uint8Array(size);
12839
- // Process the bytes.
12840
- while (pbegin !== pend) {
12841
- let carry = source[pbegin];
12842
- // Apply "b58 = b58 * 256 + ch".
12843
- let i = 0;
12844
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
12845
- carry += (256 * b58[it1]) >>> 0;
12846
- b58[it1] = (carry % BASE) >>> 0;
12847
- carry = (carry / BASE) >>> 0;
12848
- }
12849
- if (carry !== 0) { throw new Error('Non-zero carry') }
12850
- length = i;
12851
- pbegin++;
12852
- }
12853
- // Skip leading zeroes in base58 result.
12854
- let it2 = size - length;
12855
- while (it2 !== size && b58[it2] === 0) {
12856
- it2++;
12857
- }
12858
- // Translate the result into a string.
12859
- let str = LEADER.repeat(zeroes);
12860
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
12861
- return str
12862
- }
12863
- function decodeUnsafe (source) {
12864
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
12865
- if (source.length === 0) { return new Uint8Array() }
12866
- let psz = 0;
12867
- // Skip and count leading '1's.
12868
- let zeroes = 0;
12869
- let length = 0;
12870
- while (source[psz] === LEADER) {
12871
- zeroes++;
12872
- psz++;
12873
- }
12874
- // Allocate enough space in big-endian base256 representation.
12875
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
12876
- const b256 = new Uint8Array(size);
12877
- // Process the characters.
12878
- while (psz < source.length) {
12879
- // Find code of next character
12880
- const charCode = source.charCodeAt(psz);
12881
- // Base map can not be indexed using char code
12882
- if (charCode > 255) { return }
12883
- // Decode character
12884
- let carry = BASE_MAP[charCode];
12885
- // Invalid character
12886
- if (carry === 255) { return }
12887
- let i = 0;
12888
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
12889
- carry += (BASE * b256[it3]) >>> 0;
12890
- b256[it3] = (carry % 256) >>> 0;
12891
- carry = (carry / 256) >>> 0;
12892
- }
12893
- if (carry !== 0) { throw new Error('Non-zero carry') }
12894
- length = i;
12895
- psz++;
12896
- }
12897
- // Skip leading zeroes in b256.
12898
- let it4 = size - length;
12899
- while (it4 !== size && b256[it4] === 0) {
12900
- it4++;
12901
- }
12902
- const vch = new Uint8Array(zeroes + (size - it4));
12903
- let j = zeroes;
12904
- while (it4 !== size) {
12905
- vch[j++] = b256[it4++];
12906
- }
12907
- return vch
12908
- }
12909
- function decode (string) {
12910
- const buffer = decodeUnsafe(string);
12911
- if (buffer) { return buffer }
12912
- throw new Error('Non-base' + BASE + ' character')
12913
- }
12914
- return {
12915
- encode,
12916
- decodeUnsafe,
12917
- decode
12918
- }
12919
- }
12920
-
12921
- var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
12922
- var bs58 = base(ALPHABET);
12923
-
12924
- var index = /*#__PURE__*/Object.freeze({
12925
- __proto__: null,
12926
- default: bs58
12927
- });
12906
+ var safeBuffer = {exports: {}};
12907
+
12908
+ var buffer = {};
12909
+
12910
+ var base64Js = {};
12911
+
12912
+ var hasRequiredBase64Js;
12913
+
12914
+ function requireBase64Js () {
12915
+ if (hasRequiredBase64Js) return base64Js;
12916
+ hasRequiredBase64Js = 1;
12917
+
12918
+ base64Js.byteLength = byteLength;
12919
+ base64Js.toByteArray = toByteArray;
12920
+ base64Js.fromByteArray = fromByteArray;
12921
+
12922
+ var lookup = [];
12923
+ var revLookup = [];
12924
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
12925
+
12926
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
12927
+ for (var i = 0, len = code.length; i < len; ++i) {
12928
+ lookup[i] = code[i];
12929
+ revLookup[code.charCodeAt(i)] = i;
12930
+ }
12931
+
12932
+ // Support decoding URL-safe base64 strings, as Node.js does.
12933
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
12934
+ revLookup['-'.charCodeAt(0)] = 62;
12935
+ revLookup['_'.charCodeAt(0)] = 63;
12936
+
12937
+ function getLens (b64) {
12938
+ var len = b64.length;
12939
+
12940
+ if (len % 4 > 0) {
12941
+ throw new Error('Invalid string. Length must be a multiple of 4')
12942
+ }
12943
+
12944
+ // Trim off extra bytes after placeholder bytes are found
12945
+ // See: https://github.com/beatgammit/base64-js/issues/42
12946
+ var validLen = b64.indexOf('=');
12947
+ if (validLen === -1) validLen = len;
12948
+
12949
+ var placeHoldersLen = validLen === len
12950
+ ? 0
12951
+ : 4 - (validLen % 4);
12952
+
12953
+ return [validLen, placeHoldersLen]
12954
+ }
12955
+
12956
+ // base64 is 4/3 + up to two characters of the original data
12957
+ function byteLength (b64) {
12958
+ var lens = getLens(b64);
12959
+ var validLen = lens[0];
12960
+ var placeHoldersLen = lens[1];
12961
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
12962
+ }
12963
+
12964
+ function _byteLength (b64, validLen, placeHoldersLen) {
12965
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
12966
+ }
12967
+
12968
+ function toByteArray (b64) {
12969
+ var tmp;
12970
+ var lens = getLens(b64);
12971
+ var validLen = lens[0];
12972
+ var placeHoldersLen = lens[1];
12973
+
12974
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
12975
+
12976
+ var curByte = 0;
12977
+
12978
+ // if there are placeholders, only get up to the last complete 4 chars
12979
+ var len = placeHoldersLen > 0
12980
+ ? validLen - 4
12981
+ : validLen;
12982
+
12983
+ var i;
12984
+ for (i = 0; i < len; i += 4) {
12985
+ tmp =
12986
+ (revLookup[b64.charCodeAt(i)] << 18) |
12987
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
12988
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
12989
+ revLookup[b64.charCodeAt(i + 3)];
12990
+ arr[curByte++] = (tmp >> 16) & 0xFF;
12991
+ arr[curByte++] = (tmp >> 8) & 0xFF;
12992
+ arr[curByte++] = tmp & 0xFF;
12993
+ }
12994
+
12995
+ if (placeHoldersLen === 2) {
12996
+ tmp =
12997
+ (revLookup[b64.charCodeAt(i)] << 2) |
12998
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
12999
+ arr[curByte++] = tmp & 0xFF;
13000
+ }
13001
+
13002
+ if (placeHoldersLen === 1) {
13003
+ tmp =
13004
+ (revLookup[b64.charCodeAt(i)] << 10) |
13005
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
13006
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
13007
+ arr[curByte++] = (tmp >> 8) & 0xFF;
13008
+ arr[curByte++] = tmp & 0xFF;
13009
+ }
13010
+
13011
+ return arr
13012
+ }
13013
+
13014
+ function tripletToBase64 (num) {
13015
+ return lookup[num >> 18 & 0x3F] +
13016
+ lookup[num >> 12 & 0x3F] +
13017
+ lookup[num >> 6 & 0x3F] +
13018
+ lookup[num & 0x3F]
13019
+ }
13020
+
13021
+ function encodeChunk (uint8, start, end) {
13022
+ var tmp;
13023
+ var output = [];
13024
+ for (var i = start; i < end; i += 3) {
13025
+ tmp =
13026
+ ((uint8[i] << 16) & 0xFF0000) +
13027
+ ((uint8[i + 1] << 8) & 0xFF00) +
13028
+ (uint8[i + 2] & 0xFF);
13029
+ output.push(tripletToBase64(tmp));
13030
+ }
13031
+ return output.join('')
13032
+ }
13033
+
13034
+ function fromByteArray (uint8) {
13035
+ var tmp;
13036
+ var len = uint8.length;
13037
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
13038
+ var parts = [];
13039
+ var maxChunkLength = 16383; // must be multiple of 3
13040
+
13041
+ // go through the array every three bytes, we'll deal with trailing stuff later
13042
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
13043
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
13044
+ }
13045
+
13046
+ // pad the end with zeros, but make sure to not forget the extra bytes
13047
+ if (extraBytes === 1) {
13048
+ tmp = uint8[len - 1];
13049
+ parts.push(
13050
+ lookup[tmp >> 2] +
13051
+ lookup[(tmp << 4) & 0x3F] +
13052
+ '=='
13053
+ );
13054
+ } else if (extraBytes === 2) {
13055
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
13056
+ parts.push(
13057
+ lookup[tmp >> 10] +
13058
+ lookup[(tmp >> 4) & 0x3F] +
13059
+ lookup[(tmp << 2) & 0x3F] +
13060
+ '='
13061
+ );
13062
+ }
13063
+
13064
+ return parts.join('')
13065
+ }
13066
+ return base64Js;
13067
+ }
13068
+
13069
+ var ieee754 = {};
13070
+
13071
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
13072
+
13073
+ var hasRequiredIeee754;
13074
+
13075
+ function requireIeee754 () {
13076
+ if (hasRequiredIeee754) return ieee754;
13077
+ hasRequiredIeee754 = 1;
13078
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
13079
+ var e, m;
13080
+ var eLen = (nBytes * 8) - mLen - 1;
13081
+ var eMax = (1 << eLen) - 1;
13082
+ var eBias = eMax >> 1;
13083
+ var nBits = -7;
13084
+ var i = isLE ? (nBytes - 1) : 0;
13085
+ var d = isLE ? -1 : 1;
13086
+ var s = buffer[offset + i];
13087
+
13088
+ i += d;
13089
+
13090
+ e = s & ((1 << (-nBits)) - 1);
13091
+ s >>= (-nBits);
13092
+ nBits += eLen;
13093
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
13094
+
13095
+ m = e & ((1 << (-nBits)) - 1);
13096
+ e >>= (-nBits);
13097
+ nBits += mLen;
13098
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
13099
+
13100
+ if (e === 0) {
13101
+ e = 1 - eBias;
13102
+ } else if (e === eMax) {
13103
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
13104
+ } else {
13105
+ m = m + Math.pow(2, mLen);
13106
+ e = e - eBias;
13107
+ }
13108
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
13109
+ };
13110
+
13111
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
13112
+ var e, m, c;
13113
+ var eLen = (nBytes * 8) - mLen - 1;
13114
+ var eMax = (1 << eLen) - 1;
13115
+ var eBias = eMax >> 1;
13116
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
13117
+ var i = isLE ? 0 : (nBytes - 1);
13118
+ var d = isLE ? 1 : -1;
13119
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
13120
+
13121
+ value = Math.abs(value);
13122
+
13123
+ if (isNaN(value) || value === Infinity) {
13124
+ m = isNaN(value) ? 1 : 0;
13125
+ e = eMax;
13126
+ } else {
13127
+ e = Math.floor(Math.log(value) / Math.LN2);
13128
+ if (value * (c = Math.pow(2, -e)) < 1) {
13129
+ e--;
13130
+ c *= 2;
13131
+ }
13132
+ if (e + eBias >= 1) {
13133
+ value += rt / c;
13134
+ } else {
13135
+ value += rt * Math.pow(2, 1 - eBias);
13136
+ }
13137
+ if (value * c >= 2) {
13138
+ e++;
13139
+ c /= 2;
13140
+ }
13141
+
13142
+ if (e + eBias >= eMax) {
13143
+ m = 0;
13144
+ e = eMax;
13145
+ } else if (e + eBias >= 1) {
13146
+ m = ((value * c) - 1) * Math.pow(2, mLen);
13147
+ e = e + eBias;
13148
+ } else {
13149
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
13150
+ e = 0;
13151
+ }
13152
+ }
13153
+
13154
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
13155
+
13156
+ e = (e << mLen) | m;
13157
+ eLen += mLen;
13158
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
13159
+
13160
+ buffer[offset + i - d] |= s * 128;
13161
+ };
13162
+ return ieee754;
13163
+ }
13164
+
13165
+ /*!
13166
+ * The buffer module from node.js, for the browser.
13167
+ *
13168
+ * @author Feross Aboukhadijeh <https://feross.org>
13169
+ * @license MIT
13170
+ */
13171
+
13172
+ var hasRequiredBuffer;
13173
+
13174
+ function requireBuffer () {
13175
+ if (hasRequiredBuffer) return buffer;
13176
+ hasRequiredBuffer = 1;
13177
+ (function (exports$1) {
13178
+
13179
+ const base64 = requireBase64Js();
13180
+ const ieee754 = requireIeee754();
13181
+ const customInspectSymbol =
13182
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
13183
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
13184
+ : null;
13185
+
13186
+ exports$1.Buffer = Buffer;
13187
+ exports$1.SlowBuffer = SlowBuffer;
13188
+ exports$1.INSPECT_MAX_BYTES = 50;
13189
+
13190
+ const K_MAX_LENGTH = 0x7fffffff;
13191
+ exports$1.kMaxLength = K_MAX_LENGTH;
13192
+
13193
+ /**
13194
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
13195
+ * === true Use Uint8Array implementation (fastest)
13196
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
13197
+ * implementation (most compatible, even IE6)
13198
+ *
13199
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
13200
+ * Opera 11.6+, iOS 4.2+.
13201
+ *
13202
+ * We report that the browser does not support typed arrays if the are not subclassable
13203
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
13204
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
13205
+ * for __proto__ and has a buggy typed array implementation.
13206
+ */
13207
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
13208
+
13209
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
13210
+ typeof console.error === 'function') {
13211
+ console.error(
13212
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
13213
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
13214
+ );
13215
+ }
13216
+
13217
+ function typedArraySupport () {
13218
+ // Can typed array instances can be augmented?
13219
+ try {
13220
+ const arr = new Uint8Array(1);
13221
+ const proto = { foo: function () { return 42 } };
13222
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
13223
+ Object.setPrototypeOf(arr, proto);
13224
+ return arr.foo() === 42
13225
+ } catch (e) {
13226
+ return false
13227
+ }
13228
+ }
13229
+
13230
+ Object.defineProperty(Buffer.prototype, 'parent', {
13231
+ enumerable: true,
13232
+ get: function () {
13233
+ if (!Buffer.isBuffer(this)) return undefined
13234
+ return this.buffer
13235
+ }
13236
+ });
13237
+
13238
+ Object.defineProperty(Buffer.prototype, 'offset', {
13239
+ enumerable: true,
13240
+ get: function () {
13241
+ if (!Buffer.isBuffer(this)) return undefined
13242
+ return this.byteOffset
13243
+ }
13244
+ });
13245
+
13246
+ function createBuffer (length) {
13247
+ if (length > K_MAX_LENGTH) {
13248
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
13249
+ }
13250
+ // Return an augmented `Uint8Array` instance
13251
+ const buf = new Uint8Array(length);
13252
+ Object.setPrototypeOf(buf, Buffer.prototype);
13253
+ return buf
13254
+ }
13255
+
13256
+ /**
13257
+ * The Buffer constructor returns instances of `Uint8Array` that have their
13258
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
13259
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
13260
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
13261
+ * returns a single octet.
13262
+ *
13263
+ * The `Uint8Array` prototype remains unmodified.
13264
+ */
13265
+
13266
+ function Buffer (arg, encodingOrOffset, length) {
13267
+ // Common case.
13268
+ if (typeof arg === 'number') {
13269
+ if (typeof encodingOrOffset === 'string') {
13270
+ throw new TypeError(
13271
+ 'The "string" argument must be of type string. Received type number'
13272
+ )
13273
+ }
13274
+ return allocUnsafe(arg)
13275
+ }
13276
+ return from(arg, encodingOrOffset, length)
13277
+ }
13278
+
13279
+ Buffer.poolSize = 8192; // not used by this implementation
13280
+
13281
+ function from (value, encodingOrOffset, length) {
13282
+ if (typeof value === 'string') {
13283
+ return fromString(value, encodingOrOffset)
13284
+ }
13285
+
13286
+ if (ArrayBuffer.isView(value)) {
13287
+ return fromArrayView(value)
13288
+ }
13289
+
13290
+ if (value == null) {
13291
+ throw new TypeError(
13292
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
13293
+ 'or Array-like Object. Received type ' + (typeof value)
13294
+ )
13295
+ }
13296
+
13297
+ if (isInstance(value, ArrayBuffer) ||
13298
+ (value && isInstance(value.buffer, ArrayBuffer))) {
13299
+ return fromArrayBuffer(value, encodingOrOffset, length)
13300
+ }
13301
+
13302
+ if (typeof SharedArrayBuffer !== 'undefined' &&
13303
+ (isInstance(value, SharedArrayBuffer) ||
13304
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
13305
+ return fromArrayBuffer(value, encodingOrOffset, length)
13306
+ }
13307
+
13308
+ if (typeof value === 'number') {
13309
+ throw new TypeError(
13310
+ 'The "value" argument must not be of type number. Received type number'
13311
+ )
13312
+ }
13313
+
13314
+ const valueOf = value.valueOf && value.valueOf();
13315
+ if (valueOf != null && valueOf !== value) {
13316
+ return Buffer.from(valueOf, encodingOrOffset, length)
13317
+ }
13318
+
13319
+ const b = fromObject(value);
13320
+ if (b) return b
13321
+
13322
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
13323
+ typeof value[Symbol.toPrimitive] === 'function') {
13324
+ return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
13325
+ }
13326
+
13327
+ throw new TypeError(
13328
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
13329
+ 'or Array-like Object. Received type ' + (typeof value)
13330
+ )
13331
+ }
13332
+
13333
+ /**
13334
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
13335
+ * if value is a number.
13336
+ * Buffer.from(str[, encoding])
13337
+ * Buffer.from(array)
13338
+ * Buffer.from(buffer)
13339
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
13340
+ **/
13341
+ Buffer.from = function (value, encodingOrOffset, length) {
13342
+ return from(value, encodingOrOffset, length)
13343
+ };
13344
+
13345
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
13346
+ // https://github.com/feross/buffer/pull/148
13347
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
13348
+ Object.setPrototypeOf(Buffer, Uint8Array);
13349
+
13350
+ function assertSize (size) {
13351
+ if (typeof size !== 'number') {
13352
+ throw new TypeError('"size" argument must be of type number')
13353
+ } else if (size < 0) {
13354
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
13355
+ }
13356
+ }
13357
+
13358
+ function alloc (size, fill, encoding) {
13359
+ assertSize(size);
13360
+ if (size <= 0) {
13361
+ return createBuffer(size)
13362
+ }
13363
+ if (fill !== undefined) {
13364
+ // Only pay attention to encoding if it's a string. This
13365
+ // prevents accidentally sending in a number that would
13366
+ // be interpreted as a start offset.
13367
+ return typeof encoding === 'string'
13368
+ ? createBuffer(size).fill(fill, encoding)
13369
+ : createBuffer(size).fill(fill)
13370
+ }
13371
+ return createBuffer(size)
13372
+ }
13373
+
13374
+ /**
13375
+ * Creates a new filled Buffer instance.
13376
+ * alloc(size[, fill[, encoding]])
13377
+ **/
13378
+ Buffer.alloc = function (size, fill, encoding) {
13379
+ return alloc(size, fill, encoding)
13380
+ };
13381
+
13382
+ function allocUnsafe (size) {
13383
+ assertSize(size);
13384
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
13385
+ }
13386
+
13387
+ /**
13388
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
13389
+ * */
13390
+ Buffer.allocUnsafe = function (size) {
13391
+ return allocUnsafe(size)
13392
+ };
13393
+ /**
13394
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
13395
+ */
13396
+ Buffer.allocUnsafeSlow = function (size) {
13397
+ return allocUnsafe(size)
13398
+ };
13399
+
13400
+ function fromString (string, encoding) {
13401
+ if (typeof encoding !== 'string' || encoding === '') {
13402
+ encoding = 'utf8';
13403
+ }
13404
+
13405
+ if (!Buffer.isEncoding(encoding)) {
13406
+ throw new TypeError('Unknown encoding: ' + encoding)
13407
+ }
13408
+
13409
+ const length = byteLength(string, encoding) | 0;
13410
+ let buf = createBuffer(length);
13411
+
13412
+ const actual = buf.write(string, encoding);
13413
+
13414
+ if (actual !== length) {
13415
+ // Writing a hex string, for example, that contains invalid characters will
13416
+ // cause everything after the first invalid character to be ignored. (e.g.
13417
+ // 'abxxcd' will be treated as 'ab')
13418
+ buf = buf.slice(0, actual);
13419
+ }
13420
+
13421
+ return buf
13422
+ }
13423
+
13424
+ function fromArrayLike (array) {
13425
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
13426
+ const buf = createBuffer(length);
13427
+ for (let i = 0; i < length; i += 1) {
13428
+ buf[i] = array[i] & 255;
13429
+ }
13430
+ return buf
13431
+ }
13432
+
13433
+ function fromArrayView (arrayView) {
13434
+ if (isInstance(arrayView, Uint8Array)) {
13435
+ const copy = new Uint8Array(arrayView);
13436
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
13437
+ }
13438
+ return fromArrayLike(arrayView)
13439
+ }
13440
+
13441
+ function fromArrayBuffer (array, byteOffset, length) {
13442
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
13443
+ throw new RangeError('"offset" is outside of buffer bounds')
13444
+ }
13445
+
13446
+ if (array.byteLength < byteOffset + (length || 0)) {
13447
+ throw new RangeError('"length" is outside of buffer bounds')
13448
+ }
13449
+
13450
+ let buf;
13451
+ if (byteOffset === undefined && length === undefined) {
13452
+ buf = new Uint8Array(array);
13453
+ } else if (length === undefined) {
13454
+ buf = new Uint8Array(array, byteOffset);
13455
+ } else {
13456
+ buf = new Uint8Array(array, byteOffset, length);
13457
+ }
13458
+
13459
+ // Return an augmented `Uint8Array` instance
13460
+ Object.setPrototypeOf(buf, Buffer.prototype);
13461
+
13462
+ return buf
13463
+ }
13464
+
13465
+ function fromObject (obj) {
13466
+ if (Buffer.isBuffer(obj)) {
13467
+ const len = checked(obj.length) | 0;
13468
+ const buf = createBuffer(len);
13469
+
13470
+ if (buf.length === 0) {
13471
+ return buf
13472
+ }
13473
+
13474
+ obj.copy(buf, 0, 0, len);
13475
+ return buf
13476
+ }
13477
+
13478
+ if (obj.length !== undefined) {
13479
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
13480
+ return createBuffer(0)
13481
+ }
13482
+ return fromArrayLike(obj)
13483
+ }
13484
+
13485
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
13486
+ return fromArrayLike(obj.data)
13487
+ }
13488
+ }
13489
+
13490
+ function checked (length) {
13491
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
13492
+ // length is NaN (which is otherwise coerced to zero.)
13493
+ if (length >= K_MAX_LENGTH) {
13494
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
13495
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
13496
+ }
13497
+ return length | 0
13498
+ }
13499
+
13500
+ function SlowBuffer (length) {
13501
+ if (+length != length) { // eslint-disable-line eqeqeq
13502
+ length = 0;
13503
+ }
13504
+ return Buffer.alloc(+length)
13505
+ }
13506
+
13507
+ Buffer.isBuffer = function isBuffer (b) {
13508
+ return b != null && b._isBuffer === true &&
13509
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
13510
+ };
13511
+
13512
+ Buffer.compare = function compare (a, b) {
13513
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
13514
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
13515
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
13516
+ throw new TypeError(
13517
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
13518
+ )
13519
+ }
13520
+
13521
+ if (a === b) return 0
13522
+
13523
+ let x = a.length;
13524
+ let y = b.length;
13525
+
13526
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
13527
+ if (a[i] !== b[i]) {
13528
+ x = a[i];
13529
+ y = b[i];
13530
+ break
13531
+ }
13532
+ }
13533
+
13534
+ if (x < y) return -1
13535
+ if (y < x) return 1
13536
+ return 0
13537
+ };
13538
+
13539
+ Buffer.isEncoding = function isEncoding (encoding) {
13540
+ switch (String(encoding).toLowerCase()) {
13541
+ case 'hex':
13542
+ case 'utf8':
13543
+ case 'utf-8':
13544
+ case 'ascii':
13545
+ case 'latin1':
13546
+ case 'binary':
13547
+ case 'base64':
13548
+ case 'ucs2':
13549
+ case 'ucs-2':
13550
+ case 'utf16le':
13551
+ case 'utf-16le':
13552
+ return true
13553
+ default:
13554
+ return false
13555
+ }
13556
+ };
13557
+
13558
+ Buffer.concat = function concat (list, length) {
13559
+ if (!Array.isArray(list)) {
13560
+ throw new TypeError('"list" argument must be an Array of Buffers')
13561
+ }
13562
+
13563
+ if (list.length === 0) {
13564
+ return Buffer.alloc(0)
13565
+ }
13566
+
13567
+ let i;
13568
+ if (length === undefined) {
13569
+ length = 0;
13570
+ for (i = 0; i < list.length; ++i) {
13571
+ length += list[i].length;
13572
+ }
13573
+ }
13574
+
13575
+ const buffer = Buffer.allocUnsafe(length);
13576
+ let pos = 0;
13577
+ for (i = 0; i < list.length; ++i) {
13578
+ let buf = list[i];
13579
+ if (isInstance(buf, Uint8Array)) {
13580
+ if (pos + buf.length > buffer.length) {
13581
+ if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
13582
+ buf.copy(buffer, pos);
13583
+ } else {
13584
+ Uint8Array.prototype.set.call(
13585
+ buffer,
13586
+ buf,
13587
+ pos
13588
+ );
13589
+ }
13590
+ } else if (!Buffer.isBuffer(buf)) {
13591
+ throw new TypeError('"list" argument must be an Array of Buffers')
13592
+ } else {
13593
+ buf.copy(buffer, pos);
13594
+ }
13595
+ pos += buf.length;
13596
+ }
13597
+ return buffer
13598
+ };
13599
+
13600
+ function byteLength (string, encoding) {
13601
+ if (Buffer.isBuffer(string)) {
13602
+ return string.length
13603
+ }
13604
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
13605
+ return string.byteLength
13606
+ }
13607
+ if (typeof string !== 'string') {
13608
+ throw new TypeError(
13609
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
13610
+ 'Received type ' + typeof string
13611
+ )
13612
+ }
13613
+
13614
+ const len = string.length;
13615
+ const mustMatch = (arguments.length > 2 && arguments[2] === true);
13616
+ if (!mustMatch && len === 0) return 0
13617
+
13618
+ // Use a for loop to avoid recursion
13619
+ let loweredCase = false;
13620
+ for (;;) {
13621
+ switch (encoding) {
13622
+ case 'ascii':
13623
+ case 'latin1':
13624
+ case 'binary':
13625
+ return len
13626
+ case 'utf8':
13627
+ case 'utf-8':
13628
+ return utf8ToBytes(string).length
13629
+ case 'ucs2':
13630
+ case 'ucs-2':
13631
+ case 'utf16le':
13632
+ case 'utf-16le':
13633
+ return len * 2
13634
+ case 'hex':
13635
+ return len >>> 1
13636
+ case 'base64':
13637
+ return base64ToBytes(string).length
13638
+ default:
13639
+ if (loweredCase) {
13640
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
13641
+ }
13642
+ encoding = ('' + encoding).toLowerCase();
13643
+ loweredCase = true;
13644
+ }
13645
+ }
13646
+ }
13647
+ Buffer.byteLength = byteLength;
13648
+
13649
+ function slowToString (encoding, start, end) {
13650
+ let loweredCase = false;
13651
+
13652
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
13653
+ // property of a typed array.
13654
+
13655
+ // This behaves neither like String nor Uint8Array in that we set start/end
13656
+ // to their upper/lower bounds if the value passed is out of range.
13657
+ // undefined is handled specially as per ECMA-262 6th Edition,
13658
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
13659
+ if (start === undefined || start < 0) {
13660
+ start = 0;
13661
+ }
13662
+ // Return early if start > this.length. Done here to prevent potential uint32
13663
+ // coercion fail below.
13664
+ if (start > this.length) {
13665
+ return ''
13666
+ }
13667
+
13668
+ if (end === undefined || end > this.length) {
13669
+ end = this.length;
13670
+ }
13671
+
13672
+ if (end <= 0) {
13673
+ return ''
13674
+ }
13675
+
13676
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
13677
+ end >>>= 0;
13678
+ start >>>= 0;
13679
+
13680
+ if (end <= start) {
13681
+ return ''
13682
+ }
13683
+
13684
+ if (!encoding) encoding = 'utf8';
13685
+
13686
+ while (true) {
13687
+ switch (encoding) {
13688
+ case 'hex':
13689
+ return hexSlice(this, start, end)
13690
+
13691
+ case 'utf8':
13692
+ case 'utf-8':
13693
+ return utf8Slice(this, start, end)
13694
+
13695
+ case 'ascii':
13696
+ return asciiSlice(this, start, end)
13697
+
13698
+ case 'latin1':
13699
+ case 'binary':
13700
+ return latin1Slice(this, start, end)
13701
+
13702
+ case 'base64':
13703
+ return base64Slice(this, start, end)
13704
+
13705
+ case 'ucs2':
13706
+ case 'ucs-2':
13707
+ case 'utf16le':
13708
+ case 'utf-16le':
13709
+ return utf16leSlice(this, start, end)
13710
+
13711
+ default:
13712
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
13713
+ encoding = (encoding + '').toLowerCase();
13714
+ loweredCase = true;
13715
+ }
13716
+ }
13717
+ }
13718
+
13719
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
13720
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
13721
+ // reliably in a browserify context because there could be multiple different
13722
+ // copies of the 'buffer' package in use. This method works even for Buffer
13723
+ // instances that were created from another copy of the `buffer` package.
13724
+ // See: https://github.com/feross/buffer/issues/154
13725
+ Buffer.prototype._isBuffer = true;
13726
+
13727
+ function swap (b, n, m) {
13728
+ const i = b[n];
13729
+ b[n] = b[m];
13730
+ b[m] = i;
13731
+ }
13732
+
13733
+ Buffer.prototype.swap16 = function swap16 () {
13734
+ const len = this.length;
13735
+ if (len % 2 !== 0) {
13736
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
13737
+ }
13738
+ for (let i = 0; i < len; i += 2) {
13739
+ swap(this, i, i + 1);
13740
+ }
13741
+ return this
13742
+ };
13743
+
13744
+ Buffer.prototype.swap32 = function swap32 () {
13745
+ const len = this.length;
13746
+ if (len % 4 !== 0) {
13747
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
13748
+ }
13749
+ for (let i = 0; i < len; i += 4) {
13750
+ swap(this, i, i + 3);
13751
+ swap(this, i + 1, i + 2);
13752
+ }
13753
+ return this
13754
+ };
13755
+
13756
+ Buffer.prototype.swap64 = function swap64 () {
13757
+ const len = this.length;
13758
+ if (len % 8 !== 0) {
13759
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
13760
+ }
13761
+ for (let i = 0; i < len; i += 8) {
13762
+ swap(this, i, i + 7);
13763
+ swap(this, i + 1, i + 6);
13764
+ swap(this, i + 2, i + 5);
13765
+ swap(this, i + 3, i + 4);
13766
+ }
13767
+ return this
13768
+ };
13769
+
13770
+ Buffer.prototype.toString = function toString () {
13771
+ const length = this.length;
13772
+ if (length === 0) return ''
13773
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
13774
+ return slowToString.apply(this, arguments)
13775
+ };
13776
+
13777
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
13778
+
13779
+ Buffer.prototype.equals = function equals (b) {
13780
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
13781
+ if (this === b) return true
13782
+ return Buffer.compare(this, b) === 0
13783
+ };
13784
+
13785
+ Buffer.prototype.inspect = function inspect () {
13786
+ let str = '';
13787
+ const max = exports$1.INSPECT_MAX_BYTES;
13788
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
13789
+ if (this.length > max) str += ' ... ';
13790
+ return '<Buffer ' + str + '>'
13791
+ };
13792
+ if (customInspectSymbol) {
13793
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
13794
+ }
13795
+
13796
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
13797
+ if (isInstance(target, Uint8Array)) {
13798
+ target = Buffer.from(target, target.offset, target.byteLength);
13799
+ }
13800
+ if (!Buffer.isBuffer(target)) {
13801
+ throw new TypeError(
13802
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
13803
+ 'Received type ' + (typeof target)
13804
+ )
13805
+ }
13806
+
13807
+ if (start === undefined) {
13808
+ start = 0;
13809
+ }
13810
+ if (end === undefined) {
13811
+ end = target ? target.length : 0;
13812
+ }
13813
+ if (thisStart === undefined) {
13814
+ thisStart = 0;
13815
+ }
13816
+ if (thisEnd === undefined) {
13817
+ thisEnd = this.length;
13818
+ }
13819
+
13820
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
13821
+ throw new RangeError('out of range index')
13822
+ }
13823
+
13824
+ if (thisStart >= thisEnd && start >= end) {
13825
+ return 0
13826
+ }
13827
+ if (thisStart >= thisEnd) {
13828
+ return -1
13829
+ }
13830
+ if (start >= end) {
13831
+ return 1
13832
+ }
13833
+
13834
+ start >>>= 0;
13835
+ end >>>= 0;
13836
+ thisStart >>>= 0;
13837
+ thisEnd >>>= 0;
13838
+
13839
+ if (this === target) return 0
13840
+
13841
+ let x = thisEnd - thisStart;
13842
+ let y = end - start;
13843
+ const len = Math.min(x, y);
13844
+
13845
+ const thisCopy = this.slice(thisStart, thisEnd);
13846
+ const targetCopy = target.slice(start, end);
13847
+
13848
+ for (let i = 0; i < len; ++i) {
13849
+ if (thisCopy[i] !== targetCopy[i]) {
13850
+ x = thisCopy[i];
13851
+ y = targetCopy[i];
13852
+ break
13853
+ }
13854
+ }
13855
+
13856
+ if (x < y) return -1
13857
+ if (y < x) return 1
13858
+ return 0
13859
+ };
13860
+
13861
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
13862
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
13863
+ //
13864
+ // Arguments:
13865
+ // - buffer - a Buffer to search
13866
+ // - val - a string, Buffer, or number
13867
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
13868
+ // - encoding - an optional encoding, relevant is val is a string
13869
+ // - dir - true for indexOf, false for lastIndexOf
13870
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
13871
+ // Empty buffer means no match
13872
+ if (buffer.length === 0) return -1
13873
+
13874
+ // Normalize byteOffset
13875
+ if (typeof byteOffset === 'string') {
13876
+ encoding = byteOffset;
13877
+ byteOffset = 0;
13878
+ } else if (byteOffset > 0x7fffffff) {
13879
+ byteOffset = 0x7fffffff;
13880
+ } else if (byteOffset < -2147483648) {
13881
+ byteOffset = -2147483648;
13882
+ }
13883
+ byteOffset = +byteOffset; // Coerce to Number.
13884
+ if (numberIsNaN(byteOffset)) {
13885
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
13886
+ byteOffset = dir ? 0 : (buffer.length - 1);
13887
+ }
13888
+
13889
+ // Normalize byteOffset: negative offsets start from the end of the buffer
13890
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
13891
+ if (byteOffset >= buffer.length) {
13892
+ if (dir) return -1
13893
+ else byteOffset = buffer.length - 1;
13894
+ } else if (byteOffset < 0) {
13895
+ if (dir) byteOffset = 0;
13896
+ else return -1
13897
+ }
13898
+
13899
+ // Normalize val
13900
+ if (typeof val === 'string') {
13901
+ val = Buffer.from(val, encoding);
13902
+ }
13903
+
13904
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
13905
+ if (Buffer.isBuffer(val)) {
13906
+ // Special case: looking for empty string/buffer always fails
13907
+ if (val.length === 0) {
13908
+ return -1
13909
+ }
13910
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
13911
+ } else if (typeof val === 'number') {
13912
+ val = val & 0xFF; // Search for a byte value [0-255]
13913
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
13914
+ if (dir) {
13915
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
13916
+ } else {
13917
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
13918
+ }
13919
+ }
13920
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
13921
+ }
13922
+
13923
+ throw new TypeError('val must be string, number or Buffer')
13924
+ }
13925
+
13926
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
13927
+ let indexSize = 1;
13928
+ let arrLength = arr.length;
13929
+ let valLength = val.length;
13930
+
13931
+ if (encoding !== undefined) {
13932
+ encoding = String(encoding).toLowerCase();
13933
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
13934
+ encoding === 'utf16le' || encoding === 'utf-16le') {
13935
+ if (arr.length < 2 || val.length < 2) {
13936
+ return -1
13937
+ }
13938
+ indexSize = 2;
13939
+ arrLength /= 2;
13940
+ valLength /= 2;
13941
+ byteOffset /= 2;
13942
+ }
13943
+ }
13944
+
13945
+ function read (buf, i) {
13946
+ if (indexSize === 1) {
13947
+ return buf[i]
13948
+ } else {
13949
+ return buf.readUInt16BE(i * indexSize)
13950
+ }
13951
+ }
13952
+
13953
+ let i;
13954
+ if (dir) {
13955
+ let foundIndex = -1;
13956
+ for (i = byteOffset; i < arrLength; i++) {
13957
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
13958
+ if (foundIndex === -1) foundIndex = i;
13959
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
13960
+ } else {
13961
+ if (foundIndex !== -1) i -= i - foundIndex;
13962
+ foundIndex = -1;
13963
+ }
13964
+ }
13965
+ } else {
13966
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
13967
+ for (i = byteOffset; i >= 0; i--) {
13968
+ let found = true;
13969
+ for (let j = 0; j < valLength; j++) {
13970
+ if (read(arr, i + j) !== read(val, j)) {
13971
+ found = false;
13972
+ break
13973
+ }
13974
+ }
13975
+ if (found) return i
13976
+ }
13977
+ }
13978
+
13979
+ return -1
13980
+ }
13981
+
13982
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
13983
+ return this.indexOf(val, byteOffset, encoding) !== -1
13984
+ };
13985
+
13986
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
13987
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
13988
+ };
13989
+
13990
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
13991
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
13992
+ };
13993
+
13994
+ function hexWrite (buf, string, offset, length) {
13995
+ offset = Number(offset) || 0;
13996
+ const remaining = buf.length - offset;
13997
+ if (!length) {
13998
+ length = remaining;
13999
+ } else {
14000
+ length = Number(length);
14001
+ if (length > remaining) {
14002
+ length = remaining;
14003
+ }
14004
+ }
14005
+
14006
+ const strLen = string.length;
14007
+
14008
+ if (length > strLen / 2) {
14009
+ length = strLen / 2;
14010
+ }
14011
+ let i;
14012
+ for (i = 0; i < length; ++i) {
14013
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
14014
+ if (numberIsNaN(parsed)) return i
14015
+ buf[offset + i] = parsed;
14016
+ }
14017
+ return i
14018
+ }
14019
+
14020
+ function utf8Write (buf, string, offset, length) {
14021
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
14022
+ }
14023
+
14024
+ function asciiWrite (buf, string, offset, length) {
14025
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
14026
+ }
14027
+
14028
+ function base64Write (buf, string, offset, length) {
14029
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
14030
+ }
14031
+
14032
+ function ucs2Write (buf, string, offset, length) {
14033
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
14034
+ }
14035
+
14036
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
14037
+ // Buffer#write(string)
14038
+ if (offset === undefined) {
14039
+ encoding = 'utf8';
14040
+ length = this.length;
14041
+ offset = 0;
14042
+ // Buffer#write(string, encoding)
14043
+ } else if (length === undefined && typeof offset === 'string') {
14044
+ encoding = offset;
14045
+ length = this.length;
14046
+ offset = 0;
14047
+ // Buffer#write(string, offset[, length][, encoding])
14048
+ } else if (isFinite(offset)) {
14049
+ offset = offset >>> 0;
14050
+ if (isFinite(length)) {
14051
+ length = length >>> 0;
14052
+ if (encoding === undefined) encoding = 'utf8';
14053
+ } else {
14054
+ encoding = length;
14055
+ length = undefined;
14056
+ }
14057
+ } else {
14058
+ throw new Error(
14059
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
14060
+ )
14061
+ }
14062
+
14063
+ const remaining = this.length - offset;
14064
+ if (length === undefined || length > remaining) length = remaining;
14065
+
14066
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
14067
+ throw new RangeError('Attempt to write outside buffer bounds')
14068
+ }
14069
+
14070
+ if (!encoding) encoding = 'utf8';
14071
+
14072
+ let loweredCase = false;
14073
+ for (;;) {
14074
+ switch (encoding) {
14075
+ case 'hex':
14076
+ return hexWrite(this, string, offset, length)
14077
+
14078
+ case 'utf8':
14079
+ case 'utf-8':
14080
+ return utf8Write(this, string, offset, length)
14081
+
14082
+ case 'ascii':
14083
+ case 'latin1':
14084
+ case 'binary':
14085
+ return asciiWrite(this, string, offset, length)
14086
+
14087
+ case 'base64':
14088
+ // Warning: maxLength not taken into account in base64Write
14089
+ return base64Write(this, string, offset, length)
14090
+
14091
+ case 'ucs2':
14092
+ case 'ucs-2':
14093
+ case 'utf16le':
14094
+ case 'utf-16le':
14095
+ return ucs2Write(this, string, offset, length)
14096
+
14097
+ default:
14098
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
14099
+ encoding = ('' + encoding).toLowerCase();
14100
+ loweredCase = true;
14101
+ }
14102
+ }
14103
+ };
14104
+
14105
+ Buffer.prototype.toJSON = function toJSON () {
14106
+ return {
14107
+ type: 'Buffer',
14108
+ data: Array.prototype.slice.call(this._arr || this, 0)
14109
+ }
14110
+ };
14111
+
14112
+ function base64Slice (buf, start, end) {
14113
+ if (start === 0 && end === buf.length) {
14114
+ return base64.fromByteArray(buf)
14115
+ } else {
14116
+ return base64.fromByteArray(buf.slice(start, end))
14117
+ }
14118
+ }
14119
+
14120
+ function utf8Slice (buf, start, end) {
14121
+ end = Math.min(buf.length, end);
14122
+ const res = [];
14123
+
14124
+ let i = start;
14125
+ while (i < end) {
14126
+ const firstByte = buf[i];
14127
+ let codePoint = null;
14128
+ let bytesPerSequence = (firstByte > 0xEF)
14129
+ ? 4
14130
+ : (firstByte > 0xDF)
14131
+ ? 3
14132
+ : (firstByte > 0xBF)
14133
+ ? 2
14134
+ : 1;
14135
+
14136
+ if (i + bytesPerSequence <= end) {
14137
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
14138
+
14139
+ switch (bytesPerSequence) {
14140
+ case 1:
14141
+ if (firstByte < 0x80) {
14142
+ codePoint = firstByte;
14143
+ }
14144
+ break
14145
+ case 2:
14146
+ secondByte = buf[i + 1];
14147
+ if ((secondByte & 0xC0) === 0x80) {
14148
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
14149
+ if (tempCodePoint > 0x7F) {
14150
+ codePoint = tempCodePoint;
14151
+ }
14152
+ }
14153
+ break
14154
+ case 3:
14155
+ secondByte = buf[i + 1];
14156
+ thirdByte = buf[i + 2];
14157
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
14158
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
14159
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
14160
+ codePoint = tempCodePoint;
14161
+ }
14162
+ }
14163
+ break
14164
+ case 4:
14165
+ secondByte = buf[i + 1];
14166
+ thirdByte = buf[i + 2];
14167
+ fourthByte = buf[i + 3];
14168
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
14169
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
14170
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
14171
+ codePoint = tempCodePoint;
14172
+ }
14173
+ }
14174
+ }
14175
+ }
14176
+
14177
+ if (codePoint === null) {
14178
+ // we did not generate a valid codePoint so insert a
14179
+ // replacement char (U+FFFD) and advance only 1 byte
14180
+ codePoint = 0xFFFD;
14181
+ bytesPerSequence = 1;
14182
+ } else if (codePoint > 0xFFFF) {
14183
+ // encode to utf16 (surrogate pair dance)
14184
+ codePoint -= 0x10000;
14185
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
14186
+ codePoint = 0xDC00 | codePoint & 0x3FF;
14187
+ }
14188
+
14189
+ res.push(codePoint);
14190
+ i += bytesPerSequence;
14191
+ }
14192
+
14193
+ return decodeCodePointsArray(res)
14194
+ }
14195
+
14196
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
14197
+ // the lowest limit is Chrome, with 0x10000 args.
14198
+ // We go 1 magnitude less, for safety
14199
+ const MAX_ARGUMENTS_LENGTH = 0x1000;
14200
+
14201
+ function decodeCodePointsArray (codePoints) {
14202
+ const len = codePoints.length;
14203
+ if (len <= MAX_ARGUMENTS_LENGTH) {
14204
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
14205
+ }
14206
+
14207
+ // Decode in chunks to avoid "call stack size exceeded".
14208
+ let res = '';
14209
+ let i = 0;
14210
+ while (i < len) {
14211
+ res += String.fromCharCode.apply(
14212
+ String,
14213
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
14214
+ );
14215
+ }
14216
+ return res
14217
+ }
14218
+
14219
+ function asciiSlice (buf, start, end) {
14220
+ let ret = '';
14221
+ end = Math.min(buf.length, end);
14222
+
14223
+ for (let i = start; i < end; ++i) {
14224
+ ret += String.fromCharCode(buf[i] & 0x7F);
14225
+ }
14226
+ return ret
14227
+ }
14228
+
14229
+ function latin1Slice (buf, start, end) {
14230
+ let ret = '';
14231
+ end = Math.min(buf.length, end);
14232
+
14233
+ for (let i = start; i < end; ++i) {
14234
+ ret += String.fromCharCode(buf[i]);
14235
+ }
14236
+ return ret
14237
+ }
14238
+
14239
+ function hexSlice (buf, start, end) {
14240
+ const len = buf.length;
14241
+
14242
+ if (!start || start < 0) start = 0;
14243
+ if (!end || end < 0 || end > len) end = len;
14244
+
14245
+ let out = '';
14246
+ for (let i = start; i < end; ++i) {
14247
+ out += hexSliceLookupTable[buf[i]];
14248
+ }
14249
+ return out
14250
+ }
14251
+
14252
+ function utf16leSlice (buf, start, end) {
14253
+ const bytes = buf.slice(start, end);
14254
+ let res = '';
14255
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
14256
+ for (let i = 0; i < bytes.length - 1; i += 2) {
14257
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
14258
+ }
14259
+ return res
14260
+ }
14261
+
14262
+ Buffer.prototype.slice = function slice (start, end) {
14263
+ const len = this.length;
14264
+ start = ~~start;
14265
+ end = end === undefined ? len : ~~end;
14266
+
14267
+ if (start < 0) {
14268
+ start += len;
14269
+ if (start < 0) start = 0;
14270
+ } else if (start > len) {
14271
+ start = len;
14272
+ }
14273
+
14274
+ if (end < 0) {
14275
+ end += len;
14276
+ if (end < 0) end = 0;
14277
+ } else if (end > len) {
14278
+ end = len;
14279
+ }
14280
+
14281
+ if (end < start) end = start;
14282
+
14283
+ const newBuf = this.subarray(start, end);
14284
+ // Return an augmented `Uint8Array` instance
14285
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
14286
+
14287
+ return newBuf
14288
+ };
14289
+
14290
+ /*
14291
+ * Need to make sure that buffer isn't trying to write out of bounds.
14292
+ */
14293
+ function checkOffset (offset, ext, length) {
14294
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
14295
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
14296
+ }
14297
+
14298
+ Buffer.prototype.readUintLE =
14299
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
14300
+ offset = offset >>> 0;
14301
+ byteLength = byteLength >>> 0;
14302
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14303
+
14304
+ let val = this[offset];
14305
+ let mul = 1;
14306
+ let i = 0;
14307
+ while (++i < byteLength && (mul *= 0x100)) {
14308
+ val += this[offset + i] * mul;
14309
+ }
14310
+
14311
+ return val
14312
+ };
14313
+
14314
+ Buffer.prototype.readUintBE =
14315
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
14316
+ offset = offset >>> 0;
14317
+ byteLength = byteLength >>> 0;
14318
+ if (!noAssert) {
14319
+ checkOffset(offset, byteLength, this.length);
14320
+ }
14321
+
14322
+ let val = this[offset + --byteLength];
14323
+ let mul = 1;
14324
+ while (byteLength > 0 && (mul *= 0x100)) {
14325
+ val += this[offset + --byteLength] * mul;
14326
+ }
14327
+
14328
+ return val
14329
+ };
14330
+
14331
+ Buffer.prototype.readUint8 =
14332
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
14333
+ offset = offset >>> 0;
14334
+ if (!noAssert) checkOffset(offset, 1, this.length);
14335
+ return this[offset]
14336
+ };
14337
+
14338
+ Buffer.prototype.readUint16LE =
14339
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
14340
+ offset = offset >>> 0;
14341
+ if (!noAssert) checkOffset(offset, 2, this.length);
14342
+ return this[offset] | (this[offset + 1] << 8)
14343
+ };
14344
+
14345
+ Buffer.prototype.readUint16BE =
14346
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
14347
+ offset = offset >>> 0;
14348
+ if (!noAssert) checkOffset(offset, 2, this.length);
14349
+ return (this[offset] << 8) | this[offset + 1]
14350
+ };
14351
+
14352
+ Buffer.prototype.readUint32LE =
14353
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
14354
+ offset = offset >>> 0;
14355
+ if (!noAssert) checkOffset(offset, 4, this.length);
14356
+
14357
+ return ((this[offset]) |
14358
+ (this[offset + 1] << 8) |
14359
+ (this[offset + 2] << 16)) +
14360
+ (this[offset + 3] * 0x1000000)
14361
+ };
14362
+
14363
+ Buffer.prototype.readUint32BE =
14364
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
14365
+ offset = offset >>> 0;
14366
+ if (!noAssert) checkOffset(offset, 4, this.length);
14367
+
14368
+ return (this[offset] * 0x1000000) +
14369
+ ((this[offset + 1] << 16) |
14370
+ (this[offset + 2] << 8) |
14371
+ this[offset + 3])
14372
+ };
14373
+
14374
+ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
14375
+ offset = offset >>> 0;
14376
+ validateNumber(offset, 'offset');
14377
+ const first = this[offset];
14378
+ const last = this[offset + 7];
14379
+ if (first === undefined || last === undefined) {
14380
+ boundsError(offset, this.length - 8);
14381
+ }
14382
+
14383
+ const lo = first +
14384
+ this[++offset] * 2 ** 8 +
14385
+ this[++offset] * 2 ** 16 +
14386
+ this[++offset] * 2 ** 24;
14387
+
14388
+ const hi = this[++offset] +
14389
+ this[++offset] * 2 ** 8 +
14390
+ this[++offset] * 2 ** 16 +
14391
+ last * 2 ** 24;
14392
+
14393
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
14394
+ });
14395
+
14396
+ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
14397
+ offset = offset >>> 0;
14398
+ validateNumber(offset, 'offset');
14399
+ const first = this[offset];
14400
+ const last = this[offset + 7];
14401
+ if (first === undefined || last === undefined) {
14402
+ boundsError(offset, this.length - 8);
14403
+ }
14404
+
14405
+ const hi = first * 2 ** 24 +
14406
+ this[++offset] * 2 ** 16 +
14407
+ this[++offset] * 2 ** 8 +
14408
+ this[++offset];
14409
+
14410
+ const lo = this[++offset] * 2 ** 24 +
14411
+ this[++offset] * 2 ** 16 +
14412
+ this[++offset] * 2 ** 8 +
14413
+ last;
14414
+
14415
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
14416
+ });
14417
+
14418
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
14419
+ offset = offset >>> 0;
14420
+ byteLength = byteLength >>> 0;
14421
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14422
+
14423
+ let val = this[offset];
14424
+ let mul = 1;
14425
+ let i = 0;
14426
+ while (++i < byteLength && (mul *= 0x100)) {
14427
+ val += this[offset + i] * mul;
14428
+ }
14429
+ mul *= 0x80;
14430
+
14431
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
14432
+
14433
+ return val
14434
+ };
14435
+
14436
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
14437
+ offset = offset >>> 0;
14438
+ byteLength = byteLength >>> 0;
14439
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14440
+
14441
+ let i = byteLength;
14442
+ let mul = 1;
14443
+ let val = this[offset + --i];
14444
+ while (i > 0 && (mul *= 0x100)) {
14445
+ val += this[offset + --i] * mul;
14446
+ }
14447
+ mul *= 0x80;
14448
+
14449
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
14450
+
14451
+ return val
14452
+ };
14453
+
14454
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
14455
+ offset = offset >>> 0;
14456
+ if (!noAssert) checkOffset(offset, 1, this.length);
14457
+ if (!(this[offset] & 0x80)) return (this[offset])
14458
+ return ((0xff - this[offset] + 1) * -1)
14459
+ };
14460
+
14461
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
14462
+ offset = offset >>> 0;
14463
+ if (!noAssert) checkOffset(offset, 2, this.length);
14464
+ const val = this[offset] | (this[offset + 1] << 8);
14465
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
14466
+ };
14467
+
14468
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
14469
+ offset = offset >>> 0;
14470
+ if (!noAssert) checkOffset(offset, 2, this.length);
14471
+ const val = this[offset + 1] | (this[offset] << 8);
14472
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
14473
+ };
14474
+
14475
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
14476
+ offset = offset >>> 0;
14477
+ if (!noAssert) checkOffset(offset, 4, this.length);
14478
+
14479
+ return (this[offset]) |
14480
+ (this[offset + 1] << 8) |
14481
+ (this[offset + 2] << 16) |
14482
+ (this[offset + 3] << 24)
14483
+ };
14484
+
14485
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
14486
+ offset = offset >>> 0;
14487
+ if (!noAssert) checkOffset(offset, 4, this.length);
14488
+
14489
+ return (this[offset] << 24) |
14490
+ (this[offset + 1] << 16) |
14491
+ (this[offset + 2] << 8) |
14492
+ (this[offset + 3])
14493
+ };
14494
+
14495
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
14496
+ offset = offset >>> 0;
14497
+ validateNumber(offset, 'offset');
14498
+ const first = this[offset];
14499
+ const last = this[offset + 7];
14500
+ if (first === undefined || last === undefined) {
14501
+ boundsError(offset, this.length - 8);
14502
+ }
14503
+
14504
+ const val = this[offset + 4] +
14505
+ this[offset + 5] * 2 ** 8 +
14506
+ this[offset + 6] * 2 ** 16 +
14507
+ (last << 24); // Overflow
14508
+
14509
+ return (BigInt(val) << BigInt(32)) +
14510
+ BigInt(first +
14511
+ this[++offset] * 2 ** 8 +
14512
+ this[++offset] * 2 ** 16 +
14513
+ this[++offset] * 2 ** 24)
14514
+ });
14515
+
14516
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
14517
+ offset = offset >>> 0;
14518
+ validateNumber(offset, 'offset');
14519
+ const first = this[offset];
14520
+ const last = this[offset + 7];
14521
+ if (first === undefined || last === undefined) {
14522
+ boundsError(offset, this.length - 8);
14523
+ }
14524
+
14525
+ const val = (first << 24) + // Overflow
14526
+ this[++offset] * 2 ** 16 +
14527
+ this[++offset] * 2 ** 8 +
14528
+ this[++offset];
14529
+
14530
+ return (BigInt(val) << BigInt(32)) +
14531
+ BigInt(this[++offset] * 2 ** 24 +
14532
+ this[++offset] * 2 ** 16 +
14533
+ this[++offset] * 2 ** 8 +
14534
+ last)
14535
+ });
14536
+
14537
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
14538
+ offset = offset >>> 0;
14539
+ if (!noAssert) checkOffset(offset, 4, this.length);
14540
+ return ieee754.read(this, offset, true, 23, 4)
14541
+ };
14542
+
14543
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
14544
+ offset = offset >>> 0;
14545
+ if (!noAssert) checkOffset(offset, 4, this.length);
14546
+ return ieee754.read(this, offset, false, 23, 4)
14547
+ };
14548
+
14549
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
14550
+ offset = offset >>> 0;
14551
+ if (!noAssert) checkOffset(offset, 8, this.length);
14552
+ return ieee754.read(this, offset, true, 52, 8)
14553
+ };
14554
+
14555
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
14556
+ offset = offset >>> 0;
14557
+ if (!noAssert) checkOffset(offset, 8, this.length);
14558
+ return ieee754.read(this, offset, false, 52, 8)
14559
+ };
14560
+
14561
+ function checkInt (buf, value, offset, ext, max, min) {
14562
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
14563
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
14564
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
14565
+ }
14566
+
14567
+ Buffer.prototype.writeUintLE =
14568
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
14569
+ value = +value;
14570
+ offset = offset >>> 0;
14571
+ byteLength = byteLength >>> 0;
14572
+ if (!noAssert) {
14573
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
14574
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
14575
+ }
14576
+
14577
+ let mul = 1;
14578
+ let i = 0;
14579
+ this[offset] = value & 0xFF;
14580
+ while (++i < byteLength && (mul *= 0x100)) {
14581
+ this[offset + i] = (value / mul) & 0xFF;
14582
+ }
14583
+
14584
+ return offset + byteLength
14585
+ };
14586
+
14587
+ Buffer.prototype.writeUintBE =
14588
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
14589
+ value = +value;
14590
+ offset = offset >>> 0;
14591
+ byteLength = byteLength >>> 0;
14592
+ if (!noAssert) {
14593
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
14594
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
14595
+ }
14596
+
14597
+ let i = byteLength - 1;
14598
+ let mul = 1;
14599
+ this[offset + i] = value & 0xFF;
14600
+ while (--i >= 0 && (mul *= 0x100)) {
14601
+ this[offset + i] = (value / mul) & 0xFF;
14602
+ }
14603
+
14604
+ return offset + byteLength
14605
+ };
14606
+
14607
+ Buffer.prototype.writeUint8 =
14608
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
14609
+ value = +value;
14610
+ offset = offset >>> 0;
14611
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
14612
+ this[offset] = (value & 0xff);
14613
+ return offset + 1
14614
+ };
14615
+
14616
+ Buffer.prototype.writeUint16LE =
14617
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
14618
+ value = +value;
14619
+ offset = offset >>> 0;
14620
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
14621
+ this[offset] = (value & 0xff);
14622
+ this[offset + 1] = (value >>> 8);
14623
+ return offset + 2
14624
+ };
14625
+
14626
+ Buffer.prototype.writeUint16BE =
14627
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
14628
+ value = +value;
14629
+ offset = offset >>> 0;
14630
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
14631
+ this[offset] = (value >>> 8);
14632
+ this[offset + 1] = (value & 0xff);
14633
+ return offset + 2
14634
+ };
14635
+
14636
+ Buffer.prototype.writeUint32LE =
14637
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
14638
+ value = +value;
14639
+ offset = offset >>> 0;
14640
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
14641
+ this[offset + 3] = (value >>> 24);
14642
+ this[offset + 2] = (value >>> 16);
14643
+ this[offset + 1] = (value >>> 8);
14644
+ this[offset] = (value & 0xff);
14645
+ return offset + 4
14646
+ };
14647
+
14648
+ Buffer.prototype.writeUint32BE =
14649
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
14650
+ value = +value;
14651
+ offset = offset >>> 0;
14652
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
14653
+ this[offset] = (value >>> 24);
14654
+ this[offset + 1] = (value >>> 16);
14655
+ this[offset + 2] = (value >>> 8);
14656
+ this[offset + 3] = (value & 0xff);
14657
+ return offset + 4
14658
+ };
14659
+
14660
+ function wrtBigUInt64LE (buf, value, offset, min, max) {
14661
+ checkIntBI(value, min, max, buf, offset, 7);
14662
+
14663
+ let lo = Number(value & BigInt(0xffffffff));
14664
+ buf[offset++] = lo;
14665
+ lo = lo >> 8;
14666
+ buf[offset++] = lo;
14667
+ lo = lo >> 8;
14668
+ buf[offset++] = lo;
14669
+ lo = lo >> 8;
14670
+ buf[offset++] = lo;
14671
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
14672
+ buf[offset++] = hi;
14673
+ hi = hi >> 8;
14674
+ buf[offset++] = hi;
14675
+ hi = hi >> 8;
14676
+ buf[offset++] = hi;
14677
+ hi = hi >> 8;
14678
+ buf[offset++] = hi;
14679
+ return offset
14680
+ }
14681
+
14682
+ function wrtBigUInt64BE (buf, value, offset, min, max) {
14683
+ checkIntBI(value, min, max, buf, offset, 7);
14684
+
14685
+ let lo = Number(value & BigInt(0xffffffff));
14686
+ buf[offset + 7] = lo;
14687
+ lo = lo >> 8;
14688
+ buf[offset + 6] = lo;
14689
+ lo = lo >> 8;
14690
+ buf[offset + 5] = lo;
14691
+ lo = lo >> 8;
14692
+ buf[offset + 4] = lo;
14693
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
14694
+ buf[offset + 3] = hi;
14695
+ hi = hi >> 8;
14696
+ buf[offset + 2] = hi;
14697
+ hi = hi >> 8;
14698
+ buf[offset + 1] = hi;
14699
+ hi = hi >> 8;
14700
+ buf[offset] = hi;
14701
+ return offset + 8
14702
+ }
14703
+
14704
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
14705
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
14706
+ });
14707
+
14708
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
14709
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
14710
+ });
14711
+
14712
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
14713
+ value = +value;
14714
+ offset = offset >>> 0;
14715
+ if (!noAssert) {
14716
+ const limit = Math.pow(2, (8 * byteLength) - 1);
14717
+
14718
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
14719
+ }
14720
+
14721
+ let i = 0;
14722
+ let mul = 1;
14723
+ let sub = 0;
14724
+ this[offset] = value & 0xFF;
14725
+ while (++i < byteLength && (mul *= 0x100)) {
14726
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
14727
+ sub = 1;
14728
+ }
14729
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
14730
+ }
14731
+
14732
+ return offset + byteLength
14733
+ };
14734
+
14735
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
14736
+ value = +value;
14737
+ offset = offset >>> 0;
14738
+ if (!noAssert) {
14739
+ const limit = Math.pow(2, (8 * byteLength) - 1);
14740
+
14741
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
14742
+ }
14743
+
14744
+ let i = byteLength - 1;
14745
+ let mul = 1;
14746
+ let sub = 0;
14747
+ this[offset + i] = value & 0xFF;
14748
+ while (--i >= 0 && (mul *= 0x100)) {
14749
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
14750
+ sub = 1;
14751
+ }
14752
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
14753
+ }
14754
+
14755
+ return offset + byteLength
14756
+ };
14757
+
14758
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
14759
+ value = +value;
14760
+ offset = offset >>> 0;
14761
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
14762
+ if (value < 0) value = 0xff + value + 1;
14763
+ this[offset] = (value & 0xff);
14764
+ return offset + 1
14765
+ };
14766
+
14767
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
14768
+ value = +value;
14769
+ offset = offset >>> 0;
14770
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
14771
+ this[offset] = (value & 0xff);
14772
+ this[offset + 1] = (value >>> 8);
14773
+ return offset + 2
14774
+ };
14775
+
14776
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
14777
+ value = +value;
14778
+ offset = offset >>> 0;
14779
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
14780
+ this[offset] = (value >>> 8);
14781
+ this[offset + 1] = (value & 0xff);
14782
+ return offset + 2
14783
+ };
14784
+
14785
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
14786
+ value = +value;
14787
+ offset = offset >>> 0;
14788
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
14789
+ this[offset] = (value & 0xff);
14790
+ this[offset + 1] = (value >>> 8);
14791
+ this[offset + 2] = (value >>> 16);
14792
+ this[offset + 3] = (value >>> 24);
14793
+ return offset + 4
14794
+ };
14795
+
14796
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
14797
+ value = +value;
14798
+ offset = offset >>> 0;
14799
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
14800
+ if (value < 0) value = 0xffffffff + value + 1;
14801
+ this[offset] = (value >>> 24);
14802
+ this[offset + 1] = (value >>> 16);
14803
+ this[offset + 2] = (value >>> 8);
14804
+ this[offset + 3] = (value & 0xff);
14805
+ return offset + 4
14806
+ };
14807
+
14808
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
14809
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
14810
+ });
14811
+
14812
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
14813
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
14814
+ });
14815
+
14816
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
14817
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
14818
+ if (offset < 0) throw new RangeError('Index out of range')
14819
+ }
14820
+
14821
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
14822
+ value = +value;
14823
+ offset = offset >>> 0;
14824
+ if (!noAssert) {
14825
+ checkIEEE754(buf, value, offset, 4);
14826
+ }
14827
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
14828
+ return offset + 4
14829
+ }
14830
+
14831
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
14832
+ return writeFloat(this, value, offset, true, noAssert)
14833
+ };
14834
+
14835
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
14836
+ return writeFloat(this, value, offset, false, noAssert)
14837
+ };
14838
+
14839
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
14840
+ value = +value;
14841
+ offset = offset >>> 0;
14842
+ if (!noAssert) {
14843
+ checkIEEE754(buf, value, offset, 8);
14844
+ }
14845
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
14846
+ return offset + 8
14847
+ }
14848
+
14849
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
14850
+ return writeDouble(this, value, offset, true, noAssert)
14851
+ };
14852
+
14853
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
14854
+ return writeDouble(this, value, offset, false, noAssert)
14855
+ };
14856
+
14857
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
14858
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
14859
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
14860
+ if (!start) start = 0;
14861
+ if (!end && end !== 0) end = this.length;
14862
+ if (targetStart >= target.length) targetStart = target.length;
14863
+ if (!targetStart) targetStart = 0;
14864
+ if (end > 0 && end < start) end = start;
14865
+
14866
+ // Copy 0 bytes; we're done
14867
+ if (end === start) return 0
14868
+ if (target.length === 0 || this.length === 0) return 0
14869
+
14870
+ // Fatal error conditions
14871
+ if (targetStart < 0) {
14872
+ throw new RangeError('targetStart out of bounds')
14873
+ }
14874
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
14875
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
14876
+
14877
+ // Are we oob?
14878
+ if (end > this.length) end = this.length;
14879
+ if (target.length - targetStart < end - start) {
14880
+ end = target.length - targetStart + start;
14881
+ }
14882
+
14883
+ const len = end - start;
14884
+
14885
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
14886
+ // Use built-in when available, missing from IE11
14887
+ this.copyWithin(targetStart, start, end);
14888
+ } else {
14889
+ Uint8Array.prototype.set.call(
14890
+ target,
14891
+ this.subarray(start, end),
14892
+ targetStart
14893
+ );
14894
+ }
14895
+
14896
+ return len
14897
+ };
14898
+
14899
+ // Usage:
14900
+ // buffer.fill(number[, offset[, end]])
14901
+ // buffer.fill(buffer[, offset[, end]])
14902
+ // buffer.fill(string[, offset[, end]][, encoding])
14903
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
14904
+ // Handle string cases:
14905
+ if (typeof val === 'string') {
14906
+ if (typeof start === 'string') {
14907
+ encoding = start;
14908
+ start = 0;
14909
+ end = this.length;
14910
+ } else if (typeof end === 'string') {
14911
+ encoding = end;
14912
+ end = this.length;
14913
+ }
14914
+ if (encoding !== undefined && typeof encoding !== 'string') {
14915
+ throw new TypeError('encoding must be a string')
14916
+ }
14917
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
14918
+ throw new TypeError('Unknown encoding: ' + encoding)
14919
+ }
14920
+ if (val.length === 1) {
14921
+ const code = val.charCodeAt(0);
14922
+ if ((encoding === 'utf8' && code < 128) ||
14923
+ encoding === 'latin1') {
14924
+ // Fast path: If `val` fits into a single byte, use that numeric value.
14925
+ val = code;
14926
+ }
14927
+ }
14928
+ } else if (typeof val === 'number') {
14929
+ val = val & 255;
14930
+ } else if (typeof val === 'boolean') {
14931
+ val = Number(val);
14932
+ }
14933
+
14934
+ // Invalid ranges are not set to a default, so can range check early.
14935
+ if (start < 0 || this.length < start || this.length < end) {
14936
+ throw new RangeError('Out of range index')
14937
+ }
14938
+
14939
+ if (end <= start) {
14940
+ return this
14941
+ }
14942
+
14943
+ start = start >>> 0;
14944
+ end = end === undefined ? this.length : end >>> 0;
14945
+
14946
+ if (!val) val = 0;
14947
+
14948
+ let i;
14949
+ if (typeof val === 'number') {
14950
+ for (i = start; i < end; ++i) {
14951
+ this[i] = val;
14952
+ }
14953
+ } else {
14954
+ const bytes = Buffer.isBuffer(val)
14955
+ ? val
14956
+ : Buffer.from(val, encoding);
14957
+ const len = bytes.length;
14958
+ if (len === 0) {
14959
+ throw new TypeError('The value "' + val +
14960
+ '" is invalid for argument "value"')
14961
+ }
14962
+ for (i = 0; i < end - start; ++i) {
14963
+ this[i + start] = bytes[i % len];
14964
+ }
14965
+ }
14966
+
14967
+ return this
14968
+ };
14969
+
14970
+ // CUSTOM ERRORS
14971
+ // =============
14972
+
14973
+ // Simplified versions from Node, changed for Buffer-only usage
14974
+ const errors = {};
14975
+ function E (sym, getMessage, Base) {
14976
+ errors[sym] = class NodeError extends Base {
14977
+ constructor () {
14978
+ super();
14979
+
14980
+ Object.defineProperty(this, 'message', {
14981
+ value: getMessage.apply(this, arguments),
14982
+ writable: true,
14983
+ configurable: true
14984
+ });
14985
+
14986
+ // Add the error code to the name to include it in the stack trace.
14987
+ this.name = `${this.name} [${sym}]`;
14988
+ // Access the stack to generate the error message including the error code
14989
+ // from the name.
14990
+ this.stack; // eslint-disable-line no-unused-expressions
14991
+ // Reset the name to the actual name.
14992
+ delete this.name;
14993
+ }
14994
+
14995
+ get code () {
14996
+ return sym
14997
+ }
14998
+
14999
+ set code (value) {
15000
+ Object.defineProperty(this, 'code', {
15001
+ configurable: true,
15002
+ enumerable: true,
15003
+ value,
15004
+ writable: true
15005
+ });
15006
+ }
15007
+
15008
+ toString () {
15009
+ return `${this.name} [${sym}]: ${this.message}`
15010
+ }
15011
+ };
15012
+ }
15013
+
15014
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
15015
+ function (name) {
15016
+ if (name) {
15017
+ return `${name} is outside of buffer bounds`
15018
+ }
15019
+
15020
+ return 'Attempt to access memory outside buffer bounds'
15021
+ }, RangeError);
15022
+ E('ERR_INVALID_ARG_TYPE',
15023
+ function (name, actual) {
15024
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
15025
+ }, TypeError);
15026
+ E('ERR_OUT_OF_RANGE',
15027
+ function (str, range, input) {
15028
+ let msg = `The value of "${str}" is out of range.`;
15029
+ let received = input;
15030
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
15031
+ received = addNumericalSeparator(String(input));
15032
+ } else if (typeof input === 'bigint') {
15033
+ received = String(input);
15034
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
15035
+ received = addNumericalSeparator(received);
15036
+ }
15037
+ received += 'n';
15038
+ }
15039
+ msg += ` It must be ${range}. Received ${received}`;
15040
+ return msg
15041
+ }, RangeError);
15042
+
15043
+ function addNumericalSeparator (val) {
15044
+ let res = '';
15045
+ let i = val.length;
15046
+ const start = val[0] === '-' ? 1 : 0;
15047
+ for (; i >= start + 4; i -= 3) {
15048
+ res = `_${val.slice(i - 3, i)}${res}`;
15049
+ }
15050
+ return `${val.slice(0, i)}${res}`
15051
+ }
15052
+
15053
+ // CHECK FUNCTIONS
15054
+ // ===============
15055
+
15056
+ function checkBounds (buf, offset, byteLength) {
15057
+ validateNumber(offset, 'offset');
15058
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
15059
+ boundsError(offset, buf.length - (byteLength + 1));
15060
+ }
15061
+ }
15062
+
15063
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
15064
+ if (value > max || value < min) {
15065
+ const n = typeof min === 'bigint' ? 'n' : '';
15066
+ let range;
15067
+ {
15068
+ if (min === 0 || min === BigInt(0)) {
15069
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
15070
+ } else {
15071
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
15072
+ `${(byteLength + 1) * 8 - 1}${n}`;
15073
+ }
15074
+ }
15075
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
15076
+ }
15077
+ checkBounds(buf, offset, byteLength);
15078
+ }
15079
+
15080
+ function validateNumber (value, name) {
15081
+ if (typeof value !== 'number') {
15082
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
15083
+ }
15084
+ }
15085
+
15086
+ function boundsError (value, length, type) {
15087
+ if (Math.floor(value) !== value) {
15088
+ validateNumber(value, type);
15089
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
15090
+ }
15091
+
15092
+ if (length < 0) {
15093
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
15094
+ }
15095
+
15096
+ throw new errors.ERR_OUT_OF_RANGE('offset',
15097
+ `>= ${0} and <= ${length}`,
15098
+ value)
15099
+ }
15100
+
15101
+ // HELPER FUNCTIONS
15102
+ // ================
15103
+
15104
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
15105
+
15106
+ function base64clean (str) {
15107
+ // Node takes equal signs as end of the Base64 encoding
15108
+ str = str.split('=')[0];
15109
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
15110
+ str = str.trim().replace(INVALID_BASE64_RE, '');
15111
+ // Node converts strings with length < 2 to ''
15112
+ if (str.length < 2) return ''
15113
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
15114
+ while (str.length % 4 !== 0) {
15115
+ str = str + '=';
15116
+ }
15117
+ return str
15118
+ }
15119
+
15120
+ function utf8ToBytes (string, units) {
15121
+ units = units || Infinity;
15122
+ let codePoint;
15123
+ const length = string.length;
15124
+ let leadSurrogate = null;
15125
+ const bytes = [];
15126
+
15127
+ for (let i = 0; i < length; ++i) {
15128
+ codePoint = string.charCodeAt(i);
15129
+
15130
+ // is surrogate component
15131
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
15132
+ // last char was a lead
15133
+ if (!leadSurrogate) {
15134
+ // no lead yet
15135
+ if (codePoint > 0xDBFF) {
15136
+ // unexpected trail
15137
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15138
+ continue
15139
+ } else if (i + 1 === length) {
15140
+ // unpaired lead
15141
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15142
+ continue
15143
+ }
15144
+
15145
+ // valid lead
15146
+ leadSurrogate = codePoint;
15147
+
15148
+ continue
15149
+ }
15150
+
15151
+ // 2 leads in a row
15152
+ if (codePoint < 0xDC00) {
15153
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15154
+ leadSurrogate = codePoint;
15155
+ continue
15156
+ }
15157
+
15158
+ // valid surrogate pair
15159
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
15160
+ } else if (leadSurrogate) {
15161
+ // valid bmp char, but last char was a lead
15162
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15163
+ }
15164
+
15165
+ leadSurrogate = null;
15166
+
15167
+ // encode utf8
15168
+ if (codePoint < 0x80) {
15169
+ if ((units -= 1) < 0) break
15170
+ bytes.push(codePoint);
15171
+ } else if (codePoint < 0x800) {
15172
+ if ((units -= 2) < 0) break
15173
+ bytes.push(
15174
+ codePoint >> 0x6 | 0xC0,
15175
+ codePoint & 0x3F | 0x80
15176
+ );
15177
+ } else if (codePoint < 0x10000) {
15178
+ if ((units -= 3) < 0) break
15179
+ bytes.push(
15180
+ codePoint >> 0xC | 0xE0,
15181
+ codePoint >> 0x6 & 0x3F | 0x80,
15182
+ codePoint & 0x3F | 0x80
15183
+ );
15184
+ } else if (codePoint < 0x110000) {
15185
+ if ((units -= 4) < 0) break
15186
+ bytes.push(
15187
+ codePoint >> 0x12 | 0xF0,
15188
+ codePoint >> 0xC & 0x3F | 0x80,
15189
+ codePoint >> 0x6 & 0x3F | 0x80,
15190
+ codePoint & 0x3F | 0x80
15191
+ );
15192
+ } else {
15193
+ throw new Error('Invalid code point')
15194
+ }
15195
+ }
15196
+
15197
+ return bytes
15198
+ }
15199
+
15200
+ function asciiToBytes (str) {
15201
+ const byteArray = [];
15202
+ for (let i = 0; i < str.length; ++i) {
15203
+ // Node's code seems to be doing this and not & 0x7F..
15204
+ byteArray.push(str.charCodeAt(i) & 0xFF);
15205
+ }
15206
+ return byteArray
15207
+ }
15208
+
15209
+ function utf16leToBytes (str, units) {
15210
+ let c, hi, lo;
15211
+ const byteArray = [];
15212
+ for (let i = 0; i < str.length; ++i) {
15213
+ if ((units -= 2) < 0) break
15214
+
15215
+ c = str.charCodeAt(i);
15216
+ hi = c >> 8;
15217
+ lo = c % 256;
15218
+ byteArray.push(lo);
15219
+ byteArray.push(hi);
15220
+ }
15221
+
15222
+ return byteArray
15223
+ }
15224
+
15225
+ function base64ToBytes (str) {
15226
+ return base64.toByteArray(base64clean(str))
15227
+ }
15228
+
15229
+ function blitBuffer (src, dst, offset, length) {
15230
+ let i;
15231
+ for (i = 0; i < length; ++i) {
15232
+ if ((i + offset >= dst.length) || (i >= src.length)) break
15233
+ dst[i + offset] = src[i];
15234
+ }
15235
+ return i
15236
+ }
15237
+
15238
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
15239
+ // the `instanceof` check but they should be treated as of that type.
15240
+ // See: https://github.com/feross/buffer/issues/166
15241
+ function isInstance (obj, type) {
15242
+ return obj instanceof type ||
15243
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
15244
+ obj.constructor.name === type.name)
15245
+ }
15246
+ function numberIsNaN (obj) {
15247
+ // For IE11 support
15248
+ return obj !== obj // eslint-disable-line no-self-compare
15249
+ }
15250
+
15251
+ // Create lookup table for `toString('hex')`
15252
+ // See: https://github.com/feross/buffer/issues/219
15253
+ const hexSliceLookupTable = (function () {
15254
+ const alphabet = '0123456789abcdef';
15255
+ const table = new Array(256);
15256
+ for (let i = 0; i < 16; ++i) {
15257
+ const i16 = i * 16;
15258
+ for (let j = 0; j < 16; ++j) {
15259
+ table[i16 + j] = alphabet[i] + alphabet[j];
15260
+ }
15261
+ }
15262
+ return table
15263
+ })();
15264
+
15265
+ // Return not function with Error if BigInt not supported
15266
+ function defineBigIntMethod (fn) {
15267
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
15268
+ }
15269
+
15270
+ function BufferBigIntNotDefined () {
15271
+ throw new Error('BigInt not supported')
15272
+ }
15273
+ } (buffer));
15274
+ return buffer;
15275
+ }
15276
+
15277
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
15278
+
15279
+ var hasRequiredSafeBuffer;
15280
+
15281
+ function requireSafeBuffer () {
15282
+ if (hasRequiredSafeBuffer) return safeBuffer.exports;
15283
+ hasRequiredSafeBuffer = 1;
15284
+ (function (module, exports$1) {
15285
+ /* eslint-disable node/no-deprecated-api */
15286
+ var buffer = requireBuffer();
15287
+ var Buffer = buffer.Buffer;
15288
+
15289
+ // alternative to using Object.keys for old browsers
15290
+ function copyProps (src, dst) {
15291
+ for (var key in src) {
15292
+ dst[key] = src[key];
15293
+ }
15294
+ }
15295
+ if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
15296
+ module.exports = buffer;
15297
+ } else {
15298
+ // Copy properties from require('buffer')
15299
+ copyProps(buffer, exports$1);
15300
+ exports$1.Buffer = SafeBuffer;
15301
+ }
15302
+
15303
+ function SafeBuffer (arg, encodingOrOffset, length) {
15304
+ return Buffer(arg, encodingOrOffset, length)
15305
+ }
15306
+
15307
+ SafeBuffer.prototype = Object.create(Buffer.prototype);
15308
+
15309
+ // Copy static methods from Buffer
15310
+ copyProps(Buffer, SafeBuffer);
15311
+
15312
+ SafeBuffer.from = function (arg, encodingOrOffset, length) {
15313
+ if (typeof arg === 'number') {
15314
+ throw new TypeError('Argument must not be a number')
15315
+ }
15316
+ return Buffer(arg, encodingOrOffset, length)
15317
+ };
15318
+
15319
+ SafeBuffer.alloc = function (size, fill, encoding) {
15320
+ if (typeof size !== 'number') {
15321
+ throw new TypeError('Argument must be a number')
15322
+ }
15323
+ var buf = Buffer(size);
15324
+ if (fill !== undefined) {
15325
+ if (typeof encoding === 'string') {
15326
+ buf.fill(fill, encoding);
15327
+ } else {
15328
+ buf.fill(fill);
15329
+ }
15330
+ } else {
15331
+ buf.fill(0);
15332
+ }
15333
+ return buf
15334
+ };
15335
+
15336
+ SafeBuffer.allocUnsafe = function (size) {
15337
+ if (typeof size !== 'number') {
15338
+ throw new TypeError('Argument must be a number')
15339
+ }
15340
+ return Buffer(size)
15341
+ };
15342
+
15343
+ SafeBuffer.allocUnsafeSlow = function (size) {
15344
+ if (typeof size !== 'number') {
15345
+ throw new TypeError('Argument must be a number')
15346
+ }
15347
+ return buffer.SlowBuffer(size)
15348
+ };
15349
+ } (safeBuffer, safeBuffer.exports));
15350
+ return safeBuffer.exports;
15351
+ }
15352
+
15353
+ var src;
15354
+ var hasRequiredSrc;
15355
+
15356
+ function requireSrc () {
15357
+ if (hasRequiredSrc) return src;
15358
+ hasRequiredSrc = 1;
15359
+ // base-x encoding / decoding
15360
+ // Copyright (c) 2018 base-x contributors
15361
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
15362
+ // Distributed under the MIT software license, see the accompanying
15363
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
15364
+ // @ts-ignore
15365
+ var _Buffer = requireSafeBuffer().Buffer;
15366
+ function base (ALPHABET) {
15367
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
15368
+ var BASE_MAP = new Uint8Array(256);
15369
+ for (var j = 0; j < BASE_MAP.length; j++) {
15370
+ BASE_MAP[j] = 255;
15371
+ }
15372
+ for (var i = 0; i < ALPHABET.length; i++) {
15373
+ var x = ALPHABET.charAt(i);
15374
+ var xc = x.charCodeAt(0);
15375
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
15376
+ BASE_MAP[xc] = i;
15377
+ }
15378
+ var BASE = ALPHABET.length;
15379
+ var LEADER = ALPHABET.charAt(0);
15380
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
15381
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
15382
+ function encode (source) {
15383
+ if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source); }
15384
+ if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
15385
+ if (source.length === 0) { return '' }
15386
+ // Skip & count leading zeroes.
15387
+ var zeroes = 0;
15388
+ var length = 0;
15389
+ var pbegin = 0;
15390
+ var pend = source.length;
15391
+ while (pbegin !== pend && source[pbegin] === 0) {
15392
+ pbegin++;
15393
+ zeroes++;
15394
+ }
15395
+ // Allocate enough space in big-endian base58 representation.
15396
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
15397
+ var b58 = new Uint8Array(size);
15398
+ // Process the bytes.
15399
+ while (pbegin !== pend) {
15400
+ var carry = source[pbegin];
15401
+ // Apply "b58 = b58 * 256 + ch".
15402
+ var i = 0;
15403
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
15404
+ carry += (256 * b58[it1]) >>> 0;
15405
+ b58[it1] = (carry % BASE) >>> 0;
15406
+ carry = (carry / BASE) >>> 0;
15407
+ }
15408
+ if (carry !== 0) { throw new Error('Non-zero carry') }
15409
+ length = i;
15410
+ pbegin++;
15411
+ }
15412
+ // Skip leading zeroes in base58 result.
15413
+ var it2 = size - length;
15414
+ while (it2 !== size && b58[it2] === 0) {
15415
+ it2++;
15416
+ }
15417
+ // Translate the result into a string.
15418
+ var str = LEADER.repeat(zeroes);
15419
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
15420
+ return str
15421
+ }
15422
+ function decodeUnsafe (source) {
15423
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
15424
+ if (source.length === 0) { return _Buffer.alloc(0) }
15425
+ var psz = 0;
15426
+ // Skip and count leading '1's.
15427
+ var zeroes = 0;
15428
+ var length = 0;
15429
+ while (source[psz] === LEADER) {
15430
+ zeroes++;
15431
+ psz++;
15432
+ }
15433
+ // Allocate enough space in big-endian base256 representation.
15434
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
15435
+ var b256 = new Uint8Array(size);
15436
+ // Process the characters.
15437
+ while (psz < source.length) {
15438
+ // Find code of next character
15439
+ var charCode = source.charCodeAt(psz);
15440
+ // Base map can not be indexed using char code
15441
+ if (charCode > 255) { return }
15442
+ // Decode character
15443
+ var carry = BASE_MAP[charCode];
15444
+ // Invalid character
15445
+ if (carry === 255) { return }
15446
+ var i = 0;
15447
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
15448
+ carry += (BASE * b256[it3]) >>> 0;
15449
+ b256[it3] = (carry % 256) >>> 0;
15450
+ carry = (carry / 256) >>> 0;
15451
+ }
15452
+ if (carry !== 0) { throw new Error('Non-zero carry') }
15453
+ length = i;
15454
+ psz++;
15455
+ }
15456
+ // Skip leading zeroes in b256.
15457
+ var it4 = size - length;
15458
+ while (it4 !== size && b256[it4] === 0) {
15459
+ it4++;
15460
+ }
15461
+ var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
15462
+ vch.fill(0x00, 0, zeroes);
15463
+ var j = zeroes;
15464
+ while (it4 !== size) {
15465
+ vch[j++] = b256[it4++];
15466
+ }
15467
+ return vch
15468
+ }
15469
+ function decode (string) {
15470
+ var buffer = decodeUnsafe(string);
15471
+ if (buffer) { return buffer }
15472
+ throw new Error('Non-base' + BASE + ' character')
15473
+ }
15474
+ return {
15475
+ encode: encode,
15476
+ decodeUnsafe: decodeUnsafe,
15477
+ decode: decode
15478
+ }
15479
+ }
15480
+ src = base;
15481
+ return src;
15482
+ }
15483
+
15484
+ var bs58$1;
15485
+ var hasRequiredBs58;
15486
+
15487
+ function requireBs58 () {
15488
+ if (hasRequiredBs58) return bs58$1;
15489
+ hasRequiredBs58 = 1;
15490
+ var basex = requireSrc();
15491
+ var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
15492
+
15493
+ bs58$1 = basex(ALPHABET);
15494
+ return bs58$1;
15495
+ }
15496
+
15497
+ var bs58Exports = requireBs58();
15498
+ var bs58 = /*@__PURE__*/getDefaultExportFromCjs$1(bs58Exports);
15499
+
15500
+ var index = /*#__PURE__*/_mergeNamespaces({
15501
+ __proto__: null,
15502
+ default: bs58
15503
+ }, [bs58Exports]);
12928
15504
 
12929
15505
  /**
12930
15506
  * Privy Expo Auth Provider — React Native implementation of AuthProvider.
@@ -13265,5 +15841,5 @@ class PrivyExpoProvider {
13265
15841
  }
13266
15842
  }
13267
15843
 
13268
- export { closeAllSubscriptions as $, set as A, setMany as B, setFile as C, getFiles as D, runQuery as E, runQueryMany as F, runExpression as G, runExpressionMany as H, signMessage as I, signTransaction as J, signAndSubmitTransaction as K, count as L, aggregate as M, subscribe as N, useAuth as O, getIdToken as P, setPlatform as Q, MockAuthProvider as R, SOLANA_MAINNET_RPC_URL as S, DEFAULT_TEST_ADDRESS as T, OffchainAuthProvider as U, PrivyExpoProvider as V, WebSessionManager as W, InsufficientBalanceError as X, ReactNativeSessionManager as Y, ServerSessionManager as Z, clearCache as _, SOLANA_DEVNET_RPC_URL as a, getCachedData as a0, reconnectWithNewAuth as a1, refreshSession as a2, signSessionCreateMessage as a3, index as a4, buildSetDocumentsTransaction as b, convertRemainingAccounts as c, bs58 as d, confirmAndCheckTransaction as e, createSessionWithPrivy as f, getPlatform as g, SURFNET_RPC_URL$1 as h, detectMobile as i, detectAndroid as j, setAuthLoading as k, genAuthNonce as l, genSolanaMessage as m, createSessionWithSignature as n, getDefaultExportFromCjs$1 as o, init as p, getCurrentUser as q, onAuthStateChanged as r, setCurrentUser as s, onAuthLoadingChanged as t, getAuthLoading as u, login as v, logout as w, getConfig as x, getAuthProvider as y, get as z };
13269
- //# sourceMappingURL=index.native-BB7er4-z.esm.js.map
15844
+ export { ReactNativeSessionManager as $, getAuthProvider as A, get as B, set as C, setMany as D, setFile as E, getFiles as F, runQuery as G, runQueryMany as H, runExpression as I, runExpressionMany as J, signMessage as K, signTransaction as L, signAndSubmitTransaction as M, count as N, aggregate as O, subscribe as P, useAuth as Q, deserializeTransaction as R, SOLANA_MAINNET_RPC_URL as S, getIdToken as T, setPlatform as U, MockAuthProvider as V, WebSessionManager as W, DEFAULT_TEST_ADDRESS as X, OffchainAuthProvider as Y, PrivyExpoProvider as Z, InsufficientBalanceError as _, SOLANA_DEVNET_RPC_URL as a, ServerSessionManager as a0, clearCache as a1, closeAllSubscriptions as a2, getCachedData as a3, getMany as a4, reconnectWithNewAuth as a5, refreshSession as a6, signSessionCreateMessage as a7, buildSetDocumentsTransaction as b, convertRemainingAccounts as c, bs58 as d, confirmAndCheckTransaction as e, createSessionWithPrivy as f, getPlatform as g, SURFNET_RPC_URL$1 as h, index as i, detectMobile as j, detectAndroid as k, setAuthLoading as l, genAuthNonce as m, genSolanaMessage as n, createSessionWithSignature as o, getDefaultExportFromCjs$1 as p, init as q, requireBuffer as r, setCurrentUser as s, getCurrentUser as t, onAuthStateChanged as u, onAuthLoadingChanged as v, getAuthLoading as w, login as x, logout as y, getConfig as z };
15845
+ //# sourceMappingURL=index.native-DAyMVhFq.esm.js.map