@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.esm.js
CHANGED
|
@@ -737,6 +737,36 @@ class CompiledKeys {
|
|
|
737
737
|
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
741
|
+
/**
|
|
742
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
743
|
+
*/
|
|
744
|
+
|
|
745
|
+
function guardedShift(byteArray) {
|
|
746
|
+
if (byteArray.length === 0) {
|
|
747
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
return byteArray.shift();
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
754
|
+
* the array.
|
|
755
|
+
*/
|
|
756
|
+
|
|
757
|
+
function guardedSplice(byteArray, ...args) {
|
|
758
|
+
var _args$;
|
|
759
|
+
|
|
760
|
+
const [start] = args;
|
|
761
|
+
|
|
762
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
763
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
764
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
return byteArray.splice(...args);
|
|
768
|
+
}
|
|
769
|
+
|
|
740
770
|
/**
|
|
741
771
|
* An instruction to execute by a program
|
|
742
772
|
*
|
|
@@ -878,37 +908,33 @@ class Message {
|
|
|
878
908
|
static from(buffer) {
|
|
879
909
|
// Slice up wire data
|
|
880
910
|
let byteArray = [...buffer];
|
|
881
|
-
const numRequiredSignatures = byteArray
|
|
911
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
882
912
|
|
|
883
913
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
884
914
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
885
915
|
}
|
|
886
916
|
|
|
887
|
-
const numReadonlySignedAccounts = byteArray
|
|
888
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
917
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
918
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
889
919
|
const accountCount = decodeLength(byteArray);
|
|
890
920
|
let accountKeys = [];
|
|
891
921
|
|
|
892
922
|
for (let i = 0; i < accountCount; i++) {
|
|
893
|
-
const account = byteArray
|
|
894
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
923
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
895
924
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
896
925
|
}
|
|
897
926
|
|
|
898
|
-
const recentBlockhash = byteArray
|
|
899
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
927
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
900
928
|
const instructionCount = decodeLength(byteArray);
|
|
901
929
|
let instructions = [];
|
|
902
930
|
|
|
903
931
|
for (let i = 0; i < instructionCount; i++) {
|
|
904
|
-
const programIdIndex = byteArray
|
|
932
|
+
const programIdIndex = guardedShift(byteArray);
|
|
905
933
|
const accountCount = decodeLength(byteArray);
|
|
906
|
-
const accounts = byteArray
|
|
907
|
-
byteArray = byteArray.slice(accountCount);
|
|
934
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
908
935
|
const dataLength = decodeLength(byteArray);
|
|
909
|
-
const dataSlice = byteArray
|
|
936
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
910
937
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
911
|
-
byteArray = byteArray.slice(dataLength);
|
|
912
938
|
instructions.push({
|
|
913
939
|
programIdIndex,
|
|
914
940
|
accounts,
|
|
@@ -1121,33 +1147,33 @@ class MessageV0 {
|
|
|
1121
1147
|
|
|
1122
1148
|
static deserialize(serializedMessage) {
|
|
1123
1149
|
let byteArray = [...serializedMessage];
|
|
1124
|
-
const prefix = byteArray
|
|
1150
|
+
const prefix = guardedShift(byteArray);
|
|
1125
1151
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1126
1152
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1127
1153
|
const version = maskedPrefix;
|
|
1128
1154
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1129
1155
|
const header = {
|
|
1130
|
-
numRequiredSignatures: byteArray
|
|
1131
|
-
numReadonlySignedAccounts: byteArray
|
|
1132
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1156
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1157
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1158
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1133
1159
|
};
|
|
1134
1160
|
const staticAccountKeys = [];
|
|
1135
1161
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1136
1162
|
|
|
1137
1163
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1138
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1164
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1139
1165
|
}
|
|
1140
1166
|
|
|
1141
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1167
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1142
1168
|
const instructionCount = decodeLength(byteArray);
|
|
1143
1169
|
const compiledInstructions = [];
|
|
1144
1170
|
|
|
1145
1171
|
for (let i = 0; i < instructionCount; i++) {
|
|
1146
|
-
const programIdIndex = byteArray
|
|
1172
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1147
1173
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1148
|
-
const accountKeyIndexes = byteArray
|
|
1174
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1149
1175
|
const dataLength = decodeLength(byteArray);
|
|
1150
|
-
const data = new Uint8Array(byteArray
|
|
1176
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1151
1177
|
compiledInstructions.push({
|
|
1152
1178
|
programIdIndex,
|
|
1153
1179
|
accountKeyIndexes,
|
|
@@ -1159,11 +1185,11 @@ class MessageV0 {
|
|
|
1159
1185
|
const addressTableLookups = [];
|
|
1160
1186
|
|
|
1161
1187
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1162
|
-
const accountKey = new PublicKey(byteArray
|
|
1188
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1163
1189
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1164
|
-
const writableIndexes = byteArray
|
|
1190
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1165
1191
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1166
|
-
const readonlyIndexes = byteArray
|
|
1192
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1167
1193
|
addressTableLookups.push({
|
|
1168
1194
|
accountKey,
|
|
1169
1195
|
writableIndexes,
|
|
@@ -1894,8 +1920,7 @@ class Transaction {
|
|
|
1894
1920
|
let signatures = [];
|
|
1895
1921
|
|
|
1896
1922
|
for (let i = 0; i < signatureCount; i++) {
|
|
1897
|
-
const signature = byteArray
|
|
1898
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1923
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1899
1924
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1900
1925
|
}
|
|
1901
1926
|
|
|
@@ -2093,7 +2118,7 @@ class VersionedTransaction {
|
|
|
2093
2118
|
const signaturesLength = decodeLength(byteArray);
|
|
2094
2119
|
|
|
2095
2120
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2096
|
-
signatures.push(new Uint8Array(byteArray
|
|
2121
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2097
2122
|
}
|
|
2098
2123
|
|
|
2099
2124
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -3529,7 +3554,7 @@ class AddressLookupTableAccount {
|
|
|
3529
3554
|
}
|
|
3530
3555
|
|
|
3531
3556
|
isActive() {
|
|
3532
|
-
const U64_MAX =
|
|
3557
|
+
const U64_MAX = 18446744073709551615n;
|
|
3533
3558
|
return this.state.deactivationSlot === U64_MAX;
|
|
3534
3559
|
}
|
|
3535
3560
|
|
|
@@ -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.61.2") !== 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
|
|
@@ -9470,10 +9495,8 @@ class ValidatorInfo {
|
|
|
9470
9495
|
const configKeys = [];
|
|
9471
9496
|
|
|
9472
9497
|
for (let i = 0; i < 2; i++) {
|
|
9473
|
-
const publicKey = new PublicKey(byteArray
|
|
9474
|
-
|
|
9475
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9476
|
-
byteArray = byteArray.slice(1);
|
|
9498
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9499
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9477
9500
|
configKeys.push({
|
|
9478
9501
|
publicKey,
|
|
9479
9502
|
isSigner
|