@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.
package/lib/index.cjs.js CHANGED
@@ -2281,6 +2281,40 @@ function encodeLength(bytes, len) {
2281
2281
  }
2282
2282
  }
2283
2283
 
2284
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2285
+ /**
2286
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2287
+ */
2288
+
2289
+ function guardedShift(byteArray) {
2290
+ if (byteArray.length === 0) {
2291
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2292
+ }
2293
+
2294
+ return byteArray.shift();
2295
+ }
2296
+ /**
2297
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2298
+ * the array.
2299
+ */
2300
+
2301
+ function guardedSplice(byteArray, ...args) {
2302
+ var _args$;
2303
+
2304
+ const [start] = args;
2305
+
2306
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2307
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2308
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2309
+ }
2310
+
2311
+ return byteArray.splice(...args);
2312
+ }
2313
+
2314
+ /**
2315
+ * Message constructor arguments
2316
+ */
2317
+
2284
2318
  const PUBKEY_LENGTH = 32;
2285
2319
  /**
2286
2320
  * List of instructions to be processed atomically
@@ -2375,32 +2409,28 @@ class Message {
2375
2409
  static from(buffer$1) {
2376
2410
  // Slice up wire data
2377
2411
  let byteArray = [...buffer$1];
2378
- const numRequiredSignatures = byteArray.shift();
2379
- const numReadonlySignedAccounts = byteArray.shift();
2380
- const numReadonlyUnsignedAccounts = byteArray.shift();
2412
+ const numRequiredSignatures = guardedShift(byteArray);
2413
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2414
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2381
2415
  const accountCount = decodeLength(byteArray);
2382
2416
  let accountKeys = [];
2383
2417
 
2384
2418
  for (let i = 0; i < accountCount; i++) {
2385
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2386
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2419
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2387
2420
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2388
2421
  }
2389
2422
 
2390
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2391
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2423
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2392
2424
  const instructionCount = decodeLength(byteArray);
2393
2425
  let instructions = [];
2394
2426
 
2395
2427
  for (let i = 0; i < instructionCount; i++) {
2396
- const programIdIndex = byteArray.shift();
2428
+ const programIdIndex = guardedShift(byteArray);
2397
2429
  const accountCount = decodeLength(byteArray);
2398
- const accounts = byteArray.slice(0, accountCount);
2399
- byteArray = byteArray.slice(accountCount);
2430
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2400
2431
  const dataLength = decodeLength(byteArray);
2401
- const dataSlice = byteArray.slice(0, dataLength);
2432
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2402
2433
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2403
- byteArray = byteArray.slice(dataLength);
2404
2434
  instructions.push({
2405
2435
  programIdIndex,
2406
2436
  accounts,
@@ -2429,6 +2459,10 @@ function assert (condition, message) {
2429
2459
  }
2430
2460
  }
2431
2461
 
2462
+ /**
2463
+ * Transaction signature as base-58 encoded string
2464
+ */
2465
+
2432
2466
  exports.TransactionStatus = void 0;
2433
2467
  /**
2434
2468
  * Default (empty) signature
@@ -3108,8 +3142,7 @@ class Transaction {
3108
3142
  let signatures = [];
3109
3143
 
3110
3144
  for (let i = 0; i < signatureCount; i++) {
3111
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3112
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3145
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3113
3146
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3114
3147
  }
3115
3148
 
@@ -5547,7 +5580,7 @@ const LogsNotificationResult = superstruct.type({
5547
5580
 
5548
5581
  /** @internal */
5549
5582
  const COMMON_HTTP_HEADERS = {
5550
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5583
+ 'solana-client': `js/${(_process$env$npm_pack = "1.53.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5551
5584
  };
5552
5585
  /**
5553
5586
  * A connection to a fullnode JSON RPC endpoint
@@ -10267,10 +10300,8 @@ class ValidatorInfo {
10267
10300
  const configKeys = [];
10268
10301
 
10269
10302
  for (let i = 0; i < 2; i++) {
10270
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10271
- byteArray = byteArray.slice(PUBKEY_LENGTH);
10272
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10273
- byteArray = byteArray.slice(1);
10303
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
10304
+ const isSigner = guardedShift(byteArray) === 1;
10274
10305
  configKeys.push({
10275
10306
  publicKey,
10276
10307
  isSigner