@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.
package/lib/index.esm.js CHANGED
@@ -2117,6 +2117,36 @@ function encodeLength(bytes, len) {
2117
2117
  }
2118
2118
  }
2119
2119
 
2120
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2121
+ /**
2122
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2123
+ */
2124
+
2125
+ function guardedShift(byteArray) {
2126
+ if (byteArray.length === 0) {
2127
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2128
+ }
2129
+
2130
+ return byteArray.shift();
2131
+ }
2132
+ /**
2133
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2134
+ * the array.
2135
+ */
2136
+
2137
+ function guardedSplice(byteArray, ...args) {
2138
+ var _args$;
2139
+
2140
+ const [start] = args;
2141
+
2142
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2143
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2144
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2145
+ }
2146
+
2147
+ return byteArray.splice(...args);
2148
+ }
2149
+
2120
2150
  /**
2121
2151
  * The message header, identifying signed and read-only account
2122
2152
  */
@@ -2215,32 +2245,28 @@ class Message {
2215
2245
  static from(buffer) {
2216
2246
  // Slice up wire data
2217
2247
  let byteArray = [...buffer];
2218
- const numRequiredSignatures = byteArray.shift();
2219
- const numReadonlySignedAccounts = byteArray.shift();
2220
- const numReadonlyUnsignedAccounts = byteArray.shift();
2248
+ const numRequiredSignatures = guardedShift(byteArray);
2249
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2250
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2221
2251
  const accountCount = decodeLength(byteArray);
2222
2252
  let accountKeys = [];
2223
2253
 
2224
2254
  for (let i = 0; i < accountCount; i++) {
2225
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2226
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2255
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2227
2256
  accountKeys.push(bs58.encode(Buffer.from(account)));
2228
2257
  }
2229
2258
 
2230
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2231
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2259
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2232
2260
  const instructionCount = decodeLength(byteArray);
2233
2261
  let instructions = [];
2234
2262
 
2235
2263
  for (let i = 0; i < instructionCount; i++) {
2236
- const programIdIndex = byteArray.shift();
2264
+ const programIdIndex = guardedShift(byteArray);
2237
2265
  const accountCount = decodeLength(byteArray);
2238
- const accounts = byteArray.slice(0, accountCount);
2239
- byteArray = byteArray.slice(accountCount);
2266
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2240
2267
  const dataLength = decodeLength(byteArray);
2241
- const dataSlice = byteArray.slice(0, dataLength);
2268
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2242
2269
  const data = bs58.encode(Buffer.from(dataSlice));
2243
- byteArray = byteArray.slice(dataLength);
2244
2270
  instructions.push({
2245
2271
  programIdIndex,
2246
2272
  accounts,
@@ -2269,6 +2295,10 @@ function assert (condition, message) {
2269
2295
  }
2270
2296
  }
2271
2297
 
2298
+ /**
2299
+ * Transaction signature as base-58 encoded string
2300
+ */
2301
+
2272
2302
  /**
2273
2303
  * Default (empty) signature
2274
2304
  *
@@ -2854,8 +2884,7 @@ class Transaction {
2854
2884
  let signatures = [];
2855
2885
 
2856
2886
  for (let i = 0; i < signatureCount; i++) {
2857
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2858
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2887
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2859
2888
  signatures.push(bs58.encode(Buffer.from(signature)));
2860
2889
  }
2861
2890
 
@@ -8365,10 +8394,8 @@ class ValidatorInfo {
8365
8394
  const configKeys = [];
8366
8395
 
8367
8396
  for (let i = 0; i < 2; i++) {
8368
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8369
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8370
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8371
- byteArray = byteArray.slice(1);
8397
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8398
+ const isSigner = guardedShift(byteArray) === 1;
8372
8399
  configKeys.push({
8373
8400
  publicKey,
8374
8401
  isSigner