@solana/web3.js 1.46.0 → 1.46.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.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
@@ -3023,8 +3053,7 @@ class Transaction {
3023
3053
  let signatures = [];
3024
3054
 
3025
3055
  for (let i = 0; i < signatureCount; i++) {
3026
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3027
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3056
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3028
3057
  signatures.push(bs58.encode(Buffer.from(signature)));
3029
3058
  }
3030
3059
 
@@ -5560,7 +5589,7 @@ const LogsNotificationResult = type({
5560
5589
 
5561
5590
  /** @internal */
5562
5591
  const COMMON_HTTP_HEADERS = {
5563
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5592
+ 'solana-client': `js/${(_process$env$npm_pack = "1.46.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5564
5593
  };
5565
5594
  /**
5566
5595
  * A connection to a fullnode JSON RPC endpoint
@@ -9431,10 +9460,8 @@ class ValidatorInfo {
9431
9460
  const configKeys = [];
9432
9461
 
9433
9462
  for (let i = 0; i < 2; i++) {
9434
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9435
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9436
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9437
- byteArray = byteArray.slice(1);
9463
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9464
+ const isSigner = guardedShift(byteArray) === 1;
9438
9465
  configKeys.push({
9439
9466
  publicKey,
9440
9467
  isSigner