@solana/web3.js 1.28.0 → 1.28.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 +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.cjs.js
CHANGED
|
@@ -479,6 +479,36 @@ function encodeLength(bytes, len) {
|
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
483
|
+
/**
|
|
484
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
485
|
+
*/
|
|
486
|
+
|
|
487
|
+
function guardedShift(byteArray) {
|
|
488
|
+
if (byteArray.length === 0) {
|
|
489
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return byteArray.shift();
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
496
|
+
* the array.
|
|
497
|
+
*/
|
|
498
|
+
|
|
499
|
+
function guardedSplice(byteArray, ...args) {
|
|
500
|
+
var _args$;
|
|
501
|
+
|
|
502
|
+
const [start] = args;
|
|
503
|
+
|
|
504
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
505
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
506
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return byteArray.splice(...args);
|
|
510
|
+
}
|
|
511
|
+
|
|
482
512
|
/**
|
|
483
513
|
* The message header, identifying signed and read-only account
|
|
484
514
|
*/
|
|
@@ -582,32 +612,28 @@ class Message {
|
|
|
582
612
|
static from(buffer$1) {
|
|
583
613
|
// Slice up wire data
|
|
584
614
|
let byteArray = [...buffer$1];
|
|
585
|
-
const numRequiredSignatures = byteArray
|
|
586
|
-
const numReadonlySignedAccounts = byteArray
|
|
587
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
615
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
616
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
617
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
588
618
|
const accountCount = decodeLength(byteArray);
|
|
589
619
|
let accountKeys = [];
|
|
590
620
|
|
|
591
621
|
for (let i = 0; i < accountCount; i++) {
|
|
592
|
-
const account = byteArray
|
|
593
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
622
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
594
623
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
595
624
|
}
|
|
596
625
|
|
|
597
|
-
const recentBlockhash = byteArray
|
|
598
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
626
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
599
627
|
const instructionCount = decodeLength(byteArray);
|
|
600
628
|
let instructions = [];
|
|
601
629
|
|
|
602
630
|
for (let i = 0; i < instructionCount; i++) {
|
|
603
|
-
const programIdIndex = byteArray
|
|
631
|
+
const programIdIndex = guardedShift(byteArray);
|
|
604
632
|
const accountCount = decodeLength(byteArray);
|
|
605
|
-
const accounts = byteArray
|
|
606
|
-
byteArray = byteArray.slice(accountCount);
|
|
633
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
607
634
|
const dataLength = decodeLength(byteArray);
|
|
608
|
-
const dataSlice = byteArray
|
|
635
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
609
636
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
610
|
-
byteArray = byteArray.slice(dataLength);
|
|
611
637
|
instructions.push({
|
|
612
638
|
programIdIndex,
|
|
613
639
|
accounts,
|
|
@@ -636,6 +662,10 @@ function assert (condition, message) {
|
|
|
636
662
|
}
|
|
637
663
|
}
|
|
638
664
|
|
|
665
|
+
/**
|
|
666
|
+
* Transaction signature as base-58 encoded string
|
|
667
|
+
*/
|
|
668
|
+
|
|
639
669
|
/**
|
|
640
670
|
* Default (empty) signature
|
|
641
671
|
*
|
|
@@ -1229,8 +1259,7 @@ class Transaction {
|
|
|
1229
1259
|
let signatures = [];
|
|
1230
1260
|
|
|
1231
1261
|
for (let i = 0; i < signatureCount; i++) {
|
|
1232
|
-
const signature = byteArray
|
|
1233
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1262
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1234
1263
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1235
1264
|
}
|
|
1236
1265
|
|
|
@@ -6764,10 +6793,8 @@ class ValidatorInfo {
|
|
|
6764
6793
|
const configKeys = [];
|
|
6765
6794
|
|
|
6766
6795
|
for (let i = 0; i < 2; i++) {
|
|
6767
|
-
const publicKey = new PublicKey(byteArray
|
|
6768
|
-
|
|
6769
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6770
|
-
byteArray = byteArray.slice(1);
|
|
6796
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6797
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6771
6798
|
configKeys.push({
|
|
6772
6799
|
publicKey,
|
|
6773
6800
|
isSigner
|