@solana/web3.js 1.61.0 → 1.61.2
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 +56 -33
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +56 -33
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +56 -33
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +56 -33
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +56 -33
- 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 +56 -33
- 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/programs/address-lookup-table/state.ts +1 -1
- 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.cjs.js
CHANGED
|
@@ -770,6 +770,36 @@ class CompiledKeys {
|
|
|
770
770
|
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
774
|
+
/**
|
|
775
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
776
|
+
*/
|
|
777
|
+
|
|
778
|
+
function guardedShift(byteArray) {
|
|
779
|
+
if (byteArray.length === 0) {
|
|
780
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return byteArray.shift();
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
787
|
+
* the array.
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
function guardedSplice(byteArray, ...args) {
|
|
791
|
+
var _args$;
|
|
792
|
+
|
|
793
|
+
const [start] = args;
|
|
794
|
+
|
|
795
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
796
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
797
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return byteArray.splice(...args);
|
|
801
|
+
}
|
|
802
|
+
|
|
773
803
|
/**
|
|
774
804
|
* An instruction to execute by a program
|
|
775
805
|
*
|
|
@@ -911,37 +941,33 @@ class Message {
|
|
|
911
941
|
static from(buffer$1) {
|
|
912
942
|
// Slice up wire data
|
|
913
943
|
let byteArray = [...buffer$1];
|
|
914
|
-
const numRequiredSignatures = byteArray
|
|
944
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
915
945
|
|
|
916
946
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
917
947
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
918
948
|
}
|
|
919
949
|
|
|
920
|
-
const numReadonlySignedAccounts = byteArray
|
|
921
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
950
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
951
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
922
952
|
const accountCount = decodeLength(byteArray);
|
|
923
953
|
let accountKeys = [];
|
|
924
954
|
|
|
925
955
|
for (let i = 0; i < accountCount; i++) {
|
|
926
|
-
const account = byteArray
|
|
927
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
956
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
928
957
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
929
958
|
}
|
|
930
959
|
|
|
931
|
-
const recentBlockhash = byteArray
|
|
932
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
960
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
933
961
|
const instructionCount = decodeLength(byteArray);
|
|
934
962
|
let instructions = [];
|
|
935
963
|
|
|
936
964
|
for (let i = 0; i < instructionCount; i++) {
|
|
937
|
-
const programIdIndex = byteArray
|
|
965
|
+
const programIdIndex = guardedShift(byteArray);
|
|
938
966
|
const accountCount = decodeLength(byteArray);
|
|
939
|
-
const accounts = byteArray
|
|
940
|
-
byteArray = byteArray.slice(accountCount);
|
|
967
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
941
968
|
const dataLength = decodeLength(byteArray);
|
|
942
|
-
const dataSlice = byteArray
|
|
969
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
943
970
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
944
|
-
byteArray = byteArray.slice(dataLength);
|
|
945
971
|
instructions.push({
|
|
946
972
|
programIdIndex,
|
|
947
973
|
accounts,
|
|
@@ -1154,33 +1180,33 @@ class MessageV0 {
|
|
|
1154
1180
|
|
|
1155
1181
|
static deserialize(serializedMessage) {
|
|
1156
1182
|
let byteArray = [...serializedMessage];
|
|
1157
|
-
const prefix = byteArray
|
|
1183
|
+
const prefix = guardedShift(byteArray);
|
|
1158
1184
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1159
1185
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1160
1186
|
const version = maskedPrefix;
|
|
1161
1187
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1162
1188
|
const header = {
|
|
1163
|
-
numRequiredSignatures: byteArray
|
|
1164
|
-
numReadonlySignedAccounts: byteArray
|
|
1165
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1189
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1190
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1191
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1166
1192
|
};
|
|
1167
1193
|
const staticAccountKeys = [];
|
|
1168
1194
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1169
1195
|
|
|
1170
1196
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1171
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1197
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1172
1198
|
}
|
|
1173
1199
|
|
|
1174
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1200
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1175
1201
|
const instructionCount = decodeLength(byteArray);
|
|
1176
1202
|
const compiledInstructions = [];
|
|
1177
1203
|
|
|
1178
1204
|
for (let i = 0; i < instructionCount; i++) {
|
|
1179
|
-
const programIdIndex = byteArray
|
|
1205
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1180
1206
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1181
|
-
const accountKeyIndexes = byteArray
|
|
1207
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1182
1208
|
const dataLength = decodeLength(byteArray);
|
|
1183
|
-
const data = new Uint8Array(byteArray
|
|
1209
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1184
1210
|
compiledInstructions.push({
|
|
1185
1211
|
programIdIndex,
|
|
1186
1212
|
accountKeyIndexes,
|
|
@@ -1192,11 +1218,11 @@ class MessageV0 {
|
|
|
1192
1218
|
const addressTableLookups = [];
|
|
1193
1219
|
|
|
1194
1220
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1195
|
-
const accountKey = new PublicKey(byteArray
|
|
1221
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1196
1222
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1197
|
-
const writableIndexes = byteArray
|
|
1223
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1198
1224
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1199
|
-
const readonlyIndexes = byteArray
|
|
1225
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1200
1226
|
addressTableLookups.push({
|
|
1201
1227
|
accountKey,
|
|
1202
1228
|
writableIndexes,
|
|
@@ -1927,8 +1953,7 @@ class Transaction {
|
|
|
1927
1953
|
let signatures = [];
|
|
1928
1954
|
|
|
1929
1955
|
for (let i = 0; i < signatureCount; i++) {
|
|
1930
|
-
const signature = byteArray
|
|
1931
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1956
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1932
1957
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1933
1958
|
}
|
|
1934
1959
|
|
|
@@ -2126,7 +2151,7 @@ class VersionedTransaction {
|
|
|
2126
2151
|
const signaturesLength = decodeLength(byteArray);
|
|
2127
2152
|
|
|
2128
2153
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2129
|
-
signatures.push(new Uint8Array(byteArray
|
|
2154
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2130
2155
|
}
|
|
2131
2156
|
|
|
2132
2157
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -3562,7 +3587,7 @@ class AddressLookupTableAccount {
|
|
|
3562
3587
|
}
|
|
3563
3588
|
|
|
3564
3589
|
isActive() {
|
|
3565
|
-
const U64_MAX =
|
|
3590
|
+
const U64_MAX = 18446744073709551615n;
|
|
3566
3591
|
return this.state.deactivationSlot === U64_MAX;
|
|
3567
3592
|
}
|
|
3568
3593
|
|
|
@@ -4586,7 +4611,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4586
4611
|
|
|
4587
4612
|
/** @internal */
|
|
4588
4613
|
const COMMON_HTTP_HEADERS = {
|
|
4589
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4614
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.61.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4590
4615
|
};
|
|
4591
4616
|
/**
|
|
4592
4617
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9503,10 +9528,8 @@ class ValidatorInfo {
|
|
|
9503
9528
|
const configKeys = [];
|
|
9504
9529
|
|
|
9505
9530
|
for (let i = 0; i < 2; i++) {
|
|
9506
|
-
const publicKey = new PublicKey(byteArray
|
|
9507
|
-
|
|
9508
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9509
|
-
byteArray = byteArray.slice(1);
|
|
9531
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9532
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9510
9533
|
configKeys.push({
|
|
9511
9534
|
publicKey,
|
|
9512
9535
|
isSigner
|