@solana/web3.js 1.42.0 → 1.42.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
@@ -2236,6 +2236,36 @@ function encodeLength(bytes, len) {
2236
2236
  }
2237
2237
  }
2238
2238
 
2239
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2240
+ /**
2241
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2242
+ */
2243
+
2244
+ function guardedShift(byteArray) {
2245
+ if (byteArray.length === 0) {
2246
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2247
+ }
2248
+
2249
+ return byteArray.shift();
2250
+ }
2251
+ /**
2252
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2253
+ * the array.
2254
+ */
2255
+
2256
+ function guardedSplice(byteArray, ...args) {
2257
+ var _args$;
2258
+
2259
+ const [start] = args;
2260
+
2261
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2262
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2263
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2264
+ }
2265
+
2266
+ return byteArray.splice(...args);
2267
+ }
2268
+
2239
2269
  /**
2240
2270
  * The message header, identifying signed and read-only account
2241
2271
  */
@@ -2334,32 +2364,28 @@ class Message {
2334
2364
  static from(buffer$1) {
2335
2365
  // Slice up wire data
2336
2366
  let byteArray = [...buffer$1];
2337
- const numRequiredSignatures = byteArray.shift();
2338
- const numReadonlySignedAccounts = byteArray.shift();
2339
- const numReadonlyUnsignedAccounts = byteArray.shift();
2367
+ const numRequiredSignatures = guardedShift(byteArray);
2368
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2369
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2340
2370
  const accountCount = decodeLength(byteArray);
2341
2371
  let accountKeys = [];
2342
2372
 
2343
2373
  for (let i = 0; i < accountCount; i++) {
2344
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2345
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2374
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2346
2375
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2347
2376
  }
2348
2377
 
2349
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2350
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2378
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2351
2379
  const instructionCount = decodeLength(byteArray);
2352
2380
  let instructions = [];
2353
2381
 
2354
2382
  for (let i = 0; i < instructionCount; i++) {
2355
- const programIdIndex = byteArray.shift();
2383
+ const programIdIndex = guardedShift(byteArray);
2356
2384
  const accountCount = decodeLength(byteArray);
2357
- const accounts = byteArray.slice(0, accountCount);
2358
- byteArray = byteArray.slice(accountCount);
2385
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2359
2386
  const dataLength = decodeLength(byteArray);
2360
- const dataSlice = byteArray.slice(0, dataLength);
2387
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2361
2388
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2362
- byteArray = byteArray.slice(dataLength);
2363
2389
  instructions.push({
2364
2390
  programIdIndex,
2365
2391
  accounts,
@@ -2388,6 +2414,10 @@ function assert (condition, message) {
2388
2414
  }
2389
2415
  }
2390
2416
 
2417
+ /**
2418
+ * Transaction signature as base-58 encoded string
2419
+ */
2420
+
2391
2421
  exports.TransactionStatus = void 0;
2392
2422
  /**
2393
2423
  * Default (empty) signature
@@ -3038,8 +3068,7 @@ class Transaction {
3038
3068
  let signatures = [];
3039
3069
 
3040
3070
  for (let i = 0; i < signatureCount; i++) {
3041
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3042
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3071
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3043
3072
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3044
3073
  }
3045
3074
 
@@ -9252,10 +9281,8 @@ class ValidatorInfo {
9252
9281
  const configKeys = [];
9253
9282
 
9254
9283
  for (let i = 0; i < 2; i++) {
9255
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9256
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9257
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9258
- byteArray = byteArray.slice(1);
9284
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9285
+ const isSigner = guardedShift(byteArray) === 1;
9259
9286
  configKeys.push({
9260
9287
  publicKey,
9261
9288
  isSigner