@pooflabs/web 0.0.83-rc2 → 0.0.84

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 (61) hide show
  1. package/dist/{index-BycoUXcq.js → index-BM6hgCdH.js} +2 -149
  2. package/dist/index-BM6hgCdH.js.map +1 -0
  3. package/dist/{index-HSa4FZ9y.js → index-BPlF6-PQ.js} +279 -159
  4. package/dist/index-BPlF6-PQ.js.map +1 -0
  5. package/dist/index-Bp4b5LXs.js +8 -0
  6. package/dist/index-Bp4b5LXs.js.map +1 -0
  7. package/dist/index-C80kRxWk.esm.js +6 -0
  8. package/dist/index-C80kRxWk.esm.js.map +1 -0
  9. package/dist/{index-dyXVIGCy.esm.js → index-CH2G5Y9i.esm.js} +2 -149
  10. package/dist/index-CH2G5Y9i.esm.js.map +1 -0
  11. package/dist/{index-DQLduP63.js → index-CSeN3jbG.js} +3 -150
  12. package/dist/index-CSeN3jbG.js.map +1 -0
  13. package/dist/{index-p1LvAs78.esm.js → index-XHbmzFFO.esm.js} +279 -159
  14. package/dist/index-XHbmzFFO.esm.js.map +1 -0
  15. package/dist/{index-DEwS-N9F.esm.js → index-ep10Sw82.esm.js} +3 -150
  16. package/dist/index-ep10Sw82.esm.js.map +1 -0
  17. package/dist/{index.browser-DEfS865o.js → index.browser-BvNsUWjt.js} +2 -2
  18. package/dist/{index.browser-DEfS865o.js.map → index.browser-BvNsUWjt.js.map} +1 -1
  19. package/dist/{index.browser-jwJFPtjK.js → index.browser-BwIqqM4U.js} +2 -2
  20. package/dist/{index.browser-jwJFPtjK.js.map → index.browser-BwIqqM4U.js.map} +1 -1
  21. package/dist/{index.browser-DQvFxLjk.js → index.browser-C1QL04xM.js} +2 -2
  22. package/dist/{index.browser-DQvFxLjk.js.map → index.browser-C1QL04xM.js.map} +1 -1
  23. package/dist/{index.browser-Dekybe_E.esm.js → index.browser-Cgj7Hs6n.esm.js} +2 -2
  24. package/dist/{index.browser-Dekybe_E.esm.js.map → index.browser-Cgj7Hs6n.esm.js.map} +1 -1
  25. package/dist/{index.browser-zXADedzh.esm.js → index.browser-CifFI7Ju.esm.js} +2 -2
  26. package/dist/{index.browser-zXADedzh.esm.js.map → index.browser-CifFI7Ju.esm.js.map} +1 -1
  27. package/dist/{index.browser-CbVXUCv0.esm.js → index.browser-D8VWPXTZ.esm.js} +2 -2
  28. package/dist/{index.browser-CbVXUCv0.esm.js.map → index.browser-D8VWPXTZ.esm.js.map} +1 -1
  29. package/dist/index.esm.js +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/{index.native-CawD5H6H.js → index.native-BmtuyGXs.js} +2677 -187
  32. package/dist/index.native-BmtuyGXs.js.map +1 -0
  33. package/dist/{index.native-Brt4NkkH.esm.js → index.native-X01vlukI.esm.js} +2677 -188
  34. package/dist/index.native-X01vlukI.esm.js.map +1 -0
  35. package/dist/index.native.esm.js +1 -1
  36. package/dist/index.native.js +1 -1
  37. package/dist/{phantom-wallet-provider-CjI_IIr9.js → phantom-wallet-provider-C_LPU6Ns.js} +4 -4
  38. package/dist/{phantom-wallet-provider-CjI_IIr9.js.map → phantom-wallet-provider-C_LPU6Ns.js.map} +1 -1
  39. package/dist/{phantom-wallet-provider-BR5R3OAI.esm.js → phantom-wallet-provider-DRvhBbbR.esm.js} +4 -4
  40. package/dist/{phantom-wallet-provider-BR5R3OAI.esm.js.map → phantom-wallet-provider-DRvhBbbR.esm.js.map} +1 -1
  41. package/dist/{privy-wallet-provider-wN23XtR8.js → privy-wallet-provider-DQM8xO38.js} +3 -3
  42. package/dist/{privy-wallet-provider-wN23XtR8.js.map → privy-wallet-provider-DQM8xO38.js.map} +1 -1
  43. package/dist/{privy-wallet-provider-ZQ4fLg4f.esm.js → privy-wallet-provider-ZGu8q5T5.esm.js} +3 -3
  44. package/dist/{privy-wallet-provider-ZQ4fLg4f.esm.js.map → privy-wallet-provider-ZGu8q5T5.esm.js.map} +1 -1
  45. package/dist/{solana-mobile-wallet-provider-Dt8K5Ils.js → solana-mobile-wallet-provider-6gNw2_bX.js} +4 -4
  46. package/dist/{solana-mobile-wallet-provider-Dt8K5Ils.js.map → solana-mobile-wallet-provider-6gNw2_bX.js.map} +1 -1
  47. package/dist/{solana-mobile-wallet-provider-DhtoJcqW.esm.js → solana-mobile-wallet-provider-B65A7abd.esm.js} +4 -4
  48. package/dist/{solana-mobile-wallet-provider-DhtoJcqW.esm.js.map → solana-mobile-wallet-provider-B65A7abd.esm.js.map} +1 -1
  49. package/package.json +2 -2
  50. package/dist/index-Bdcc5821.js +0 -2375
  51. package/dist/index-Bdcc5821.js.map +0 -1
  52. package/dist/index-BycoUXcq.js.map +0 -1
  53. package/dist/index-CrOVJFX9.esm.js +0 -2373
  54. package/dist/index-CrOVJFX9.esm.js.map +0 -1
  55. package/dist/index-DEwS-N9F.esm.js.map +0 -1
  56. package/dist/index-DQLduP63.js.map +0 -1
  57. package/dist/index-HSa4FZ9y.js.map +0 -1
  58. package/dist/index-dyXVIGCy.esm.js.map +0 -1
  59. package/dist/index-p1LvAs78.esm.js.map +0 -1
  60. package/dist/index.native-Brt4NkkH.esm.js.map +0 -1
  61. package/dist/index.native-CawD5H6H.js.map +0 -1
@@ -6888,19 +6888,19 @@ var webSessionManager = /*#__PURE__*/Object.freeze({
6888
6888
  WebSessionManager: WebSessionManager
6889
6889
  });
6890
6890
 
6891
- var buffer = {};
6891
+ var buffer$1 = {};
6892
6892
 
6893
- var base64Js = {};
6893
+ var base64Js$1 = {};
6894
6894
 
6895
- var hasRequiredBase64Js;
6895
+ var hasRequiredBase64Js$1;
6896
6896
 
6897
- function requireBase64Js () {
6898
- if (hasRequiredBase64Js) return base64Js;
6899
- hasRequiredBase64Js = 1;
6897
+ function requireBase64Js$1 () {
6898
+ if (hasRequiredBase64Js$1) return base64Js$1;
6899
+ hasRequiredBase64Js$1 = 1;
6900
6900
 
6901
- base64Js.byteLength = byteLength;
6902
- base64Js.toByteArray = toByteArray;
6903
- base64Js.fromByteArray = fromByteArray;
6901
+ base64Js$1.byteLength = byteLength;
6902
+ base64Js$1.toByteArray = toByteArray;
6903
+ base64Js$1.fromByteArray = fromByteArray;
6904
6904
 
6905
6905
  var lookup = [];
6906
6906
  var revLookup = [];
@@ -7046,19 +7046,19 @@ function requireBase64Js () {
7046
7046
 
7047
7047
  return parts.join('')
7048
7048
  }
7049
- return base64Js;
7049
+ return base64Js$1;
7050
7050
  }
7051
7051
 
7052
- var ieee754 = {};
7052
+ var ieee754$1 = {};
7053
7053
 
7054
7054
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
7055
7055
 
7056
- var hasRequiredIeee754;
7056
+ var hasRequiredIeee754$1;
7057
7057
 
7058
- function requireIeee754 () {
7059
- if (hasRequiredIeee754) return ieee754;
7060
- hasRequiredIeee754 = 1;
7061
- ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
7058
+ function requireIeee754$1 () {
7059
+ if (hasRequiredIeee754$1) return ieee754$1;
7060
+ hasRequiredIeee754$1 = 1;
7061
+ ieee754$1.read = function (buffer, offset, isLE, mLen, nBytes) {
7062
7062
  var e, m;
7063
7063
  var eLen = (nBytes * 8) - mLen - 1;
7064
7064
  var eMax = (1 << eLen) - 1;
@@ -7091,7 +7091,7 @@ function requireIeee754 () {
7091
7091
  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
7092
7092
  };
7093
7093
 
7094
- ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
7094
+ ieee754$1.write = function (buffer, value, offset, isLE, mLen, nBytes) {
7095
7095
  var e, m, c;
7096
7096
  var eLen = (nBytes * 8) - mLen - 1;
7097
7097
  var eMax = (1 << eLen) - 1;
@@ -7142,7 +7142,7 @@ function requireIeee754 () {
7142
7142
 
7143
7143
  buffer[offset + i - d] |= s * 128;
7144
7144
  };
7145
- return ieee754;
7145
+ return ieee754$1;
7146
7146
  }
7147
7147
 
7148
7148
  /*!
@@ -7152,15 +7152,15 @@ function requireIeee754 () {
7152
7152
  * @license MIT
7153
7153
  */
7154
7154
 
7155
- var hasRequiredBuffer;
7155
+ var hasRequiredBuffer$1;
7156
7156
 
7157
- function requireBuffer () {
7158
- if (hasRequiredBuffer) return buffer;
7159
- hasRequiredBuffer = 1;
7157
+ function requireBuffer$1 () {
7158
+ if (hasRequiredBuffer$1) return buffer$1;
7159
+ hasRequiredBuffer$1 = 1;
7160
7160
  (function (exports$1) {
7161
7161
 
7162
- const base64 = requireBase64Js();
7163
- const ieee754 = requireIeee754();
7162
+ const base64 = requireBase64Js$1();
7163
+ const ieee754 = requireIeee754$1();
7164
7164
  const customInspectSymbol =
7165
7165
  (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
7166
7166
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
@@ -9253,24 +9253,24 @@ function requireBuffer () {
9253
9253
  function BufferBigIntNotDefined () {
9254
9254
  throw new Error('BigInt not supported')
9255
9255
  }
9256
- } (buffer));
9257
- return buffer;
9256
+ } (buffer$1));
9257
+ return buffer$1;
9258
9258
  }
9259
9259
 
9260
- var bufferExports = requireBuffer();
9260
+ var bufferExports = requireBuffer$1();
9261
9261
 
9262
- var safeBuffer = {exports: {}};
9262
+ var safeBuffer$1 = {exports: {}};
9263
9263
 
9264
9264
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
9265
9265
 
9266
- var hasRequiredSafeBuffer;
9266
+ var hasRequiredSafeBuffer$1;
9267
9267
 
9268
- function requireSafeBuffer () {
9269
- if (hasRequiredSafeBuffer) return safeBuffer.exports;
9270
- hasRequiredSafeBuffer = 1;
9268
+ function requireSafeBuffer$1 () {
9269
+ if (hasRequiredSafeBuffer$1) return safeBuffer$1.exports;
9270
+ hasRequiredSafeBuffer$1 = 1;
9271
9271
  (function (module, exports$1) {
9272
9272
  /* eslint-disable node/no-deprecated-api */
9273
- var buffer = requireBuffer();
9273
+ var buffer = requireBuffer$1();
9274
9274
  var Buffer = buffer.Buffer;
9275
9275
 
9276
9276
  // alternative to using Object.keys for old browsers
@@ -9333,23 +9333,23 @@ function requireSafeBuffer () {
9333
9333
  }
9334
9334
  return buffer.SlowBuffer(size)
9335
9335
  };
9336
- } (safeBuffer, safeBuffer.exports));
9337
- return safeBuffer.exports;
9336
+ } (safeBuffer$1, safeBuffer$1.exports));
9337
+ return safeBuffer$1.exports;
9338
9338
  }
9339
9339
 
9340
- var src;
9341
- var hasRequiredSrc;
9340
+ var src$1;
9341
+ var hasRequiredSrc$1;
9342
9342
 
9343
- function requireSrc () {
9344
- if (hasRequiredSrc) return src;
9345
- hasRequiredSrc = 1;
9343
+ function requireSrc$1 () {
9344
+ if (hasRequiredSrc$1) return src$1;
9345
+ hasRequiredSrc$1 = 1;
9346
9346
  // base-x encoding / decoding
9347
9347
  // Copyright (c) 2018 base-x contributors
9348
9348
  // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
9349
9349
  // Distributed under the MIT software license, see the accompanying
9350
9350
  // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
9351
9351
  // @ts-ignore
9352
- var _Buffer = requireSafeBuffer().Buffer;
9352
+ var _Buffer = requireSafeBuffer$1().Buffer;
9353
9353
  function base (ALPHABET) {
9354
9354
  if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
9355
9355
  var BASE_MAP = new Uint8Array(256);
@@ -9464,8 +9464,8 @@ function requireSrc () {
9464
9464
  decode: decode
9465
9465
  }
9466
9466
  }
9467
- src = base;
9468
- return src;
9467
+ src$1 = base;
9468
+ return src$1;
9469
9469
  }
9470
9470
 
9471
9471
  var bs58$1;
@@ -9474,7 +9474,7 @@ var hasRequiredBs58;
9474
9474
  function requireBs58 () {
9475
9475
  if (hasRequiredBs58) return bs58$1;
9476
9476
  hasRequiredBs58 = 1;
9477
- var basex = requireSrc();
9477
+ var basex = requireSrc$1();
9478
9478
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
9479
9479
 
9480
9480
  bs58$1 = basex(ALPHABET);
@@ -9561,6 +9561,12 @@ async function genSolanaMessage(address, nonce) {
9561
9561
  // Serialization Helpers
9562
9562
  // ─────────────────────────────────────────────────────────────
9563
9563
  function isHexString(value) {
9564
+ // Only strings can be hex-encoded. Numbers, BNs, and other shapes coming back
9565
+ // from the API for u64Val/i64Val should fall through to `new BN(value)` which
9566
+ // accepts those shapes natively. Without this guard, calling .startsWith on a
9567
+ // non-string blows up with TypeError.
9568
+ if (typeof value !== "string")
9569
+ return false;
9564
9570
  // Matches strings containing only 0-9, a-f, or A-F (optionally prefixed with 0x)
9565
9571
  let testValue = value;
9566
9572
  // Handle negative values
@@ -9656,8 +9662,11 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
9656
9662
  }
9657
9663
  else if (idl.address === "poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp") {
9658
9664
  const program = new Program(idl, anchorProvider);
9665
+ // Targets `set_documents_v2` (Vec<u8> ra_indices). The on-chain program
9666
+ // also exposes the legacy `set_documents` (Vec<u64>) so SDKs already on npm
9667
+ // continue to work — but new releases of this SDK speak v2 only.
9659
9668
  tx = await program.methods
9660
- .setDocuments(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
9669
+ .setDocumentsV2(args.app_id, prepareAnchorArgs(args.documents), args.delete_paths, args.txData, simulate)
9661
9670
  .preInstructions(instructions)
9662
9671
  .accounts({
9663
9672
  payer: payerPublicKey
@@ -10012,11 +10021,17 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
10012
10021
  if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
10013
10022
  Object.assign(headers, _overrides.headers);
10014
10023
  }
10024
+ // Writes (PUT/POST/DELETE) can take significantly longer than reads —
10025
+ // server-side they may trigger ad-hoc LUT creation (create + extend +
10026
+ // wait-for-finalization, ~15-30s on mainnet). Use a larger default for
10027
+ // non-GET so the SDK doesn't time out before client-api responds.
10028
+ const isRead = method.toUpperCase() === "GET";
10029
+ const defaultTimeout = isRead ? 30000 : 90000;
10015
10030
  const requestConfig = {
10016
10031
  method,
10017
10032
  url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
10018
10033
  headers,
10019
- timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : 30000,
10034
+ timeout: (_a = _overrides === null || _overrides === void 0 ? void 0 : _overrides.timeout) !== null && _a !== void 0 ? _a : defaultTimeout,
10020
10035
  };
10021
10036
  if (method !== "GET" && method !== "get") {
10022
10037
  requestConfig.data = data ? JSON.stringify(data) : {};
@@ -10661,21 +10676,38 @@ async function setMany(many, options) {
10661
10676
  setDocumentData: tx.transactionArgs.setDocumentData,
10662
10677
  deletePaths: tx.transactionArgs.deletePaths,
10663
10678
  idl: tx.idl,
10664
- txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => {
10665
- var _a;
10666
- return ({
10667
- pluginFunctionKey: txData.pluginFunctionKey,
10668
- txData: bufferExports.Buffer.from(txData.txData),
10669
- raIndices: (_a = txData.raIndices) === null || _a === void 0 ? void 0 : _a.map((raIndex) => {
10670
- if (isHexString(raIndex)) {
10671
- return new BN(raIndex, "hex");
10679
+ txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({
10680
+ pluginFunctionKey: txData.pluginFunctionKey,
10681
+ txData: bufferExports.Buffer.from(txData.txData),
10682
+ // raIndices is Vec<u8> on-chain (serialized as Buffer/bytes). The server may send
10683
+ // it as a Buffer, a number[], a Uint8Array, or — over JSON — as Node's serialized
10684
+ // Buffer shape {type: "Buffer", data: number[]} (the default `JSON.stringify(buf)`
10685
+ // output). Normalise all of those to Buffer here. Each value must fit in u8 (matches
10686
+ // Solana's instruction-level account indexing); throw clearly if anything is out of range.
10687
+ raIndices: (() => {
10688
+ const raw = txData.raIndices;
10689
+ if (raw == null)
10690
+ return bufferExports.Buffer.alloc(0);
10691
+ if (bufferExports.Buffer.isBuffer(raw))
10692
+ return raw;
10693
+ if (raw instanceof Uint8Array)
10694
+ return bufferExports.Buffer.from(raw);
10695
+ // Node's JSON-serialised Buffer: {type: "Buffer", data: number[]}
10696
+ const arrayLike = Array.isArray(raw)
10697
+ ? raw
10698
+ : (raw && typeof raw === 'object' && Array.isArray(raw.data))
10699
+ ? raw.data
10700
+ : (() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();
10701
+ const bytes = arrayLike.map((raIndex) => {
10702
+ const n = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);
10703
+ if (!Number.isInteger(n) || n < 0 || n > 255) {
10704
+ throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);
10672
10705
  }
10673
- else {
10674
- return new BN(raIndex);
10675
- }
10676
- }),
10677
- });
10678
- })) !== null && _b !== void 0 ? _b : [],
10706
+ return n;
10707
+ });
10708
+ return bufferExports.Buffer.from(bytes);
10709
+ })(),
10710
+ }))) !== null && _b !== void 0 ? _b : [],
10679
10711
  };
10680
10712
  const config = await getConfig();
10681
10713
  const solTransaction = {
@@ -12833,15 +12865,15 @@ function clearIncompatibleSession() {
12833
12865
  // Lazy loaders for web-only providers.
12834
12866
  // Using dynamic import() ensures Metro (RN) never resolves these modules.
12835
12867
  async function loadPrivyWalletProvider() {
12836
- const mod = await import('./privy-wallet-provider-ZQ4fLg4f.esm.js');
12868
+ const mod = await import('./privy-wallet-provider-ZGu8q5T5.esm.js');
12837
12869
  return mod.PrivyWalletProvider;
12838
12870
  }
12839
12871
  async function loadPhantomWalletProvider() {
12840
- const mod = await import('./phantom-wallet-provider-BR5R3OAI.esm.js');
12872
+ const mod = await import('./phantom-wallet-provider-DRvhBbbR.esm.js');
12841
12873
  return { PhantomWalletProvider: mod.PhantomWalletProvider };
12842
12874
  }
12843
12875
  async function loadSolanaMobileWalletProvider() {
12844
- const mod = await import('./solana-mobile-wallet-provider-DhtoJcqW.esm.js');
12876
+ const mod = await import('./solana-mobile-wallet-provider-B65A7abd.esm.js');
12845
12877
  return mod.SolanaMobileWalletProvider;
12846
12878
  }
12847
12879
  async function hotSwapToPrivyProvider(config) {
@@ -13259,132 +13291,2589 @@ async function confirmAndCheckTransaction(connection, signature) {
13259
13291
  throw new Error('Transaction confirmation timeout');
13260
13292
  }
13261
13293
 
13262
- // base-x encoding / decoding
13263
- // Copyright (c) 2018 base-x contributors
13264
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
13265
- // Distributed under the MIT software license, see the accompanying
13266
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
13267
- function base (ALPHABET) {
13268
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
13269
- const BASE_MAP = new Uint8Array(256);
13270
- for (let j = 0; j < BASE_MAP.length; j++) {
13271
- BASE_MAP[j] = 255;
13272
- }
13273
- for (let i = 0; i < ALPHABET.length; i++) {
13274
- const x = ALPHABET.charAt(i);
13275
- const xc = x.charCodeAt(0);
13276
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
13277
- BASE_MAP[xc] = i;
13278
- }
13279
- const BASE = ALPHABET.length;
13280
- const LEADER = ALPHABET.charAt(0);
13281
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
13282
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
13283
- function encode (source) {
13284
- // eslint-disable-next-line no-empty
13285
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
13286
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
13287
- } else if (Array.isArray(source)) {
13288
- source = Uint8Array.from(source);
13289
- }
13290
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
13291
- if (source.length === 0) { return '' }
13292
- // Skip & count leading zeroes.
13293
- let zeroes = 0;
13294
- let length = 0;
13295
- let pbegin = 0;
13296
- const pend = source.length;
13297
- while (pbegin !== pend && source[pbegin] === 0) {
13298
- pbegin++;
13299
- zeroes++;
13300
- }
13301
- // Allocate enough space in big-endian base58 representation.
13302
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
13303
- const b58 = new Uint8Array(size);
13304
- // Process the bytes.
13305
- while (pbegin !== pend) {
13306
- let carry = source[pbegin];
13307
- // Apply "b58 = b58 * 256 + ch".
13308
- let i = 0;
13309
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
13310
- carry += (256 * b58[it1]) >>> 0;
13311
- b58[it1] = (carry % BASE) >>> 0;
13312
- carry = (carry / BASE) >>> 0;
13313
- }
13314
- if (carry !== 0) { throw new Error('Non-zero carry') }
13315
- length = i;
13316
- pbegin++;
13317
- }
13318
- // Skip leading zeroes in base58 result.
13319
- let it2 = size - length;
13320
- while (it2 !== size && b58[it2] === 0) {
13321
- it2++;
13322
- }
13323
- // Translate the result into a string.
13324
- let str = LEADER.repeat(zeroes);
13325
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
13326
- return str
13327
- }
13328
- function decodeUnsafe (source) {
13329
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
13330
- if (source.length === 0) { return new Uint8Array() }
13331
- let psz = 0;
13332
- // Skip and count leading '1's.
13333
- let zeroes = 0;
13334
- let length = 0;
13335
- while (source[psz] === LEADER) {
13336
- zeroes++;
13337
- psz++;
13338
- }
13339
- // Allocate enough space in big-endian base256 representation.
13340
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
13341
- const b256 = new Uint8Array(size);
13342
- // Process the characters.
13343
- while (psz < source.length) {
13344
- // Find code of next character
13345
- const charCode = source.charCodeAt(psz);
13346
- // Base map can not be indexed using char code
13347
- if (charCode > 255) { return }
13348
- // Decode character
13349
- let carry = BASE_MAP[charCode];
13350
- // Invalid character
13351
- if (carry === 255) { return }
13352
- let i = 0;
13353
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
13354
- carry += (BASE * b256[it3]) >>> 0;
13355
- b256[it3] = (carry % 256) >>> 0;
13356
- carry = (carry / 256) >>> 0;
13357
- }
13358
- if (carry !== 0) { throw new Error('Non-zero carry') }
13359
- length = i;
13360
- psz++;
13361
- }
13362
- // Skip leading zeroes in b256.
13363
- let it4 = size - length;
13364
- while (it4 !== size && b256[it4] === 0) {
13365
- it4++;
13366
- }
13367
- const vch = new Uint8Array(zeroes + (size - it4));
13368
- let j = zeroes;
13369
- while (it4 !== size) {
13370
- vch[j++] = b256[it4++];
13371
- }
13372
- return vch
13373
- }
13374
- function decode (string) {
13375
- const buffer = decodeUnsafe(string);
13376
- if (buffer) { return buffer }
13377
- throw new Error('Non-base' + BASE + ' character')
13378
- }
13379
- return {
13380
- encode,
13381
- decodeUnsafe,
13382
- decode
13383
- }
13294
+ var safeBuffer = {exports: {}};
13295
+
13296
+ var buffer = {};
13297
+
13298
+ var base64Js = {};
13299
+
13300
+ var hasRequiredBase64Js;
13301
+
13302
+ function requireBase64Js () {
13303
+ if (hasRequiredBase64Js) return base64Js;
13304
+ hasRequiredBase64Js = 1;
13305
+
13306
+ base64Js.byteLength = byteLength;
13307
+ base64Js.toByteArray = toByteArray;
13308
+ base64Js.fromByteArray = fromByteArray;
13309
+
13310
+ var lookup = [];
13311
+ var revLookup = [];
13312
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
13313
+
13314
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
13315
+ for (var i = 0, len = code.length; i < len; ++i) {
13316
+ lookup[i] = code[i];
13317
+ revLookup[code.charCodeAt(i)] = i;
13318
+ }
13319
+
13320
+ // Support decoding URL-safe base64 strings, as Node.js does.
13321
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
13322
+ revLookup['-'.charCodeAt(0)] = 62;
13323
+ revLookup['_'.charCodeAt(0)] = 63;
13324
+
13325
+ function getLens (b64) {
13326
+ var len = b64.length;
13327
+
13328
+ if (len % 4 > 0) {
13329
+ throw new Error('Invalid string. Length must be a multiple of 4')
13330
+ }
13331
+
13332
+ // Trim off extra bytes after placeholder bytes are found
13333
+ // See: https://github.com/beatgammit/base64-js/issues/42
13334
+ var validLen = b64.indexOf('=');
13335
+ if (validLen === -1) validLen = len;
13336
+
13337
+ var placeHoldersLen = validLen === len
13338
+ ? 0
13339
+ : 4 - (validLen % 4);
13340
+
13341
+ return [validLen, placeHoldersLen]
13342
+ }
13343
+
13344
+ // base64 is 4/3 + up to two characters of the original data
13345
+ function byteLength (b64) {
13346
+ var lens = getLens(b64);
13347
+ var validLen = lens[0];
13348
+ var placeHoldersLen = lens[1];
13349
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
13350
+ }
13351
+
13352
+ function _byteLength (b64, validLen, placeHoldersLen) {
13353
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
13354
+ }
13355
+
13356
+ function toByteArray (b64) {
13357
+ var tmp;
13358
+ var lens = getLens(b64);
13359
+ var validLen = lens[0];
13360
+ var placeHoldersLen = lens[1];
13361
+
13362
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
13363
+
13364
+ var curByte = 0;
13365
+
13366
+ // if there are placeholders, only get up to the last complete 4 chars
13367
+ var len = placeHoldersLen > 0
13368
+ ? validLen - 4
13369
+ : validLen;
13370
+
13371
+ var i;
13372
+ for (i = 0; i < len; i += 4) {
13373
+ tmp =
13374
+ (revLookup[b64.charCodeAt(i)] << 18) |
13375
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
13376
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
13377
+ revLookup[b64.charCodeAt(i + 3)];
13378
+ arr[curByte++] = (tmp >> 16) & 0xFF;
13379
+ arr[curByte++] = (tmp >> 8) & 0xFF;
13380
+ arr[curByte++] = tmp & 0xFF;
13381
+ }
13382
+
13383
+ if (placeHoldersLen === 2) {
13384
+ tmp =
13385
+ (revLookup[b64.charCodeAt(i)] << 2) |
13386
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
13387
+ arr[curByte++] = tmp & 0xFF;
13388
+ }
13389
+
13390
+ if (placeHoldersLen === 1) {
13391
+ tmp =
13392
+ (revLookup[b64.charCodeAt(i)] << 10) |
13393
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
13394
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
13395
+ arr[curByte++] = (tmp >> 8) & 0xFF;
13396
+ arr[curByte++] = tmp & 0xFF;
13397
+ }
13398
+
13399
+ return arr
13400
+ }
13401
+
13402
+ function tripletToBase64 (num) {
13403
+ return lookup[num >> 18 & 0x3F] +
13404
+ lookup[num >> 12 & 0x3F] +
13405
+ lookup[num >> 6 & 0x3F] +
13406
+ lookup[num & 0x3F]
13407
+ }
13408
+
13409
+ function encodeChunk (uint8, start, end) {
13410
+ var tmp;
13411
+ var output = [];
13412
+ for (var i = start; i < end; i += 3) {
13413
+ tmp =
13414
+ ((uint8[i] << 16) & 0xFF0000) +
13415
+ ((uint8[i + 1] << 8) & 0xFF00) +
13416
+ (uint8[i + 2] & 0xFF);
13417
+ output.push(tripletToBase64(tmp));
13418
+ }
13419
+ return output.join('')
13420
+ }
13421
+
13422
+ function fromByteArray (uint8) {
13423
+ var tmp;
13424
+ var len = uint8.length;
13425
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
13426
+ var parts = [];
13427
+ var maxChunkLength = 16383; // must be multiple of 3
13428
+
13429
+ // go through the array every three bytes, we'll deal with trailing stuff later
13430
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
13431
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
13432
+ }
13433
+
13434
+ // pad the end with zeros, but make sure to not forget the extra bytes
13435
+ if (extraBytes === 1) {
13436
+ tmp = uint8[len - 1];
13437
+ parts.push(
13438
+ lookup[tmp >> 2] +
13439
+ lookup[(tmp << 4) & 0x3F] +
13440
+ '=='
13441
+ );
13442
+ } else if (extraBytes === 2) {
13443
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
13444
+ parts.push(
13445
+ lookup[tmp >> 10] +
13446
+ lookup[(tmp >> 4) & 0x3F] +
13447
+ lookup[(tmp << 2) & 0x3F] +
13448
+ '='
13449
+ );
13450
+ }
13451
+
13452
+ return parts.join('')
13453
+ }
13454
+ return base64Js;
13384
13455
  }
13385
13456
 
13457
+ var ieee754 = {};
13458
+
13459
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
13460
+
13461
+ var hasRequiredIeee754;
13462
+
13463
+ function requireIeee754 () {
13464
+ if (hasRequiredIeee754) return ieee754;
13465
+ hasRequiredIeee754 = 1;
13466
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
13467
+ var e, m;
13468
+ var eLen = (nBytes * 8) - mLen - 1;
13469
+ var eMax = (1 << eLen) - 1;
13470
+ var eBias = eMax >> 1;
13471
+ var nBits = -7;
13472
+ var i = isLE ? (nBytes - 1) : 0;
13473
+ var d = isLE ? -1 : 1;
13474
+ var s = buffer[offset + i];
13475
+
13476
+ i += d;
13477
+
13478
+ e = s & ((1 << (-nBits)) - 1);
13479
+ s >>= (-nBits);
13480
+ nBits += eLen;
13481
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
13482
+
13483
+ m = e & ((1 << (-nBits)) - 1);
13484
+ e >>= (-nBits);
13485
+ nBits += mLen;
13486
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
13487
+
13488
+ if (e === 0) {
13489
+ e = 1 - eBias;
13490
+ } else if (e === eMax) {
13491
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
13492
+ } else {
13493
+ m = m + Math.pow(2, mLen);
13494
+ e = e - eBias;
13495
+ }
13496
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
13497
+ };
13498
+
13499
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
13500
+ var e, m, c;
13501
+ var eLen = (nBytes * 8) - mLen - 1;
13502
+ var eMax = (1 << eLen) - 1;
13503
+ var eBias = eMax >> 1;
13504
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
13505
+ var i = isLE ? 0 : (nBytes - 1);
13506
+ var d = isLE ? 1 : -1;
13507
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
13508
+
13509
+ value = Math.abs(value);
13510
+
13511
+ if (isNaN(value) || value === Infinity) {
13512
+ m = isNaN(value) ? 1 : 0;
13513
+ e = eMax;
13514
+ } else {
13515
+ e = Math.floor(Math.log(value) / Math.LN2);
13516
+ if (value * (c = Math.pow(2, -e)) < 1) {
13517
+ e--;
13518
+ c *= 2;
13519
+ }
13520
+ if (e + eBias >= 1) {
13521
+ value += rt / c;
13522
+ } else {
13523
+ value += rt * Math.pow(2, 1 - eBias);
13524
+ }
13525
+ if (value * c >= 2) {
13526
+ e++;
13527
+ c /= 2;
13528
+ }
13529
+
13530
+ if (e + eBias >= eMax) {
13531
+ m = 0;
13532
+ e = eMax;
13533
+ } else if (e + eBias >= 1) {
13534
+ m = ((value * c) - 1) * Math.pow(2, mLen);
13535
+ e = e + eBias;
13536
+ } else {
13537
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
13538
+ e = 0;
13539
+ }
13540
+ }
13541
+
13542
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
13543
+
13544
+ e = (e << mLen) | m;
13545
+ eLen += mLen;
13546
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
13547
+
13548
+ buffer[offset + i - d] |= s * 128;
13549
+ };
13550
+ return ieee754;
13551
+ }
13552
+
13553
+ /*!
13554
+ * The buffer module from node.js, for the browser.
13555
+ *
13556
+ * @author Feross Aboukhadijeh <https://feross.org>
13557
+ * @license MIT
13558
+ */
13559
+
13560
+ var hasRequiredBuffer;
13561
+
13562
+ function requireBuffer () {
13563
+ if (hasRequiredBuffer) return buffer;
13564
+ hasRequiredBuffer = 1;
13565
+ (function (exports$1) {
13566
+
13567
+ const base64 = requireBase64Js();
13568
+ const ieee754 = requireIeee754();
13569
+ const customInspectSymbol =
13570
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
13571
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
13572
+ : null;
13573
+
13574
+ exports$1.Buffer = Buffer;
13575
+ exports$1.SlowBuffer = SlowBuffer;
13576
+ exports$1.INSPECT_MAX_BYTES = 50;
13577
+
13578
+ const K_MAX_LENGTH = 0x7fffffff;
13579
+ exports$1.kMaxLength = K_MAX_LENGTH;
13580
+
13581
+ /**
13582
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
13583
+ * === true Use Uint8Array implementation (fastest)
13584
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
13585
+ * implementation (most compatible, even IE6)
13586
+ *
13587
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
13588
+ * Opera 11.6+, iOS 4.2+.
13589
+ *
13590
+ * We report that the browser does not support typed arrays if the are not subclassable
13591
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
13592
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
13593
+ * for __proto__ and has a buggy typed array implementation.
13594
+ */
13595
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
13596
+
13597
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
13598
+ typeof console.error === 'function') {
13599
+ console.error(
13600
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
13601
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
13602
+ );
13603
+ }
13604
+
13605
+ function typedArraySupport () {
13606
+ // Can typed array instances can be augmented?
13607
+ try {
13608
+ const arr = new Uint8Array(1);
13609
+ const proto = { foo: function () { return 42 } };
13610
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
13611
+ Object.setPrototypeOf(arr, proto);
13612
+ return arr.foo() === 42
13613
+ } catch (e) {
13614
+ return false
13615
+ }
13616
+ }
13617
+
13618
+ Object.defineProperty(Buffer.prototype, 'parent', {
13619
+ enumerable: true,
13620
+ get: function () {
13621
+ if (!Buffer.isBuffer(this)) return undefined
13622
+ return this.buffer
13623
+ }
13624
+ });
13625
+
13626
+ Object.defineProperty(Buffer.prototype, 'offset', {
13627
+ enumerable: true,
13628
+ get: function () {
13629
+ if (!Buffer.isBuffer(this)) return undefined
13630
+ return this.byteOffset
13631
+ }
13632
+ });
13633
+
13634
+ function createBuffer (length) {
13635
+ if (length > K_MAX_LENGTH) {
13636
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
13637
+ }
13638
+ // Return an augmented `Uint8Array` instance
13639
+ const buf = new Uint8Array(length);
13640
+ Object.setPrototypeOf(buf, Buffer.prototype);
13641
+ return buf
13642
+ }
13643
+
13644
+ /**
13645
+ * The Buffer constructor returns instances of `Uint8Array` that have their
13646
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
13647
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
13648
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
13649
+ * returns a single octet.
13650
+ *
13651
+ * The `Uint8Array` prototype remains unmodified.
13652
+ */
13653
+
13654
+ function Buffer (arg, encodingOrOffset, length) {
13655
+ // Common case.
13656
+ if (typeof arg === 'number') {
13657
+ if (typeof encodingOrOffset === 'string') {
13658
+ throw new TypeError(
13659
+ 'The "string" argument must be of type string. Received type number'
13660
+ )
13661
+ }
13662
+ return allocUnsafe(arg)
13663
+ }
13664
+ return from(arg, encodingOrOffset, length)
13665
+ }
13666
+
13667
+ Buffer.poolSize = 8192; // not used by this implementation
13668
+
13669
+ function from (value, encodingOrOffset, length) {
13670
+ if (typeof value === 'string') {
13671
+ return fromString(value, encodingOrOffset)
13672
+ }
13673
+
13674
+ if (ArrayBuffer.isView(value)) {
13675
+ return fromArrayView(value)
13676
+ }
13677
+
13678
+ if (value == null) {
13679
+ throw new TypeError(
13680
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
13681
+ 'or Array-like Object. Received type ' + (typeof value)
13682
+ )
13683
+ }
13684
+
13685
+ if (isInstance(value, ArrayBuffer) ||
13686
+ (value && isInstance(value.buffer, ArrayBuffer))) {
13687
+ return fromArrayBuffer(value, encodingOrOffset, length)
13688
+ }
13689
+
13690
+ if (typeof SharedArrayBuffer !== 'undefined' &&
13691
+ (isInstance(value, SharedArrayBuffer) ||
13692
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
13693
+ return fromArrayBuffer(value, encodingOrOffset, length)
13694
+ }
13695
+
13696
+ if (typeof value === 'number') {
13697
+ throw new TypeError(
13698
+ 'The "value" argument must not be of type number. Received type number'
13699
+ )
13700
+ }
13701
+
13702
+ const valueOf = value.valueOf && value.valueOf();
13703
+ if (valueOf != null && valueOf !== value) {
13704
+ return Buffer.from(valueOf, encodingOrOffset, length)
13705
+ }
13706
+
13707
+ const b = fromObject(value);
13708
+ if (b) return b
13709
+
13710
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
13711
+ typeof value[Symbol.toPrimitive] === 'function') {
13712
+ return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
13713
+ }
13714
+
13715
+ throw new TypeError(
13716
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
13717
+ 'or Array-like Object. Received type ' + (typeof value)
13718
+ )
13719
+ }
13720
+
13721
+ /**
13722
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
13723
+ * if value is a number.
13724
+ * Buffer.from(str[, encoding])
13725
+ * Buffer.from(array)
13726
+ * Buffer.from(buffer)
13727
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
13728
+ **/
13729
+ Buffer.from = function (value, encodingOrOffset, length) {
13730
+ return from(value, encodingOrOffset, length)
13731
+ };
13732
+
13733
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
13734
+ // https://github.com/feross/buffer/pull/148
13735
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
13736
+ Object.setPrototypeOf(Buffer, Uint8Array);
13737
+
13738
+ function assertSize (size) {
13739
+ if (typeof size !== 'number') {
13740
+ throw new TypeError('"size" argument must be of type number')
13741
+ } else if (size < 0) {
13742
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
13743
+ }
13744
+ }
13745
+
13746
+ function alloc (size, fill, encoding) {
13747
+ assertSize(size);
13748
+ if (size <= 0) {
13749
+ return createBuffer(size)
13750
+ }
13751
+ if (fill !== undefined) {
13752
+ // Only pay attention to encoding if it's a string. This
13753
+ // prevents accidentally sending in a number that would
13754
+ // be interpreted as a start offset.
13755
+ return typeof encoding === 'string'
13756
+ ? createBuffer(size).fill(fill, encoding)
13757
+ : createBuffer(size).fill(fill)
13758
+ }
13759
+ return createBuffer(size)
13760
+ }
13761
+
13762
+ /**
13763
+ * Creates a new filled Buffer instance.
13764
+ * alloc(size[, fill[, encoding]])
13765
+ **/
13766
+ Buffer.alloc = function (size, fill, encoding) {
13767
+ return alloc(size, fill, encoding)
13768
+ };
13769
+
13770
+ function allocUnsafe (size) {
13771
+ assertSize(size);
13772
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
13773
+ }
13774
+
13775
+ /**
13776
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
13777
+ * */
13778
+ Buffer.allocUnsafe = function (size) {
13779
+ return allocUnsafe(size)
13780
+ };
13781
+ /**
13782
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
13783
+ */
13784
+ Buffer.allocUnsafeSlow = function (size) {
13785
+ return allocUnsafe(size)
13786
+ };
13787
+
13788
+ function fromString (string, encoding) {
13789
+ if (typeof encoding !== 'string' || encoding === '') {
13790
+ encoding = 'utf8';
13791
+ }
13792
+
13793
+ if (!Buffer.isEncoding(encoding)) {
13794
+ throw new TypeError('Unknown encoding: ' + encoding)
13795
+ }
13796
+
13797
+ const length = byteLength(string, encoding) | 0;
13798
+ let buf = createBuffer(length);
13799
+
13800
+ const actual = buf.write(string, encoding);
13801
+
13802
+ if (actual !== length) {
13803
+ // Writing a hex string, for example, that contains invalid characters will
13804
+ // cause everything after the first invalid character to be ignored. (e.g.
13805
+ // 'abxxcd' will be treated as 'ab')
13806
+ buf = buf.slice(0, actual);
13807
+ }
13808
+
13809
+ return buf
13810
+ }
13811
+
13812
+ function fromArrayLike (array) {
13813
+ const length = array.length < 0 ? 0 : checked(array.length) | 0;
13814
+ const buf = createBuffer(length);
13815
+ for (let i = 0; i < length; i += 1) {
13816
+ buf[i] = array[i] & 255;
13817
+ }
13818
+ return buf
13819
+ }
13820
+
13821
+ function fromArrayView (arrayView) {
13822
+ if (isInstance(arrayView, Uint8Array)) {
13823
+ const copy = new Uint8Array(arrayView);
13824
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
13825
+ }
13826
+ return fromArrayLike(arrayView)
13827
+ }
13828
+
13829
+ function fromArrayBuffer (array, byteOffset, length) {
13830
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
13831
+ throw new RangeError('"offset" is outside of buffer bounds')
13832
+ }
13833
+
13834
+ if (array.byteLength < byteOffset + (length || 0)) {
13835
+ throw new RangeError('"length" is outside of buffer bounds')
13836
+ }
13837
+
13838
+ let buf;
13839
+ if (byteOffset === undefined && length === undefined) {
13840
+ buf = new Uint8Array(array);
13841
+ } else if (length === undefined) {
13842
+ buf = new Uint8Array(array, byteOffset);
13843
+ } else {
13844
+ buf = new Uint8Array(array, byteOffset, length);
13845
+ }
13846
+
13847
+ // Return an augmented `Uint8Array` instance
13848
+ Object.setPrototypeOf(buf, Buffer.prototype);
13849
+
13850
+ return buf
13851
+ }
13852
+
13853
+ function fromObject (obj) {
13854
+ if (Buffer.isBuffer(obj)) {
13855
+ const len = checked(obj.length) | 0;
13856
+ const buf = createBuffer(len);
13857
+
13858
+ if (buf.length === 0) {
13859
+ return buf
13860
+ }
13861
+
13862
+ obj.copy(buf, 0, 0, len);
13863
+ return buf
13864
+ }
13865
+
13866
+ if (obj.length !== undefined) {
13867
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
13868
+ return createBuffer(0)
13869
+ }
13870
+ return fromArrayLike(obj)
13871
+ }
13872
+
13873
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
13874
+ return fromArrayLike(obj.data)
13875
+ }
13876
+ }
13877
+
13878
+ function checked (length) {
13879
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
13880
+ // length is NaN (which is otherwise coerced to zero.)
13881
+ if (length >= K_MAX_LENGTH) {
13882
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
13883
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
13884
+ }
13885
+ return length | 0
13886
+ }
13887
+
13888
+ function SlowBuffer (length) {
13889
+ if (+length != length) { // eslint-disable-line eqeqeq
13890
+ length = 0;
13891
+ }
13892
+ return Buffer.alloc(+length)
13893
+ }
13894
+
13895
+ Buffer.isBuffer = function isBuffer (b) {
13896
+ return b != null && b._isBuffer === true &&
13897
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
13898
+ };
13899
+
13900
+ Buffer.compare = function compare (a, b) {
13901
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
13902
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
13903
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
13904
+ throw new TypeError(
13905
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
13906
+ )
13907
+ }
13908
+
13909
+ if (a === b) return 0
13910
+
13911
+ let x = a.length;
13912
+ let y = b.length;
13913
+
13914
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
13915
+ if (a[i] !== b[i]) {
13916
+ x = a[i];
13917
+ y = b[i];
13918
+ break
13919
+ }
13920
+ }
13921
+
13922
+ if (x < y) return -1
13923
+ if (y < x) return 1
13924
+ return 0
13925
+ };
13926
+
13927
+ Buffer.isEncoding = function isEncoding (encoding) {
13928
+ switch (String(encoding).toLowerCase()) {
13929
+ case 'hex':
13930
+ case 'utf8':
13931
+ case 'utf-8':
13932
+ case 'ascii':
13933
+ case 'latin1':
13934
+ case 'binary':
13935
+ case 'base64':
13936
+ case 'ucs2':
13937
+ case 'ucs-2':
13938
+ case 'utf16le':
13939
+ case 'utf-16le':
13940
+ return true
13941
+ default:
13942
+ return false
13943
+ }
13944
+ };
13945
+
13946
+ Buffer.concat = function concat (list, length) {
13947
+ if (!Array.isArray(list)) {
13948
+ throw new TypeError('"list" argument must be an Array of Buffers')
13949
+ }
13950
+
13951
+ if (list.length === 0) {
13952
+ return Buffer.alloc(0)
13953
+ }
13954
+
13955
+ let i;
13956
+ if (length === undefined) {
13957
+ length = 0;
13958
+ for (i = 0; i < list.length; ++i) {
13959
+ length += list[i].length;
13960
+ }
13961
+ }
13962
+
13963
+ const buffer = Buffer.allocUnsafe(length);
13964
+ let pos = 0;
13965
+ for (i = 0; i < list.length; ++i) {
13966
+ let buf = list[i];
13967
+ if (isInstance(buf, Uint8Array)) {
13968
+ if (pos + buf.length > buffer.length) {
13969
+ if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
13970
+ buf.copy(buffer, pos);
13971
+ } else {
13972
+ Uint8Array.prototype.set.call(
13973
+ buffer,
13974
+ buf,
13975
+ pos
13976
+ );
13977
+ }
13978
+ } else if (!Buffer.isBuffer(buf)) {
13979
+ throw new TypeError('"list" argument must be an Array of Buffers')
13980
+ } else {
13981
+ buf.copy(buffer, pos);
13982
+ }
13983
+ pos += buf.length;
13984
+ }
13985
+ return buffer
13986
+ };
13987
+
13988
+ function byteLength (string, encoding) {
13989
+ if (Buffer.isBuffer(string)) {
13990
+ return string.length
13991
+ }
13992
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
13993
+ return string.byteLength
13994
+ }
13995
+ if (typeof string !== 'string') {
13996
+ throw new TypeError(
13997
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
13998
+ 'Received type ' + typeof string
13999
+ )
14000
+ }
14001
+
14002
+ const len = string.length;
14003
+ const mustMatch = (arguments.length > 2 && arguments[2] === true);
14004
+ if (!mustMatch && len === 0) return 0
14005
+
14006
+ // Use a for loop to avoid recursion
14007
+ let loweredCase = false;
14008
+ for (;;) {
14009
+ switch (encoding) {
14010
+ case 'ascii':
14011
+ case 'latin1':
14012
+ case 'binary':
14013
+ return len
14014
+ case 'utf8':
14015
+ case 'utf-8':
14016
+ return utf8ToBytes(string).length
14017
+ case 'ucs2':
14018
+ case 'ucs-2':
14019
+ case 'utf16le':
14020
+ case 'utf-16le':
14021
+ return len * 2
14022
+ case 'hex':
14023
+ return len >>> 1
14024
+ case 'base64':
14025
+ return base64ToBytes(string).length
14026
+ default:
14027
+ if (loweredCase) {
14028
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
14029
+ }
14030
+ encoding = ('' + encoding).toLowerCase();
14031
+ loweredCase = true;
14032
+ }
14033
+ }
14034
+ }
14035
+ Buffer.byteLength = byteLength;
14036
+
14037
+ function slowToString (encoding, start, end) {
14038
+ let loweredCase = false;
14039
+
14040
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
14041
+ // property of a typed array.
14042
+
14043
+ // This behaves neither like String nor Uint8Array in that we set start/end
14044
+ // to their upper/lower bounds if the value passed is out of range.
14045
+ // undefined is handled specially as per ECMA-262 6th Edition,
14046
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
14047
+ if (start === undefined || start < 0) {
14048
+ start = 0;
14049
+ }
14050
+ // Return early if start > this.length. Done here to prevent potential uint32
14051
+ // coercion fail below.
14052
+ if (start > this.length) {
14053
+ return ''
14054
+ }
14055
+
14056
+ if (end === undefined || end > this.length) {
14057
+ end = this.length;
14058
+ }
14059
+
14060
+ if (end <= 0) {
14061
+ return ''
14062
+ }
14063
+
14064
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
14065
+ end >>>= 0;
14066
+ start >>>= 0;
14067
+
14068
+ if (end <= start) {
14069
+ return ''
14070
+ }
14071
+
14072
+ if (!encoding) encoding = 'utf8';
14073
+
14074
+ while (true) {
14075
+ switch (encoding) {
14076
+ case 'hex':
14077
+ return hexSlice(this, start, end)
14078
+
14079
+ case 'utf8':
14080
+ case 'utf-8':
14081
+ return utf8Slice(this, start, end)
14082
+
14083
+ case 'ascii':
14084
+ return asciiSlice(this, start, end)
14085
+
14086
+ case 'latin1':
14087
+ case 'binary':
14088
+ return latin1Slice(this, start, end)
14089
+
14090
+ case 'base64':
14091
+ return base64Slice(this, start, end)
14092
+
14093
+ case 'ucs2':
14094
+ case 'ucs-2':
14095
+ case 'utf16le':
14096
+ case 'utf-16le':
14097
+ return utf16leSlice(this, start, end)
14098
+
14099
+ default:
14100
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
14101
+ encoding = (encoding + '').toLowerCase();
14102
+ loweredCase = true;
14103
+ }
14104
+ }
14105
+ }
14106
+
14107
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
14108
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
14109
+ // reliably in a browserify context because there could be multiple different
14110
+ // copies of the 'buffer' package in use. This method works even for Buffer
14111
+ // instances that were created from another copy of the `buffer` package.
14112
+ // See: https://github.com/feross/buffer/issues/154
14113
+ Buffer.prototype._isBuffer = true;
14114
+
14115
+ function swap (b, n, m) {
14116
+ const i = b[n];
14117
+ b[n] = b[m];
14118
+ b[m] = i;
14119
+ }
14120
+
14121
+ Buffer.prototype.swap16 = function swap16 () {
14122
+ const len = this.length;
14123
+ if (len % 2 !== 0) {
14124
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
14125
+ }
14126
+ for (let i = 0; i < len; i += 2) {
14127
+ swap(this, i, i + 1);
14128
+ }
14129
+ return this
14130
+ };
14131
+
14132
+ Buffer.prototype.swap32 = function swap32 () {
14133
+ const len = this.length;
14134
+ if (len % 4 !== 0) {
14135
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
14136
+ }
14137
+ for (let i = 0; i < len; i += 4) {
14138
+ swap(this, i, i + 3);
14139
+ swap(this, i + 1, i + 2);
14140
+ }
14141
+ return this
14142
+ };
14143
+
14144
+ Buffer.prototype.swap64 = function swap64 () {
14145
+ const len = this.length;
14146
+ if (len % 8 !== 0) {
14147
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
14148
+ }
14149
+ for (let i = 0; i < len; i += 8) {
14150
+ swap(this, i, i + 7);
14151
+ swap(this, i + 1, i + 6);
14152
+ swap(this, i + 2, i + 5);
14153
+ swap(this, i + 3, i + 4);
14154
+ }
14155
+ return this
14156
+ };
14157
+
14158
+ Buffer.prototype.toString = function toString () {
14159
+ const length = this.length;
14160
+ if (length === 0) return ''
14161
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
14162
+ return slowToString.apply(this, arguments)
14163
+ };
14164
+
14165
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
14166
+
14167
+ Buffer.prototype.equals = function equals (b) {
14168
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
14169
+ if (this === b) return true
14170
+ return Buffer.compare(this, b) === 0
14171
+ };
14172
+
14173
+ Buffer.prototype.inspect = function inspect () {
14174
+ let str = '';
14175
+ const max = exports$1.INSPECT_MAX_BYTES;
14176
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
14177
+ if (this.length > max) str += ' ... ';
14178
+ return '<Buffer ' + str + '>'
14179
+ };
14180
+ if (customInspectSymbol) {
14181
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
14182
+ }
14183
+
14184
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
14185
+ if (isInstance(target, Uint8Array)) {
14186
+ target = Buffer.from(target, target.offset, target.byteLength);
14187
+ }
14188
+ if (!Buffer.isBuffer(target)) {
14189
+ throw new TypeError(
14190
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
14191
+ 'Received type ' + (typeof target)
14192
+ )
14193
+ }
14194
+
14195
+ if (start === undefined) {
14196
+ start = 0;
14197
+ }
14198
+ if (end === undefined) {
14199
+ end = target ? target.length : 0;
14200
+ }
14201
+ if (thisStart === undefined) {
14202
+ thisStart = 0;
14203
+ }
14204
+ if (thisEnd === undefined) {
14205
+ thisEnd = this.length;
14206
+ }
14207
+
14208
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
14209
+ throw new RangeError('out of range index')
14210
+ }
14211
+
14212
+ if (thisStart >= thisEnd && start >= end) {
14213
+ return 0
14214
+ }
14215
+ if (thisStart >= thisEnd) {
14216
+ return -1
14217
+ }
14218
+ if (start >= end) {
14219
+ return 1
14220
+ }
14221
+
14222
+ start >>>= 0;
14223
+ end >>>= 0;
14224
+ thisStart >>>= 0;
14225
+ thisEnd >>>= 0;
14226
+
14227
+ if (this === target) return 0
14228
+
14229
+ let x = thisEnd - thisStart;
14230
+ let y = end - start;
14231
+ const len = Math.min(x, y);
14232
+
14233
+ const thisCopy = this.slice(thisStart, thisEnd);
14234
+ const targetCopy = target.slice(start, end);
14235
+
14236
+ for (let i = 0; i < len; ++i) {
14237
+ if (thisCopy[i] !== targetCopy[i]) {
14238
+ x = thisCopy[i];
14239
+ y = targetCopy[i];
14240
+ break
14241
+ }
14242
+ }
14243
+
14244
+ if (x < y) return -1
14245
+ if (y < x) return 1
14246
+ return 0
14247
+ };
14248
+
14249
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
14250
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
14251
+ //
14252
+ // Arguments:
14253
+ // - buffer - a Buffer to search
14254
+ // - val - a string, Buffer, or number
14255
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
14256
+ // - encoding - an optional encoding, relevant is val is a string
14257
+ // - dir - true for indexOf, false for lastIndexOf
14258
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
14259
+ // Empty buffer means no match
14260
+ if (buffer.length === 0) return -1
14261
+
14262
+ // Normalize byteOffset
14263
+ if (typeof byteOffset === 'string') {
14264
+ encoding = byteOffset;
14265
+ byteOffset = 0;
14266
+ } else if (byteOffset > 0x7fffffff) {
14267
+ byteOffset = 0x7fffffff;
14268
+ } else if (byteOffset < -2147483648) {
14269
+ byteOffset = -2147483648;
14270
+ }
14271
+ byteOffset = +byteOffset; // Coerce to Number.
14272
+ if (numberIsNaN(byteOffset)) {
14273
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
14274
+ byteOffset = dir ? 0 : (buffer.length - 1);
14275
+ }
14276
+
14277
+ // Normalize byteOffset: negative offsets start from the end of the buffer
14278
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
14279
+ if (byteOffset >= buffer.length) {
14280
+ if (dir) return -1
14281
+ else byteOffset = buffer.length - 1;
14282
+ } else if (byteOffset < 0) {
14283
+ if (dir) byteOffset = 0;
14284
+ else return -1
14285
+ }
14286
+
14287
+ // Normalize val
14288
+ if (typeof val === 'string') {
14289
+ val = Buffer.from(val, encoding);
14290
+ }
14291
+
14292
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
14293
+ if (Buffer.isBuffer(val)) {
14294
+ // Special case: looking for empty string/buffer always fails
14295
+ if (val.length === 0) {
14296
+ return -1
14297
+ }
14298
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
14299
+ } else if (typeof val === 'number') {
14300
+ val = val & 0xFF; // Search for a byte value [0-255]
14301
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
14302
+ if (dir) {
14303
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
14304
+ } else {
14305
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
14306
+ }
14307
+ }
14308
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
14309
+ }
14310
+
14311
+ throw new TypeError('val must be string, number or Buffer')
14312
+ }
14313
+
14314
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
14315
+ let indexSize = 1;
14316
+ let arrLength = arr.length;
14317
+ let valLength = val.length;
14318
+
14319
+ if (encoding !== undefined) {
14320
+ encoding = String(encoding).toLowerCase();
14321
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
14322
+ encoding === 'utf16le' || encoding === 'utf-16le') {
14323
+ if (arr.length < 2 || val.length < 2) {
14324
+ return -1
14325
+ }
14326
+ indexSize = 2;
14327
+ arrLength /= 2;
14328
+ valLength /= 2;
14329
+ byteOffset /= 2;
14330
+ }
14331
+ }
14332
+
14333
+ function read (buf, i) {
14334
+ if (indexSize === 1) {
14335
+ return buf[i]
14336
+ } else {
14337
+ return buf.readUInt16BE(i * indexSize)
14338
+ }
14339
+ }
14340
+
14341
+ let i;
14342
+ if (dir) {
14343
+ let foundIndex = -1;
14344
+ for (i = byteOffset; i < arrLength; i++) {
14345
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
14346
+ if (foundIndex === -1) foundIndex = i;
14347
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
14348
+ } else {
14349
+ if (foundIndex !== -1) i -= i - foundIndex;
14350
+ foundIndex = -1;
14351
+ }
14352
+ }
14353
+ } else {
14354
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
14355
+ for (i = byteOffset; i >= 0; i--) {
14356
+ let found = true;
14357
+ for (let j = 0; j < valLength; j++) {
14358
+ if (read(arr, i + j) !== read(val, j)) {
14359
+ found = false;
14360
+ break
14361
+ }
14362
+ }
14363
+ if (found) return i
14364
+ }
14365
+ }
14366
+
14367
+ return -1
14368
+ }
14369
+
14370
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
14371
+ return this.indexOf(val, byteOffset, encoding) !== -1
14372
+ };
14373
+
14374
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
14375
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
14376
+ };
14377
+
14378
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
14379
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
14380
+ };
14381
+
14382
+ function hexWrite (buf, string, offset, length) {
14383
+ offset = Number(offset) || 0;
14384
+ const remaining = buf.length - offset;
14385
+ if (!length) {
14386
+ length = remaining;
14387
+ } else {
14388
+ length = Number(length);
14389
+ if (length > remaining) {
14390
+ length = remaining;
14391
+ }
14392
+ }
14393
+
14394
+ const strLen = string.length;
14395
+
14396
+ if (length > strLen / 2) {
14397
+ length = strLen / 2;
14398
+ }
14399
+ let i;
14400
+ for (i = 0; i < length; ++i) {
14401
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
14402
+ if (numberIsNaN(parsed)) return i
14403
+ buf[offset + i] = parsed;
14404
+ }
14405
+ return i
14406
+ }
14407
+
14408
+ function utf8Write (buf, string, offset, length) {
14409
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
14410
+ }
14411
+
14412
+ function asciiWrite (buf, string, offset, length) {
14413
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
14414
+ }
14415
+
14416
+ function base64Write (buf, string, offset, length) {
14417
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
14418
+ }
14419
+
14420
+ function ucs2Write (buf, string, offset, length) {
14421
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
14422
+ }
14423
+
14424
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
14425
+ // Buffer#write(string)
14426
+ if (offset === undefined) {
14427
+ encoding = 'utf8';
14428
+ length = this.length;
14429
+ offset = 0;
14430
+ // Buffer#write(string, encoding)
14431
+ } else if (length === undefined && typeof offset === 'string') {
14432
+ encoding = offset;
14433
+ length = this.length;
14434
+ offset = 0;
14435
+ // Buffer#write(string, offset[, length][, encoding])
14436
+ } else if (isFinite(offset)) {
14437
+ offset = offset >>> 0;
14438
+ if (isFinite(length)) {
14439
+ length = length >>> 0;
14440
+ if (encoding === undefined) encoding = 'utf8';
14441
+ } else {
14442
+ encoding = length;
14443
+ length = undefined;
14444
+ }
14445
+ } else {
14446
+ throw new Error(
14447
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
14448
+ )
14449
+ }
14450
+
14451
+ const remaining = this.length - offset;
14452
+ if (length === undefined || length > remaining) length = remaining;
14453
+
14454
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
14455
+ throw new RangeError('Attempt to write outside buffer bounds')
14456
+ }
14457
+
14458
+ if (!encoding) encoding = 'utf8';
14459
+
14460
+ let loweredCase = false;
14461
+ for (;;) {
14462
+ switch (encoding) {
14463
+ case 'hex':
14464
+ return hexWrite(this, string, offset, length)
14465
+
14466
+ case 'utf8':
14467
+ case 'utf-8':
14468
+ return utf8Write(this, string, offset, length)
14469
+
14470
+ case 'ascii':
14471
+ case 'latin1':
14472
+ case 'binary':
14473
+ return asciiWrite(this, string, offset, length)
14474
+
14475
+ case 'base64':
14476
+ // Warning: maxLength not taken into account in base64Write
14477
+ return base64Write(this, string, offset, length)
14478
+
14479
+ case 'ucs2':
14480
+ case 'ucs-2':
14481
+ case 'utf16le':
14482
+ case 'utf-16le':
14483
+ return ucs2Write(this, string, offset, length)
14484
+
14485
+ default:
14486
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
14487
+ encoding = ('' + encoding).toLowerCase();
14488
+ loweredCase = true;
14489
+ }
14490
+ }
14491
+ };
14492
+
14493
+ Buffer.prototype.toJSON = function toJSON () {
14494
+ return {
14495
+ type: 'Buffer',
14496
+ data: Array.prototype.slice.call(this._arr || this, 0)
14497
+ }
14498
+ };
14499
+
14500
+ function base64Slice (buf, start, end) {
14501
+ if (start === 0 && end === buf.length) {
14502
+ return base64.fromByteArray(buf)
14503
+ } else {
14504
+ return base64.fromByteArray(buf.slice(start, end))
14505
+ }
14506
+ }
14507
+
14508
+ function utf8Slice (buf, start, end) {
14509
+ end = Math.min(buf.length, end);
14510
+ const res = [];
14511
+
14512
+ let i = start;
14513
+ while (i < end) {
14514
+ const firstByte = buf[i];
14515
+ let codePoint = null;
14516
+ let bytesPerSequence = (firstByte > 0xEF)
14517
+ ? 4
14518
+ : (firstByte > 0xDF)
14519
+ ? 3
14520
+ : (firstByte > 0xBF)
14521
+ ? 2
14522
+ : 1;
14523
+
14524
+ if (i + bytesPerSequence <= end) {
14525
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
14526
+
14527
+ switch (bytesPerSequence) {
14528
+ case 1:
14529
+ if (firstByte < 0x80) {
14530
+ codePoint = firstByte;
14531
+ }
14532
+ break
14533
+ case 2:
14534
+ secondByte = buf[i + 1];
14535
+ if ((secondByte & 0xC0) === 0x80) {
14536
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
14537
+ if (tempCodePoint > 0x7F) {
14538
+ codePoint = tempCodePoint;
14539
+ }
14540
+ }
14541
+ break
14542
+ case 3:
14543
+ secondByte = buf[i + 1];
14544
+ thirdByte = buf[i + 2];
14545
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
14546
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
14547
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
14548
+ codePoint = tempCodePoint;
14549
+ }
14550
+ }
14551
+ break
14552
+ case 4:
14553
+ secondByte = buf[i + 1];
14554
+ thirdByte = buf[i + 2];
14555
+ fourthByte = buf[i + 3];
14556
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
14557
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
14558
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
14559
+ codePoint = tempCodePoint;
14560
+ }
14561
+ }
14562
+ }
14563
+ }
14564
+
14565
+ if (codePoint === null) {
14566
+ // we did not generate a valid codePoint so insert a
14567
+ // replacement char (U+FFFD) and advance only 1 byte
14568
+ codePoint = 0xFFFD;
14569
+ bytesPerSequence = 1;
14570
+ } else if (codePoint > 0xFFFF) {
14571
+ // encode to utf16 (surrogate pair dance)
14572
+ codePoint -= 0x10000;
14573
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
14574
+ codePoint = 0xDC00 | codePoint & 0x3FF;
14575
+ }
14576
+
14577
+ res.push(codePoint);
14578
+ i += bytesPerSequence;
14579
+ }
14580
+
14581
+ return decodeCodePointsArray(res)
14582
+ }
14583
+
14584
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
14585
+ // the lowest limit is Chrome, with 0x10000 args.
14586
+ // We go 1 magnitude less, for safety
14587
+ const MAX_ARGUMENTS_LENGTH = 0x1000;
14588
+
14589
+ function decodeCodePointsArray (codePoints) {
14590
+ const len = codePoints.length;
14591
+ if (len <= MAX_ARGUMENTS_LENGTH) {
14592
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
14593
+ }
14594
+
14595
+ // Decode in chunks to avoid "call stack size exceeded".
14596
+ let res = '';
14597
+ let i = 0;
14598
+ while (i < len) {
14599
+ res += String.fromCharCode.apply(
14600
+ String,
14601
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
14602
+ );
14603
+ }
14604
+ return res
14605
+ }
14606
+
14607
+ function asciiSlice (buf, start, end) {
14608
+ let ret = '';
14609
+ end = Math.min(buf.length, end);
14610
+
14611
+ for (let i = start; i < end; ++i) {
14612
+ ret += String.fromCharCode(buf[i] & 0x7F);
14613
+ }
14614
+ return ret
14615
+ }
14616
+
14617
+ function latin1Slice (buf, start, end) {
14618
+ let ret = '';
14619
+ end = Math.min(buf.length, end);
14620
+
14621
+ for (let i = start; i < end; ++i) {
14622
+ ret += String.fromCharCode(buf[i]);
14623
+ }
14624
+ return ret
14625
+ }
14626
+
14627
+ function hexSlice (buf, start, end) {
14628
+ const len = buf.length;
14629
+
14630
+ if (!start || start < 0) start = 0;
14631
+ if (!end || end < 0 || end > len) end = len;
14632
+
14633
+ let out = '';
14634
+ for (let i = start; i < end; ++i) {
14635
+ out += hexSliceLookupTable[buf[i]];
14636
+ }
14637
+ return out
14638
+ }
14639
+
14640
+ function utf16leSlice (buf, start, end) {
14641
+ const bytes = buf.slice(start, end);
14642
+ let res = '';
14643
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
14644
+ for (let i = 0; i < bytes.length - 1; i += 2) {
14645
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
14646
+ }
14647
+ return res
14648
+ }
14649
+
14650
+ Buffer.prototype.slice = function slice (start, end) {
14651
+ const len = this.length;
14652
+ start = ~~start;
14653
+ end = end === undefined ? len : ~~end;
14654
+
14655
+ if (start < 0) {
14656
+ start += len;
14657
+ if (start < 0) start = 0;
14658
+ } else if (start > len) {
14659
+ start = len;
14660
+ }
14661
+
14662
+ if (end < 0) {
14663
+ end += len;
14664
+ if (end < 0) end = 0;
14665
+ } else if (end > len) {
14666
+ end = len;
14667
+ }
14668
+
14669
+ if (end < start) end = start;
14670
+
14671
+ const newBuf = this.subarray(start, end);
14672
+ // Return an augmented `Uint8Array` instance
14673
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
14674
+
14675
+ return newBuf
14676
+ };
14677
+
14678
+ /*
14679
+ * Need to make sure that buffer isn't trying to write out of bounds.
14680
+ */
14681
+ function checkOffset (offset, ext, length) {
14682
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
14683
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
14684
+ }
14685
+
14686
+ Buffer.prototype.readUintLE =
14687
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
14688
+ offset = offset >>> 0;
14689
+ byteLength = byteLength >>> 0;
14690
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14691
+
14692
+ let val = this[offset];
14693
+ let mul = 1;
14694
+ let i = 0;
14695
+ while (++i < byteLength && (mul *= 0x100)) {
14696
+ val += this[offset + i] * mul;
14697
+ }
14698
+
14699
+ return val
14700
+ };
14701
+
14702
+ Buffer.prototype.readUintBE =
14703
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
14704
+ offset = offset >>> 0;
14705
+ byteLength = byteLength >>> 0;
14706
+ if (!noAssert) {
14707
+ checkOffset(offset, byteLength, this.length);
14708
+ }
14709
+
14710
+ let val = this[offset + --byteLength];
14711
+ let mul = 1;
14712
+ while (byteLength > 0 && (mul *= 0x100)) {
14713
+ val += this[offset + --byteLength] * mul;
14714
+ }
14715
+
14716
+ return val
14717
+ };
14718
+
14719
+ Buffer.prototype.readUint8 =
14720
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
14721
+ offset = offset >>> 0;
14722
+ if (!noAssert) checkOffset(offset, 1, this.length);
14723
+ return this[offset]
14724
+ };
14725
+
14726
+ Buffer.prototype.readUint16LE =
14727
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
14728
+ offset = offset >>> 0;
14729
+ if (!noAssert) checkOffset(offset, 2, this.length);
14730
+ return this[offset] | (this[offset + 1] << 8)
14731
+ };
14732
+
14733
+ Buffer.prototype.readUint16BE =
14734
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
14735
+ offset = offset >>> 0;
14736
+ if (!noAssert) checkOffset(offset, 2, this.length);
14737
+ return (this[offset] << 8) | this[offset + 1]
14738
+ };
14739
+
14740
+ Buffer.prototype.readUint32LE =
14741
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
14742
+ offset = offset >>> 0;
14743
+ if (!noAssert) checkOffset(offset, 4, this.length);
14744
+
14745
+ return ((this[offset]) |
14746
+ (this[offset + 1] << 8) |
14747
+ (this[offset + 2] << 16)) +
14748
+ (this[offset + 3] * 0x1000000)
14749
+ };
14750
+
14751
+ Buffer.prototype.readUint32BE =
14752
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
14753
+ offset = offset >>> 0;
14754
+ if (!noAssert) checkOffset(offset, 4, this.length);
14755
+
14756
+ return (this[offset] * 0x1000000) +
14757
+ ((this[offset + 1] << 16) |
14758
+ (this[offset + 2] << 8) |
14759
+ this[offset + 3])
14760
+ };
14761
+
14762
+ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
14763
+ offset = offset >>> 0;
14764
+ validateNumber(offset, 'offset');
14765
+ const first = this[offset];
14766
+ const last = this[offset + 7];
14767
+ if (first === undefined || last === undefined) {
14768
+ boundsError(offset, this.length - 8);
14769
+ }
14770
+
14771
+ const lo = first +
14772
+ this[++offset] * 2 ** 8 +
14773
+ this[++offset] * 2 ** 16 +
14774
+ this[++offset] * 2 ** 24;
14775
+
14776
+ const hi = this[++offset] +
14777
+ this[++offset] * 2 ** 8 +
14778
+ this[++offset] * 2 ** 16 +
14779
+ last * 2 ** 24;
14780
+
14781
+ return BigInt(lo) + (BigInt(hi) << BigInt(32))
14782
+ });
14783
+
14784
+ Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
14785
+ offset = offset >>> 0;
14786
+ validateNumber(offset, 'offset');
14787
+ const first = this[offset];
14788
+ const last = this[offset + 7];
14789
+ if (first === undefined || last === undefined) {
14790
+ boundsError(offset, this.length - 8);
14791
+ }
14792
+
14793
+ const hi = first * 2 ** 24 +
14794
+ this[++offset] * 2 ** 16 +
14795
+ this[++offset] * 2 ** 8 +
14796
+ this[++offset];
14797
+
14798
+ const lo = this[++offset] * 2 ** 24 +
14799
+ this[++offset] * 2 ** 16 +
14800
+ this[++offset] * 2 ** 8 +
14801
+ last;
14802
+
14803
+ return (BigInt(hi) << BigInt(32)) + BigInt(lo)
14804
+ });
14805
+
14806
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
14807
+ offset = offset >>> 0;
14808
+ byteLength = byteLength >>> 0;
14809
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14810
+
14811
+ let val = this[offset];
14812
+ let mul = 1;
14813
+ let i = 0;
14814
+ while (++i < byteLength && (mul *= 0x100)) {
14815
+ val += this[offset + i] * mul;
14816
+ }
14817
+ mul *= 0x80;
14818
+
14819
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
14820
+
14821
+ return val
14822
+ };
14823
+
14824
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
14825
+ offset = offset >>> 0;
14826
+ byteLength = byteLength >>> 0;
14827
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
14828
+
14829
+ let i = byteLength;
14830
+ let mul = 1;
14831
+ let val = this[offset + --i];
14832
+ while (i > 0 && (mul *= 0x100)) {
14833
+ val += this[offset + --i] * mul;
14834
+ }
14835
+ mul *= 0x80;
14836
+
14837
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
14838
+
14839
+ return val
14840
+ };
14841
+
14842
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
14843
+ offset = offset >>> 0;
14844
+ if (!noAssert) checkOffset(offset, 1, this.length);
14845
+ if (!(this[offset] & 0x80)) return (this[offset])
14846
+ return ((0xff - this[offset] + 1) * -1)
14847
+ };
14848
+
14849
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
14850
+ offset = offset >>> 0;
14851
+ if (!noAssert) checkOffset(offset, 2, this.length);
14852
+ const val = this[offset] | (this[offset + 1] << 8);
14853
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
14854
+ };
14855
+
14856
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
14857
+ offset = offset >>> 0;
14858
+ if (!noAssert) checkOffset(offset, 2, this.length);
14859
+ const val = this[offset + 1] | (this[offset] << 8);
14860
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
14861
+ };
14862
+
14863
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
14864
+ offset = offset >>> 0;
14865
+ if (!noAssert) checkOffset(offset, 4, this.length);
14866
+
14867
+ return (this[offset]) |
14868
+ (this[offset + 1] << 8) |
14869
+ (this[offset + 2] << 16) |
14870
+ (this[offset + 3] << 24)
14871
+ };
14872
+
14873
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
14874
+ offset = offset >>> 0;
14875
+ if (!noAssert) checkOffset(offset, 4, this.length);
14876
+
14877
+ return (this[offset] << 24) |
14878
+ (this[offset + 1] << 16) |
14879
+ (this[offset + 2] << 8) |
14880
+ (this[offset + 3])
14881
+ };
14882
+
14883
+ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
14884
+ offset = offset >>> 0;
14885
+ validateNumber(offset, 'offset');
14886
+ const first = this[offset];
14887
+ const last = this[offset + 7];
14888
+ if (first === undefined || last === undefined) {
14889
+ boundsError(offset, this.length - 8);
14890
+ }
14891
+
14892
+ const val = this[offset + 4] +
14893
+ this[offset + 5] * 2 ** 8 +
14894
+ this[offset + 6] * 2 ** 16 +
14895
+ (last << 24); // Overflow
14896
+
14897
+ return (BigInt(val) << BigInt(32)) +
14898
+ BigInt(first +
14899
+ this[++offset] * 2 ** 8 +
14900
+ this[++offset] * 2 ** 16 +
14901
+ this[++offset] * 2 ** 24)
14902
+ });
14903
+
14904
+ Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
14905
+ offset = offset >>> 0;
14906
+ validateNumber(offset, 'offset');
14907
+ const first = this[offset];
14908
+ const last = this[offset + 7];
14909
+ if (first === undefined || last === undefined) {
14910
+ boundsError(offset, this.length - 8);
14911
+ }
14912
+
14913
+ const val = (first << 24) + // Overflow
14914
+ this[++offset] * 2 ** 16 +
14915
+ this[++offset] * 2 ** 8 +
14916
+ this[++offset];
14917
+
14918
+ return (BigInt(val) << BigInt(32)) +
14919
+ BigInt(this[++offset] * 2 ** 24 +
14920
+ this[++offset] * 2 ** 16 +
14921
+ this[++offset] * 2 ** 8 +
14922
+ last)
14923
+ });
14924
+
14925
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
14926
+ offset = offset >>> 0;
14927
+ if (!noAssert) checkOffset(offset, 4, this.length);
14928
+ return ieee754.read(this, offset, true, 23, 4)
14929
+ };
14930
+
14931
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
14932
+ offset = offset >>> 0;
14933
+ if (!noAssert) checkOffset(offset, 4, this.length);
14934
+ return ieee754.read(this, offset, false, 23, 4)
14935
+ };
14936
+
14937
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
14938
+ offset = offset >>> 0;
14939
+ if (!noAssert) checkOffset(offset, 8, this.length);
14940
+ return ieee754.read(this, offset, true, 52, 8)
14941
+ };
14942
+
14943
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
14944
+ offset = offset >>> 0;
14945
+ if (!noAssert) checkOffset(offset, 8, this.length);
14946
+ return ieee754.read(this, offset, false, 52, 8)
14947
+ };
14948
+
14949
+ function checkInt (buf, value, offset, ext, max, min) {
14950
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
14951
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
14952
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
14953
+ }
14954
+
14955
+ Buffer.prototype.writeUintLE =
14956
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
14957
+ value = +value;
14958
+ offset = offset >>> 0;
14959
+ byteLength = byteLength >>> 0;
14960
+ if (!noAssert) {
14961
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
14962
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
14963
+ }
14964
+
14965
+ let mul = 1;
14966
+ let i = 0;
14967
+ this[offset] = value & 0xFF;
14968
+ while (++i < byteLength && (mul *= 0x100)) {
14969
+ this[offset + i] = (value / mul) & 0xFF;
14970
+ }
14971
+
14972
+ return offset + byteLength
14973
+ };
14974
+
14975
+ Buffer.prototype.writeUintBE =
14976
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
14977
+ value = +value;
14978
+ offset = offset >>> 0;
14979
+ byteLength = byteLength >>> 0;
14980
+ if (!noAssert) {
14981
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
14982
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
14983
+ }
14984
+
14985
+ let i = byteLength - 1;
14986
+ let mul = 1;
14987
+ this[offset + i] = value & 0xFF;
14988
+ while (--i >= 0 && (mul *= 0x100)) {
14989
+ this[offset + i] = (value / mul) & 0xFF;
14990
+ }
14991
+
14992
+ return offset + byteLength
14993
+ };
14994
+
14995
+ Buffer.prototype.writeUint8 =
14996
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
14997
+ value = +value;
14998
+ offset = offset >>> 0;
14999
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
15000
+ this[offset] = (value & 0xff);
15001
+ return offset + 1
15002
+ };
15003
+
15004
+ Buffer.prototype.writeUint16LE =
15005
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
15006
+ value = +value;
15007
+ offset = offset >>> 0;
15008
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
15009
+ this[offset] = (value & 0xff);
15010
+ this[offset + 1] = (value >>> 8);
15011
+ return offset + 2
15012
+ };
15013
+
15014
+ Buffer.prototype.writeUint16BE =
15015
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
15016
+ value = +value;
15017
+ offset = offset >>> 0;
15018
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
15019
+ this[offset] = (value >>> 8);
15020
+ this[offset + 1] = (value & 0xff);
15021
+ return offset + 2
15022
+ };
15023
+
15024
+ Buffer.prototype.writeUint32LE =
15025
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
15026
+ value = +value;
15027
+ offset = offset >>> 0;
15028
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
15029
+ this[offset + 3] = (value >>> 24);
15030
+ this[offset + 2] = (value >>> 16);
15031
+ this[offset + 1] = (value >>> 8);
15032
+ this[offset] = (value & 0xff);
15033
+ return offset + 4
15034
+ };
15035
+
15036
+ Buffer.prototype.writeUint32BE =
15037
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
15038
+ value = +value;
15039
+ offset = offset >>> 0;
15040
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
15041
+ this[offset] = (value >>> 24);
15042
+ this[offset + 1] = (value >>> 16);
15043
+ this[offset + 2] = (value >>> 8);
15044
+ this[offset + 3] = (value & 0xff);
15045
+ return offset + 4
15046
+ };
15047
+
15048
+ function wrtBigUInt64LE (buf, value, offset, min, max) {
15049
+ checkIntBI(value, min, max, buf, offset, 7);
15050
+
15051
+ let lo = Number(value & BigInt(0xffffffff));
15052
+ buf[offset++] = lo;
15053
+ lo = lo >> 8;
15054
+ buf[offset++] = lo;
15055
+ lo = lo >> 8;
15056
+ buf[offset++] = lo;
15057
+ lo = lo >> 8;
15058
+ buf[offset++] = lo;
15059
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
15060
+ buf[offset++] = hi;
15061
+ hi = hi >> 8;
15062
+ buf[offset++] = hi;
15063
+ hi = hi >> 8;
15064
+ buf[offset++] = hi;
15065
+ hi = hi >> 8;
15066
+ buf[offset++] = hi;
15067
+ return offset
15068
+ }
15069
+
15070
+ function wrtBigUInt64BE (buf, value, offset, min, max) {
15071
+ checkIntBI(value, min, max, buf, offset, 7);
15072
+
15073
+ let lo = Number(value & BigInt(0xffffffff));
15074
+ buf[offset + 7] = lo;
15075
+ lo = lo >> 8;
15076
+ buf[offset + 6] = lo;
15077
+ lo = lo >> 8;
15078
+ buf[offset + 5] = lo;
15079
+ lo = lo >> 8;
15080
+ buf[offset + 4] = lo;
15081
+ let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
15082
+ buf[offset + 3] = hi;
15083
+ hi = hi >> 8;
15084
+ buf[offset + 2] = hi;
15085
+ hi = hi >> 8;
15086
+ buf[offset + 1] = hi;
15087
+ hi = hi >> 8;
15088
+ buf[offset] = hi;
15089
+ return offset + 8
15090
+ }
15091
+
15092
+ Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
15093
+ return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
15094
+ });
15095
+
15096
+ Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
15097
+ return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
15098
+ });
15099
+
15100
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
15101
+ value = +value;
15102
+ offset = offset >>> 0;
15103
+ if (!noAssert) {
15104
+ const limit = Math.pow(2, (8 * byteLength) - 1);
15105
+
15106
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
15107
+ }
15108
+
15109
+ let i = 0;
15110
+ let mul = 1;
15111
+ let sub = 0;
15112
+ this[offset] = value & 0xFF;
15113
+ while (++i < byteLength && (mul *= 0x100)) {
15114
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
15115
+ sub = 1;
15116
+ }
15117
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
15118
+ }
15119
+
15120
+ return offset + byteLength
15121
+ };
15122
+
15123
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
15124
+ value = +value;
15125
+ offset = offset >>> 0;
15126
+ if (!noAssert) {
15127
+ const limit = Math.pow(2, (8 * byteLength) - 1);
15128
+
15129
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
15130
+ }
15131
+
15132
+ let i = byteLength - 1;
15133
+ let mul = 1;
15134
+ let sub = 0;
15135
+ this[offset + i] = value & 0xFF;
15136
+ while (--i >= 0 && (mul *= 0x100)) {
15137
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
15138
+ sub = 1;
15139
+ }
15140
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
15141
+ }
15142
+
15143
+ return offset + byteLength
15144
+ };
15145
+
15146
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
15147
+ value = +value;
15148
+ offset = offset >>> 0;
15149
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
15150
+ if (value < 0) value = 0xff + value + 1;
15151
+ this[offset] = (value & 0xff);
15152
+ return offset + 1
15153
+ };
15154
+
15155
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
15156
+ value = +value;
15157
+ offset = offset >>> 0;
15158
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
15159
+ this[offset] = (value & 0xff);
15160
+ this[offset + 1] = (value >>> 8);
15161
+ return offset + 2
15162
+ };
15163
+
15164
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
15165
+ value = +value;
15166
+ offset = offset >>> 0;
15167
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
15168
+ this[offset] = (value >>> 8);
15169
+ this[offset + 1] = (value & 0xff);
15170
+ return offset + 2
15171
+ };
15172
+
15173
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
15174
+ value = +value;
15175
+ offset = offset >>> 0;
15176
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
15177
+ this[offset] = (value & 0xff);
15178
+ this[offset + 1] = (value >>> 8);
15179
+ this[offset + 2] = (value >>> 16);
15180
+ this[offset + 3] = (value >>> 24);
15181
+ return offset + 4
15182
+ };
15183
+
15184
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
15185
+ value = +value;
15186
+ offset = offset >>> 0;
15187
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
15188
+ if (value < 0) value = 0xffffffff + value + 1;
15189
+ this[offset] = (value >>> 24);
15190
+ this[offset + 1] = (value >>> 16);
15191
+ this[offset + 2] = (value >>> 8);
15192
+ this[offset + 3] = (value & 0xff);
15193
+ return offset + 4
15194
+ };
15195
+
15196
+ Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
15197
+ return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
15198
+ });
15199
+
15200
+ Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
15201
+ return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
15202
+ });
15203
+
15204
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
15205
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
15206
+ if (offset < 0) throw new RangeError('Index out of range')
15207
+ }
15208
+
15209
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
15210
+ value = +value;
15211
+ offset = offset >>> 0;
15212
+ if (!noAssert) {
15213
+ checkIEEE754(buf, value, offset, 4);
15214
+ }
15215
+ ieee754.write(buf, value, offset, littleEndian, 23, 4);
15216
+ return offset + 4
15217
+ }
15218
+
15219
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
15220
+ return writeFloat(this, value, offset, true, noAssert)
15221
+ };
15222
+
15223
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
15224
+ return writeFloat(this, value, offset, false, noAssert)
15225
+ };
15226
+
15227
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
15228
+ value = +value;
15229
+ offset = offset >>> 0;
15230
+ if (!noAssert) {
15231
+ checkIEEE754(buf, value, offset, 8);
15232
+ }
15233
+ ieee754.write(buf, value, offset, littleEndian, 52, 8);
15234
+ return offset + 8
15235
+ }
15236
+
15237
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
15238
+ return writeDouble(this, value, offset, true, noAssert)
15239
+ };
15240
+
15241
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
15242
+ return writeDouble(this, value, offset, false, noAssert)
15243
+ };
15244
+
15245
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
15246
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
15247
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
15248
+ if (!start) start = 0;
15249
+ if (!end && end !== 0) end = this.length;
15250
+ if (targetStart >= target.length) targetStart = target.length;
15251
+ if (!targetStart) targetStart = 0;
15252
+ if (end > 0 && end < start) end = start;
15253
+
15254
+ // Copy 0 bytes; we're done
15255
+ if (end === start) return 0
15256
+ if (target.length === 0 || this.length === 0) return 0
15257
+
15258
+ // Fatal error conditions
15259
+ if (targetStart < 0) {
15260
+ throw new RangeError('targetStart out of bounds')
15261
+ }
15262
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
15263
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
15264
+
15265
+ // Are we oob?
15266
+ if (end > this.length) end = this.length;
15267
+ if (target.length - targetStart < end - start) {
15268
+ end = target.length - targetStart + start;
15269
+ }
15270
+
15271
+ const len = end - start;
15272
+
15273
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
15274
+ // Use built-in when available, missing from IE11
15275
+ this.copyWithin(targetStart, start, end);
15276
+ } else {
15277
+ Uint8Array.prototype.set.call(
15278
+ target,
15279
+ this.subarray(start, end),
15280
+ targetStart
15281
+ );
15282
+ }
15283
+
15284
+ return len
15285
+ };
15286
+
15287
+ // Usage:
15288
+ // buffer.fill(number[, offset[, end]])
15289
+ // buffer.fill(buffer[, offset[, end]])
15290
+ // buffer.fill(string[, offset[, end]][, encoding])
15291
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
15292
+ // Handle string cases:
15293
+ if (typeof val === 'string') {
15294
+ if (typeof start === 'string') {
15295
+ encoding = start;
15296
+ start = 0;
15297
+ end = this.length;
15298
+ } else if (typeof end === 'string') {
15299
+ encoding = end;
15300
+ end = this.length;
15301
+ }
15302
+ if (encoding !== undefined && typeof encoding !== 'string') {
15303
+ throw new TypeError('encoding must be a string')
15304
+ }
15305
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
15306
+ throw new TypeError('Unknown encoding: ' + encoding)
15307
+ }
15308
+ if (val.length === 1) {
15309
+ const code = val.charCodeAt(0);
15310
+ if ((encoding === 'utf8' && code < 128) ||
15311
+ encoding === 'latin1') {
15312
+ // Fast path: If `val` fits into a single byte, use that numeric value.
15313
+ val = code;
15314
+ }
15315
+ }
15316
+ } else if (typeof val === 'number') {
15317
+ val = val & 255;
15318
+ } else if (typeof val === 'boolean') {
15319
+ val = Number(val);
15320
+ }
15321
+
15322
+ // Invalid ranges are not set to a default, so can range check early.
15323
+ if (start < 0 || this.length < start || this.length < end) {
15324
+ throw new RangeError('Out of range index')
15325
+ }
15326
+
15327
+ if (end <= start) {
15328
+ return this
15329
+ }
15330
+
15331
+ start = start >>> 0;
15332
+ end = end === undefined ? this.length : end >>> 0;
15333
+
15334
+ if (!val) val = 0;
15335
+
15336
+ let i;
15337
+ if (typeof val === 'number') {
15338
+ for (i = start; i < end; ++i) {
15339
+ this[i] = val;
15340
+ }
15341
+ } else {
15342
+ const bytes = Buffer.isBuffer(val)
15343
+ ? val
15344
+ : Buffer.from(val, encoding);
15345
+ const len = bytes.length;
15346
+ if (len === 0) {
15347
+ throw new TypeError('The value "' + val +
15348
+ '" is invalid for argument "value"')
15349
+ }
15350
+ for (i = 0; i < end - start; ++i) {
15351
+ this[i + start] = bytes[i % len];
15352
+ }
15353
+ }
15354
+
15355
+ return this
15356
+ };
15357
+
15358
+ // CUSTOM ERRORS
15359
+ // =============
15360
+
15361
+ // Simplified versions from Node, changed for Buffer-only usage
15362
+ const errors = {};
15363
+ function E (sym, getMessage, Base) {
15364
+ errors[sym] = class NodeError extends Base {
15365
+ constructor () {
15366
+ super();
15367
+
15368
+ Object.defineProperty(this, 'message', {
15369
+ value: getMessage.apply(this, arguments),
15370
+ writable: true,
15371
+ configurable: true
15372
+ });
15373
+
15374
+ // Add the error code to the name to include it in the stack trace.
15375
+ this.name = `${this.name} [${sym}]`;
15376
+ // Access the stack to generate the error message including the error code
15377
+ // from the name.
15378
+ this.stack; // eslint-disable-line no-unused-expressions
15379
+ // Reset the name to the actual name.
15380
+ delete this.name;
15381
+ }
15382
+
15383
+ get code () {
15384
+ return sym
15385
+ }
15386
+
15387
+ set code (value) {
15388
+ Object.defineProperty(this, 'code', {
15389
+ configurable: true,
15390
+ enumerable: true,
15391
+ value,
15392
+ writable: true
15393
+ });
15394
+ }
15395
+
15396
+ toString () {
15397
+ return `${this.name} [${sym}]: ${this.message}`
15398
+ }
15399
+ };
15400
+ }
15401
+
15402
+ E('ERR_BUFFER_OUT_OF_BOUNDS',
15403
+ function (name) {
15404
+ if (name) {
15405
+ return `${name} is outside of buffer bounds`
15406
+ }
15407
+
15408
+ return 'Attempt to access memory outside buffer bounds'
15409
+ }, RangeError);
15410
+ E('ERR_INVALID_ARG_TYPE',
15411
+ function (name, actual) {
15412
+ return `The "${name}" argument must be of type number. Received type ${typeof actual}`
15413
+ }, TypeError);
15414
+ E('ERR_OUT_OF_RANGE',
15415
+ function (str, range, input) {
15416
+ let msg = `The value of "${str}" is out of range.`;
15417
+ let received = input;
15418
+ if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
15419
+ received = addNumericalSeparator(String(input));
15420
+ } else if (typeof input === 'bigint') {
15421
+ received = String(input);
15422
+ if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
15423
+ received = addNumericalSeparator(received);
15424
+ }
15425
+ received += 'n';
15426
+ }
15427
+ msg += ` It must be ${range}. Received ${received}`;
15428
+ return msg
15429
+ }, RangeError);
15430
+
15431
+ function addNumericalSeparator (val) {
15432
+ let res = '';
15433
+ let i = val.length;
15434
+ const start = val[0] === '-' ? 1 : 0;
15435
+ for (; i >= start + 4; i -= 3) {
15436
+ res = `_${val.slice(i - 3, i)}${res}`;
15437
+ }
15438
+ return `${val.slice(0, i)}${res}`
15439
+ }
15440
+
15441
+ // CHECK FUNCTIONS
15442
+ // ===============
15443
+
15444
+ function checkBounds (buf, offset, byteLength) {
15445
+ validateNumber(offset, 'offset');
15446
+ if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
15447
+ boundsError(offset, buf.length - (byteLength + 1));
15448
+ }
15449
+ }
15450
+
15451
+ function checkIntBI (value, min, max, buf, offset, byteLength) {
15452
+ if (value > max || value < min) {
15453
+ const n = typeof min === 'bigint' ? 'n' : '';
15454
+ let range;
15455
+ {
15456
+ if (min === 0 || min === BigInt(0)) {
15457
+ range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
15458
+ } else {
15459
+ range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
15460
+ `${(byteLength + 1) * 8 - 1}${n}`;
15461
+ }
15462
+ }
15463
+ throw new errors.ERR_OUT_OF_RANGE('value', range, value)
15464
+ }
15465
+ checkBounds(buf, offset, byteLength);
15466
+ }
15467
+
15468
+ function validateNumber (value, name) {
15469
+ if (typeof value !== 'number') {
15470
+ throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
15471
+ }
15472
+ }
15473
+
15474
+ function boundsError (value, length, type) {
15475
+ if (Math.floor(value) !== value) {
15476
+ validateNumber(value, type);
15477
+ throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
15478
+ }
15479
+
15480
+ if (length < 0) {
15481
+ throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
15482
+ }
15483
+
15484
+ throw new errors.ERR_OUT_OF_RANGE('offset',
15485
+ `>= ${0} and <= ${length}`,
15486
+ value)
15487
+ }
15488
+
15489
+ // HELPER FUNCTIONS
15490
+ // ================
15491
+
15492
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
15493
+
15494
+ function base64clean (str) {
15495
+ // Node takes equal signs as end of the Base64 encoding
15496
+ str = str.split('=')[0];
15497
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
15498
+ str = str.trim().replace(INVALID_BASE64_RE, '');
15499
+ // Node converts strings with length < 2 to ''
15500
+ if (str.length < 2) return ''
15501
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
15502
+ while (str.length % 4 !== 0) {
15503
+ str = str + '=';
15504
+ }
15505
+ return str
15506
+ }
15507
+
15508
+ function utf8ToBytes (string, units) {
15509
+ units = units || Infinity;
15510
+ let codePoint;
15511
+ const length = string.length;
15512
+ let leadSurrogate = null;
15513
+ const bytes = [];
15514
+
15515
+ for (let i = 0; i < length; ++i) {
15516
+ codePoint = string.charCodeAt(i);
15517
+
15518
+ // is surrogate component
15519
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
15520
+ // last char was a lead
15521
+ if (!leadSurrogate) {
15522
+ // no lead yet
15523
+ if (codePoint > 0xDBFF) {
15524
+ // unexpected trail
15525
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15526
+ continue
15527
+ } else if (i + 1 === length) {
15528
+ // unpaired lead
15529
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15530
+ continue
15531
+ }
15532
+
15533
+ // valid lead
15534
+ leadSurrogate = codePoint;
15535
+
15536
+ continue
15537
+ }
15538
+
15539
+ // 2 leads in a row
15540
+ if (codePoint < 0xDC00) {
15541
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15542
+ leadSurrogate = codePoint;
15543
+ continue
15544
+ }
15545
+
15546
+ // valid surrogate pair
15547
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
15548
+ } else if (leadSurrogate) {
15549
+ // valid bmp char, but last char was a lead
15550
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
15551
+ }
15552
+
15553
+ leadSurrogate = null;
15554
+
15555
+ // encode utf8
15556
+ if (codePoint < 0x80) {
15557
+ if ((units -= 1) < 0) break
15558
+ bytes.push(codePoint);
15559
+ } else if (codePoint < 0x800) {
15560
+ if ((units -= 2) < 0) break
15561
+ bytes.push(
15562
+ codePoint >> 0x6 | 0xC0,
15563
+ codePoint & 0x3F | 0x80
15564
+ );
15565
+ } else if (codePoint < 0x10000) {
15566
+ if ((units -= 3) < 0) break
15567
+ bytes.push(
15568
+ codePoint >> 0xC | 0xE0,
15569
+ codePoint >> 0x6 & 0x3F | 0x80,
15570
+ codePoint & 0x3F | 0x80
15571
+ );
15572
+ } else if (codePoint < 0x110000) {
15573
+ if ((units -= 4) < 0) break
15574
+ bytes.push(
15575
+ codePoint >> 0x12 | 0xF0,
15576
+ codePoint >> 0xC & 0x3F | 0x80,
15577
+ codePoint >> 0x6 & 0x3F | 0x80,
15578
+ codePoint & 0x3F | 0x80
15579
+ );
15580
+ } else {
15581
+ throw new Error('Invalid code point')
15582
+ }
15583
+ }
15584
+
15585
+ return bytes
15586
+ }
15587
+
15588
+ function asciiToBytes (str) {
15589
+ const byteArray = [];
15590
+ for (let i = 0; i < str.length; ++i) {
15591
+ // Node's code seems to be doing this and not & 0x7F..
15592
+ byteArray.push(str.charCodeAt(i) & 0xFF);
15593
+ }
15594
+ return byteArray
15595
+ }
15596
+
15597
+ function utf16leToBytes (str, units) {
15598
+ let c, hi, lo;
15599
+ const byteArray = [];
15600
+ for (let i = 0; i < str.length; ++i) {
15601
+ if ((units -= 2) < 0) break
15602
+
15603
+ c = str.charCodeAt(i);
15604
+ hi = c >> 8;
15605
+ lo = c % 256;
15606
+ byteArray.push(lo);
15607
+ byteArray.push(hi);
15608
+ }
15609
+
15610
+ return byteArray
15611
+ }
15612
+
15613
+ function base64ToBytes (str) {
15614
+ return base64.toByteArray(base64clean(str))
15615
+ }
15616
+
15617
+ function blitBuffer (src, dst, offset, length) {
15618
+ let i;
15619
+ for (i = 0; i < length; ++i) {
15620
+ if ((i + offset >= dst.length) || (i >= src.length)) break
15621
+ dst[i + offset] = src[i];
15622
+ }
15623
+ return i
15624
+ }
15625
+
15626
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
15627
+ // the `instanceof` check but they should be treated as of that type.
15628
+ // See: https://github.com/feross/buffer/issues/166
15629
+ function isInstance (obj, type) {
15630
+ return obj instanceof type ||
15631
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
15632
+ obj.constructor.name === type.name)
15633
+ }
15634
+ function numberIsNaN (obj) {
15635
+ // For IE11 support
15636
+ return obj !== obj // eslint-disable-line no-self-compare
15637
+ }
15638
+
15639
+ // Create lookup table for `toString('hex')`
15640
+ // See: https://github.com/feross/buffer/issues/219
15641
+ const hexSliceLookupTable = (function () {
15642
+ const alphabet = '0123456789abcdef';
15643
+ const table = new Array(256);
15644
+ for (let i = 0; i < 16; ++i) {
15645
+ const i16 = i * 16;
15646
+ for (let j = 0; j < 16; ++j) {
15647
+ table[i16 + j] = alphabet[i] + alphabet[j];
15648
+ }
15649
+ }
15650
+ return table
15651
+ })();
15652
+
15653
+ // Return not function with Error if BigInt not supported
15654
+ function defineBigIntMethod (fn) {
15655
+ return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
15656
+ }
15657
+
15658
+ function BufferBigIntNotDefined () {
15659
+ throw new Error('BigInt not supported')
15660
+ }
15661
+ } (buffer));
15662
+ return buffer;
15663
+ }
15664
+
15665
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
15666
+
15667
+ var hasRequiredSafeBuffer;
15668
+
15669
+ function requireSafeBuffer () {
15670
+ if (hasRequiredSafeBuffer) return safeBuffer.exports;
15671
+ hasRequiredSafeBuffer = 1;
15672
+ (function (module, exports$1) {
15673
+ /* eslint-disable node/no-deprecated-api */
15674
+ var buffer = requireBuffer();
15675
+ var Buffer = buffer.Buffer;
15676
+
15677
+ // alternative to using Object.keys for old browsers
15678
+ function copyProps (src, dst) {
15679
+ for (var key in src) {
15680
+ dst[key] = src[key];
15681
+ }
15682
+ }
15683
+ if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
15684
+ module.exports = buffer;
15685
+ } else {
15686
+ // Copy properties from require('buffer')
15687
+ copyProps(buffer, exports$1);
15688
+ exports$1.Buffer = SafeBuffer;
15689
+ }
15690
+
15691
+ function SafeBuffer (arg, encodingOrOffset, length) {
15692
+ return Buffer(arg, encodingOrOffset, length)
15693
+ }
15694
+
15695
+ SafeBuffer.prototype = Object.create(Buffer.prototype);
15696
+
15697
+ // Copy static methods from Buffer
15698
+ copyProps(Buffer, SafeBuffer);
15699
+
15700
+ SafeBuffer.from = function (arg, encodingOrOffset, length) {
15701
+ if (typeof arg === 'number') {
15702
+ throw new TypeError('Argument must not be a number')
15703
+ }
15704
+ return Buffer(arg, encodingOrOffset, length)
15705
+ };
15706
+
15707
+ SafeBuffer.alloc = function (size, fill, encoding) {
15708
+ if (typeof size !== 'number') {
15709
+ throw new TypeError('Argument must be a number')
15710
+ }
15711
+ var buf = Buffer(size);
15712
+ if (fill !== undefined) {
15713
+ if (typeof encoding === 'string') {
15714
+ buf.fill(fill, encoding);
15715
+ } else {
15716
+ buf.fill(fill);
15717
+ }
15718
+ } else {
15719
+ buf.fill(0);
15720
+ }
15721
+ return buf
15722
+ };
15723
+
15724
+ SafeBuffer.allocUnsafe = function (size) {
15725
+ if (typeof size !== 'number') {
15726
+ throw new TypeError('Argument must be a number')
15727
+ }
15728
+ return Buffer(size)
15729
+ };
15730
+
15731
+ SafeBuffer.allocUnsafeSlow = function (size) {
15732
+ if (typeof size !== 'number') {
15733
+ throw new TypeError('Argument must be a number')
15734
+ }
15735
+ return buffer.SlowBuffer(size)
15736
+ };
15737
+ } (safeBuffer, safeBuffer.exports));
15738
+ return safeBuffer.exports;
15739
+ }
15740
+
15741
+ var src;
15742
+ var hasRequiredSrc;
15743
+
15744
+ function requireSrc () {
15745
+ if (hasRequiredSrc) return src;
15746
+ hasRequiredSrc = 1;
15747
+ // base-x encoding / decoding
15748
+ // Copyright (c) 2018 base-x contributors
15749
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
15750
+ // Distributed under the MIT software license, see the accompanying
15751
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
15752
+ // @ts-ignore
15753
+ var _Buffer = requireSafeBuffer().Buffer;
15754
+ function base (ALPHABET) {
15755
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
15756
+ var BASE_MAP = new Uint8Array(256);
15757
+ for (var j = 0; j < BASE_MAP.length; j++) {
15758
+ BASE_MAP[j] = 255;
15759
+ }
15760
+ for (var i = 0; i < ALPHABET.length; i++) {
15761
+ var x = ALPHABET.charAt(i);
15762
+ var xc = x.charCodeAt(0);
15763
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
15764
+ BASE_MAP[xc] = i;
15765
+ }
15766
+ var BASE = ALPHABET.length;
15767
+ var LEADER = ALPHABET.charAt(0);
15768
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
15769
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
15770
+ function encode (source) {
15771
+ if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source); }
15772
+ if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
15773
+ if (source.length === 0) { return '' }
15774
+ // Skip & count leading zeroes.
15775
+ var zeroes = 0;
15776
+ var length = 0;
15777
+ var pbegin = 0;
15778
+ var pend = source.length;
15779
+ while (pbegin !== pend && source[pbegin] === 0) {
15780
+ pbegin++;
15781
+ zeroes++;
15782
+ }
15783
+ // Allocate enough space in big-endian base58 representation.
15784
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
15785
+ var b58 = new Uint8Array(size);
15786
+ // Process the bytes.
15787
+ while (pbegin !== pend) {
15788
+ var carry = source[pbegin];
15789
+ // Apply "b58 = b58 * 256 + ch".
15790
+ var i = 0;
15791
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
15792
+ carry += (256 * b58[it1]) >>> 0;
15793
+ b58[it1] = (carry % BASE) >>> 0;
15794
+ carry = (carry / BASE) >>> 0;
15795
+ }
15796
+ if (carry !== 0) { throw new Error('Non-zero carry') }
15797
+ length = i;
15798
+ pbegin++;
15799
+ }
15800
+ // Skip leading zeroes in base58 result.
15801
+ var it2 = size - length;
15802
+ while (it2 !== size && b58[it2] === 0) {
15803
+ it2++;
15804
+ }
15805
+ // Translate the result into a string.
15806
+ var str = LEADER.repeat(zeroes);
15807
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
15808
+ return str
15809
+ }
15810
+ function decodeUnsafe (source) {
15811
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
15812
+ if (source.length === 0) { return _Buffer.alloc(0) }
15813
+ var psz = 0;
15814
+ // Skip and count leading '1's.
15815
+ var zeroes = 0;
15816
+ var length = 0;
15817
+ while (source[psz] === LEADER) {
15818
+ zeroes++;
15819
+ psz++;
15820
+ }
15821
+ // Allocate enough space in big-endian base256 representation.
15822
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
15823
+ var b256 = new Uint8Array(size);
15824
+ // Process the characters.
15825
+ while (psz < source.length) {
15826
+ // Find code of next character
15827
+ var charCode = source.charCodeAt(psz);
15828
+ // Base map can not be indexed using char code
15829
+ if (charCode > 255) { return }
15830
+ // Decode character
15831
+ var carry = BASE_MAP[charCode];
15832
+ // Invalid character
15833
+ if (carry === 255) { return }
15834
+ var i = 0;
15835
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
15836
+ carry += (BASE * b256[it3]) >>> 0;
15837
+ b256[it3] = (carry % 256) >>> 0;
15838
+ carry = (carry / 256) >>> 0;
15839
+ }
15840
+ if (carry !== 0) { throw new Error('Non-zero carry') }
15841
+ length = i;
15842
+ psz++;
15843
+ }
15844
+ // Skip leading zeroes in b256.
15845
+ var it4 = size - length;
15846
+ while (it4 !== size && b256[it4] === 0) {
15847
+ it4++;
15848
+ }
15849
+ var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
15850
+ vch.fill(0x00, 0, zeroes);
15851
+ var j = zeroes;
15852
+ while (it4 !== size) {
15853
+ vch[j++] = b256[it4++];
15854
+ }
15855
+ return vch
15856
+ }
15857
+ function decode (string) {
15858
+ var buffer = decodeUnsafe(string);
15859
+ if (buffer) { return buffer }
15860
+ throw new Error('Non-base' + BASE + ' character')
15861
+ }
15862
+ return {
15863
+ encode: encode,
15864
+ decodeUnsafe: decodeUnsafe,
15865
+ decode: decode
15866
+ }
15867
+ }
15868
+ src = base;
15869
+ return src;
15870
+ }
15871
+
15872
+ var srcExports = requireSrc();
15873
+ var basex = /*@__PURE__*/getDefaultExportFromCjs$1(srcExports);
15874
+
13386
15875
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
13387
- var base58 = base(ALPHABET);
15876
+ var base58 = basex(ALPHABET);
13388
15877
 
13389
15878
  var index = /*#__PURE__*/Object.freeze({
13390
15879
  __proto__: null,
@@ -13730,5 +16219,5 @@ class PrivyExpoProvider {
13730
16219
  }
13731
16220
  }
13732
16221
 
13733
- export { clearCache 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, deserializeTransaction as P, getIdToken as Q, setPlatform as R, SOLANA_MAINNET_RPC_URL as S, MockAuthProvider as T, DEFAULT_TEST_ADDRESS as U, OffchainAuthProvider as V, WebSessionManager as W, PrivyExpoProvider as X, InsufficientBalanceError as Y, ReactNativeSessionManager as Z, ServerSessionManager as _, SOLANA_DEVNET_RPC_URL as a, closeAllSubscriptions as a0, getCachedData as a1, getMany as a2, reconnectWithNewAuth as a3, refreshSession as a4, signSessionCreateMessage as a5, index as a6, buildSetDocumentsTransaction as b, convertRemainingAccounts as c, base58 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 };
13734
- //# sourceMappingURL=index.native-Brt4NkkH.esm.js.map
16222
+ export { ServerSessionManager as $, get as A, set as B, setMany as C, setFile as D, getFiles as E, runQuery as F, runQueryMany as G, runExpression as H, runExpressionMany as I, signMessage as J, signTransaction as K, signAndSubmitTransaction as L, count as M, aggregate as N, subscribe as O, useAuth as P, deserializeTransaction as Q, getIdToken as R, SOLANA_MAINNET_RPC_URL as S, setPlatform as T, MockAuthProvider as U, DEFAULT_TEST_ADDRESS as V, WebSessionManager as W, OffchainAuthProvider as X, PrivyExpoProvider as Y, InsufficientBalanceError as Z, ReactNativeSessionManager as _, SOLANA_DEVNET_RPC_URL as a, clearCache as a0, closeAllSubscriptions as a1, getCachedData as a2, getMany as a3, reconnectWithNewAuth as a4, refreshSession as a5, signSessionCreateMessage as a6, index as a7, buildSetDocumentsTransaction as b, convertRemainingAccounts as c, base58 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, requireBuffer as r, setCurrentUser as s, onAuthStateChanged as t, onAuthLoadingChanged as u, getAuthLoading as v, login as w, logout as x, getConfig as y, getAuthProvider as z };
16223
+ //# sourceMappingURL=index.native-X01vlukI.esm.js.map