@solana/web3.js 1.43.5 → 1.43.7

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.d.ts CHANGED
@@ -415,6 +415,7 @@ declare module '@solana/web3.js' {
415
415
  /** A recent blockhash */
416
416
  recentBlockhash?: Blockhash;
417
417
  };
418
+ export type TransactionCtorFields = TransactionCtorFields_DEPRECATED;
418
419
  /**
419
420
  * List of Transaction object fields that may be initialized at construction
420
421
  */
package/lib/index.esm.js CHANGED
@@ -2211,6 +2211,36 @@ function encodeLength(bytes, len) {
2211
2211
  }
2212
2212
  }
2213
2213
 
2214
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2215
+ /**
2216
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2217
+ */
2218
+
2219
+ function guardedShift(byteArray) {
2220
+ if (byteArray.length === 0) {
2221
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2222
+ }
2223
+
2224
+ return byteArray.shift();
2225
+ }
2226
+ /**
2227
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2228
+ * the array.
2229
+ */
2230
+
2231
+ function guardedSplice(byteArray, ...args) {
2232
+ var _args$;
2233
+
2234
+ const [start] = args;
2235
+
2236
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2237
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2238
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2239
+ }
2240
+
2241
+ return byteArray.splice(...args);
2242
+ }
2243
+
2214
2244
  /**
2215
2245
  * The message header, identifying signed and read-only account
2216
2246
  */
@@ -2309,32 +2339,28 @@ class Message {
2309
2339
  static from(buffer) {
2310
2340
  // Slice up wire data
2311
2341
  let byteArray = [...buffer];
2312
- const numRequiredSignatures = byteArray.shift();
2313
- const numReadonlySignedAccounts = byteArray.shift();
2314
- const numReadonlyUnsignedAccounts = byteArray.shift();
2342
+ const numRequiredSignatures = guardedShift(byteArray);
2343
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2344
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2315
2345
  const accountCount = decodeLength(byteArray);
2316
2346
  let accountKeys = [];
2317
2347
 
2318
2348
  for (let i = 0; i < accountCount; i++) {
2319
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2320
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2349
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2321
2350
  accountKeys.push(bs58.encode(Buffer.from(account)));
2322
2351
  }
2323
2352
 
2324
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2325
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2353
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2326
2354
  const instructionCount = decodeLength(byteArray);
2327
2355
  let instructions = [];
2328
2356
 
2329
2357
  for (let i = 0; i < instructionCount; i++) {
2330
- const programIdIndex = byteArray.shift();
2358
+ const programIdIndex = guardedShift(byteArray);
2331
2359
  const accountCount = decodeLength(byteArray);
2332
- const accounts = byteArray.slice(0, accountCount);
2333
- byteArray = byteArray.slice(accountCount);
2360
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2334
2361
  const dataLength = decodeLength(byteArray);
2335
- const dataSlice = byteArray.slice(0, dataLength);
2362
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2336
2363
  const data = bs58.encode(Buffer.from(dataSlice));
2337
- byteArray = byteArray.slice(dataLength);
2338
2364
  instructions.push({
2339
2365
  programIdIndex,
2340
2366
  accounts,
@@ -2363,6 +2389,10 @@ function assert (condition, message) {
2363
2389
  }
2364
2390
  }
2365
2391
 
2392
+ /**
2393
+ * Transaction signature as base-58 encoded string
2394
+ */
2395
+
2366
2396
  let TransactionStatus;
2367
2397
  /**
2368
2398
  * Default (empty) signature
@@ -3020,8 +3050,7 @@ class Transaction {
3020
3050
  let signatures = [];
3021
3051
 
3022
3052
  for (let i = 0; i < signatureCount; i++) {
3023
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3024
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3053
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3025
3054
  signatures.push(bs58.encode(Buffer.from(signature)));
3026
3055
  }
3027
3056
 
@@ -9329,10 +9358,8 @@ class ValidatorInfo {
9329
9358
  const configKeys = [];
9330
9359
 
9331
9360
  for (let i = 0; i < 2; i++) {
9332
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9333
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9334
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9335
- byteArray = byteArray.slice(1);
9361
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9362
+ const isSigner = guardedShift(byteArray) === 1;
9336
9363
  configKeys.push({
9337
9364
  publicKey,
9338
9365
  isSigner