@solana/web3.js 1.37.1 → 1.37.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
@@ -2204,6 +2204,36 @@ function encodeLength(bytes, len) {
2204
2204
  }
2205
2205
  }
2206
2206
 
2207
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2208
+ /**
2209
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2210
+ */
2211
+
2212
+ function guardedShift(byteArray) {
2213
+ if (byteArray.length === 0) {
2214
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2215
+ }
2216
+
2217
+ return byteArray.shift();
2218
+ }
2219
+ /**
2220
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2221
+ * the array.
2222
+ */
2223
+
2224
+ function guardedSplice(byteArray, ...args) {
2225
+ var _args$;
2226
+
2227
+ const [start] = args;
2228
+
2229
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2230
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2231
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2232
+ }
2233
+
2234
+ return byteArray.splice(...args);
2235
+ }
2236
+
2207
2237
  /**
2208
2238
  * The message header, identifying signed and read-only account
2209
2239
  */
@@ -2302,32 +2332,28 @@ class Message {
2302
2332
  static from(buffer$1) {
2303
2333
  // Slice up wire data
2304
2334
  let byteArray = [...buffer$1];
2305
- const numRequiredSignatures = byteArray.shift();
2306
- const numReadonlySignedAccounts = byteArray.shift();
2307
- const numReadonlyUnsignedAccounts = byteArray.shift();
2335
+ const numRequiredSignatures = guardedShift(byteArray);
2336
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2337
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2308
2338
  const accountCount = decodeLength(byteArray);
2309
2339
  let accountKeys = [];
2310
2340
 
2311
2341
  for (let i = 0; i < accountCount; i++) {
2312
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2313
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2342
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2314
2343
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2315
2344
  }
2316
2345
 
2317
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2318
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2346
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2319
2347
  const instructionCount = decodeLength(byteArray);
2320
2348
  let instructions = [];
2321
2349
 
2322
2350
  for (let i = 0; i < instructionCount; i++) {
2323
- const programIdIndex = byteArray.shift();
2351
+ const programIdIndex = guardedShift(byteArray);
2324
2352
  const accountCount = decodeLength(byteArray);
2325
- const accounts = byteArray.slice(0, accountCount);
2326
- byteArray = byteArray.slice(accountCount);
2353
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2327
2354
  const dataLength = decodeLength(byteArray);
2328
- const dataSlice = byteArray.slice(0, dataLength);
2355
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2329
2356
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2330
- byteArray = byteArray.slice(dataLength);
2331
2357
  instructions.push({
2332
2358
  programIdIndex,
2333
2359
  accounts,
@@ -2356,6 +2382,10 @@ function assert (condition, message) {
2356
2382
  }
2357
2383
  }
2358
2384
 
2385
+ /**
2386
+ * Transaction signature as base-58 encoded string
2387
+ */
2388
+
2359
2389
  /**
2360
2390
  * Default (empty) signature
2361
2391
  *
@@ -2950,8 +2980,7 @@ class Transaction {
2950
2980
  let signatures = [];
2951
2981
 
2952
2982
  for (let i = 0; i < signatureCount; i++) {
2953
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2954
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2983
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2955
2984
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
2956
2985
  }
2957
2986
 
@@ -6756,7 +6785,14 @@ class Connection {
6756
6785
  let transaction;
6757
6786
 
6758
6787
  if (transactionOrMessage instanceof Transaction) {
6759
- transaction = transactionOrMessage;
6788
+ let originalTx = transactionOrMessage;
6789
+ transaction = new Transaction({
6790
+ recentBlockhash: originalTx.recentBlockhash,
6791
+ nonceInfo: originalTx.nonceInfo,
6792
+ feePayer: originalTx.feePayer,
6793
+ signatures: [...originalTx.signatures]
6794
+ });
6795
+ transaction.instructions = transactionOrMessage.instructions;
6760
6796
  } else {
6761
6797
  transaction = Transaction.populate(transactionOrMessage);
6762
6798
  }
@@ -7029,6 +7065,7 @@ class Connection {
7029
7065
 
7030
7066
  _resetSubscriptions() {
7031
7067
  Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7068
+ Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
7032
7069
  Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7033
7070
  Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
7034
7071
  Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
@@ -8780,10 +8817,8 @@ class ValidatorInfo {
8780
8817
  const configKeys = [];
8781
8818
 
8782
8819
  for (let i = 0; i < 2; i++) {
8783
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8784
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8785
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8786
- byteArray = byteArray.slice(1);
8820
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8821
+ const isSigner = guardedShift(byteArray) === 1;
8787
8822
  configKeys.push({
8788
8823
  publicKey,
8789
8824
  isSigner