@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.
@@ -2187,6 +2187,36 @@ function encodeLength(bytes, len) {
2187
2187
  }
2188
2188
  }
2189
2189
 
2190
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2191
+ /**
2192
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2193
+ */
2194
+
2195
+ function guardedShift(byteArray) {
2196
+ if (byteArray.length === 0) {
2197
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2198
+ }
2199
+
2200
+ return byteArray.shift();
2201
+ }
2202
+ /**
2203
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2204
+ * the array.
2205
+ */
2206
+
2207
+ function guardedSplice(byteArray, ...args) {
2208
+ var _args$;
2209
+
2210
+ const [start] = args;
2211
+
2212
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2213
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2214
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2215
+ }
2216
+
2217
+ return byteArray.splice(...args);
2218
+ }
2219
+
2190
2220
  /**
2191
2221
  * The message header, identifying signed and read-only account
2192
2222
  */
@@ -2285,32 +2315,28 @@ class Message {
2285
2315
  static from(buffer) {
2286
2316
  // Slice up wire data
2287
2317
  let byteArray = [...buffer];
2288
- const numRequiredSignatures = byteArray.shift();
2289
- const numReadonlySignedAccounts = byteArray.shift();
2290
- const numReadonlyUnsignedAccounts = byteArray.shift();
2318
+ const numRequiredSignatures = guardedShift(byteArray);
2319
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2320
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2291
2321
  const accountCount = decodeLength(byteArray);
2292
2322
  let accountKeys = [];
2293
2323
 
2294
2324
  for (let i = 0; i < accountCount; i++) {
2295
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2296
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2325
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2297
2326
  accountKeys.push(bs58.encode(Buffer.from(account)));
2298
2327
  }
2299
2328
 
2300
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2301
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2329
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2302
2330
  const instructionCount = decodeLength(byteArray);
2303
2331
  let instructions = [];
2304
2332
 
2305
2333
  for (let i = 0; i < instructionCount; i++) {
2306
- const programIdIndex = byteArray.shift();
2334
+ const programIdIndex = guardedShift(byteArray);
2307
2335
  const accountCount = decodeLength(byteArray);
2308
- const accounts = byteArray.slice(0, accountCount);
2309
- byteArray = byteArray.slice(accountCount);
2336
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2310
2337
  const dataLength = decodeLength(byteArray);
2311
- const dataSlice = byteArray.slice(0, dataLength);
2338
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2312
2339
  const data = bs58.encode(Buffer.from(dataSlice));
2313
- byteArray = byteArray.slice(dataLength);
2314
2340
  instructions.push({
2315
2341
  programIdIndex,
2316
2342
  accounts,
@@ -2339,6 +2365,10 @@ function assert (condition, message) {
2339
2365
  }
2340
2366
  }
2341
2367
 
2368
+ /**
2369
+ * Transaction signature as base-58 encoded string
2370
+ */
2371
+
2342
2372
  let TransactionStatus;
2343
2373
  /**
2344
2374
  * Default (empty) signature
@@ -2999,8 +3029,7 @@ class Transaction {
2999
3029
  let signatures = [];
3000
3030
 
3001
3031
  for (let i = 0; i < signatureCount; i++) {
3002
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
3003
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
3032
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
3004
3033
  signatures.push(bs58.encode(Buffer.from(signature)));
3005
3034
  }
3006
3035
 
@@ -5478,7 +5507,7 @@ const LogsNotificationResult = type({
5478
5507
 
5479
5508
  /** @internal */
5480
5509
  const COMMON_HTTP_HEADERS = {
5481
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5510
+ 'solana-client': `js/${(_process$env$npm_pack = "1.46.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5482
5511
  };
5483
5512
  /**
5484
5513
  * A connection to a fullnode JSON RPC endpoint
@@ -9349,10 +9378,8 @@ class ValidatorInfo {
9349
9378
  const configKeys = [];
9350
9379
 
9351
9380
  for (let i = 0; i < 2; i++) {
9352
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9353
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9354
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9355
- byteArray = byteArray.slice(1);
9381
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9382
+ const isSigner = guardedShift(byteArray) === 1;
9356
9383
  configKeys.push({
9357
9384
  publicKey,
9358
9385
  isSigner