@solana/web3.js 1.34.0 → 1.34.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
@@ -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
 
@@ -8600,10 +8629,8 @@ class ValidatorInfo {
8600
8629
  const configKeys = [];
8601
8630
 
8602
8631
  for (let i = 0; i < 2; i++) {
8603
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8604
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8605
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8606
- byteArray = byteArray.slice(1);
8632
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8633
+ const isSigner = guardedShift(byteArray) === 1;
8607
8634
  configKeys.push({
8608
8635
  publicKey,
8609
8636
  isSigner