@solana/web3.js 1.72.0 → 1.72.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 +278 -80
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +273 -75
- 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
|
@@ -757,6 +757,36 @@ class CompiledKeys {
|
|
|
757
757
|
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
761
|
+
/**
|
|
762
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
763
|
+
*/
|
|
764
|
+
|
|
765
|
+
function guardedShift(byteArray) {
|
|
766
|
+
if (byteArray.length === 0) {
|
|
767
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return byteArray.shift();
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
774
|
+
* the array.
|
|
775
|
+
*/
|
|
776
|
+
|
|
777
|
+
function guardedSplice(byteArray, ...args) {
|
|
778
|
+
var _args$;
|
|
779
|
+
|
|
780
|
+
const [start] = args;
|
|
781
|
+
|
|
782
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
783
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
784
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
return byteArray.splice(...args);
|
|
788
|
+
}
|
|
789
|
+
|
|
760
790
|
/**
|
|
761
791
|
* An instruction to execute by a program
|
|
762
792
|
*
|
|
@@ -908,37 +938,33 @@ class Message {
|
|
|
908
938
|
static from(buffer) {
|
|
909
939
|
// Slice up wire data
|
|
910
940
|
let byteArray = [...buffer];
|
|
911
|
-
const numRequiredSignatures = byteArray
|
|
941
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
912
942
|
|
|
913
943
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
914
944
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
915
945
|
}
|
|
916
946
|
|
|
917
|
-
const numReadonlySignedAccounts = byteArray
|
|
918
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
947
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
948
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
919
949
|
const accountCount = decodeLength(byteArray);
|
|
920
950
|
let accountKeys = [];
|
|
921
951
|
|
|
922
952
|
for (let i = 0; i < accountCount; i++) {
|
|
923
|
-
const account = byteArray
|
|
924
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
953
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
925
954
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
926
955
|
}
|
|
927
956
|
|
|
928
|
-
const recentBlockhash = byteArray
|
|
929
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
957
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
930
958
|
const instructionCount = decodeLength(byteArray);
|
|
931
959
|
let instructions = [];
|
|
932
960
|
|
|
933
961
|
for (let i = 0; i < instructionCount; i++) {
|
|
934
|
-
const programIdIndex = byteArray
|
|
962
|
+
const programIdIndex = guardedShift(byteArray);
|
|
935
963
|
const accountCount = decodeLength(byteArray);
|
|
936
|
-
const accounts = byteArray
|
|
937
|
-
byteArray = byteArray.slice(accountCount);
|
|
964
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
938
965
|
const dataLength = decodeLength(byteArray);
|
|
939
|
-
const dataSlice = byteArray
|
|
966
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
940
967
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
941
|
-
byteArray = byteArray.slice(dataLength);
|
|
942
968
|
instructions.push({
|
|
943
969
|
programIdIndex,
|
|
944
970
|
accounts,
|
|
@@ -1174,33 +1200,33 @@ class MessageV0 {
|
|
|
1174
1200
|
|
|
1175
1201
|
static deserialize(serializedMessage) {
|
|
1176
1202
|
let byteArray = [...serializedMessage];
|
|
1177
|
-
const prefix = byteArray
|
|
1203
|
+
const prefix = guardedShift(byteArray);
|
|
1178
1204
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1179
1205
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1180
1206
|
const version = maskedPrefix;
|
|
1181
1207
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1182
1208
|
const header = {
|
|
1183
|
-
numRequiredSignatures: byteArray
|
|
1184
|
-
numReadonlySignedAccounts: byteArray
|
|
1185
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1209
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1210
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1211
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1186
1212
|
};
|
|
1187
1213
|
const staticAccountKeys = [];
|
|
1188
1214
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1189
1215
|
|
|
1190
1216
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1191
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1217
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1192
1218
|
}
|
|
1193
1219
|
|
|
1194
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1220
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1195
1221
|
const instructionCount = decodeLength(byteArray);
|
|
1196
1222
|
const compiledInstructions = [];
|
|
1197
1223
|
|
|
1198
1224
|
for (let i = 0; i < instructionCount; i++) {
|
|
1199
|
-
const programIdIndex = byteArray
|
|
1225
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1200
1226
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1201
|
-
const accountKeyIndexes = byteArray
|
|
1227
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1202
1228
|
const dataLength = decodeLength(byteArray);
|
|
1203
|
-
const data = new Uint8Array(byteArray
|
|
1229
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1204
1230
|
compiledInstructions.push({
|
|
1205
1231
|
programIdIndex,
|
|
1206
1232
|
accountKeyIndexes,
|
|
@@ -1212,11 +1238,11 @@ class MessageV0 {
|
|
|
1212
1238
|
const addressTableLookups = [];
|
|
1213
1239
|
|
|
1214
1240
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1215
|
-
const accountKey = new PublicKey(byteArray
|
|
1241
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1216
1242
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1217
|
-
const writableIndexes = byteArray
|
|
1243
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1218
1244
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1219
|
-
const readonlyIndexes = byteArray
|
|
1245
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1220
1246
|
addressTableLookups.push({
|
|
1221
1247
|
accountKey,
|
|
1222
1248
|
writableIndexes,
|
|
@@ -1958,8 +1984,7 @@ class Transaction {
|
|
|
1958
1984
|
let signatures = [];
|
|
1959
1985
|
|
|
1960
1986
|
for (let i = 0; i < signatureCount; i++) {
|
|
1961
|
-
const signature = byteArray
|
|
1962
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1987
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1963
1988
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1964
1989
|
}
|
|
1965
1990
|
|
|
@@ -2157,7 +2182,7 @@ class VersionedTransaction {
|
|
|
2157
2182
|
const signaturesLength = decodeLength(byteArray);
|
|
2158
2183
|
|
|
2159
2184
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2160
|
-
signatures.push(new Uint8Array(byteArray
|
|
2185
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2161
2186
|
}
|
|
2162
2187
|
|
|
2163
2188
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4689,7 +4714,7 @@ const LogsNotificationResult = type({
|
|
|
4689
4714
|
|
|
4690
4715
|
/** @internal */
|
|
4691
4716
|
const COMMON_HTTP_HEADERS = {
|
|
4692
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4717
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.72.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4693
4718
|
};
|
|
4694
4719
|
/**
|
|
4695
4720
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -10122,10 +10147,8 @@ class ValidatorInfo {
|
|
|
10122
10147
|
const configKeys = [];
|
|
10123
10148
|
|
|
10124
10149
|
for (let i = 0; i < 2; i++) {
|
|
10125
|
-
const publicKey = new PublicKey(byteArray
|
|
10126
|
-
|
|
10127
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10128
|
-
byteArray = byteArray.slice(1);
|
|
10150
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10151
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10129
10152
|
configKeys.push({
|
|
10130
10153
|
publicKey,
|
|
10131
10154
|
isSigner
|