@solana/web3.js 1.52.0 → 1.52.1

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.
@@ -2361,6 +2361,36 @@ function encodeLength(bytes, len) {
2361
2361
  }
2362
2362
  }
2363
2363
 
2364
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2365
+ /**
2366
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2367
+ */
2368
+
2369
+ function guardedShift(byteArray) {
2370
+ if (byteArray.length === 0) {
2371
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2372
+ }
2373
+
2374
+ return byteArray.shift();
2375
+ }
2376
+ /**
2377
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2378
+ * the array.
2379
+ */
2380
+
2381
+ function guardedSplice(byteArray, ...args) {
2382
+ var _args$;
2383
+
2384
+ const [start] = args;
2385
+
2386
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2387
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2388
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2389
+ }
2390
+
2391
+ return byteArray.splice(...args);
2392
+ }
2393
+
2364
2394
  /**
2365
2395
  * The message header, identifying signed and read-only account
2366
2396
  */
@@ -2459,32 +2489,28 @@ class Message {
2459
2489
  static from(buffer$1) {
2460
2490
  // Slice up wire data
2461
2491
  let byteArray = [...buffer$1];
2462
- const numRequiredSignatures = byteArray.shift();
2463
- const numReadonlySignedAccounts = byteArray.shift();
2464
- const numReadonlyUnsignedAccounts = byteArray.shift();
2492
+ const numRequiredSignatures = guardedShift(byteArray);
2493
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2494
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2465
2495
  const accountCount = decodeLength(byteArray);
2466
2496
  let accountKeys = [];
2467
2497
 
2468
2498
  for (let i = 0; i < accountCount; i++) {
2469
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2470
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2499
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2471
2500
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2472
2501
  }
2473
2502
 
2474
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2475
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2503
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2476
2504
  const instructionCount = decodeLength(byteArray);
2477
2505
  let instructions = [];
2478
2506
 
2479
2507
  for (let i = 0; i < instructionCount; i++) {
2480
- const programIdIndex = byteArray.shift();
2508
+ const programIdIndex = guardedShift(byteArray);
2481
2509
  const accountCount = decodeLength(byteArray);
2482
- const accounts = byteArray.slice(0, accountCount);
2483
- byteArray = byteArray.slice(accountCount);
2510
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2484
2511
  const dataLength = decodeLength(byteArray);
2485
- const dataSlice = byteArray.slice(0, dataLength);
2512
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2486
2513
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2487
- byteArray = byteArray.slice(dataLength);
2488
2514
  instructions.push({
2489
2515
  programIdIndex,
2490
2516
  accounts,
@@ -2513,6 +2539,10 @@ function assert (condition, message) {
2513
2539
  }
2514
2540
  }
2515
2541
 
2542
+ /**
2543
+ * Transaction signature as base-58 encoded string
2544
+ */
2545
+
2516
2546
  exports.TransactionStatus = void 0;
2517
2547
  /**
2518
2548
  * Default (empty) signature
@@ -3192,8 +3222,7 @@ class Transaction {
3192
3222
  let signatures = [];
3193
3223
 
3194
3224
  for (let i = 0; i < signatureCount; i++) {
3195
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3196
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3225
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3197
3226
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3198
3227
  }
3199
3228
 
@@ -5857,7 +5886,7 @@ const LogsNotificationResult = superstruct.type({
5857
5886
 
5858
5887
  /** @internal */
5859
5888
  const COMMON_HTTP_HEADERS = {
5860
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5889
+ 'solana-client': `js/${(_process$env$npm_pack = "1.52.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5861
5890
  };
5862
5891
  /**
5863
5892
  * A connection to a fullnode JSON RPC endpoint
@@ -9786,10 +9815,8 @@ class ValidatorInfo {
9786
9815
  const configKeys = [];
9787
9816
 
9788
9817
  for (let i = 0; i < 2; i++) {
9789
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9790
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9791
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9792
- byteArray = byteArray.slice(1);
9818
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9819
+ const isSigner = guardedShift(byteArray) === 1;
9793
9820
  configKeys.push({
9794
9821
  publicKey,
9795
9822
  isSigner