@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.browser.esm.js
CHANGED
|
@@ -735,6 +735,36 @@ class CompiledKeys {
|
|
|
735
735
|
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
739
|
+
/**
|
|
740
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
741
|
+
*/
|
|
742
|
+
|
|
743
|
+
function guardedShift(byteArray) {
|
|
744
|
+
if (byteArray.length === 0) {
|
|
745
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
return byteArray.shift();
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
752
|
+
* the array.
|
|
753
|
+
*/
|
|
754
|
+
|
|
755
|
+
function guardedSplice(byteArray, ...args) {
|
|
756
|
+
var _args$;
|
|
757
|
+
|
|
758
|
+
const [start] = args;
|
|
759
|
+
|
|
760
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
761
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
762
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
return byteArray.splice(...args);
|
|
766
|
+
}
|
|
767
|
+
|
|
738
768
|
/**
|
|
739
769
|
* An instruction to execute by a program
|
|
740
770
|
*
|
|
@@ -886,37 +916,33 @@ class Message {
|
|
|
886
916
|
static from(buffer) {
|
|
887
917
|
// Slice up wire data
|
|
888
918
|
let byteArray = [...buffer];
|
|
889
|
-
const numRequiredSignatures = byteArray
|
|
919
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
890
920
|
|
|
891
921
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
892
922
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
893
923
|
}
|
|
894
924
|
|
|
895
|
-
const numReadonlySignedAccounts = byteArray
|
|
896
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
925
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
926
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
897
927
|
const accountCount = decodeLength(byteArray);
|
|
898
928
|
let accountKeys = [];
|
|
899
929
|
|
|
900
930
|
for (let i = 0; i < accountCount; i++) {
|
|
901
|
-
const account = byteArray
|
|
902
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
931
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
903
932
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
904
933
|
}
|
|
905
934
|
|
|
906
|
-
const recentBlockhash = byteArray
|
|
907
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
935
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
908
936
|
const instructionCount = decodeLength(byteArray);
|
|
909
937
|
let instructions = [];
|
|
910
938
|
|
|
911
939
|
for (let i = 0; i < instructionCount; i++) {
|
|
912
|
-
const programIdIndex = byteArray
|
|
940
|
+
const programIdIndex = guardedShift(byteArray);
|
|
913
941
|
const accountCount = decodeLength(byteArray);
|
|
914
|
-
const accounts = byteArray
|
|
915
|
-
byteArray = byteArray.slice(accountCount);
|
|
942
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
916
943
|
const dataLength = decodeLength(byteArray);
|
|
917
|
-
const dataSlice = byteArray
|
|
944
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
918
945
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
919
|
-
byteArray = byteArray.slice(dataLength);
|
|
920
946
|
instructions.push({
|
|
921
947
|
programIdIndex,
|
|
922
948
|
accounts,
|
|
@@ -1152,33 +1178,33 @@ class MessageV0 {
|
|
|
1152
1178
|
|
|
1153
1179
|
static deserialize(serializedMessage) {
|
|
1154
1180
|
let byteArray = [...serializedMessage];
|
|
1155
|
-
const prefix = byteArray
|
|
1181
|
+
const prefix = guardedShift(byteArray);
|
|
1156
1182
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1157
1183
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1158
1184
|
const version = maskedPrefix;
|
|
1159
1185
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1160
1186
|
const header = {
|
|
1161
|
-
numRequiredSignatures: byteArray
|
|
1162
|
-
numReadonlySignedAccounts: byteArray
|
|
1163
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1187
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1188
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1189
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1164
1190
|
};
|
|
1165
1191
|
const staticAccountKeys = [];
|
|
1166
1192
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1167
1193
|
|
|
1168
1194
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1169
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1195
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1170
1196
|
}
|
|
1171
1197
|
|
|
1172
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1198
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1173
1199
|
const instructionCount = decodeLength(byteArray);
|
|
1174
1200
|
const compiledInstructions = [];
|
|
1175
1201
|
|
|
1176
1202
|
for (let i = 0; i < instructionCount; i++) {
|
|
1177
|
-
const programIdIndex = byteArray
|
|
1203
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1178
1204
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1179
|
-
const accountKeyIndexes = byteArray
|
|
1205
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1180
1206
|
const dataLength = decodeLength(byteArray);
|
|
1181
|
-
const data = new Uint8Array(byteArray
|
|
1207
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1182
1208
|
compiledInstructions.push({
|
|
1183
1209
|
programIdIndex,
|
|
1184
1210
|
accountKeyIndexes,
|
|
@@ -1190,11 +1216,11 @@ class MessageV0 {
|
|
|
1190
1216
|
const addressTableLookups = [];
|
|
1191
1217
|
|
|
1192
1218
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1193
|
-
const accountKey = new PublicKey(byteArray
|
|
1219
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1194
1220
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1195
|
-
const writableIndexes = byteArray
|
|
1221
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1196
1222
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1197
|
-
const readonlyIndexes = byteArray
|
|
1223
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1198
1224
|
addressTableLookups.push({
|
|
1199
1225
|
accountKey,
|
|
1200
1226
|
writableIndexes,
|
|
@@ -1925,8 +1951,7 @@ class Transaction {
|
|
|
1925
1951
|
let signatures = [];
|
|
1926
1952
|
|
|
1927
1953
|
for (let i = 0; i < signatureCount; i++) {
|
|
1928
|
-
const signature = byteArray
|
|
1929
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1954
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1930
1955
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1931
1956
|
}
|
|
1932
1957
|
|
|
@@ -2124,7 +2149,7 @@ class VersionedTransaction {
|
|
|
2124
2149
|
const signaturesLength = decodeLength(byteArray);
|
|
2125
2150
|
|
|
2126
2151
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2127
|
-
signatures.push(new Uint8Array(byteArray
|
|
2152
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2128
2153
|
}
|
|
2129
2154
|
|
|
2130
2155
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4554,7 +4579,7 @@ const LogsNotificationResult = type({
|
|
|
4554
4579
|
|
|
4555
4580
|
/** @internal */
|
|
4556
4581
|
const COMMON_HTTP_HEADERS = {
|
|
4557
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4582
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4558
4583
|
};
|
|
4559
4584
|
/**
|
|
4560
4585
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9659,10 +9684,8 @@ class ValidatorInfo {
|
|
|
9659
9684
|
const configKeys = [];
|
|
9660
9685
|
|
|
9661
9686
|
for (let i = 0; i < 2; i++) {
|
|
9662
|
-
const publicKey = new PublicKey(byteArray
|
|
9663
|
-
|
|
9664
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9665
|
-
byteArray = byteArray.slice(1);
|
|
9687
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9688
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9666
9689
|
configKeys.push({
|
|
9667
9690
|
publicKey,
|
|
9668
9691
|
isSigner
|