@solana/web3.js 1.43.5 → 1.43.7

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
@@ -2245,6 +2245,36 @@ function encodeLength(bytes, len) {
2245
2245
  }
2246
2246
  }
2247
2247
 
2248
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2249
+ /**
2250
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2251
+ */
2252
+
2253
+ function guardedShift(byteArray) {
2254
+ if (byteArray.length === 0) {
2255
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2256
+ }
2257
+
2258
+ return byteArray.shift();
2259
+ }
2260
+ /**
2261
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2262
+ * the array.
2263
+ */
2264
+
2265
+ function guardedSplice(byteArray, ...args) {
2266
+ var _args$;
2267
+
2268
+ const [start] = args;
2269
+
2270
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2271
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2272
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2273
+ }
2274
+
2275
+ return byteArray.splice(...args);
2276
+ }
2277
+
2248
2278
  /**
2249
2279
  * The message header, identifying signed and read-only account
2250
2280
  */
@@ -2343,32 +2373,28 @@ class Message {
2343
2373
  static from(buffer$1) {
2344
2374
  // Slice up wire data
2345
2375
  let byteArray = [...buffer$1];
2346
- const numRequiredSignatures = byteArray.shift();
2347
- const numReadonlySignedAccounts = byteArray.shift();
2348
- const numReadonlyUnsignedAccounts = byteArray.shift();
2376
+ const numRequiredSignatures = guardedShift(byteArray);
2377
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2378
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2349
2379
  const accountCount = decodeLength(byteArray);
2350
2380
  let accountKeys = [];
2351
2381
 
2352
2382
  for (let i = 0; i < accountCount; i++) {
2353
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2354
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2383
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2355
2384
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2356
2385
  }
2357
2386
 
2358
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2359
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2387
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2360
2388
  const instructionCount = decodeLength(byteArray);
2361
2389
  let instructions = [];
2362
2390
 
2363
2391
  for (let i = 0; i < instructionCount; i++) {
2364
- const programIdIndex = byteArray.shift();
2392
+ const programIdIndex = guardedShift(byteArray);
2365
2393
  const accountCount = decodeLength(byteArray);
2366
- const accounts = byteArray.slice(0, accountCount);
2367
- byteArray = byteArray.slice(accountCount);
2394
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2368
2395
  const dataLength = decodeLength(byteArray);
2369
- const dataSlice = byteArray.slice(0, dataLength);
2396
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2370
2397
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2371
- byteArray = byteArray.slice(dataLength);
2372
2398
  instructions.push({
2373
2399
  programIdIndex,
2374
2400
  accounts,
@@ -2397,6 +2423,10 @@ function assert (condition, message) {
2397
2423
  }
2398
2424
  }
2399
2425
 
2426
+ /**
2427
+ * Transaction signature as base-58 encoded string
2428
+ */
2429
+
2400
2430
  exports.TransactionStatus = void 0;
2401
2431
  /**
2402
2432
  * Default (empty) signature
@@ -3054,8 +3084,7 @@ class Transaction {
3054
3084
  let signatures = [];
3055
3085
 
3056
3086
  for (let i = 0; i < signatureCount; i++) {
3057
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3058
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3087
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3059
3088
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3060
3089
  }
3061
3090
 
@@ -9363,10 +9392,8 @@ class ValidatorInfo {
9363
9392
  const configKeys = [];
9364
9393
 
9365
9394
  for (let i = 0; i < 2; i++) {
9366
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9367
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9368
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9369
- byteArray = byteArray.slice(1);
9395
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9396
+ const isSigner = guardedShift(byteArray) === 1;
9370
9397
  configKeys.push({
9371
9398
  publicKey,
9372
9399
  isSigner