@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.
@@ -2213,6 +2213,36 @@ function encodeLength(bytes, len) {
2213
2213
  }
2214
2214
  }
2215
2215
 
2216
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2217
+ /**
2218
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2219
+ */
2220
+
2221
+ function guardedShift(byteArray) {
2222
+ if (byteArray.length === 0) {
2223
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2224
+ }
2225
+
2226
+ return byteArray.shift();
2227
+ }
2228
+ /**
2229
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2230
+ * the array.
2231
+ */
2232
+
2233
+ function guardedSplice(byteArray, ...args) {
2234
+ var _args$;
2235
+
2236
+ const [start] = args;
2237
+
2238
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2239
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2240
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2241
+ }
2242
+
2243
+ return byteArray.splice(...args);
2244
+ }
2245
+
2216
2246
  /**
2217
2247
  * The message header, identifying signed and read-only account
2218
2248
  */
@@ -2311,32 +2341,28 @@ class Message {
2311
2341
  static from(buffer$1) {
2312
2342
  // Slice up wire data
2313
2343
  let byteArray = [...buffer$1];
2314
- const numRequiredSignatures = byteArray.shift();
2315
- const numReadonlySignedAccounts = byteArray.shift();
2316
- const numReadonlyUnsignedAccounts = byteArray.shift();
2344
+ const numRequiredSignatures = guardedShift(byteArray);
2345
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2346
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2317
2347
  const accountCount = decodeLength(byteArray);
2318
2348
  let accountKeys = [];
2319
2349
 
2320
2350
  for (let i = 0; i < accountCount; i++) {
2321
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2322
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2351
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2323
2352
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2324
2353
  }
2325
2354
 
2326
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2327
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2355
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2328
2356
  const instructionCount = decodeLength(byteArray);
2329
2357
  let instructions = [];
2330
2358
 
2331
2359
  for (let i = 0; i < instructionCount; i++) {
2332
- const programIdIndex = byteArray.shift();
2360
+ const programIdIndex = guardedShift(byteArray);
2333
2361
  const accountCount = decodeLength(byteArray);
2334
- const accounts = byteArray.slice(0, accountCount);
2335
- byteArray = byteArray.slice(accountCount);
2362
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2336
2363
  const dataLength = decodeLength(byteArray);
2337
- const dataSlice = byteArray.slice(0, dataLength);
2364
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2338
2365
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2339
- byteArray = byteArray.slice(dataLength);
2340
2366
  instructions.push({
2341
2367
  programIdIndex,
2342
2368
  accounts,
@@ -2365,6 +2391,10 @@ function assert (condition, message) {
2365
2391
  }
2366
2392
  }
2367
2393
 
2394
+ /**
2395
+ * Transaction signature as base-58 encoded string
2396
+ */
2397
+
2368
2398
  /**
2369
2399
  * Default (empty) signature
2370
2400
  *
@@ -3010,8 +3040,7 @@ class Transaction {
3010
3040
  let signatures = [];
3011
3041
 
3012
3042
  for (let i = 0; i < signatureCount; i++) {
3013
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
3014
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
3043
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
3015
3044
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3016
3045
  }
3017
3046
 
@@ -9393,10 +9422,8 @@ class ValidatorInfo {
9393
9422
  const configKeys = [];
9394
9423
 
9395
9424
  for (let i = 0; i < 2; i++) {
9396
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9397
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9398
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9399
- byteArray = byteArray.slice(1);
9425
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9426
+ const isSigner = guardedShift(byteArray) === 1;
9400
9427
  configKeys.push({
9401
9428
  publicKey,
9402
9429
  isSigner