@solana/web3.js 1.40.1 → 1.40.2
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 +22 -22
- 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.browser.esm.js
CHANGED
|
@@ -2181,6 +2181,36 @@ function encodeLength(bytes, len) {
|
|
|
2181
2181
|
}
|
|
2182
2182
|
}
|
|
2183
2183
|
|
|
2184
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2185
|
+
/**
|
|
2186
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2187
|
+
*/
|
|
2188
|
+
|
|
2189
|
+
function guardedShift(byteArray) {
|
|
2190
|
+
if (byteArray.length === 0) {
|
|
2191
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
return byteArray.shift();
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2198
|
+
* the array.
|
|
2199
|
+
*/
|
|
2200
|
+
|
|
2201
|
+
function guardedSplice(byteArray, ...args) {
|
|
2202
|
+
var _args$;
|
|
2203
|
+
|
|
2204
|
+
const [start] = args;
|
|
2205
|
+
|
|
2206
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2207
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2208
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
return byteArray.splice(...args);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2184
2214
|
/**
|
|
2185
2215
|
* The message header, identifying signed and read-only account
|
|
2186
2216
|
*/
|
|
@@ -2279,32 +2309,28 @@ class Message {
|
|
|
2279
2309
|
static from(buffer) {
|
|
2280
2310
|
// Slice up wire data
|
|
2281
2311
|
let byteArray = [...buffer];
|
|
2282
|
-
const numRequiredSignatures = byteArray
|
|
2283
|
-
const numReadonlySignedAccounts = byteArray
|
|
2284
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2312
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2313
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2314
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2285
2315
|
const accountCount = decodeLength(byteArray);
|
|
2286
2316
|
let accountKeys = [];
|
|
2287
2317
|
|
|
2288
2318
|
for (let i = 0; i < accountCount; i++) {
|
|
2289
|
-
const account = byteArray
|
|
2290
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2319
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2291
2320
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2292
2321
|
}
|
|
2293
2322
|
|
|
2294
|
-
const recentBlockhash = byteArray
|
|
2295
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2323
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2296
2324
|
const instructionCount = decodeLength(byteArray);
|
|
2297
2325
|
let instructions = [];
|
|
2298
2326
|
|
|
2299
2327
|
for (let i = 0; i < instructionCount; i++) {
|
|
2300
|
-
const programIdIndex = byteArray
|
|
2328
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2301
2329
|
const accountCount = decodeLength(byteArray);
|
|
2302
|
-
const accounts = byteArray
|
|
2303
|
-
byteArray = byteArray.slice(accountCount);
|
|
2330
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2304
2331
|
const dataLength = decodeLength(byteArray);
|
|
2305
|
-
const dataSlice = byteArray
|
|
2332
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2306
2333
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2307
|
-
byteArray = byteArray.slice(dataLength);
|
|
2308
2334
|
instructions.push({
|
|
2309
2335
|
programIdIndex,
|
|
2310
2336
|
accounts,
|
|
@@ -2333,6 +2359,10 @@ function assert (condition, message) {
|
|
|
2333
2359
|
}
|
|
2334
2360
|
}
|
|
2335
2361
|
|
|
2362
|
+
/**
|
|
2363
|
+
* Transaction signature as base-58 encoded string
|
|
2364
|
+
*/
|
|
2365
|
+
|
|
2336
2366
|
/**
|
|
2337
2367
|
* Default (empty) signature
|
|
2338
2368
|
*
|
|
@@ -2978,8 +3008,7 @@ class Transaction {
|
|
|
2978
3008
|
let signatures = [];
|
|
2979
3009
|
|
|
2980
3010
|
for (let i = 0; i < signatureCount; i++) {
|
|
2981
|
-
const signature = byteArray
|
|
2982
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
3011
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2983
3012
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2984
3013
|
}
|
|
2985
3014
|
|
|
@@ -9361,10 +9390,8 @@ class ValidatorInfo {
|
|
|
9361
9390
|
const configKeys = [];
|
|
9362
9391
|
|
|
9363
9392
|
for (let i = 0; i < 2; i++) {
|
|
9364
|
-
const publicKey = new PublicKey(byteArray
|
|
9365
|
-
|
|
9366
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9367
|
-
byteArray = byteArray.slice(1);
|
|
9393
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9394
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9368
9395
|
configKeys.push({
|
|
9369
9396
|
publicKey,
|
|
9370
9397
|
isSigner
|