@pooflabs/web 0.0.82 → 0.0.83-rc1

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