@solana/web3.js 1.29.3 → 1.29.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.
package/lib/index.cjs.js CHANGED
@@ -2157,6 +2157,36 @@ function encodeLength(bytes, len) {
2157
2157
  }
2158
2158
  }
2159
2159
 
2160
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2161
+ /**
2162
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2163
+ */
2164
+
2165
+ function guardedShift(byteArray) {
2166
+ if (byteArray.length === 0) {
2167
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2168
+ }
2169
+
2170
+ return byteArray.shift();
2171
+ }
2172
+ /**
2173
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2174
+ * the array.
2175
+ */
2176
+
2177
+ function guardedSplice(byteArray, ...args) {
2178
+ var _args$;
2179
+
2180
+ const [start] = args;
2181
+
2182
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2183
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2184
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2185
+ }
2186
+
2187
+ return byteArray.splice(...args);
2188
+ }
2189
+
2160
2190
  /**
2161
2191
  * The message header, identifying signed and read-only account
2162
2192
  */
@@ -2260,32 +2290,28 @@ class Message {
2260
2290
  static from(buffer$1) {
2261
2291
  // Slice up wire data
2262
2292
  let byteArray = [...buffer$1];
2263
- const numRequiredSignatures = byteArray.shift();
2264
- const numReadonlySignedAccounts = byteArray.shift();
2265
- const numReadonlyUnsignedAccounts = byteArray.shift();
2293
+ const numRequiredSignatures = guardedShift(byteArray);
2294
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2295
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2266
2296
  const accountCount = decodeLength(byteArray);
2267
2297
  let accountKeys = [];
2268
2298
 
2269
2299
  for (let i = 0; i < accountCount; i++) {
2270
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2271
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2300
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2272
2301
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2273
2302
  }
2274
2303
 
2275
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2276
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2304
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2277
2305
  const instructionCount = decodeLength(byteArray);
2278
2306
  let instructions = [];
2279
2307
 
2280
2308
  for (let i = 0; i < instructionCount; i++) {
2281
- const programIdIndex = byteArray.shift();
2309
+ const programIdIndex = guardedShift(byteArray);
2282
2310
  const accountCount = decodeLength(byteArray);
2283
- const accounts = byteArray.slice(0, accountCount);
2284
- byteArray = byteArray.slice(accountCount);
2311
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2285
2312
  const dataLength = decodeLength(byteArray);
2286
- const dataSlice = byteArray.slice(0, dataLength);
2313
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2287
2314
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2288
- byteArray = byteArray.slice(dataLength);
2289
2315
  instructions.push({
2290
2316
  programIdIndex,
2291
2317
  accounts,
@@ -2314,6 +2340,10 @@ function assert (condition, message) {
2314
2340
  }
2315
2341
  }
2316
2342
 
2343
+ /**
2344
+ * Transaction signature as base-58 encoded string
2345
+ */
2346
+
2317
2347
  /**
2318
2348
  * Default (empty) signature
2319
2349
  *
@@ -2907,8 +2937,7 @@ class Transaction {
2907
2937
  let signatures = [];
2908
2938
 
2909
2939
  for (let i = 0; i < signatureCount; i++) {
2910
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2911
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2940
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2912
2941
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
2913
2942
  }
2914
2943
 
@@ -8464,10 +8493,8 @@ class ValidatorInfo {
8464
8493
  const configKeys = [];
8465
8494
 
8466
8495
  for (let i = 0; i < 2; i++) {
8467
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8468
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8469
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8470
- byteArray = byteArray.slice(1);
8496
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8497
+ const isSigner = guardedShift(byteArray) === 1;
8471
8498
  configKeys.push({
8472
8499
  publicKey,
8473
8500
  isSigner