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