@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.
@@ -2330,6 +2330,36 @@ function encodeLength(bytes, len) {
2330
2330
  }
2331
2331
  }
2332
2332
 
2333
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2334
+ /**
2335
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2336
+ */
2337
+
2338
+ function guardedShift(byteArray) {
2339
+ if (byteArray.length === 0) {
2340
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2341
+ }
2342
+
2343
+ return byteArray.shift();
2344
+ }
2345
+ /**
2346
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2347
+ * the array.
2348
+ */
2349
+
2350
+ function guardedSplice(byteArray, ...args) {
2351
+ var _args$;
2352
+
2353
+ const [start] = args;
2354
+
2355
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2356
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2357
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2358
+ }
2359
+
2360
+ return byteArray.splice(...args);
2361
+ }
2362
+
2333
2363
  /**
2334
2364
  * The message header, identifying signed and read-only account
2335
2365
  */
@@ -2428,32 +2458,28 @@ class Message {
2428
2458
  static from(buffer) {
2429
2459
  // Slice up wire data
2430
2460
  let byteArray = [...buffer];
2431
- const numRequiredSignatures = byteArray.shift();
2432
- const numReadonlySignedAccounts = byteArray.shift();
2433
- const numReadonlyUnsignedAccounts = byteArray.shift();
2461
+ const numRequiredSignatures = guardedShift(byteArray);
2462
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2463
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2434
2464
  const accountCount = decodeLength(byteArray);
2435
2465
  let accountKeys = [];
2436
2466
 
2437
2467
  for (let i = 0; i < accountCount; i++) {
2438
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2439
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2468
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2440
2469
  accountKeys.push(bs58.encode(Buffer.from(account)));
2441
2470
  }
2442
2471
 
2443
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2444
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2472
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2445
2473
  const instructionCount = decodeLength(byteArray);
2446
2474
  let instructions = [];
2447
2475
 
2448
2476
  for (let i = 0; i < instructionCount; i++) {
2449
- const programIdIndex = byteArray.shift();
2477
+ const programIdIndex = guardedShift(byteArray);
2450
2478
  const accountCount = decodeLength(byteArray);
2451
- const accounts = byteArray.slice(0, accountCount);
2452
- byteArray = byteArray.slice(accountCount);
2479
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2453
2480
  const dataLength = decodeLength(byteArray);
2454
- const dataSlice = byteArray.slice(0, dataLength);
2481
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2455
2482
  const data = bs58.encode(Buffer.from(dataSlice));
2456
- byteArray = byteArray.slice(dataLength);
2457
2483
  instructions.push({
2458
2484
  programIdIndex,
2459
2485
  accounts,
@@ -2482,6 +2508,10 @@ function assert (condition, message) {
2482
2508
  }
2483
2509
  }
2484
2510
 
2511
+ /**
2512
+ * Transaction signature as base-58 encoded string
2513
+ */
2514
+
2485
2515
  let TransactionStatus;
2486
2516
  /**
2487
2517
  * Default (empty) signature
@@ -3161,8 +3191,7 @@ class Transaction {
3161
3191
  let signatures = [];
3162
3192
 
3163
3193
  for (let i = 0; i < signatureCount; i++) {
3164
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3165
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3194
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3166
3195
  signatures.push(bs58.encode(Buffer.from(signature)));
3167
3196
  }
3168
3197
 
@@ -5826,7 +5855,7 @@ const LogsNotificationResult = type({
5826
5855
 
5827
5856
  /** @internal */
5828
5857
  const COMMON_HTTP_HEADERS = {
5829
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5858
+ 'solana-client': `js/${(_process$env$npm_pack = "1.52.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5830
5859
  };
5831
5860
  /**
5832
5861
  * A connection to a fullnode JSON RPC endpoint
@@ -9755,10 +9784,8 @@ class ValidatorInfo {
9755
9784
  const configKeys = [];
9756
9785
 
9757
9786
  for (let i = 0; i < 2; i++) {
9758
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9759
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9760
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9761
- byteArray = byteArray.slice(1);
9787
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9788
+ const isSigner = guardedShift(byteArray) === 1;
9762
9789
  configKeys.push({
9763
9790
  publicKey,
9764
9791
  isSigner