@solana/web3.js 1.15.0 → 1.15.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
|
@@ -1321,6 +1321,36 @@ function encodeLength(bytes, len) {
|
|
|
1321
1321
|
}
|
|
1322
1322
|
}
|
|
1323
1323
|
|
|
1324
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1325
|
+
/**
|
|
1326
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1327
|
+
*/
|
|
1328
|
+
|
|
1329
|
+
function guardedShift(byteArray) {
|
|
1330
|
+
if (byteArray.length === 0) {
|
|
1331
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
return byteArray.shift();
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1338
|
+
* the array.
|
|
1339
|
+
*/
|
|
1340
|
+
|
|
1341
|
+
function guardedSplice(byteArray, ...args) {
|
|
1342
|
+
var _args$;
|
|
1343
|
+
|
|
1344
|
+
const [start] = args;
|
|
1345
|
+
|
|
1346
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1347
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1348
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
return byteArray.splice(...args);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1324
1354
|
/**
|
|
1325
1355
|
* The message header, identifying signed and read-only account
|
|
1326
1356
|
*/
|
|
@@ -1397,32 +1427,28 @@ class Message {
|
|
|
1397
1427
|
static from(buffer) {
|
|
1398
1428
|
// Slice up wire data
|
|
1399
1429
|
let byteArray = [...buffer];
|
|
1400
|
-
const numRequiredSignatures = byteArray
|
|
1401
|
-
const numReadonlySignedAccounts = byteArray
|
|
1402
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1430
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1431
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1432
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1403
1433
|
const accountCount = decodeLength(byteArray);
|
|
1404
1434
|
let accountKeys = [];
|
|
1405
1435
|
|
|
1406
1436
|
for (let i = 0; i < accountCount; i++) {
|
|
1407
|
-
const account = byteArray
|
|
1408
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1437
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1409
1438
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1410
1439
|
}
|
|
1411
1440
|
|
|
1412
|
-
const recentBlockhash = byteArray
|
|
1413
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1441
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1414
1442
|
const instructionCount = decodeLength(byteArray);
|
|
1415
1443
|
let instructions = [];
|
|
1416
1444
|
|
|
1417
1445
|
for (let i = 0; i < instructionCount; i++) {
|
|
1418
|
-
const programIdIndex = byteArray
|
|
1446
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1419
1447
|
const accountCount = decodeLength(byteArray);
|
|
1420
|
-
const accounts = byteArray
|
|
1421
|
-
byteArray = byteArray.slice(accountCount);
|
|
1448
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1422
1449
|
const dataLength = decodeLength(byteArray);
|
|
1423
|
-
const dataSlice = byteArray
|
|
1450
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1424
1451
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1425
|
-
byteArray = byteArray.slice(dataLength);
|
|
1426
1452
|
instructions.push({
|
|
1427
1453
|
programIdIndex,
|
|
1428
1454
|
accounts,
|
|
@@ -1445,6 +1471,10 @@ class Message {
|
|
|
1445
1471
|
|
|
1446
1472
|
}
|
|
1447
1473
|
|
|
1474
|
+
/**
|
|
1475
|
+
* Transaction signature as base-58 encoded string
|
|
1476
|
+
*/
|
|
1477
|
+
|
|
1448
1478
|
/**
|
|
1449
1479
|
* Default (empty) signature
|
|
1450
1480
|
*
|
|
@@ -2028,8 +2058,7 @@ class Transaction {
|
|
|
2028
2058
|
let signatures = [];
|
|
2029
2059
|
|
|
2030
2060
|
for (let i = 0; i < signatureCount; i++) {
|
|
2031
|
-
const signature = byteArray
|
|
2032
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2061
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2033
2062
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2034
2063
|
}
|
|
2035
2064
|
|
|
@@ -8181,10 +8210,8 @@ class ValidatorInfo {
|
|
|
8181
8210
|
const configKeys = [];
|
|
8182
8211
|
|
|
8183
8212
|
for (let i = 0; i < 2; i++) {
|
|
8184
|
-
const publicKey = new PublicKey(byteArray
|
|
8185
|
-
|
|
8186
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8187
|
-
byteArray = byteArray.slice(1);
|
|
8213
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8214
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8188
8215
|
configKeys.push({
|
|
8189
8216
|
publicKey,
|
|
8190
8217
|
isSigner
|