@solana/web3.js 1.77.3 → 1.77.4
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 +50 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +50 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +50 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +50 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +50 -32
- 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/lib/index.native.js +50 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +21 -21
- 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
|
@@ -672,6 +672,31 @@ class CompiledKeys {
|
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
679
|
+
*/
|
|
680
|
+
function guardedShift(byteArray) {
|
|
681
|
+
if (byteArray.length === 0) {
|
|
682
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
683
|
+
}
|
|
684
|
+
return byteArray.shift();
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
689
|
+
* the array.
|
|
690
|
+
*/
|
|
691
|
+
function guardedSplice(byteArray, ...args) {
|
|
692
|
+
const [start] = args;
|
|
693
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
694
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
695
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
696
|
+
}
|
|
697
|
+
return byteArray.splice(...args);
|
|
698
|
+
}
|
|
699
|
+
|
|
675
700
|
/**
|
|
676
701
|
* An instruction to execute by a program
|
|
677
702
|
*
|
|
@@ -809,32 +834,28 @@ class Message {
|
|
|
809
834
|
static from(buffer) {
|
|
810
835
|
// Slice up wire data
|
|
811
836
|
let byteArray = [...buffer];
|
|
812
|
-
const numRequiredSignatures = byteArray
|
|
837
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
813
838
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
814
839
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
815
840
|
}
|
|
816
|
-
const numReadonlySignedAccounts = byteArray
|
|
817
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
841
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
842
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
818
843
|
const accountCount = decodeLength(byteArray);
|
|
819
844
|
let accountKeys = [];
|
|
820
845
|
for (let i = 0; i < accountCount; i++) {
|
|
821
|
-
const account = byteArray
|
|
822
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
846
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
823
847
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
824
848
|
}
|
|
825
|
-
const recentBlockhash = byteArray
|
|
826
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
849
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
827
850
|
const instructionCount = decodeLength(byteArray);
|
|
828
851
|
let instructions = [];
|
|
829
852
|
for (let i = 0; i < instructionCount; i++) {
|
|
830
|
-
const programIdIndex = byteArray
|
|
853
|
+
const programIdIndex = guardedShift(byteArray);
|
|
831
854
|
const accountCount = decodeLength(byteArray);
|
|
832
|
-
const accounts = byteArray
|
|
833
|
-
byteArray = byteArray.slice(accountCount);
|
|
855
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
834
856
|
const dataLength = decodeLength(byteArray);
|
|
835
|
-
const dataSlice = byteArray
|
|
857
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
836
858
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
837
|
-
byteArray = byteArray.slice(dataLength);
|
|
838
859
|
instructions.push({
|
|
839
860
|
programIdIndex,
|
|
840
861
|
accounts,
|
|
@@ -1039,30 +1060,30 @@ class MessageV0 {
|
|
|
1039
1060
|
}
|
|
1040
1061
|
static deserialize(serializedMessage) {
|
|
1041
1062
|
let byteArray = [...serializedMessage];
|
|
1042
|
-
const prefix = byteArray
|
|
1063
|
+
const prefix = guardedShift(byteArray);
|
|
1043
1064
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1044
1065
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1045
1066
|
const version = maskedPrefix;
|
|
1046
1067
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1047
1068
|
const header = {
|
|
1048
|
-
numRequiredSignatures: byteArray
|
|
1049
|
-
numReadonlySignedAccounts: byteArray
|
|
1050
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1069
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1070
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1071
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1051
1072
|
};
|
|
1052
1073
|
const staticAccountKeys = [];
|
|
1053
1074
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1054
1075
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1055
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1076
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1056
1077
|
}
|
|
1057
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1078
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1058
1079
|
const instructionCount = decodeLength(byteArray);
|
|
1059
1080
|
const compiledInstructions = [];
|
|
1060
1081
|
for (let i = 0; i < instructionCount; i++) {
|
|
1061
|
-
const programIdIndex = byteArray
|
|
1082
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1062
1083
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1063
|
-
const accountKeyIndexes = byteArray
|
|
1084
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1064
1085
|
const dataLength = decodeLength(byteArray);
|
|
1065
|
-
const data = new Uint8Array(byteArray
|
|
1086
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1066
1087
|
compiledInstructions.push({
|
|
1067
1088
|
programIdIndex,
|
|
1068
1089
|
accountKeyIndexes,
|
|
@@ -1072,11 +1093,11 @@ class MessageV0 {
|
|
|
1072
1093
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1073
1094
|
const addressTableLookups = [];
|
|
1074
1095
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1075
|
-
const accountKey = new PublicKey(byteArray
|
|
1096
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1076
1097
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1077
|
-
const writableIndexes = byteArray
|
|
1098
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1078
1099
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1079
|
-
const readonlyIndexes = byteArray
|
|
1100
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1080
1101
|
addressTableLookups.push({
|
|
1081
1102
|
accountKey,
|
|
1082
1103
|
writableIndexes,
|
|
@@ -1759,8 +1780,7 @@ class Transaction {
|
|
|
1759
1780
|
const signatureCount = decodeLength(byteArray);
|
|
1760
1781
|
let signatures = [];
|
|
1761
1782
|
for (let i = 0; i < signatureCount; i++) {
|
|
1762
|
-
const signature = byteArray
|
|
1763
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1783
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1764
1784
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1765
1785
|
}
|
|
1766
1786
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -1930,7 +1950,7 @@ class VersionedTransaction {
|
|
|
1930
1950
|
const signatures = [];
|
|
1931
1951
|
const signaturesLength = decodeLength(byteArray);
|
|
1932
1952
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1933
|
-
signatures.push(new Uint8Array(byteArray
|
|
1953
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1934
1954
|
}
|
|
1935
1955
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1936
1956
|
return new VersionedTransaction(message, signatures);
|
|
@@ -6958,7 +6978,7 @@ const LogsNotificationResult = type({
|
|
|
6958
6978
|
|
|
6959
6979
|
/** @internal */
|
|
6960
6980
|
const COMMON_HTTP_HEADERS = {
|
|
6961
|
-
'solana-client': `js/${"
|
|
6981
|
+
'solana-client': `js/${"1.77.4" }`
|
|
6962
6982
|
};
|
|
6963
6983
|
|
|
6964
6984
|
/**
|
|
@@ -11748,10 +11768,8 @@ class ValidatorInfo {
|
|
|
11748
11768
|
if (configKeyCount !== 2) return null;
|
|
11749
11769
|
const configKeys = [];
|
|
11750
11770
|
for (let i = 0; i < 2; i++) {
|
|
11751
|
-
const publicKey = new PublicKey(byteArray
|
|
11752
|
-
|
|
11753
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
11754
|
-
byteArray = byteArray.slice(1);
|
|
11771
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
11772
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
11755
11773
|
configKeys.push({
|
|
11756
11774
|
publicKey,
|
|
11757
11775
|
isSigner
|