@solana/web3.js 1.91.1 → 1.91.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.cjs.js +49 -24
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +49 -24
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +49 -24
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +49 -24
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +49 -24
- 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 +49 -24
- package/lib/index.native.js.map +1 -1
- package/package.json +2 -2
- package/src/message/legacy.ts +9 -8
- package/src/message/v0.ts +29 -12
- package/src/transaction/legacy.ts +2 -1
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -2
package/lib/index.esm.js
CHANGED
|
@@ -676,6 +676,31 @@ class CompiledKeys {
|
|
|
676
676
|
}
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
683
|
+
*/
|
|
684
|
+
function guardedShift(byteArray) {
|
|
685
|
+
if (byteArray.length === 0) {
|
|
686
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
687
|
+
}
|
|
688
|
+
return byteArray.shift();
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
693
|
+
* the array.
|
|
694
|
+
*/
|
|
695
|
+
function guardedSplice(byteArray, ...args) {
|
|
696
|
+
const [start] = args;
|
|
697
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
698
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
699
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
700
|
+
}
|
|
701
|
+
return byteArray.splice(...args);
|
|
702
|
+
}
|
|
703
|
+
|
|
679
704
|
/**
|
|
680
705
|
* An instruction to execute by a program
|
|
681
706
|
*
|
|
@@ -817,27 +842,27 @@ class Message {
|
|
|
817
842
|
static from(buffer) {
|
|
818
843
|
// Slice up wire data
|
|
819
844
|
let byteArray = [...buffer];
|
|
820
|
-
const numRequiredSignatures = byteArray
|
|
845
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
821
846
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
822
847
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
823
848
|
}
|
|
824
|
-
const numReadonlySignedAccounts = byteArray
|
|
825
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
849
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
850
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
826
851
|
const accountCount = decodeLength(byteArray);
|
|
827
852
|
let accountKeys = [];
|
|
828
853
|
for (let i = 0; i < accountCount; i++) {
|
|
829
|
-
const account = byteArray
|
|
854
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
830
855
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
831
856
|
}
|
|
832
|
-
const recentBlockhash = byteArray
|
|
857
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
833
858
|
const instructionCount = decodeLength(byteArray);
|
|
834
859
|
let instructions = [];
|
|
835
860
|
for (let i = 0; i < instructionCount; i++) {
|
|
836
|
-
const programIdIndex = byteArray
|
|
861
|
+
const programIdIndex = guardedShift(byteArray);
|
|
837
862
|
const accountCount = decodeLength(byteArray);
|
|
838
|
-
const accounts = byteArray
|
|
863
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
839
864
|
const dataLength = decodeLength(byteArray);
|
|
840
|
-
const dataSlice = byteArray
|
|
865
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
841
866
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
842
867
|
instructions.push({
|
|
843
868
|
programIdIndex,
|
|
@@ -1043,30 +1068,30 @@ class MessageV0 {
|
|
|
1043
1068
|
}
|
|
1044
1069
|
static deserialize(serializedMessage) {
|
|
1045
1070
|
let byteArray = [...serializedMessage];
|
|
1046
|
-
const prefix = byteArray
|
|
1071
|
+
const prefix = guardedShift(byteArray);
|
|
1047
1072
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1048
1073
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1049
1074
|
const version = maskedPrefix;
|
|
1050
1075
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1051
1076
|
const header = {
|
|
1052
|
-
numRequiredSignatures: byteArray
|
|
1053
|
-
numReadonlySignedAccounts: byteArray
|
|
1054
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1077
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1078
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1079
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1055
1080
|
};
|
|
1056
1081
|
const staticAccountKeys = [];
|
|
1057
1082
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1058
1083
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1059
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1084
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1060
1085
|
}
|
|
1061
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1086
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1062
1087
|
const instructionCount = decodeLength(byteArray);
|
|
1063
1088
|
const compiledInstructions = [];
|
|
1064
1089
|
for (let i = 0; i < instructionCount; i++) {
|
|
1065
|
-
const programIdIndex = byteArray
|
|
1090
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1066
1091
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1067
|
-
const accountKeyIndexes = byteArray
|
|
1092
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1068
1093
|
const dataLength = decodeLength(byteArray);
|
|
1069
|
-
const data = new Uint8Array(byteArray
|
|
1094
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1070
1095
|
compiledInstructions.push({
|
|
1071
1096
|
programIdIndex,
|
|
1072
1097
|
accountKeyIndexes,
|
|
@@ -1076,11 +1101,11 @@ class MessageV0 {
|
|
|
1076
1101
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1077
1102
|
const addressTableLookups = [];
|
|
1078
1103
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1079
|
-
const accountKey = new PublicKey(byteArray
|
|
1104
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1080
1105
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1081
|
-
const writableIndexes = byteArray
|
|
1106
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1082
1107
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1083
|
-
const readonlyIndexes = byteArray
|
|
1108
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1084
1109
|
addressTableLookups.push({
|
|
1085
1110
|
accountKey,
|
|
1086
1111
|
writableIndexes,
|
|
@@ -1871,7 +1896,7 @@ class Transaction {
|
|
|
1871
1896
|
const signatureCount = decodeLength(byteArray);
|
|
1872
1897
|
let signatures = [];
|
|
1873
1898
|
for (let i = 0; i < signatureCount; i++) {
|
|
1874
|
-
const signature = byteArray
|
|
1899
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1875
1900
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1876
1901
|
}
|
|
1877
1902
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2046,7 +2071,7 @@ class VersionedTransaction {
|
|
|
2046
2071
|
const signatures = [];
|
|
2047
2072
|
const signaturesLength = decodeLength(byteArray);
|
|
2048
2073
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2049
|
-
signatures.push(new Uint8Array(byteArray
|
|
2074
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2050
2075
|
}
|
|
2051
2076
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2052
2077
|
return new VersionedTransaction(message, signatures);
|
|
@@ -10785,8 +10810,8 @@ class ValidatorInfo {
|
|
|
10785
10810
|
if (configKeyCount !== 2) return null;
|
|
10786
10811
|
const configKeys = [];
|
|
10787
10812
|
for (let i = 0; i < 2; i++) {
|
|
10788
|
-
const publicKey = new PublicKey(byteArray
|
|
10789
|
-
const isSigner = byteArray
|
|
10813
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10814
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10790
10815
|
configKeys.push({
|
|
10791
10816
|
publicKey,
|
|
10792
10817
|
isSigner
|