@solana/web3.js 1.37.2 → 1.37.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.browser.cjs.js +45 -18
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +45 -18
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +45 -18
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +45 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +45 -18
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +24 -24
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
package/lib/index.cjs.js
CHANGED
|
@@ -2204,6 +2204,36 @@ function encodeLength(bytes, len) {
|
|
|
2204
2204
|
}
|
|
2205
2205
|
}
|
|
2206
2206
|
|
|
2207
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2208
|
+
/**
|
|
2209
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2210
|
+
*/
|
|
2211
|
+
|
|
2212
|
+
function guardedShift(byteArray) {
|
|
2213
|
+
if (byteArray.length === 0) {
|
|
2214
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
return byteArray.shift();
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2221
|
+
* the array.
|
|
2222
|
+
*/
|
|
2223
|
+
|
|
2224
|
+
function guardedSplice(byteArray, ...args) {
|
|
2225
|
+
var _args$;
|
|
2226
|
+
|
|
2227
|
+
const [start] = args;
|
|
2228
|
+
|
|
2229
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2230
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2231
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
return byteArray.splice(...args);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2207
2237
|
/**
|
|
2208
2238
|
* The message header, identifying signed and read-only account
|
|
2209
2239
|
*/
|
|
@@ -2302,32 +2332,28 @@ class Message {
|
|
|
2302
2332
|
static from(buffer$1) {
|
|
2303
2333
|
// Slice up wire data
|
|
2304
2334
|
let byteArray = [...buffer$1];
|
|
2305
|
-
const numRequiredSignatures = byteArray
|
|
2306
|
-
const numReadonlySignedAccounts = byteArray
|
|
2307
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2335
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2336
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2337
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2308
2338
|
const accountCount = decodeLength(byteArray);
|
|
2309
2339
|
let accountKeys = [];
|
|
2310
2340
|
|
|
2311
2341
|
for (let i = 0; i < accountCount; i++) {
|
|
2312
|
-
const account = byteArray
|
|
2313
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2342
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2314
2343
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2315
2344
|
}
|
|
2316
2345
|
|
|
2317
|
-
const recentBlockhash = byteArray
|
|
2318
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2346
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2319
2347
|
const instructionCount = decodeLength(byteArray);
|
|
2320
2348
|
let instructions = [];
|
|
2321
2349
|
|
|
2322
2350
|
for (let i = 0; i < instructionCount; i++) {
|
|
2323
|
-
const programIdIndex = byteArray
|
|
2351
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2324
2352
|
const accountCount = decodeLength(byteArray);
|
|
2325
|
-
const accounts = byteArray
|
|
2326
|
-
byteArray = byteArray.slice(accountCount);
|
|
2353
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2327
2354
|
const dataLength = decodeLength(byteArray);
|
|
2328
|
-
const dataSlice = byteArray
|
|
2355
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2329
2356
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
2330
|
-
byteArray = byteArray.slice(dataLength);
|
|
2331
2357
|
instructions.push({
|
|
2332
2358
|
programIdIndex,
|
|
2333
2359
|
accounts,
|
|
@@ -2356,6 +2382,10 @@ function assert (condition, message) {
|
|
|
2356
2382
|
}
|
|
2357
2383
|
}
|
|
2358
2384
|
|
|
2385
|
+
/**
|
|
2386
|
+
* Transaction signature as base-58 encoded string
|
|
2387
|
+
*/
|
|
2388
|
+
|
|
2359
2389
|
/**
|
|
2360
2390
|
* Default (empty) signature
|
|
2361
2391
|
*
|
|
@@ -2950,8 +2980,7 @@ class Transaction {
|
|
|
2950
2980
|
let signatures = [];
|
|
2951
2981
|
|
|
2952
2982
|
for (let i = 0; i < signatureCount; i++) {
|
|
2953
|
-
const signature = byteArray
|
|
2954
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2983
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2955
2984
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
2956
2985
|
}
|
|
2957
2986
|
|
|
@@ -8788,10 +8817,8 @@ class ValidatorInfo {
|
|
|
8788
8817
|
const configKeys = [];
|
|
8789
8818
|
|
|
8790
8819
|
for (let i = 0; i < 2; i++) {
|
|
8791
|
-
const publicKey = new PublicKey(byteArray
|
|
8792
|
-
|
|
8793
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8794
|
-
byteArray = byteArray.slice(1);
|
|
8820
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8821
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8795
8822
|
configKeys.push({
|
|
8796
8823
|
publicKey,
|
|
8797
8824
|
isSigner
|