@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.
@@ -2120,6 +2120,36 @@ function encodeLength(bytes, len) {
2120
2120
  }
2121
2121
  }
2122
2122
 
2123
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
2124
+ /**
2125
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
2126
+ */
2127
+
2128
+ function guardedShift(byteArray) {
2129
+ if (byteArray.length === 0) {
2130
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2131
+ }
2132
+
2133
+ return byteArray.shift();
2134
+ }
2135
+ /**
2136
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
2137
+ * the array.
2138
+ */
2139
+
2140
+ function guardedSplice(byteArray, ...args) {
2141
+ var _args$;
2142
+
2143
+ const [start] = args;
2144
+
2145
+ if (args.length === 2 // Implies that `deleteCount` was supplied
2146
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
2147
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
2148
+ }
2149
+
2150
+ return byteArray.splice(...args);
2151
+ }
2152
+
2123
2153
  /**
2124
2154
  * The message header, identifying signed and read-only account
2125
2155
  */
@@ -2218,32 +2248,28 @@ class Message {
2218
2248
  static from(buffer) {
2219
2249
  // Slice up wire data
2220
2250
  let byteArray = [...buffer];
2221
- const numRequiredSignatures = byteArray.shift();
2222
- const numReadonlySignedAccounts = byteArray.shift();
2223
- const numReadonlyUnsignedAccounts = byteArray.shift();
2251
+ const numRequiredSignatures = guardedShift(byteArray);
2252
+ const numReadonlySignedAccounts = guardedShift(byteArray);
2253
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
2224
2254
  const accountCount = decodeLength(byteArray);
2225
2255
  let accountKeys = [];
2226
2256
 
2227
2257
  for (let i = 0; i < accountCount; i++) {
2228
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2229
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2258
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2230
2259
  accountKeys.push(bs58.encode(Buffer.from(account)));
2231
2260
  }
2232
2261
 
2233
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2234
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2262
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
2235
2263
  const instructionCount = decodeLength(byteArray);
2236
2264
  let instructions = [];
2237
2265
 
2238
2266
  for (let i = 0; i < instructionCount; i++) {
2239
- const programIdIndex = byteArray.shift();
2267
+ const programIdIndex = guardedShift(byteArray);
2240
2268
  const accountCount = decodeLength(byteArray);
2241
- const accounts = byteArray.slice(0, accountCount);
2242
- byteArray = byteArray.slice(accountCount);
2269
+ const accounts = guardedSplice(byteArray, 0, accountCount);
2243
2270
  const dataLength = decodeLength(byteArray);
2244
- const dataSlice = byteArray.slice(0, dataLength);
2271
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
2245
2272
  const data = bs58.encode(Buffer.from(dataSlice));
2246
- byteArray = byteArray.slice(dataLength);
2247
2273
  instructions.push({
2248
2274
  programIdIndex,
2249
2275
  accounts,
@@ -2272,6 +2298,10 @@ function assert (condition, message) {
2272
2298
  }
2273
2299
  }
2274
2300
 
2301
+ /**
2302
+ * Transaction signature as base-58 encoded string
2303
+ */
2304
+
2275
2305
  /**
2276
2306
  * Default (empty) signature
2277
2307
  *
@@ -2858,8 +2888,7 @@ class Transaction {
2858
2888
  let signatures = [];
2859
2889
 
2860
2890
  for (let i = 0; i < signatureCount; i++) {
2861
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2862
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
2891
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2863
2892
  signatures.push(bs58.encode(Buffer.from(signature)));
2864
2893
  }
2865
2894
 
@@ -9099,10 +9128,8 @@ class ValidatorInfo {
9099
9128
  const configKeys = [];
9100
9129
 
9101
9130
  for (let i = 0; i < 2; i++) {
9102
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
9103
- byteArray = byteArray.slice(PUBKEY_LENGTH);
9104
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9105
- byteArray = byteArray.slice(1);
9131
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
9132
+ const isSigner = guardedShift(byteArray) === 1;
9106
9133
  configKeys.push({
9107
9134
  publicKey,
9108
9135
  isSigner