@solana/web3.js 1.29.3 → 1.29.4

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
@@ -2122,6 +2122,36 @@ function encodeLength(bytes, len) {
2122
2122
  }
2123
2123
  }
2124
2124
 
2125
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2126
+ /**
2127
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2128
+ */
2129
+
2130
+ function guardedShift(byteArray) {
2131
+ if (byteArray.length === 0) {
2132
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2133
+ }
2134
+
2135
+ return byteArray.shift();
2136
+ }
2137
+ /**
2138
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2139
+ * the array.
2140
+ */
2141
+
2142
+ function guardedSplice(byteArray, ...args) {
2143
+ var _args$;
2144
+
2145
+ const [start] = args;
2146
+
2147
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2148
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2149
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2150
+ }
2151
+
2152
+ return byteArray.splice(...args);
2153
+ }
2154
+
2125
2155
  /**
2126
2156
  * The message header, identifying signed and read-only account
2127
2157
  */
@@ -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
  *
@@ -2872,8 +2902,7 @@ class Transaction {
2872
2902
  let signatures = [];
2873
2903
 
2874
2904
  for (let i = 0; i < signatureCount; i++) {
2875
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2876
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2905
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2877
2906
  signatures.push(bs58.encode(Buffer.from(signature)));
2878
2907
  }
2879
2908
 
@@ -8429,10 +8458,8 @@ class ValidatorInfo {
8429
8458
  const configKeys = [];
8430
8459
 
8431
8460
  for (let i = 0; i < 2; i++) {
8432
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8433
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8434
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8435
- byteArray = byteArray.slice(1);
8461
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
8462
+ const isSigner = guardedShift(byteArray) === 1;
8436
8463
  configKeys.push({
8437
8464
  publicKey,
8438
8465
  isSigner