@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.cjs.js
CHANGED
|
@@ -708,6 +708,31 @@ class CompiledKeys {
|
|
|
708
708
|
}
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
715
|
+
*/
|
|
716
|
+
function guardedShift(byteArray) {
|
|
717
|
+
if (byteArray.length === 0) {
|
|
718
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
719
|
+
}
|
|
720
|
+
return byteArray.shift();
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
725
|
+
* the array.
|
|
726
|
+
*/
|
|
727
|
+
function guardedSplice(byteArray, ...args) {
|
|
728
|
+
const [start] = args;
|
|
729
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
730
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
731
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
732
|
+
}
|
|
733
|
+
return byteArray.splice(...args);
|
|
734
|
+
}
|
|
735
|
+
|
|
711
736
|
/**
|
|
712
737
|
* An instruction to execute by a program
|
|
713
738
|
*
|
|
@@ -849,27 +874,27 @@ class Message {
|
|
|
849
874
|
static from(buffer$1) {
|
|
850
875
|
// Slice up wire data
|
|
851
876
|
let byteArray = [...buffer$1];
|
|
852
|
-
const numRequiredSignatures = byteArray
|
|
877
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
853
878
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
854
879
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
855
880
|
}
|
|
856
|
-
const numReadonlySignedAccounts = byteArray
|
|
857
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
881
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
882
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
858
883
|
const accountCount = decodeLength(byteArray);
|
|
859
884
|
let accountKeys = [];
|
|
860
885
|
for (let i = 0; i < accountCount; i++) {
|
|
861
|
-
const account = byteArray
|
|
886
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
862
887
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
863
888
|
}
|
|
864
|
-
const recentBlockhash = byteArray
|
|
889
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
865
890
|
const instructionCount = decodeLength(byteArray);
|
|
866
891
|
let instructions = [];
|
|
867
892
|
for (let i = 0; i < instructionCount; i++) {
|
|
868
|
-
const programIdIndex = byteArray
|
|
893
|
+
const programIdIndex = guardedShift(byteArray);
|
|
869
894
|
const accountCount = decodeLength(byteArray);
|
|
870
|
-
const accounts = byteArray
|
|
895
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
871
896
|
const dataLength = decodeLength(byteArray);
|
|
872
|
-
const dataSlice = byteArray
|
|
897
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
873
898
|
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
874
899
|
instructions.push({
|
|
875
900
|
programIdIndex,
|
|
@@ -1075,30 +1100,30 @@ class MessageV0 {
|
|
|
1075
1100
|
}
|
|
1076
1101
|
static deserialize(serializedMessage) {
|
|
1077
1102
|
let byteArray = [...serializedMessage];
|
|
1078
|
-
const prefix = byteArray
|
|
1103
|
+
const prefix = guardedShift(byteArray);
|
|
1079
1104
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1080
1105
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1081
1106
|
const version = maskedPrefix;
|
|
1082
1107
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1083
1108
|
const header = {
|
|
1084
|
-
numRequiredSignatures: byteArray
|
|
1085
|
-
numReadonlySignedAccounts: byteArray
|
|
1086
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1109
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1110
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1111
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1087
1112
|
};
|
|
1088
1113
|
const staticAccountKeys = [];
|
|
1089
1114
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1090
1115
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1091
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1116
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1092
1117
|
}
|
|
1093
|
-
const recentBlockhash = bs58__default.default.encode(byteArray
|
|
1118
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1094
1119
|
const instructionCount = decodeLength(byteArray);
|
|
1095
1120
|
const compiledInstructions = [];
|
|
1096
1121
|
for (let i = 0; i < instructionCount; i++) {
|
|
1097
|
-
const programIdIndex = byteArray
|
|
1122
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1098
1123
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1099
|
-
const accountKeyIndexes = byteArray
|
|
1124
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1100
1125
|
const dataLength = decodeLength(byteArray);
|
|
1101
|
-
const data = new Uint8Array(byteArray
|
|
1126
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1102
1127
|
compiledInstructions.push({
|
|
1103
1128
|
programIdIndex,
|
|
1104
1129
|
accountKeyIndexes,
|
|
@@ -1108,11 +1133,11 @@ class MessageV0 {
|
|
|
1108
1133
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1109
1134
|
const addressTableLookups = [];
|
|
1110
1135
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1111
|
-
const accountKey = new PublicKey(byteArray
|
|
1136
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1112
1137
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1113
|
-
const writableIndexes = byteArray
|
|
1138
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1114
1139
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1115
|
-
const readonlyIndexes = byteArray
|
|
1140
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1116
1141
|
addressTableLookups.push({
|
|
1117
1142
|
accountKey,
|
|
1118
1143
|
writableIndexes,
|
|
@@ -1903,7 +1928,7 @@ class Transaction {
|
|
|
1903
1928
|
const signatureCount = decodeLength(byteArray);
|
|
1904
1929
|
let signatures = [];
|
|
1905
1930
|
for (let i = 0; i < signatureCount; i++) {
|
|
1906
|
-
const signature = byteArray
|
|
1931
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1907
1932
|
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1908
1933
|
}
|
|
1909
1934
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2078,7 +2103,7 @@ class VersionedTransaction {
|
|
|
2078
2103
|
const signatures = [];
|
|
2079
2104
|
const signaturesLength = decodeLength(byteArray);
|
|
2080
2105
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2081
|
-
signatures.push(new Uint8Array(byteArray
|
|
2106
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2082
2107
|
}
|
|
2083
2108
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2084
2109
|
return new VersionedTransaction(message, signatures);
|
|
@@ -10817,8 +10842,8 @@ class ValidatorInfo {
|
|
|
10817
10842
|
if (configKeyCount !== 2) return null;
|
|
10818
10843
|
const configKeys = [];
|
|
10819
10844
|
for (let i = 0; i < 2; i++) {
|
|
10820
|
-
const publicKey = new PublicKey(byteArray
|
|
10821
|
-
const isSigner = byteArray
|
|
10845
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10846
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10822
10847
|
configKeys.push({
|
|
10823
10848
|
publicKey,
|
|
10824
10849
|
isSigner
|