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