@solana/web3.js 1.40.1 → 1.40.2

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
@@ -2225,6 +2225,36 @@ function encodeLength(bytes, len) {
2225
2225
  }
2226
2226
  }
2227
2227
 
2228
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2229
+ /**
2230
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2231
+ */
2232
+
2233
+ function guardedShift(byteArray) {
2234
+ if (byteArray.length === 0) {
2235
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2236
+ }
2237
+
2238
+ return byteArray.shift();
2239
+ }
2240
+ /**
2241
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2242
+ * the array.
2243
+ */
2244
+
2245
+ function guardedSplice(byteArray, ...args) {
2246
+ var _args$;
2247
+
2248
+ const [start] = args;
2249
+
2250
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2251
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2252
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2253
+ }
2254
+
2255
+ return byteArray.splice(...args);
2256
+ }
2257
+
2228
2258
  /**
2229
2259
  * The message header, identifying signed and read-only account
2230
2260
  */
@@ -2323,32 +2353,28 @@ class Message {
2323
2353
  static from(buffer$1) {
2324
2354
  // Slice up wire data
2325
2355
  let byteArray = [...buffer$1];
2326
- const numRequiredSignatures = byteArray.shift();
2327
- const numReadonlySignedAccounts = byteArray.shift();
2328
- const numReadonlyUnsignedAccounts = byteArray.shift();
2356
+ const numRequiredSignatures = guardedShift(byteArray);
2357
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2358
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2329
2359
  const accountCount = decodeLength(byteArray);
2330
2360
  let accountKeys = [];
2331
2361
 
2332
2362
  for (let i = 0; i < accountCount; i++) {
2333
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2334
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2363
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2335
2364
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2336
2365
  }
2337
2366
 
2338
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2339
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2367
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2340
2368
  const instructionCount = decodeLength(byteArray);
2341
2369
  let instructions = [];
2342
2370
 
2343
2371
  for (let i = 0; i < instructionCount; i++) {
2344
- const programIdIndex = byteArray.shift();
2372
+ const programIdIndex = guardedShift(byteArray);
2345
2373
  const accountCount = decodeLength(byteArray);
2346
- const accounts = byteArray.slice(0, accountCount);
2347
- byteArray = byteArray.slice(accountCount);
2374
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2348
2375
  const dataLength = decodeLength(byteArray);
2349
- const dataSlice = byteArray.slice(0, dataLength);
2376
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2350
2377
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2351
- byteArray = byteArray.slice(dataLength);
2352
2378
  instructions.push({
2353
2379
  programIdIndex,
2354
2380
  accounts,
@@ -2377,6 +2403,10 @@ function assert (condition, message) {
2377
2403
  }
2378
2404
  }
2379
2405
 
2406
+ /**
2407
+ * Transaction signature as base-58 encoded string
2408
+ */
2409
+
2380
2410
  /**
2381
2411
  * Default (empty) signature
2382
2412
  *
@@ -3022,8 +3052,7 @@ class Transaction {
3022
3052
  let signatures = [];
3023
3053
 
3024
3054
  for (let i = 0; i < signatureCount; i++) {
3025
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
3026
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
3055
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
3027
3056
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3028
3057
  }
3029
3058
 
@@ -8899,10 +8928,8 @@ class ValidatorInfo {
8899
8928
  const configKeys = [];
8900
8929
 
8901
8930
  for (let i = 0; i < 2; i++) {
8902
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8903
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8904
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8905
- byteArray = byteArray.slice(1);
8931
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8932
+ const isSigner = guardedShift(byteArray) === 1;
8906
8933
  configKeys.push({
8907
8934
  publicKey,
8908
8935
  isSigner