@solana/web3.js 1.32.1 → 1.32.3

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
@@ -2155,6 +2155,36 @@ function encodeLength(bytes, len) {
2155
2155
  }
2156
2156
  }
2157
2157
 
2158
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2159
+ /**
2160
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2161
+ */
2162
+
2163
+ function guardedShift(byteArray) {
2164
+ if (byteArray.length === 0) {
2165
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2166
+ }
2167
+
2168
+ return byteArray.shift();
2169
+ }
2170
+ /**
2171
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2172
+ * the array.
2173
+ */
2174
+
2175
+ function guardedSplice(byteArray, ...args) {
2176
+ var _args$;
2177
+
2178
+ const [start] = args;
2179
+
2180
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2181
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2182
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2183
+ }
2184
+
2185
+ return byteArray.splice(...args);
2186
+ }
2187
+
2158
2188
  /**
2159
2189
  * The message header, identifying signed and read-only account
2160
2190
  */
@@ -2253,32 +2283,28 @@ class Message {
2253
2283
  static from(buffer$1) {
2254
2284
  // Slice up wire data
2255
2285
  let byteArray = [...buffer$1];
2256
- const numRequiredSignatures = byteArray.shift();
2257
- const numReadonlySignedAccounts = byteArray.shift();
2258
- const numReadonlyUnsignedAccounts = byteArray.shift();
2286
+ const numRequiredSignatures = guardedShift(byteArray);
2287
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2288
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2259
2289
  const accountCount = decodeLength(byteArray);
2260
2290
  let accountKeys = [];
2261
2291
 
2262
2292
  for (let i = 0; i < accountCount; i++) {
2263
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2264
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2293
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2265
2294
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2266
2295
  }
2267
2296
 
2268
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2269
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2297
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2270
2298
  const instructionCount = decodeLength(byteArray);
2271
2299
  let instructions = [];
2272
2300
 
2273
2301
  for (let i = 0; i < instructionCount; i++) {
2274
- const programIdIndex = byteArray.shift();
2302
+ const programIdIndex = guardedShift(byteArray);
2275
2303
  const accountCount = decodeLength(byteArray);
2276
- const accounts = byteArray.slice(0, accountCount);
2277
- byteArray = byteArray.slice(accountCount);
2304
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2278
2305
  const dataLength = decodeLength(byteArray);
2279
- const dataSlice = byteArray.slice(0, dataLength);
2306
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2280
2307
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2281
- byteArray = byteArray.slice(dataLength);
2282
2308
  instructions.push({
2283
2309
  programIdIndex,
2284
2310
  accounts,
@@ -2307,6 +2333,10 @@ function assert (condition, message) {
2307
2333
  }
2308
2334
  }
2309
2335
 
2336
+ /**
2337
+ * Transaction signature as base-58 encoded string
2338
+ */
2339
+
2310
2340
  /**
2311
2341
  * Default (empty) signature
2312
2342
  *
@@ -2893,8 +2923,7 @@ class Transaction {
2893
2923
  let signatures = [];
2894
2924
 
2895
2925
  for (let i = 0; i < signatureCount; i++) {
2896
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2897
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2926
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2898
2927
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
2899
2928
  }
2900
2929
 
@@ -6939,7 +6968,14 @@ class Connection {
6939
6968
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
6940
6969
  this._rpcWebSocketIdleTimeout = null;
6941
6970
 
6942
- this._rpcWebSocket.close();
6971
+ try {
6972
+ this._rpcWebSocket.close();
6973
+ } catch (err) {
6974
+ // swallow error if socket has already been closed.
6975
+ if (err instanceof Error) {
6976
+ console.log(`Error when closing socket connection: ${err.message}`);
6977
+ }
6978
+ }
6943
6979
  }, 500);
6944
6980
  }
6945
6981
 
@@ -8621,10 +8657,8 @@ class ValidatorInfo {
8621
8657
  const configKeys = [];
8622
8658
 
8623
8659
  for (let i = 0; i < 2; i++) {
8624
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8625
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8626
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8627
- byteArray = byteArray.slice(1);
8660
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8661
+ const isSigner = guardedShift(byteArray) === 1;
8628
8662
  configKeys.push({
8629
8663
  publicKey,
8630
8664
  isSigner