@solana/web3.js 1.30.2 → 1.30.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.
@@ -2110,6 +2110,36 @@ function encodeLength(bytes, len) {
2110
2110
  }
2111
2111
  }
2112
2112
 
2113
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2114
+ /**
2115
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2116
+ */
2117
+
2118
+ function guardedShift(byteArray) {
2119
+ if (byteArray.length === 0) {
2120
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2121
+ }
2122
+
2123
+ return byteArray.shift();
2124
+ }
2125
+ /**
2126
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2127
+ * the array.
2128
+ */
2129
+
2130
+ function guardedSplice(byteArray, ...args) {
2131
+ var _args$;
2132
+
2133
+ const [start] = args;
2134
+
2135
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2136
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2137
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2138
+ }
2139
+
2140
+ return byteArray.splice(...args);
2141
+ }
2142
+
2113
2143
  /**
2114
2144
  * The message header, identifying signed and read-only account
2115
2145
  */
@@ -2208,32 +2238,28 @@ class Message {
2208
2238
  static from(buffer) {
2209
2239
  // Slice up wire data
2210
2240
  let byteArray = [...buffer];
2211
- const numRequiredSignatures = byteArray.shift();
2212
- const numReadonlySignedAccounts = byteArray.shift();
2213
- const numReadonlyUnsignedAccounts = byteArray.shift();
2241
+ const numRequiredSignatures = guardedShift(byteArray);
2242
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2243
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2214
2244
  const accountCount = decodeLength(byteArray);
2215
2245
  let accountKeys = [];
2216
2246
 
2217
2247
  for (let i = 0; i < accountCount; i++) {
2218
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2219
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2248
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2220
2249
  accountKeys.push(bs58.encode(Buffer.from(account)));
2221
2250
  }
2222
2251
 
2223
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2224
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2252
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2225
2253
  const instructionCount = decodeLength(byteArray);
2226
2254
  let instructions = [];
2227
2255
 
2228
2256
  for (let i = 0; i < instructionCount; i++) {
2229
- const programIdIndex = byteArray.shift();
2257
+ const programIdIndex = guardedShift(byteArray);
2230
2258
  const accountCount = decodeLength(byteArray);
2231
- const accounts = byteArray.slice(0, accountCount);
2232
- byteArray = byteArray.slice(accountCount);
2259
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2233
2260
  const dataLength = decodeLength(byteArray);
2234
- const dataSlice = byteArray.slice(0, dataLength);
2261
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2235
2262
  const data = bs58.encode(Buffer.from(dataSlice));
2236
- byteArray = byteArray.slice(dataLength);
2237
2263
  instructions.push({
2238
2264
  programIdIndex,
2239
2265
  accounts,
@@ -2262,6 +2288,10 @@ function assert (condition, message) {
2262
2288
  }
2263
2289
  }
2264
2290
 
2291
+ /**
2292
+ * Transaction signature as base-58 encoded string
2293
+ */
2294
+
2265
2295
  /**
2266
2296
  * Default (empty) signature
2267
2297
  *
@@ -2847,8 +2877,7 @@ class Transaction {
2847
2877
  let signatures = [];
2848
2878
 
2849
2879
  for (let i = 0; i < signatureCount; i++) {
2850
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2851
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2880
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2852
2881
  signatures.push(bs58.encode(Buffer.from(signature)));
2853
2882
  }
2854
2883
 
@@ -8864,10 +8893,8 @@ class ValidatorInfo {
8864
8893
  const configKeys = [];
8865
8894
 
8866
8895
  for (let i = 0; i < 2; i++) {
8867
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8868
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8869
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8870
- byteArray = byteArray.slice(1);
8896
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8897
+ const isSigner = guardedShift(byteArray) === 1;
8871
8898
  configKeys.push({
8872
8899
  publicKey,
8873
8900
  isSigner