@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.
@@ -2192,6 +2192,36 @@ function encodeLength(bytes, len) {
2192
2192
  }
2193
2193
  }
2194
2194
 
2195
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2196
+ /**
2197
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2198
+ */
2199
+
2200
+ function guardedShift(byteArray) {
2201
+ if (byteArray.length === 0) {
2202
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2203
+ }
2204
+
2205
+ return byteArray.shift();
2206
+ }
2207
+ /**
2208
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2209
+ * the array.
2210
+ */
2211
+
2212
+ function guardedSplice(byteArray, ...args) {
2213
+ var _args$;
2214
+
2215
+ const [start] = args;
2216
+
2217
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2218
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2219
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2220
+ }
2221
+
2222
+ return byteArray.splice(...args);
2223
+ }
2224
+
2195
2225
  /**
2196
2226
  * The message header, identifying signed and read-only account
2197
2227
  */
@@ -2290,32 +2320,28 @@ class Message {
2290
2320
  static from(buffer$1) {
2291
2321
  // Slice up wire data
2292
2322
  let byteArray = [...buffer$1];
2293
- const numRequiredSignatures = byteArray.shift();
2294
- const numReadonlySignedAccounts = byteArray.shift();
2295
- const numReadonlyUnsignedAccounts = byteArray.shift();
2323
+ const numRequiredSignatures = guardedShift(byteArray);
2324
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2325
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2296
2326
  const accountCount = decodeLength(byteArray);
2297
2327
  let accountKeys = [];
2298
2328
 
2299
2329
  for (let i = 0; i < accountCount; i++) {
2300
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2301
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2330
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2302
2331
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2303
2332
  }
2304
2333
 
2305
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2306
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2334
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2307
2335
  const instructionCount = decodeLength(byteArray);
2308
2336
  let instructions = [];
2309
2337
 
2310
2338
  for (let i = 0; i < instructionCount; i++) {
2311
- const programIdIndex = byteArray.shift();
2339
+ const programIdIndex = guardedShift(byteArray);
2312
2340
  const accountCount = decodeLength(byteArray);
2313
- const accounts = byteArray.slice(0, accountCount);
2314
- byteArray = byteArray.slice(accountCount);
2341
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2315
2342
  const dataLength = decodeLength(byteArray);
2316
- const dataSlice = byteArray.slice(0, dataLength);
2343
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2317
2344
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
2318
- byteArray = byteArray.slice(dataLength);
2319
2345
  instructions.push({
2320
2346
  programIdIndex,
2321
2347
  accounts,
@@ -2344,6 +2370,10 @@ function assert (condition, message) {
2344
2370
  }
2345
2371
  }
2346
2372
 
2373
+ /**
2374
+ * Transaction signature as base-58 encoded string
2375
+ */
2376
+
2347
2377
  /**
2348
2378
  * Default (empty) signature
2349
2379
  *
@@ -2938,8 +2968,7 @@ class Transaction {
2938
2968
  let signatures = [];
2939
2969
 
2940
2970
  for (let i = 0; i < signatureCount; i++) {
2941
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2942
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2971
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2943
2972
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
2944
2973
  }
2945
2974
 
@@ -7250,7 +7279,14 @@ class Connection {
7250
7279
  let transaction;
7251
7280
 
7252
7281
  if (transactionOrMessage instanceof Transaction) {
7253
- transaction = transactionOrMessage;
7282
+ let originalTx = transactionOrMessage;
7283
+ transaction = new Transaction({
7284
+ recentBlockhash: originalTx.recentBlockhash,
7285
+ nonceInfo: originalTx.nonceInfo,
7286
+ feePayer: originalTx.feePayer,
7287
+ signatures: [...originalTx.signatures]
7288
+ });
7289
+ transaction.instructions = transactionOrMessage.instructions;
7254
7290
  } else {
7255
7291
  transaction = Transaction.populate(transactionOrMessage);
7256
7292
  }
@@ -7523,6 +7559,7 @@ class Connection {
7523
7559
 
7524
7560
  _resetSubscriptions() {
7525
7561
  Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7562
+ Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
7526
7563
  Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
7527
7564
  Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
7528
7565
  Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
@@ -9274,10 +9311,8 @@ class ValidatorInfo {
9274
9311
  const configKeys = [];
9275
9312
 
9276
9313
  for (let i = 0; i < 2; i++) {
9277
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9278
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9279
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9280
- byteArray = byteArray.slice(1);
9314
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9315
+ const isSigner = guardedShift(byteArray) === 1;
9281
9316
  configKeys.push({
9282
9317
  publicKey,
9283
9318
  isSigner