@solana/web3.js 1.18.0 → 1.18.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
|
@@ -1329,6 +1329,36 @@ function encodeLength(bytes, len) {
|
|
|
1329
1329
|
}
|
|
1330
1330
|
}
|
|
1331
1331
|
|
|
1332
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1333
|
+
/**
|
|
1334
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1335
|
+
*/
|
|
1336
|
+
|
|
1337
|
+
function guardedShift(byteArray) {
|
|
1338
|
+
if (byteArray.length === 0) {
|
|
1339
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
return byteArray.shift();
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1346
|
+
* the array.
|
|
1347
|
+
*/
|
|
1348
|
+
|
|
1349
|
+
function guardedSplice(byteArray, ...args) {
|
|
1350
|
+
var _args$;
|
|
1351
|
+
|
|
1352
|
+
const [start] = args;
|
|
1353
|
+
|
|
1354
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1355
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1356
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
return byteArray.splice(...args);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1332
1362
|
/**
|
|
1333
1363
|
* The message header, identifying signed and read-only account
|
|
1334
1364
|
*/
|
|
@@ -1413,32 +1443,28 @@ class Message {
|
|
|
1413
1443
|
static from(buffer) {
|
|
1414
1444
|
// Slice up wire data
|
|
1415
1445
|
let byteArray = [...buffer];
|
|
1416
|
-
const numRequiredSignatures = byteArray
|
|
1417
|
-
const numReadonlySignedAccounts = byteArray
|
|
1418
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1446
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1447
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1448
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1419
1449
|
const accountCount = decodeLength(byteArray);
|
|
1420
1450
|
let accountKeys = [];
|
|
1421
1451
|
|
|
1422
1452
|
for (let i = 0; i < accountCount; i++) {
|
|
1423
|
-
const account = byteArray
|
|
1424
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1453
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1425
1454
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1426
1455
|
}
|
|
1427
1456
|
|
|
1428
|
-
const recentBlockhash = byteArray
|
|
1429
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1457
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1430
1458
|
const instructionCount = decodeLength(byteArray);
|
|
1431
1459
|
let instructions = [];
|
|
1432
1460
|
|
|
1433
1461
|
for (let i = 0; i < instructionCount; i++) {
|
|
1434
|
-
const programIdIndex = byteArray
|
|
1462
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1435
1463
|
const accountCount = decodeLength(byteArray);
|
|
1436
|
-
const accounts = byteArray
|
|
1437
|
-
byteArray = byteArray.slice(accountCount);
|
|
1464
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1438
1465
|
const dataLength = decodeLength(byteArray);
|
|
1439
|
-
const dataSlice = byteArray
|
|
1466
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1440
1467
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1441
|
-
byteArray = byteArray.slice(dataLength);
|
|
1442
1468
|
instructions.push({
|
|
1443
1469
|
programIdIndex,
|
|
1444
1470
|
accounts,
|
|
@@ -1461,6 +1487,10 @@ class Message {
|
|
|
1461
1487
|
|
|
1462
1488
|
}
|
|
1463
1489
|
|
|
1490
|
+
/**
|
|
1491
|
+
* Transaction signature as base-58 encoded string
|
|
1492
|
+
*/
|
|
1493
|
+
|
|
1464
1494
|
/**
|
|
1465
1495
|
* Default (empty) signature
|
|
1466
1496
|
*
|
|
@@ -2054,8 +2084,7 @@ class Transaction {
|
|
|
2054
2084
|
let signatures = [];
|
|
2055
2085
|
|
|
2056
2086
|
for (let i = 0; i < signatureCount; i++) {
|
|
2057
|
-
const signature = byteArray
|
|
2058
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2087
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2059
2088
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2060
2089
|
}
|
|
2061
2090
|
|
|
@@ -8357,10 +8386,8 @@ class ValidatorInfo {
|
|
|
8357
8386
|
const configKeys = [];
|
|
8358
8387
|
|
|
8359
8388
|
for (let i = 0; i < 2; i++) {
|
|
8360
|
-
const publicKey = new PublicKey(byteArray
|
|
8361
|
-
|
|
8362
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8363
|
-
byteArray = byteArray.slice(1);
|
|
8389
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8390
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8364
8391
|
configKeys.push({
|
|
8365
8392
|
publicKey,
|
|
8366
8393
|
isSigner
|