@solana/web3.js 1.44.3 → 1.44.4

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.
@@ -2218,6 +2218,36 @@ function encodeLength(bytes, len) {
2218
2218
  }
2219
2219
  }
2220
2220
 
2221
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2222
+ /**
2223
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2224
+ */
2225
+
2226
+ function guardedShift(byteArray) {
2227
+ if (byteArray.length === 0) {
2228
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2229
+ }
2230
+
2231
+ return byteArray.shift();
2232
+ }
2233
+ /**
2234
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2235
+ * the array.
2236
+ */
2237
+
2238
+ function guardedSplice(byteArray, ...args) {
2239
+ var _args$;
2240
+
2241
+ const [start] = args;
2242
+
2243
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2244
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2245
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2246
+ }
2247
+
2248
+ return byteArray.splice(...args);
2249
+ }
2250
+
2221
2251
  /**
2222
2252
  * The message header, identifying signed and read-only account
2223
2253
  */
@@ -2316,32 +2346,28 @@ class Message {
2316
2346
  static from(buffer$1) {
2317
2347
  // Slice up wire data
2318
2348
  let byteArray = [...buffer$1];
2319
- const numRequiredSignatures = byteArray.shift();
2320
- const numReadonlySignedAccounts = byteArray.shift();
2321
- const numReadonlyUnsignedAccounts = byteArray.shift();
2349
+ const numRequiredSignatures = guardedShift(byteArray);
2350
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2351
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2322
2352
  const accountCount = decodeLength(byteArray);
2323
2353
  let accountKeys = [];
2324
2354
 
2325
2355
  for (let i = 0; i < accountCount; i++) {
2326
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2327
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2356
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2328
2357
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2329
2358
  }
2330
2359
 
2331
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2332
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2360
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2333
2361
  const instructionCount = decodeLength(byteArray);
2334
2362
  let instructions = [];
2335
2363
 
2336
2364
  for (let i = 0; i < instructionCount; i++) {
2337
- const programIdIndex = byteArray.shift();
2365
+ const programIdIndex = guardedShift(byteArray);
2338
2366
  const accountCount = decodeLength(byteArray);
2339
- const accounts = byteArray.slice(0, accountCount);
2340
- byteArray = byteArray.slice(accountCount);
2367
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2341
2368
  const dataLength = decodeLength(byteArray);
2342
- const dataSlice = byteArray.slice(0, dataLength);
2369
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2343
2370
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2344
- byteArray = byteArray.slice(dataLength);
2345
2371
  instructions.push({
2346
2372
  programIdIndex,
2347
2373
  accounts,
@@ -2370,6 +2396,10 @@ function assert (condition, message) {
2370
2396
  }
2371
2397
  }
2372
2398
 
2399
+ /**
2400
+ * Transaction signature as base-58 encoded string
2401
+ */
2402
+
2373
2403
  exports.TransactionStatus = void 0;
2374
2404
  /**
2375
2405
  * Default (empty) signature
@@ -3030,8 +3060,7 @@ class Transaction {
3030
3060
  let signatures = [];
3031
3061
 
3032
3062
  for (let i = 0; i < signatureCount; i++) {
3033
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3034
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3063
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3035
3064
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
3036
3065
  }
3037
3066
 
@@ -9291,10 +9320,8 @@ class ValidatorInfo {
9291
9320
  const configKeys = [];
9292
9321
 
9293
9322
  for (let i = 0; i < 2; i++) {
9294
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9295
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9296
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9297
- byteArray = byteArray.slice(1);
9323
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9324
+ const isSigner = guardedShift(byteArray) === 1;
9298
9325
  configKeys.push({
9299
9326
  publicKey,
9300
9327
  isSigner