@solana/web3.js 1.66.5 → 1.66.6
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 +55 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +55 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +55 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +55 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +55 -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 +55 -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
|
@@ -738,6 +738,36 @@ class CompiledKeys {
|
|
|
738
738
|
|
|
739
739
|
}
|
|
740
740
|
|
|
741
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
742
|
+
/**
|
|
743
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
function guardedShift(byteArray) {
|
|
747
|
+
if (byteArray.length === 0) {
|
|
748
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return byteArray.shift();
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
755
|
+
* the array.
|
|
756
|
+
*/
|
|
757
|
+
|
|
758
|
+
function guardedSplice(byteArray, ...args) {
|
|
759
|
+
var _args$;
|
|
760
|
+
|
|
761
|
+
const [start] = args;
|
|
762
|
+
|
|
763
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
764
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
765
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return byteArray.splice(...args);
|
|
769
|
+
}
|
|
770
|
+
|
|
741
771
|
/**
|
|
742
772
|
* An instruction to execute by a program
|
|
743
773
|
*
|
|
@@ -889,37 +919,33 @@ class Message {
|
|
|
889
919
|
static from(buffer) {
|
|
890
920
|
// Slice up wire data
|
|
891
921
|
let byteArray = [...buffer];
|
|
892
|
-
const numRequiredSignatures = byteArray
|
|
922
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
893
923
|
|
|
894
924
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
895
925
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
896
926
|
}
|
|
897
927
|
|
|
898
|
-
const numReadonlySignedAccounts = byteArray
|
|
899
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
928
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
929
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
900
930
|
const accountCount = decodeLength(byteArray);
|
|
901
931
|
let accountKeys = [];
|
|
902
932
|
|
|
903
933
|
for (let i = 0; i < accountCount; i++) {
|
|
904
|
-
const account = byteArray
|
|
905
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
934
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
906
935
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
907
936
|
}
|
|
908
937
|
|
|
909
|
-
const recentBlockhash = byteArray
|
|
910
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
938
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
911
939
|
const instructionCount = decodeLength(byteArray);
|
|
912
940
|
let instructions = [];
|
|
913
941
|
|
|
914
942
|
for (let i = 0; i < instructionCount; i++) {
|
|
915
|
-
const programIdIndex = byteArray
|
|
943
|
+
const programIdIndex = guardedShift(byteArray);
|
|
916
944
|
const accountCount = decodeLength(byteArray);
|
|
917
|
-
const accounts = byteArray
|
|
918
|
-
byteArray = byteArray.slice(accountCount);
|
|
945
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
919
946
|
const dataLength = decodeLength(byteArray);
|
|
920
|
-
const dataSlice = byteArray
|
|
947
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
921
948
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
922
|
-
byteArray = byteArray.slice(dataLength);
|
|
923
949
|
instructions.push({
|
|
924
950
|
programIdIndex,
|
|
925
951
|
accounts,
|
|
@@ -1155,33 +1181,33 @@ class MessageV0 {
|
|
|
1155
1181
|
|
|
1156
1182
|
static deserialize(serializedMessage) {
|
|
1157
1183
|
let byteArray = [...serializedMessage];
|
|
1158
|
-
const prefix = byteArray
|
|
1184
|
+
const prefix = guardedShift(byteArray);
|
|
1159
1185
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1160
1186
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1161
1187
|
const version = maskedPrefix;
|
|
1162
1188
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1163
1189
|
const header = {
|
|
1164
|
-
numRequiredSignatures: byteArray
|
|
1165
|
-
numReadonlySignedAccounts: byteArray
|
|
1166
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1190
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1191
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1192
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1167
1193
|
};
|
|
1168
1194
|
const staticAccountKeys = [];
|
|
1169
1195
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1170
1196
|
|
|
1171
1197
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1172
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1198
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1173
1199
|
}
|
|
1174
1200
|
|
|
1175
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1201
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1176
1202
|
const instructionCount = decodeLength(byteArray);
|
|
1177
1203
|
const compiledInstructions = [];
|
|
1178
1204
|
|
|
1179
1205
|
for (let i = 0; i < instructionCount; i++) {
|
|
1180
|
-
const programIdIndex = byteArray
|
|
1206
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1181
1207
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1182
|
-
const accountKeyIndexes = byteArray
|
|
1208
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1183
1209
|
const dataLength = decodeLength(byteArray);
|
|
1184
|
-
const data = new Uint8Array(byteArray
|
|
1210
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1185
1211
|
compiledInstructions.push({
|
|
1186
1212
|
programIdIndex,
|
|
1187
1213
|
accountKeyIndexes,
|
|
@@ -1193,11 +1219,11 @@ class MessageV0 {
|
|
|
1193
1219
|
const addressTableLookups = [];
|
|
1194
1220
|
|
|
1195
1221
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1196
|
-
const accountKey = new PublicKey(byteArray
|
|
1222
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1197
1223
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1198
|
-
const writableIndexes = byteArray
|
|
1224
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1199
1225
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1200
|
-
const readonlyIndexes = byteArray
|
|
1226
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1201
1227
|
addressTableLookups.push({
|
|
1202
1228
|
accountKey,
|
|
1203
1229
|
writableIndexes,
|
|
@@ -1928,8 +1954,7 @@ class Transaction {
|
|
|
1928
1954
|
let signatures = [];
|
|
1929
1955
|
|
|
1930
1956
|
for (let i = 0; i < signatureCount; i++) {
|
|
1931
|
-
const signature = byteArray
|
|
1932
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1957
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1933
1958
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1934
1959
|
}
|
|
1935
1960
|
|
|
@@ -2127,7 +2152,7 @@ class VersionedTransaction {
|
|
|
2127
2152
|
const signaturesLength = decodeLength(byteArray);
|
|
2128
2153
|
|
|
2129
2154
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2130
|
-
signatures.push(new Uint8Array(byteArray
|
|
2155
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2131
2156
|
}
|
|
2132
2157
|
|
|
2133
2158
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4617,7 +4642,7 @@ const LogsNotificationResult = type({
|
|
|
4617
4642
|
|
|
4618
4643
|
/** @internal */
|
|
4619
4644
|
const COMMON_HTTP_HEADERS = {
|
|
4620
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4645
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4621
4646
|
};
|
|
4622
4647
|
/**
|
|
4623
4648
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9722,10 +9747,8 @@ class ValidatorInfo {
|
|
|
9722
9747
|
const configKeys = [];
|
|
9723
9748
|
|
|
9724
9749
|
for (let i = 0; i < 2; i++) {
|
|
9725
|
-
const publicKey = new PublicKey(byteArray
|
|
9726
|
-
|
|
9727
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9728
|
-
byteArray = byteArray.slice(1);
|
|
9750
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9751
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9729
9752
|
configKeys.push({
|
|
9730
9753
|
publicKey,
|
|
9731
9754
|
isSigner
|