@solana/web3.js 1.35.0 → 1.35.2

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
@@ -754,7 +754,7 @@ declare module '@solana/web3.js' {
754
754
  export type SimulatedTransactionResponse = {
755
755
  err: TransactionError | string | null;
756
756
  logs: Array<string> | null;
757
- accounts?: SimulatedTransactionAccountInfo[] | null;
757
+ accounts?: (SimulatedTransactionAccountInfo | null)[] | null;
758
758
  unitsConsumed?: number;
759
759
  };
760
760
  export type ParsedInnerInstruction = {
package/lib/index.esm.js CHANGED
@@ -2127,6 +2127,36 @@ function encodeLength(bytes, len) {
2127
2127
  }
2128
2128
  }
2129
2129
 
2130
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2131
+ /**
2132
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2133
+ */
2134
+
2135
+ function guardedShift(byteArray) {
2136
+ if (byteArray.length === 0) {
2137
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2138
+ }
2139
+
2140
+ return byteArray.shift();
2141
+ }
2142
+ /**
2143
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2144
+ * the array.
2145
+ */
2146
+
2147
+ function guardedSplice(byteArray, ...args) {
2148
+ var _args$;
2149
+
2150
+ const [start] = args;
2151
+
2152
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2153
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2154
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2155
+ }
2156
+
2157
+ return byteArray.splice(...args);
2158
+ }
2159
+
2130
2160
  /**
2131
2161
  * The message header, identifying signed and read-only account
2132
2162
  */
@@ -2225,32 +2255,28 @@ class Message {
2225
2255
  static from(buffer) {
2226
2256
  // Slice up wire data
2227
2257
  let byteArray = [...buffer];
2228
- const numRequiredSignatures = byteArray.shift();
2229
- const numReadonlySignedAccounts = byteArray.shift();
2230
- const numReadonlyUnsignedAccounts = byteArray.shift();
2258
+ const numRequiredSignatures = guardedShift(byteArray);
2259
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2260
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2231
2261
  const accountCount = decodeLength(byteArray);
2232
2262
  let accountKeys = [];
2233
2263
 
2234
2264
  for (let i = 0; i < accountCount; i++) {
2235
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2236
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2265
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2237
2266
  accountKeys.push(bs58.encode(Buffer.from(account)));
2238
2267
  }
2239
2268
 
2240
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2241
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2269
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2242
2270
  const instructionCount = decodeLength(byteArray);
2243
2271
  let instructions = [];
2244
2272
 
2245
2273
  for (let i = 0; i < instructionCount; i++) {
2246
- const programIdIndex = byteArray.shift();
2274
+ const programIdIndex = guardedShift(byteArray);
2247
2275
  const accountCount = decodeLength(byteArray);
2248
- const accounts = byteArray.slice(0, accountCount);
2249
- byteArray = byteArray.slice(accountCount);
2276
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2250
2277
  const dataLength = decodeLength(byteArray);
2251
- const dataSlice = byteArray.slice(0, dataLength);
2278
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2252
2279
  const data = bs58.encode(Buffer.from(dataSlice));
2253
- byteArray = byteArray.slice(dataLength);
2254
2280
  instructions.push({
2255
2281
  programIdIndex,
2256
2282
  accounts,
@@ -2279,6 +2305,10 @@ function assert (condition, message) {
2279
2305
  }
2280
2306
  }
2281
2307
 
2308
+ /**
2309
+ * Transaction signature as base-58 encoded string
2310
+ */
2311
+
2282
2312
  /**
2283
2313
  * Default (empty) signature
2284
2314
  *
@@ -2865,8 +2895,7 @@ class Transaction {
2865
2895
  let signatures = [];
2866
2896
 
2867
2897
  for (let i = 0; i < signatureCount; i++) {
2868
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2869
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2898
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2870
2899
  signatures.push(bs58.encode(Buffer.from(signature)));
2871
2900
  }
2872
2901
 
@@ -4319,13 +4348,13 @@ const VersionResult = type({
4319
4348
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
4320
4349
  err: nullable(union([type({}), string()])),
4321
4350
  logs: nullable(array(string())),
4322
- accounts: optional(nullable(array(type({
4351
+ accounts: optional(nullable(array(nullable(type({
4323
4352
  executable: boolean(),
4324
4353
  owner: string(),
4325
4354
  lamports: number(),
4326
4355
  data: array(string()),
4327
4356
  rentEpoch: optional(number())
4328
- })))),
4357
+ }))))),
4329
4358
  unitsConsumed: optional(number())
4330
4359
  }));
4331
4360
 
@@ -8638,10 +8667,8 @@ class ValidatorInfo {
8638
8667
  const configKeys = [];
8639
8668
 
8640
8669
  for (let i = 0; i < 2; i++) {
8641
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8642
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8643
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8644
- byteArray = byteArray.slice(1);
8670
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8671
+ const isSigner = guardedShift(byteArray) === 1;
8645
8672
  configKeys.push({
8646
8673
  publicKey,
8647
8674
  isSigner