@solana/web3.js 1.9.0 → 1.9.2
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/README.md +1 -1
- 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.d.ts +6 -4
- 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/module.flow.js +12 -4
- package/package.json +30 -31
- package/src/connection.ts +6 -4
- 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/README.md
CHANGED
package/lib/index.browser.esm.js
CHANGED
|
@@ -1264,6 +1264,36 @@ function encodeLength(bytes, len) {
|
|
|
1264
1264
|
}
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
1267
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1268
|
+
/**
|
|
1269
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1270
|
+
*/
|
|
1271
|
+
|
|
1272
|
+
function guardedShift(byteArray) {
|
|
1273
|
+
if (byteArray.length === 0) {
|
|
1274
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return byteArray.shift();
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1281
|
+
* the array.
|
|
1282
|
+
*/
|
|
1283
|
+
|
|
1284
|
+
function guardedSplice(byteArray, ...args) {
|
|
1285
|
+
var _args$;
|
|
1286
|
+
|
|
1287
|
+
const [start] = args;
|
|
1288
|
+
|
|
1289
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1290
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1291
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
return byteArray.splice(...args);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1267
1297
|
/**
|
|
1268
1298
|
* The message header, identifying signed and read-only account
|
|
1269
1299
|
*/
|
|
@@ -1340,32 +1370,28 @@ class Message {
|
|
|
1340
1370
|
static from(buffer) {
|
|
1341
1371
|
// Slice up wire data
|
|
1342
1372
|
let byteArray = [...buffer];
|
|
1343
|
-
const numRequiredSignatures = byteArray
|
|
1344
|
-
const numReadonlySignedAccounts = byteArray
|
|
1345
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1373
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1374
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1375
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1346
1376
|
const accountCount = decodeLength(byteArray);
|
|
1347
1377
|
let accountKeys = [];
|
|
1348
1378
|
|
|
1349
1379
|
for (let i = 0; i < accountCount; i++) {
|
|
1350
|
-
const account = byteArray
|
|
1351
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1380
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1352
1381
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1353
1382
|
}
|
|
1354
1383
|
|
|
1355
|
-
const recentBlockhash = byteArray
|
|
1356
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1384
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1357
1385
|
const instructionCount = decodeLength(byteArray);
|
|
1358
1386
|
let instructions = [];
|
|
1359
1387
|
|
|
1360
1388
|
for (let i = 0; i < instructionCount; i++) {
|
|
1361
|
-
const programIdIndex = byteArray
|
|
1389
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1362
1390
|
const accountCount = decodeLength(byteArray);
|
|
1363
|
-
const accounts = byteArray
|
|
1364
|
-
byteArray = byteArray.slice(accountCount);
|
|
1391
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1365
1392
|
const dataLength = decodeLength(byteArray);
|
|
1366
|
-
const dataSlice = byteArray
|
|
1393
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1367
1394
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1368
|
-
byteArray = byteArray.slice(dataLength);
|
|
1369
1395
|
instructions.push({
|
|
1370
1396
|
programIdIndex,
|
|
1371
1397
|
accounts,
|
|
@@ -1975,8 +2001,7 @@ class Transaction {
|
|
|
1975
2001
|
let signatures = [];
|
|
1976
2002
|
|
|
1977
2003
|
for (let i = 0; i < signatureCount; i++) {
|
|
1978
|
-
const signature = byteArray
|
|
1979
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2004
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1980
2005
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1981
2006
|
}
|
|
1982
2007
|
|
|
@@ -7975,10 +8000,8 @@ class ValidatorInfo {
|
|
|
7975
8000
|
const configKeys = [];
|
|
7976
8001
|
|
|
7977
8002
|
for (let i = 0; i < 2; i++) {
|
|
7978
|
-
const publicKey = new PublicKey(byteArray
|
|
7979
|
-
|
|
7980
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
7981
|
-
byteArray = byteArray.slice(1);
|
|
8003
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8004
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
7982
8005
|
configKeys.push({
|
|
7983
8006
|
publicKey,
|
|
7984
8007
|
isSigner
|