@solana/web3.js 1.24.2 → 1.24.3
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 +3 -3
- 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.esm.js
CHANGED
|
@@ -439,6 +439,36 @@ function encodeLength(bytes, len) {
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
443
|
+
/**
|
|
444
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
function guardedShift(byteArray) {
|
|
448
|
+
if (byteArray.length === 0) {
|
|
449
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return byteArray.shift();
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
456
|
+
* the array.
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
function guardedSplice(byteArray, ...args) {
|
|
460
|
+
var _args$;
|
|
461
|
+
|
|
462
|
+
const [start] = args;
|
|
463
|
+
|
|
464
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
465
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
466
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return byteArray.splice(...args);
|
|
470
|
+
}
|
|
471
|
+
|
|
442
472
|
/**
|
|
443
473
|
* The message header, identifying signed and read-only account
|
|
444
474
|
*/
|
|
@@ -523,32 +553,28 @@ class Message {
|
|
|
523
553
|
static from(buffer) {
|
|
524
554
|
// Slice up wire data
|
|
525
555
|
let byteArray = [...buffer];
|
|
526
|
-
const numRequiredSignatures = byteArray
|
|
527
|
-
const numReadonlySignedAccounts = byteArray
|
|
528
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
556
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
557
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
558
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
529
559
|
const accountCount = decodeLength(byteArray);
|
|
530
560
|
let accountKeys = [];
|
|
531
561
|
|
|
532
562
|
for (let i = 0; i < accountCount; i++) {
|
|
533
|
-
const account = byteArray
|
|
534
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
563
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
535
564
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
536
565
|
}
|
|
537
566
|
|
|
538
|
-
const recentBlockhash = byteArray
|
|
539
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
567
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
540
568
|
const instructionCount = decodeLength(byteArray);
|
|
541
569
|
let instructions = [];
|
|
542
570
|
|
|
543
571
|
for (let i = 0; i < instructionCount; i++) {
|
|
544
|
-
const programIdIndex = byteArray
|
|
572
|
+
const programIdIndex = guardedShift(byteArray);
|
|
545
573
|
const accountCount = decodeLength(byteArray);
|
|
546
|
-
const accounts = byteArray
|
|
547
|
-
byteArray = byteArray.slice(accountCount);
|
|
574
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
548
575
|
const dataLength = decodeLength(byteArray);
|
|
549
|
-
const dataSlice = byteArray
|
|
576
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
550
577
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
551
|
-
byteArray = byteArray.slice(dataLength);
|
|
552
578
|
instructions.push({
|
|
553
579
|
programIdIndex,
|
|
554
580
|
accounts,
|
|
@@ -577,6 +603,10 @@ function assert (condition, message) {
|
|
|
577
603
|
}
|
|
578
604
|
}
|
|
579
605
|
|
|
606
|
+
/**
|
|
607
|
+
* Transaction signature as base-58 encoded string
|
|
608
|
+
*/
|
|
609
|
+
|
|
580
610
|
/**
|
|
581
611
|
* Default (empty) signature
|
|
582
612
|
*
|
|
@@ -1170,8 +1200,7 @@ class Transaction {
|
|
|
1170
1200
|
let signatures = [];
|
|
1171
1201
|
|
|
1172
1202
|
for (let i = 0; i < signatureCount; i++) {
|
|
1173
|
-
const signature = byteArray
|
|
1174
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1203
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1175
1204
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1176
1205
|
}
|
|
1177
1206
|
|
|
@@ -6569,10 +6598,8 @@ class ValidatorInfo {
|
|
|
6569
6598
|
const configKeys = [];
|
|
6570
6599
|
|
|
6571
6600
|
for (let i = 0; i < 2; i++) {
|
|
6572
|
-
const publicKey = new PublicKey(byteArray
|
|
6573
|
-
|
|
6574
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6575
|
-
byteArray = byteArray.slice(1);
|
|
6601
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6602
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6576
6603
|
configKeys.push({
|
|
6577
6604
|
publicKey,
|
|
6578
6605
|
isSigner
|