@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.
package/lib/index.cjs.js CHANGED
@@ -2388,6 +2388,36 @@ function encodeLength(bytes, len) {
2388
2388
  }
2389
2389
  }
2390
2390
 
2391
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2392
+ /**
2393
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2394
+ */
2395
+
2396
+ function guardedShift(byteArray) {
2397
+ if (byteArray.length === 0) {
2398
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2399
+ }
2400
+
2401
+ return byteArray.shift();
2402
+ }
2403
+ /**
2404
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2405
+ * the array.
2406
+ */
2407
+
2408
+ function guardedSplice(byteArray, ...args) {
2409
+ var _args$;
2410
+
2411
+ const [start] = args;
2412
+
2413
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2414
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2415
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2416
+ }
2417
+
2418
+ return byteArray.splice(...args);
2419
+ }
2420
+
2391
2421
  /**
2392
2422
  * The message header, identifying signed and read-only account
2393
2423
  */
@@ -2486,32 +2516,28 @@ class Message {
2486
2516
  static from(buffer$1) {
2487
2517
  // Slice up wire data
2488
2518
  let byteArray = [...buffer$1];
2489
- const numRequiredSignatures = byteArray.shift();
2490
- const numReadonlySignedAccounts = byteArray.shift();
2491
- const numReadonlyUnsignedAccounts = byteArray.shift();
2519
+ const numRequiredSignatures = guardedShift(byteArray);
2520
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2521
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2492
2522
  const accountCount = decodeLength(byteArray);
2493
2523
  let accountKeys = [];
2494
2524
 
2495
2525
  for (let i = 0; i < accountCount; i++) {
2496
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2497
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2526
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2498
2527
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2499
2528
  }
2500
2529
 
2501
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2502
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2530
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2503
2531
  const instructionCount = decodeLength(byteArray);
2504
2532
  let instructions = [];
2505
2533
 
2506
2534
  for (let i = 0; i < instructionCount; i++) {
2507
- const programIdIndex = byteArray.shift();
2535
+ const programIdIndex = guardedShift(byteArray);
2508
2536
  const accountCount = decodeLength(byteArray);
2509
- const accounts = byteArray.slice(0, accountCount);
2510
- byteArray = byteArray.slice(accountCount);
2537
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2511
2538
  const dataLength = decodeLength(byteArray);
2512
- const dataSlice = byteArray.slice(0, dataLength);
2539
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2513
2540
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2514
- byteArray = byteArray.slice(dataLength);
2515
2541
  instructions.push({
2516
2542
  programIdIndex,
2517
2543
  accounts,
@@ -2540,6 +2566,10 @@ function assert (condition, message) {
2540
2566
  }
2541
2567
  }
2542
2568
 
2569
+ /**
2570
+ * Transaction signature as base-58 encoded string
2571
+ */
2572
+
2543
2573
  exports.TransactionStatus = void 0;
2544
2574
  /**
2545
2575
  * Default (empty) signature
@@ -3219,8 +3249,7 @@ class Transaction {
3219
3249
  let signatures = [];
3220
3250
 
3221
3251
  for (let i = 0; i < signatureCount; i++) {
3222
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3223
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3252
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3224
3253
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3225
3254
  }
3226
3255
 
@@ -5942,7 +5971,7 @@ const LogsNotificationResult = superstruct.type({
5942
5971
 
5943
5972
  /** @internal */
5944
5973
  const COMMON_HTTP_HEADERS = {
5945
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5974
+ 'solana-client': `js/${(_process$env$npm_pack = "1.52.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5946
5975
  };
5947
5976
  /**
5948
5977
  * A connection to a fullnode JSON RPC endpoint
@@ -9871,10 +9900,8 @@ class ValidatorInfo {
9871
9900
  const configKeys = [];
9872
9901
 
9873
9902
  for (let i = 0; i < 2; i++) {
9874
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9875
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9876
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9877
- byteArray = byteArray.slice(1);
9903
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9904
+ const isSigner = guardedShift(byteArray) === 1;
9878
9905
  configKeys.push({
9879
9906
  publicKey,
9880
9907
  isSigner