@solana/web3.js 1.54.1 → 1.54.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/lib/index.browser.cjs.js +63 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +63 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +63 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +63 -32
- 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/lib/index.native.js +63 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/transaction/legacy.ts +2 -2
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -534,6 +534,44 @@ function encodeLength(bytes, len) {
|
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
538
|
+
/**
|
|
539
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
function guardedShift(byteArray) {
|
|
543
|
+
if (byteArray.length === 0) {
|
|
544
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return byteArray.shift();
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
551
|
+
* the array.
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
function guardedSplice(byteArray, ...args) {
|
|
555
|
+
var _args$;
|
|
556
|
+
|
|
557
|
+
const [start] = args;
|
|
558
|
+
|
|
559
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
560
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
561
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return byteArray.splice(...args);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* An instruction to execute by a program
|
|
569
|
+
*
|
|
570
|
+
* @property {number} programIdIndex
|
|
571
|
+
* @property {number[]} accounts
|
|
572
|
+
* @property {string} data
|
|
573
|
+
*/
|
|
574
|
+
|
|
537
575
|
/**
|
|
538
576
|
* List of instructions to be processed atomically
|
|
539
577
|
*/
|
|
@@ -646,37 +684,33 @@ class Message {
|
|
|
646
684
|
static from(buffer) {
|
|
647
685
|
// Slice up wire data
|
|
648
686
|
let byteArray = [...buffer];
|
|
649
|
-
const numRequiredSignatures = byteArray
|
|
687
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
650
688
|
|
|
651
689
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
652
690
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
653
691
|
}
|
|
654
692
|
|
|
655
|
-
const numReadonlySignedAccounts = byteArray
|
|
656
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
693
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
694
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
657
695
|
const accountCount = decodeLength(byteArray);
|
|
658
696
|
let accountKeys = [];
|
|
659
697
|
|
|
660
698
|
for (let i = 0; i < accountCount; i++) {
|
|
661
|
-
const account = byteArray
|
|
662
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
699
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
663
700
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
664
701
|
}
|
|
665
702
|
|
|
666
|
-
const recentBlockhash = byteArray
|
|
667
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
703
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
668
704
|
const instructionCount = decodeLength(byteArray);
|
|
669
705
|
let instructions = [];
|
|
670
706
|
|
|
671
707
|
for (let i = 0; i < instructionCount; i++) {
|
|
672
|
-
const programIdIndex = byteArray
|
|
708
|
+
const programIdIndex = guardedShift(byteArray);
|
|
673
709
|
const accountCount = decodeLength(byteArray);
|
|
674
|
-
const accounts = byteArray
|
|
675
|
-
byteArray = byteArray.slice(accountCount);
|
|
710
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
676
711
|
const dataLength = decodeLength(byteArray);
|
|
677
|
-
const dataSlice = byteArray
|
|
712
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
678
713
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
679
|
-
byteArray = byteArray.slice(dataLength);
|
|
680
714
|
instructions.push({
|
|
681
715
|
programIdIndex,
|
|
682
716
|
accounts,
|
|
@@ -799,33 +833,33 @@ class MessageV0 {
|
|
|
799
833
|
|
|
800
834
|
static deserialize(serializedMessage) {
|
|
801
835
|
let byteArray = [...serializedMessage];
|
|
802
|
-
const prefix = byteArray
|
|
836
|
+
const prefix = guardedShift(byteArray);
|
|
803
837
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
804
838
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
805
839
|
const version = maskedPrefix;
|
|
806
840
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
807
841
|
const header = {
|
|
808
|
-
numRequiredSignatures: byteArray
|
|
809
|
-
numReadonlySignedAccounts: byteArray
|
|
810
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
842
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
843
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
844
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
811
845
|
};
|
|
812
846
|
const staticAccountKeys = [];
|
|
813
847
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
814
848
|
|
|
815
849
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
816
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
850
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
817
851
|
}
|
|
818
852
|
|
|
819
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
853
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
820
854
|
const instructionCount = decodeLength(byteArray);
|
|
821
855
|
const compiledInstructions = [];
|
|
822
856
|
|
|
823
857
|
for (let i = 0; i < instructionCount; i++) {
|
|
824
|
-
const programIdIndex = byteArray
|
|
858
|
+
const programIdIndex = guardedShift(byteArray);
|
|
825
859
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
826
|
-
const accountKeyIndexes = byteArray
|
|
860
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
827
861
|
const dataLength = decodeLength(byteArray);
|
|
828
|
-
const data = new Uint8Array(byteArray
|
|
862
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
829
863
|
compiledInstructions.push({
|
|
830
864
|
programIdIndex,
|
|
831
865
|
accountKeyIndexes,
|
|
@@ -837,11 +871,11 @@ class MessageV0 {
|
|
|
837
871
|
const addressTableLookups = [];
|
|
838
872
|
|
|
839
873
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
840
|
-
const accountKey = new PublicKey(byteArray
|
|
874
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
841
875
|
const writableIndexesLength = decodeLength(byteArray);
|
|
842
|
-
const writableIndexes = byteArray
|
|
876
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
843
877
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
844
|
-
const readonlyIndexes = byteArray
|
|
878
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
845
879
|
addressTableLookups.push({
|
|
846
880
|
accountKey,
|
|
847
881
|
writableIndexes,
|
|
@@ -1564,8 +1598,7 @@ class Transaction {
|
|
|
1564
1598
|
let signatures = [];
|
|
1565
1599
|
|
|
1566
1600
|
for (let i = 0; i < signatureCount; i++) {
|
|
1567
|
-
const signature = byteArray
|
|
1568
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1601
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1569
1602
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1570
1603
|
}
|
|
1571
1604
|
|
|
@@ -1657,7 +1690,7 @@ class VersionedTransaction {
|
|
|
1657
1690
|
const signaturesLength = decodeLength(byteArray);
|
|
1658
1691
|
|
|
1659
1692
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1660
|
-
signatures.push(new Uint8Array(byteArray
|
|
1693
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1661
1694
|
}
|
|
1662
1695
|
|
|
1663
1696
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4081,7 +4114,7 @@ const LogsNotificationResult = type({
|
|
|
4081
4114
|
|
|
4082
4115
|
/** @internal */
|
|
4083
4116
|
const COMMON_HTTP_HEADERS = {
|
|
4084
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4117
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.54.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4085
4118
|
};
|
|
4086
4119
|
/**
|
|
4087
4120
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8835,10 +8868,8 @@ class ValidatorInfo {
|
|
|
8835
8868
|
const configKeys = [];
|
|
8836
8869
|
|
|
8837
8870
|
for (let i = 0; i < 2; i++) {
|
|
8838
|
-
const publicKey = new PublicKey(byteArray
|
|
8839
|
-
|
|
8840
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8841
|
-
byteArray = byteArray.slice(1);
|
|
8871
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8872
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8842
8873
|
configKeys.push({
|
|
8843
8874
|
publicKey,
|
|
8844
8875
|
isSigner
|