@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.
@@ -2187,6 +2187,36 @@ function encodeLength(bytes, len) {
2187
2187
  }
2188
2188
  }
2189
2189
 
2190
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2191
+ /**
2192
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2193
+ */
2194
+
2195
+ function guardedShift(byteArray) {
2196
+ if (byteArray.length === 0) {
2197
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2198
+ }
2199
+
2200
+ return byteArray.shift();
2201
+ }
2202
+ /**
2203
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2204
+ * the array.
2205
+ */
2206
+
2207
+ function guardedSplice(byteArray, ...args) {
2208
+ var _args$;
2209
+
2210
+ const [start] = args;
2211
+
2212
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2213
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2214
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2215
+ }
2216
+
2217
+ return byteArray.splice(...args);
2218
+ }
2219
+
2190
2220
  /**
2191
2221
  * The message header, identifying signed and read-only account
2192
2222
  */
@@ -2285,32 +2315,28 @@ class Message {
2285
2315
  static from(buffer) {
2286
2316
  // Slice up wire data
2287
2317
  let byteArray = [...buffer];
2288
- const numRequiredSignatures = byteArray.shift();
2289
- const numReadonlySignedAccounts = byteArray.shift();
2290
- const numReadonlyUnsignedAccounts = byteArray.shift();
2318
+ const numRequiredSignatures = guardedShift(byteArray);
2319
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2320
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2291
2321
  const accountCount = decodeLength(byteArray);
2292
2322
  let accountKeys = [];
2293
2323
 
2294
2324
  for (let i = 0; i < accountCount; i++) {
2295
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2296
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2325
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2297
2326
  accountKeys.push(bs58.encode(Buffer.from(account)));
2298
2327
  }
2299
2328
 
2300
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2301
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2329
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2302
2330
  const instructionCount = decodeLength(byteArray);
2303
2331
  let instructions = [];
2304
2332
 
2305
2333
  for (let i = 0; i < instructionCount; i++) {
2306
- const programIdIndex = byteArray.shift();
2334
+ const programIdIndex = guardedShift(byteArray);
2307
2335
  const accountCount = decodeLength(byteArray);
2308
- const accounts = byteArray.slice(0, accountCount);
2309
- byteArray = byteArray.slice(accountCount);
2336
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2310
2337
  const dataLength = decodeLength(byteArray);
2311
- const dataSlice = byteArray.slice(0, dataLength);
2338
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2312
2339
  const data = bs58.encode(Buffer.from(dataSlice));
2313
- byteArray = byteArray.slice(dataLength);
2314
2340
  instructions.push({
2315
2341
  programIdIndex,
2316
2342
  accounts,
@@ -2339,6 +2365,10 @@ function assert (condition, message) {
2339
2365
  }
2340
2366
  }
2341
2367
 
2368
+ /**
2369
+ * Transaction signature as base-58 encoded string
2370
+ */
2371
+
2342
2372
  let TransactionStatus;
2343
2373
  /**
2344
2374
  * Default (empty) signature
@@ -2996,8 +3026,7 @@ class Transaction {
2996
3026
  let signatures = [];
2997
3027
 
2998
3028
  for (let i = 0; i < signatureCount; i++) {
2999
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3000
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3029
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3001
3030
  signatures.push(bs58.encode(Buffer.from(signature)));
3002
3031
  }
3003
3032
 
@@ -9247,10 +9276,8 @@ class ValidatorInfo {
9247
9276
  const configKeys = [];
9248
9277
 
9249
9278
  for (let i = 0; i < 2; i++) {
9250
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9251
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9252
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9253
- byteArray = byteArray.slice(1);
9279
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9280
+ const isSigner = guardedShift(byteArray) === 1;
9254
9281
  configKeys.push({
9255
9282
  publicKey,
9256
9283
  isSigner