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