@solana/web3.js 1.50.1 → 1.50.2

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.
@@ -2359,6 +2359,36 @@ function encodeLength(bytes, len) {
2359
2359
  }
2360
2360
  }
2361
2361
 
2362
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2363
+ /**
2364
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2365
+ */
2366
+
2367
+ function guardedShift(byteArray) {
2368
+ if (byteArray.length === 0) {
2369
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2370
+ }
2371
+
2372
+ return byteArray.shift();
2373
+ }
2374
+ /**
2375
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2376
+ * the array.
2377
+ */
2378
+
2379
+ function guardedSplice(byteArray, ...args) {
2380
+ var _args$;
2381
+
2382
+ const [start] = args;
2383
+
2384
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2385
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2386
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2387
+ }
2388
+
2389
+ return byteArray.splice(...args);
2390
+ }
2391
+
2362
2392
  /**
2363
2393
  * The message header, identifying signed and read-only account
2364
2394
  */
@@ -2457,32 +2487,28 @@ class Message {
2457
2487
  static from(buffer$1) {
2458
2488
  // Slice up wire data
2459
2489
  let byteArray = [...buffer$1];
2460
- const numRequiredSignatures = byteArray.shift();
2461
- const numReadonlySignedAccounts = byteArray.shift();
2462
- const numReadonlyUnsignedAccounts = byteArray.shift();
2490
+ const numRequiredSignatures = guardedShift(byteArray);
2491
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2492
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2463
2493
  const accountCount = decodeLength(byteArray);
2464
2494
  let accountKeys = [];
2465
2495
 
2466
2496
  for (let i = 0; i < accountCount; i++) {
2467
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2468
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2497
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2469
2498
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2470
2499
  }
2471
2500
 
2472
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2473
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2501
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2474
2502
  const instructionCount = decodeLength(byteArray);
2475
2503
  let instructions = [];
2476
2504
 
2477
2505
  for (let i = 0; i < instructionCount; i++) {
2478
- const programIdIndex = byteArray.shift();
2506
+ const programIdIndex = guardedShift(byteArray);
2479
2507
  const accountCount = decodeLength(byteArray);
2480
- const accounts = byteArray.slice(0, accountCount);
2481
- byteArray = byteArray.slice(accountCount);
2508
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2482
2509
  const dataLength = decodeLength(byteArray);
2483
- const dataSlice = byteArray.slice(0, dataLength);
2510
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2484
2511
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2485
- byteArray = byteArray.slice(dataLength);
2486
2512
  instructions.push({
2487
2513
  programIdIndex,
2488
2514
  accounts,
@@ -2511,6 +2537,10 @@ function assert (condition, message) {
2511
2537
  }
2512
2538
  }
2513
2539
 
2540
+ /**
2541
+ * Transaction signature as base-58 encoded string
2542
+ */
2543
+
2514
2544
  exports.TransactionStatus = void 0;
2515
2545
  /**
2516
2546
  * Default (empty) signature
@@ -3190,8 +3220,7 @@ class Transaction {
3190
3220
  let signatures = [];
3191
3221
 
3192
3222
  for (let i = 0; i < signatureCount; i++) {
3193
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3194
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3223
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3195
3224
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3196
3225
  }
3197
3226
 
@@ -5849,7 +5878,7 @@ const LogsNotificationResult = superstruct.type({
5849
5878
 
5850
5879
  /** @internal */
5851
5880
  const COMMON_HTTP_HEADERS = {
5852
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5881
+ 'solana-client': `js/${(_process$env$npm_pack = "1.50.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5853
5882
  };
5854
5883
  /**
5855
5884
  * A connection to a fullnode JSON RPC endpoint
@@ -9773,10 +9802,8 @@ class ValidatorInfo {
9773
9802
  const configKeys = [];
9774
9803
 
9775
9804
  for (let i = 0; i < 2; i++) {
9776
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9777
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9778
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9779
- byteArray = byteArray.slice(1);
9805
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9806
+ const isSigner = guardedShift(byteArray) === 1;
9780
9807
  configKeys.push({
9781
9808
  publicKey,
9782
9809
  isSigner