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