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