@solana/web3.js 1.42.0 → 1.42.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.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 +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -2201,6 +2201,36 @@ function encodeLength(bytes, len) {
|
|
|
2201
2201
|
}
|
|
2202
2202
|
}
|
|
2203
2203
|
|
|
2204
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2205
|
+
/**
|
|
2206
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2207
|
+
*/
|
|
2208
|
+
|
|
2209
|
+
function guardedShift(byteArray) {
|
|
2210
|
+
if (byteArray.length === 0) {
|
|
2211
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
return byteArray.shift();
|
|
2215
|
+
}
|
|
2216
|
+
/**
|
|
2217
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2218
|
+
* the array.
|
|
2219
|
+
*/
|
|
2220
|
+
|
|
2221
|
+
function guardedSplice(byteArray, ...args) {
|
|
2222
|
+
var _args$;
|
|
2223
|
+
|
|
2224
|
+
const [start] = args;
|
|
2225
|
+
|
|
2226
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2227
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2228
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
return byteArray.splice(...args);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2204
2234
|
/**
|
|
2205
2235
|
* The message header, identifying signed and read-only account
|
|
2206
2236
|
*/
|
|
@@ -2299,32 +2329,28 @@ class Message {
|
|
|
2299
2329
|
static from(buffer) {
|
|
2300
2330
|
// Slice up wire data
|
|
2301
2331
|
let byteArray = [...buffer];
|
|
2302
|
-
const numRequiredSignatures = byteArray
|
|
2303
|
-
const numReadonlySignedAccounts = byteArray
|
|
2304
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2332
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2333
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2334
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2305
2335
|
const accountCount = decodeLength(byteArray);
|
|
2306
2336
|
let accountKeys = [];
|
|
2307
2337
|
|
|
2308
2338
|
for (let i = 0; i < accountCount; i++) {
|
|
2309
|
-
const account = byteArray
|
|
2310
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2339
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2311
2340
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2312
2341
|
}
|
|
2313
2342
|
|
|
2314
|
-
const recentBlockhash = byteArray
|
|
2315
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2343
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2316
2344
|
const instructionCount = decodeLength(byteArray);
|
|
2317
2345
|
let instructions = [];
|
|
2318
2346
|
|
|
2319
2347
|
for (let i = 0; i < instructionCount; i++) {
|
|
2320
|
-
const programIdIndex = byteArray
|
|
2348
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2321
2349
|
const accountCount = decodeLength(byteArray);
|
|
2322
|
-
const accounts = byteArray
|
|
2323
|
-
byteArray = byteArray.slice(accountCount);
|
|
2350
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2324
2351
|
const dataLength = decodeLength(byteArray);
|
|
2325
|
-
const dataSlice = byteArray
|
|
2352
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2326
2353
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2327
|
-
byteArray = byteArray.slice(dataLength);
|
|
2328
2354
|
instructions.push({
|
|
2329
2355
|
programIdIndex,
|
|
2330
2356
|
accounts,
|
|
@@ -2353,6 +2379,10 @@ function assert (condition, message) {
|
|
|
2353
2379
|
}
|
|
2354
2380
|
}
|
|
2355
2381
|
|
|
2382
|
+
/**
|
|
2383
|
+
* Transaction signature as base-58 encoded string
|
|
2384
|
+
*/
|
|
2385
|
+
|
|
2356
2386
|
let TransactionStatus;
|
|
2357
2387
|
/**
|
|
2358
2388
|
* Default (empty) signature
|
|
@@ -3003,8 +3033,7 @@ class Transaction {
|
|
|
3003
3033
|
let signatures = [];
|
|
3004
3034
|
|
|
3005
3035
|
for (let i = 0; i < signatureCount; i++) {
|
|
3006
|
-
const signature = byteArray
|
|
3007
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
3036
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
3008
3037
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
3009
3038
|
}
|
|
3010
3039
|
|
|
@@ -9217,10 +9246,8 @@ class ValidatorInfo {
|
|
|
9217
9246
|
const configKeys = [];
|
|
9218
9247
|
|
|
9219
9248
|
for (let i = 0; i < 2; i++) {
|
|
9220
|
-
const publicKey = new PublicKey(byteArray
|
|
9221
|
-
|
|
9222
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9223
|
-
byteArray = byteArray.slice(1);
|
|
9249
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9250
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9224
9251
|
configKeys.push({
|
|
9225
9252
|
publicKey,
|
|
9226
9253
|
isSigner
|