@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.cjs.js
CHANGED
|
@@ -568,6 +568,44 @@ function encodeLength(bytes, len) {
|
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
572
|
+
/**
|
|
573
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
function guardedShift(byteArray) {
|
|
577
|
+
if (byteArray.length === 0) {
|
|
578
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return byteArray.shift();
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
585
|
+
* the array.
|
|
586
|
+
*/
|
|
587
|
+
|
|
588
|
+
function guardedSplice(byteArray, ...args) {
|
|
589
|
+
var _args$;
|
|
590
|
+
|
|
591
|
+
const [start] = args;
|
|
592
|
+
|
|
593
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
594
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
595
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return byteArray.splice(...args);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* An instruction to execute by a program
|
|
603
|
+
*
|
|
604
|
+
* @property {number} programIdIndex
|
|
605
|
+
* @property {number[]} accounts
|
|
606
|
+
* @property {string} data
|
|
607
|
+
*/
|
|
608
|
+
|
|
571
609
|
/**
|
|
572
610
|
* List of instructions to be processed atomically
|
|
573
611
|
*/
|
|
@@ -680,37 +718,33 @@ class Message {
|
|
|
680
718
|
static from(buffer$1) {
|
|
681
719
|
// Slice up wire data
|
|
682
720
|
let byteArray = [...buffer$1];
|
|
683
|
-
const numRequiredSignatures = byteArray
|
|
721
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
684
722
|
|
|
685
723
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
686
724
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
687
725
|
}
|
|
688
726
|
|
|
689
|
-
const numReadonlySignedAccounts = byteArray
|
|
690
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
727
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
728
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
691
729
|
const accountCount = decodeLength(byteArray);
|
|
692
730
|
let accountKeys = [];
|
|
693
731
|
|
|
694
732
|
for (let i = 0; i < accountCount; i++) {
|
|
695
|
-
const account = byteArray
|
|
696
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
733
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
697
734
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
698
735
|
}
|
|
699
736
|
|
|
700
|
-
const recentBlockhash = byteArray
|
|
701
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
737
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
702
738
|
const instructionCount = decodeLength(byteArray);
|
|
703
739
|
let instructions = [];
|
|
704
740
|
|
|
705
741
|
for (let i = 0; i < instructionCount; i++) {
|
|
706
|
-
const programIdIndex = byteArray
|
|
742
|
+
const programIdIndex = guardedShift(byteArray);
|
|
707
743
|
const accountCount = decodeLength(byteArray);
|
|
708
|
-
const accounts = byteArray
|
|
709
|
-
byteArray = byteArray.slice(accountCount);
|
|
744
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
710
745
|
const dataLength = decodeLength(byteArray);
|
|
711
|
-
const dataSlice = byteArray
|
|
746
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
712
747
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
713
|
-
byteArray = byteArray.slice(dataLength);
|
|
714
748
|
instructions.push({
|
|
715
749
|
programIdIndex,
|
|
716
750
|
accounts,
|
|
@@ -833,33 +867,33 @@ class MessageV0 {
|
|
|
833
867
|
|
|
834
868
|
static deserialize(serializedMessage) {
|
|
835
869
|
let byteArray = [...serializedMessage];
|
|
836
|
-
const prefix = byteArray
|
|
870
|
+
const prefix = guardedShift(byteArray);
|
|
837
871
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
838
872
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
839
873
|
const version = maskedPrefix;
|
|
840
874
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
841
875
|
const header = {
|
|
842
|
-
numRequiredSignatures: byteArray
|
|
843
|
-
numReadonlySignedAccounts: byteArray
|
|
844
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
876
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
877
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
878
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
845
879
|
};
|
|
846
880
|
const staticAccountKeys = [];
|
|
847
881
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
848
882
|
|
|
849
883
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
850
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
884
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
851
885
|
}
|
|
852
886
|
|
|
853
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
887
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
854
888
|
const instructionCount = decodeLength(byteArray);
|
|
855
889
|
const compiledInstructions = [];
|
|
856
890
|
|
|
857
891
|
for (let i = 0; i < instructionCount; i++) {
|
|
858
|
-
const programIdIndex = byteArray
|
|
892
|
+
const programIdIndex = guardedShift(byteArray);
|
|
859
893
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
860
|
-
const accountKeyIndexes = byteArray
|
|
894
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
861
895
|
const dataLength = decodeLength(byteArray);
|
|
862
|
-
const data = new Uint8Array(byteArray
|
|
896
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
863
897
|
compiledInstructions.push({
|
|
864
898
|
programIdIndex,
|
|
865
899
|
accountKeyIndexes,
|
|
@@ -871,11 +905,11 @@ class MessageV0 {
|
|
|
871
905
|
const addressTableLookups = [];
|
|
872
906
|
|
|
873
907
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
874
|
-
const accountKey = new PublicKey(byteArray
|
|
908
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
875
909
|
const writableIndexesLength = decodeLength(byteArray);
|
|
876
|
-
const writableIndexes = byteArray
|
|
910
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
877
911
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
878
|
-
const readonlyIndexes = byteArray
|
|
912
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
879
913
|
addressTableLookups.push({
|
|
880
914
|
accountKey,
|
|
881
915
|
writableIndexes,
|
|
@@ -1598,8 +1632,7 @@ class Transaction {
|
|
|
1598
1632
|
let signatures = [];
|
|
1599
1633
|
|
|
1600
1634
|
for (let i = 0; i < signatureCount; i++) {
|
|
1601
|
-
const signature = byteArray
|
|
1602
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1635
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1603
1636
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1604
1637
|
}
|
|
1605
1638
|
|
|
@@ -1691,7 +1724,7 @@ class VersionedTransaction {
|
|
|
1691
1724
|
const signaturesLength = decodeLength(byteArray);
|
|
1692
1725
|
|
|
1693
1726
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1694
|
-
signatures.push(new Uint8Array(byteArray
|
|
1727
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1695
1728
|
}
|
|
1696
1729
|
|
|
1697
1730
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4115,7 +4148,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4115
4148
|
|
|
4116
4149
|
/** @internal */
|
|
4117
4150
|
const COMMON_HTTP_HEADERS = {
|
|
4118
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4151
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.54.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4119
4152
|
};
|
|
4120
4153
|
/**
|
|
4121
4154
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8869,10 +8902,8 @@ class ValidatorInfo {
|
|
|
8869
8902
|
const configKeys = [];
|
|
8870
8903
|
|
|
8871
8904
|
for (let i = 0; i < 2; i++) {
|
|
8872
|
-
const publicKey = new PublicKey(byteArray
|
|
8873
|
-
|
|
8874
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8875
|
-
byteArray = byteArray.slice(1);
|
|
8905
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8906
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8876
8907
|
configKeys.push({
|
|
8877
8908
|
publicKey,
|
|
8878
8909
|
isSigner
|