@solana/web3.js 1.33.0 → 1.33.1

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
@@ -2162,6 +2162,36 @@ function encodeLength(bytes, len) {
2162
2162
  }
2163
2163
  }
2164
2164
 
2165
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2166
+ /**
2167
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2168
+ */
2169
+
2170
+ function guardedShift(byteArray) {
2171
+ if (byteArray.length === 0) {
2172
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2173
+ }
2174
+
2175
+ return byteArray.shift();
2176
+ }
2177
+ /**
2178
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2179
+ * the array.
2180
+ */
2181
+
2182
+ function guardedSplice(byteArray, ...args) {
2183
+ var _args$;
2184
+
2185
+ const [start] = args;
2186
+
2187
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2188
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2189
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2190
+ }
2191
+
2192
+ return byteArray.splice(...args);
2193
+ }
2194
+
2165
2195
  /**
2166
2196
  * The message header, identifying signed and read-only account
2167
2197
  */
@@ -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
  *
@@ -2900,8 +2930,7 @@ class Transaction {
2900
2930
  let signatures = [];
2901
2931
 
2902
2932
  for (let i = 0; i < signatureCount; i++) {
2903
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2904
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2933
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2905
2934
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
2906
2935
  }
2907
2936
 
@@ -8635,10 +8664,8 @@ class ValidatorInfo {
8635
8664
  const configKeys = [];
8636
8665
 
8637
8666
  for (let i = 0; i < 2; i++) {
8638
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8639
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8640
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8641
- byteArray = byteArray.slice(1);
8667
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8668
+ const isSigner = guardedShift(byteArray) === 1;
8642
8669
  configKeys.push({
8643
8670
  publicKey,
8644
8671
  isSigner