@solana/web3.js 1.53.0 → 1.53.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.
@@ -2255,6 +2255,40 @@ function encodeLength(bytes, len) {
2255
2255
  }
2256
2256
  }
2257
2257
 
2258
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2259
+ /**
2260
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2261
+ */
2262
+
2263
+ function guardedShift(byteArray) {
2264
+ if (byteArray.length === 0) {
2265
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2266
+ }
2267
+
2268
+ return byteArray.shift();
2269
+ }
2270
+ /**
2271
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2272
+ * the array.
2273
+ */
2274
+
2275
+ function guardedSplice(byteArray, ...args) {
2276
+ var _args$;
2277
+
2278
+ const [start] = args;
2279
+
2280
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2281
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2282
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2283
+ }
2284
+
2285
+ return byteArray.splice(...args);
2286
+ }
2287
+
2288
+ /**
2289
+ * Message constructor arguments
2290
+ */
2291
+
2258
2292
  const PUBKEY_LENGTH = 32;
2259
2293
  /**
2260
2294
  * List of instructions to be processed atomically
@@ -2349,32 +2383,28 @@ class Message {
2349
2383
  static from(buffer$1) {
2350
2384
  // Slice up wire data
2351
2385
  let byteArray = [...buffer$1];
2352
- const numRequiredSignatures = byteArray.shift();
2353
- const numReadonlySignedAccounts = byteArray.shift();
2354
- const numReadonlyUnsignedAccounts = byteArray.shift();
2386
+ const numRequiredSignatures = guardedShift(byteArray);
2387
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2388
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2355
2389
  const accountCount = decodeLength(byteArray);
2356
2390
  let accountKeys = [];
2357
2391
 
2358
2392
  for (let i = 0; i < accountCount; i++) {
2359
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2360
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2393
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2361
2394
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2362
2395
  }
2363
2396
 
2364
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2365
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2397
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2366
2398
  const instructionCount = decodeLength(byteArray);
2367
2399
  let instructions = [];
2368
2400
 
2369
2401
  for (let i = 0; i < instructionCount; i++) {
2370
- const programIdIndex = byteArray.shift();
2402
+ const programIdIndex = guardedShift(byteArray);
2371
2403
  const accountCount = decodeLength(byteArray);
2372
- const accounts = byteArray.slice(0, accountCount);
2373
- byteArray = byteArray.slice(accountCount);
2404
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2374
2405
  const dataLength = decodeLength(byteArray);
2375
- const dataSlice = byteArray.slice(0, dataLength);
2406
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2376
2407
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2377
- byteArray = byteArray.slice(dataLength);
2378
2408
  instructions.push({
2379
2409
  programIdIndex,
2380
2410
  accounts,
@@ -2403,6 +2433,10 @@ function assert (condition, message) {
2403
2433
  }
2404
2434
  }
2405
2435
 
2436
+ /**
2437
+ * Transaction signature as base-58 encoded string
2438
+ */
2439
+
2406
2440
  exports.TransactionStatus = void 0;
2407
2441
  /**
2408
2442
  * Default (empty) signature
@@ -3082,8 +3116,7 @@ class Transaction {
3082
3116
  let signatures = [];
3083
3117
 
3084
3118
  for (let i = 0; i < signatureCount; i++) {
3085
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3086
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3119
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3087
3120
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3088
3121
  }
3089
3122
 
@@ -5461,7 +5494,7 @@ const LogsNotificationResult = superstruct.type({
5461
5494
 
5462
5495
  /** @internal */
5463
5496
  const COMMON_HTTP_HEADERS = {
5464
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5497
+ 'solana-client': `js/${(_process$env$npm_pack = "1.53.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5465
5498
  };
5466
5499
  /**
5467
5500
  * A connection to a fullnode JSON RPC endpoint
@@ -10181,10 +10214,8 @@ class ValidatorInfo {
10181
10214
  const configKeys = [];
10182
10215
 
10183
10216
  for (let i = 0; i < 2; i++) {
10184
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10185
- byteArray = byteArray.slice(PUBKEY_LENGTH);
10186
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10187
- byteArray = byteArray.slice(1);
10217
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
10218
+ const isSigner = guardedShift(byteArray) === 1;
10188
10219
  configKeys.push({
10189
10220
  publicKey,
10190
10221
  isSigner