@solana/web3.js 1.5.0 → 1.5.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.esm.js +41 -18
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +41 -18
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +41 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +42 -25
- 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 +28 -28
- 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
|
@@ -1255,6 +1255,36 @@ function encodeLength(bytes, len) {
|
|
|
1255
1255
|
}
|
|
1256
1256
|
}
|
|
1257
1257
|
|
|
1258
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1259
|
+
/**
|
|
1260
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1261
|
+
*/
|
|
1262
|
+
|
|
1263
|
+
function guardedShift(byteArray) {
|
|
1264
|
+
if (byteArray.length === 0) {
|
|
1265
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
return byteArray.shift();
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1272
|
+
* the array.
|
|
1273
|
+
*/
|
|
1274
|
+
|
|
1275
|
+
function guardedSplice(byteArray, ...args) {
|
|
1276
|
+
var _args$;
|
|
1277
|
+
|
|
1278
|
+
const [start] = args;
|
|
1279
|
+
|
|
1280
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1281
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1282
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return byteArray.splice(...args);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1258
1288
|
/**
|
|
1259
1289
|
* The message header, identifying signed and read-only account
|
|
1260
1290
|
*/
|
|
@@ -1339,32 +1369,28 @@ class Message {
|
|
|
1339
1369
|
static from(buffer) {
|
|
1340
1370
|
// Slice up wire data
|
|
1341
1371
|
let byteArray = [...buffer];
|
|
1342
|
-
const numRequiredSignatures = byteArray
|
|
1343
|
-
const numReadonlySignedAccounts = byteArray
|
|
1344
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1372
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1373
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1374
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1345
1375
|
const accountCount = decodeLength(byteArray);
|
|
1346
1376
|
let accountKeys = [];
|
|
1347
1377
|
|
|
1348
1378
|
for (let i = 0; i < accountCount; i++) {
|
|
1349
|
-
const account = byteArray
|
|
1350
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1379
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1351
1380
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1352
1381
|
}
|
|
1353
1382
|
|
|
1354
|
-
const recentBlockhash = byteArray
|
|
1355
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1383
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1356
1384
|
const instructionCount = decodeLength(byteArray);
|
|
1357
1385
|
let instructions = [];
|
|
1358
1386
|
|
|
1359
1387
|
for (let i = 0; i < instructionCount; i++) {
|
|
1360
|
-
const programIdIndex = byteArray
|
|
1388
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1361
1389
|
const accountCount = decodeLength(byteArray);
|
|
1362
|
-
const accounts = byteArray
|
|
1363
|
-
byteArray = byteArray.slice(accountCount);
|
|
1390
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1364
1391
|
const dataLength = decodeLength(byteArray);
|
|
1365
|
-
const dataSlice = byteArray
|
|
1392
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1366
1393
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1367
|
-
byteArray = byteArray.slice(dataLength);
|
|
1368
1394
|
instructions.push({
|
|
1369
1395
|
programIdIndex,
|
|
1370
1396
|
accounts,
|
|
@@ -1984,8 +2010,7 @@ class Transaction {
|
|
|
1984
2010
|
let signatures = [];
|
|
1985
2011
|
|
|
1986
2012
|
for (let i = 0; i < signatureCount; i++) {
|
|
1987
|
-
const signature = byteArray
|
|
1988
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2013
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1989
2014
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1990
2015
|
}
|
|
1991
2016
|
|
|
@@ -7814,10 +7839,8 @@ class ValidatorInfo {
|
|
|
7814
7839
|
const configKeys = [];
|
|
7815
7840
|
|
|
7816
7841
|
for (let i = 0; i < 2; i++) {
|
|
7817
|
-
const publicKey = new PublicKey(byteArray
|
|
7818
|
-
|
|
7819
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
7820
|
-
byteArray = byteArray.slice(1);
|
|
7842
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
7843
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
7821
7844
|
configKeys.push({
|
|
7822
7845
|
publicKey,
|
|
7823
7846
|
isSigner
|