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