@solana/web3.js 1.11.0 → 1.11.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 +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 +46 -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 +27 -27
- 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
|
@@ -1270,6 +1270,36 @@ function encodeLength(bytes, len) {
|
|
|
1270
1270
|
}
|
|
1271
1271
|
}
|
|
1272
1272
|
|
|
1273
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1274
|
+
/**
|
|
1275
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1276
|
+
*/
|
|
1277
|
+
|
|
1278
|
+
function guardedShift(byteArray) {
|
|
1279
|
+
if (byteArray.length === 0) {
|
|
1280
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
return byteArray.shift();
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1287
|
+
* the array.
|
|
1288
|
+
*/
|
|
1289
|
+
|
|
1290
|
+
function guardedSplice(byteArray, ...args) {
|
|
1291
|
+
var _args$;
|
|
1292
|
+
|
|
1293
|
+
const [start] = args;
|
|
1294
|
+
|
|
1295
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1296
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1297
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
return byteArray.splice(...args);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1273
1303
|
/**
|
|
1274
1304
|
* The message header, identifying signed and read-only account
|
|
1275
1305
|
*/
|
|
@@ -1346,32 +1376,28 @@ class Message {
|
|
|
1346
1376
|
static from(buffer) {
|
|
1347
1377
|
// Slice up wire data
|
|
1348
1378
|
let byteArray = [...buffer];
|
|
1349
|
-
const numRequiredSignatures = byteArray
|
|
1350
|
-
const numReadonlySignedAccounts = byteArray
|
|
1351
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1379
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1380
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1381
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1352
1382
|
const accountCount = decodeLength(byteArray);
|
|
1353
1383
|
let accountKeys = [];
|
|
1354
1384
|
|
|
1355
1385
|
for (let i = 0; i < accountCount; i++) {
|
|
1356
|
-
const account = byteArray
|
|
1357
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1386
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1358
1387
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1359
1388
|
}
|
|
1360
1389
|
|
|
1361
|
-
const recentBlockhash = byteArray
|
|
1362
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1390
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1363
1391
|
const instructionCount = decodeLength(byteArray);
|
|
1364
1392
|
let instructions = [];
|
|
1365
1393
|
|
|
1366
1394
|
for (let i = 0; i < instructionCount; i++) {
|
|
1367
|
-
const programIdIndex = byteArray
|
|
1395
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1368
1396
|
const accountCount = decodeLength(byteArray);
|
|
1369
|
-
const accounts = byteArray
|
|
1370
|
-
byteArray = byteArray.slice(accountCount);
|
|
1397
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1371
1398
|
const dataLength = decodeLength(byteArray);
|
|
1372
|
-
const dataSlice = byteArray
|
|
1399
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1373
1400
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1374
|
-
byteArray = byteArray.slice(dataLength);
|
|
1375
1401
|
instructions.push({
|
|
1376
1402
|
programIdIndex,
|
|
1377
1403
|
accounts,
|
|
@@ -1394,6 +1420,10 @@ class Message {
|
|
|
1394
1420
|
|
|
1395
1421
|
}
|
|
1396
1422
|
|
|
1423
|
+
/**
|
|
1424
|
+
* Transaction signature as base-58 encoded string
|
|
1425
|
+
*/
|
|
1426
|
+
|
|
1397
1427
|
/**
|
|
1398
1428
|
* Default (empty) signature
|
|
1399
1429
|
*
|
|
@@ -1977,8 +2007,7 @@ class Transaction {
|
|
|
1977
2007
|
let signatures = [];
|
|
1978
2008
|
|
|
1979
2009
|
for (let i = 0; i < signatureCount; i++) {
|
|
1980
|
-
const signature = byteArray
|
|
1981
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2010
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1982
2011
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1983
2012
|
}
|
|
1984
2013
|
|
|
@@ -8061,10 +8090,8 @@ class ValidatorInfo {
|
|
|
8061
8090
|
const configKeys = [];
|
|
8062
8091
|
|
|
8063
8092
|
for (let i = 0; i < 2; i++) {
|
|
8064
|
-
const publicKey = new PublicKey(byteArray
|
|
8065
|
-
|
|
8066
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8067
|
-
byteArray = byteArray.slice(1);
|
|
8093
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8094
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8068
8095
|
configKeys.push({
|
|
8069
8096
|
publicKey,
|
|
8070
8097
|
isSigner
|