@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.esm.js CHANGED
@@ -2190,6 +2190,36 @@ function encodeLength(bytes, len) {
2190
2190
  }
2191
2191
  }
2192
2192
 
2193
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2194
+ /**
2195
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2196
+ */
2197
+
2198
+ function guardedShift(byteArray) {
2199
+ if (byteArray.length === 0) {
2200
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2201
+ }
2202
+
2203
+ return byteArray.shift();
2204
+ }
2205
+ /**
2206
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2207
+ * the array.
2208
+ */
2209
+
2210
+ function guardedSplice(byteArray, ...args) {
2211
+ var _args$;
2212
+
2213
+ const [start] = args;
2214
+
2215
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2216
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2217
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2218
+ }
2219
+
2220
+ return byteArray.splice(...args);
2221
+ }
2222
+
2193
2223
  /**
2194
2224
  * The message header, identifying signed and read-only account
2195
2225
  */
@@ -2288,32 +2318,28 @@ class Message {
2288
2318
  static from(buffer) {
2289
2319
  // Slice up wire data
2290
2320
  let byteArray = [...buffer];
2291
- const numRequiredSignatures = byteArray.shift();
2292
- const numReadonlySignedAccounts = byteArray.shift();
2293
- const numReadonlyUnsignedAccounts = byteArray.shift();
2321
+ const numRequiredSignatures = guardedShift(byteArray);
2322
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2323
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2294
2324
  const accountCount = decodeLength(byteArray);
2295
2325
  let accountKeys = [];
2296
2326
 
2297
2327
  for (let i = 0; i < accountCount; i++) {
2298
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2299
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2328
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2300
2329
  accountKeys.push(bs58.encode(Buffer.from(account)));
2301
2330
  }
2302
2331
 
2303
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2304
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2332
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2305
2333
  const instructionCount = decodeLength(byteArray);
2306
2334
  let instructions = [];
2307
2335
 
2308
2336
  for (let i = 0; i < instructionCount; i++) {
2309
- const programIdIndex = byteArray.shift();
2337
+ const programIdIndex = guardedShift(byteArray);
2310
2338
  const accountCount = decodeLength(byteArray);
2311
- const accounts = byteArray.slice(0, accountCount);
2312
- byteArray = byteArray.slice(accountCount);
2339
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2313
2340
  const dataLength = decodeLength(byteArray);
2314
- const dataSlice = byteArray.slice(0, dataLength);
2341
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2315
2342
  const data = bs58.encode(Buffer.from(dataSlice));
2316
- byteArray = byteArray.slice(dataLength);
2317
2343
  instructions.push({
2318
2344
  programIdIndex,
2319
2345
  accounts,
@@ -2342,6 +2368,10 @@ function assert (condition, message) {
2342
2368
  }
2343
2369
  }
2344
2370
 
2371
+ /**
2372
+ * Transaction signature as base-58 encoded string
2373
+ */
2374
+
2345
2375
  /**
2346
2376
  * Default (empty) signature
2347
2377
  *
@@ -2987,8 +3017,7 @@ class Transaction {
2987
3017
  let signatures = [];
2988
3018
 
2989
3019
  for (let i = 0; i < signatureCount; i++) {
2990
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2991
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
3020
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2992
3021
  signatures.push(bs58.encode(Buffer.from(signature)));
2993
3022
  }
2994
3023
 
@@ -8864,10 +8893,8 @@ class ValidatorInfo {
8864
8893
  const configKeys = [];
8865
8894
 
8866
8895
  for (let i = 0; i < 2; i++) {
8867
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8868
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8869
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8870
- byteArray = byteArray.slice(1);
8896
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8897
+ const isSigner = guardedShift(byteArray) === 1;
8871
8898
  configKeys.push({
8872
8899
  publicKey,
8873
8900
  isSigner