@solana/web3.js 1.67.1 → 1.67.3
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.d.ts +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/connection.ts +2 -2
- 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.d.ts
CHANGED
|
@@ -3534,7 +3534,7 @@ declare module '@solana/web3.js' {
|
|
|
3534
3534
|
* Fetch the fee for a message from the cluster, return with context
|
|
3535
3535
|
*/
|
|
3536
3536
|
getFeeForMessage(
|
|
3537
|
-
message:
|
|
3537
|
+
message: VersionedMessage,
|
|
3538
3538
|
commitment?: Commitment,
|
|
3539
3539
|
): Promise<RpcResponseAndContext<number>>;
|
|
3540
3540
|
/**
|
package/lib/index.esm.js
CHANGED
|
@@ -753,6 +753,36 @@ class CompiledKeys {
|
|
|
753
753
|
|
|
754
754
|
}
|
|
755
755
|
|
|
756
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
757
|
+
/**
|
|
758
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
759
|
+
*/
|
|
760
|
+
|
|
761
|
+
function guardedShift(byteArray) {
|
|
762
|
+
if (byteArray.length === 0) {
|
|
763
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return byteArray.shift();
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
770
|
+
* the array.
|
|
771
|
+
*/
|
|
772
|
+
|
|
773
|
+
function guardedSplice(byteArray, ...args) {
|
|
774
|
+
var _args$;
|
|
775
|
+
|
|
776
|
+
const [start] = args;
|
|
777
|
+
|
|
778
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
779
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
780
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return byteArray.splice(...args);
|
|
784
|
+
}
|
|
785
|
+
|
|
756
786
|
/**
|
|
757
787
|
* An instruction to execute by a program
|
|
758
788
|
*
|
|
@@ -904,37 +934,33 @@ class Message {
|
|
|
904
934
|
static from(buffer) {
|
|
905
935
|
// Slice up wire data
|
|
906
936
|
let byteArray = [...buffer];
|
|
907
|
-
const numRequiredSignatures = byteArray
|
|
937
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
908
938
|
|
|
909
939
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
910
940
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
911
941
|
}
|
|
912
942
|
|
|
913
|
-
const numReadonlySignedAccounts = byteArray
|
|
914
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
943
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
944
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
915
945
|
const accountCount = decodeLength(byteArray);
|
|
916
946
|
let accountKeys = [];
|
|
917
947
|
|
|
918
948
|
for (let i = 0; i < accountCount; i++) {
|
|
919
|
-
const account = byteArray
|
|
920
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
949
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
921
950
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
922
951
|
}
|
|
923
952
|
|
|
924
|
-
const recentBlockhash = byteArray
|
|
925
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
953
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
926
954
|
const instructionCount = decodeLength(byteArray);
|
|
927
955
|
let instructions = [];
|
|
928
956
|
|
|
929
957
|
for (let i = 0; i < instructionCount; i++) {
|
|
930
|
-
const programIdIndex = byteArray
|
|
958
|
+
const programIdIndex = guardedShift(byteArray);
|
|
931
959
|
const accountCount = decodeLength(byteArray);
|
|
932
|
-
const accounts = byteArray
|
|
933
|
-
byteArray = byteArray.slice(accountCount);
|
|
960
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
934
961
|
const dataLength = decodeLength(byteArray);
|
|
935
|
-
const dataSlice = byteArray
|
|
962
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
936
963
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
937
|
-
byteArray = byteArray.slice(dataLength);
|
|
938
964
|
instructions.push({
|
|
939
965
|
programIdIndex,
|
|
940
966
|
accounts,
|
|
@@ -1170,33 +1196,33 @@ class MessageV0 {
|
|
|
1170
1196
|
|
|
1171
1197
|
static deserialize(serializedMessage) {
|
|
1172
1198
|
let byteArray = [...serializedMessage];
|
|
1173
|
-
const prefix = byteArray
|
|
1199
|
+
const prefix = guardedShift(byteArray);
|
|
1174
1200
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1175
1201
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1176
1202
|
const version = maskedPrefix;
|
|
1177
1203
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1178
1204
|
const header = {
|
|
1179
|
-
numRequiredSignatures: byteArray
|
|
1180
|
-
numReadonlySignedAccounts: byteArray
|
|
1181
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1205
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1206
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1207
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1182
1208
|
};
|
|
1183
1209
|
const staticAccountKeys = [];
|
|
1184
1210
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1185
1211
|
|
|
1186
1212
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1187
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1213
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1188
1214
|
}
|
|
1189
1215
|
|
|
1190
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1216
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1191
1217
|
const instructionCount = decodeLength(byteArray);
|
|
1192
1218
|
const compiledInstructions = [];
|
|
1193
1219
|
|
|
1194
1220
|
for (let i = 0; i < instructionCount; i++) {
|
|
1195
|
-
const programIdIndex = byteArray
|
|
1221
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1196
1222
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1197
|
-
const accountKeyIndexes = byteArray
|
|
1223
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1198
1224
|
const dataLength = decodeLength(byteArray);
|
|
1199
|
-
const data = new Uint8Array(byteArray
|
|
1225
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1200
1226
|
compiledInstructions.push({
|
|
1201
1227
|
programIdIndex,
|
|
1202
1228
|
accountKeyIndexes,
|
|
@@ -1208,11 +1234,11 @@ class MessageV0 {
|
|
|
1208
1234
|
const addressTableLookups = [];
|
|
1209
1235
|
|
|
1210
1236
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1211
|
-
const accountKey = new PublicKey(byteArray
|
|
1237
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1212
1238
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1213
|
-
const writableIndexes = byteArray
|
|
1239
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1214
1240
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1215
|
-
const readonlyIndexes = byteArray
|
|
1241
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1216
1242
|
addressTableLookups.push({
|
|
1217
1243
|
accountKey,
|
|
1218
1244
|
writableIndexes,
|
|
@@ -1952,8 +1978,7 @@ class Transaction {
|
|
|
1952
1978
|
let signatures = [];
|
|
1953
1979
|
|
|
1954
1980
|
for (let i = 0; i < signatureCount; i++) {
|
|
1955
|
-
const signature = byteArray
|
|
1956
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1981
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1957
1982
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1958
1983
|
}
|
|
1959
1984
|
|
|
@@ -2151,7 +2176,7 @@ class VersionedTransaction {
|
|
|
2151
2176
|
const signaturesLength = decodeLength(byteArray);
|
|
2152
2177
|
|
|
2153
2178
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2154
|
-
signatures.push(new Uint8Array(byteArray
|
|
2179
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2155
2180
|
}
|
|
2156
2181
|
|
|
2157
2182
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4664,7 +4689,7 @@ const LogsNotificationResult = type({
|
|
|
4664
4689
|
|
|
4665
4690
|
/** @internal */
|
|
4666
4691
|
const COMMON_HTTP_HEADERS = {
|
|
4667
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4692
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.67.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4668
4693
|
};
|
|
4669
4694
|
/**
|
|
4670
4695
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -6046,7 +6071,7 @@ class Connection {
|
|
|
6046
6071
|
|
|
6047
6072
|
|
|
6048
6073
|
async getFeeForMessage(message, commitment) {
|
|
6049
|
-
const wireMessage = message.serialize().toString('base64');
|
|
6074
|
+
const wireMessage = toBuffer(message.serialize()).toString('base64');
|
|
6050
6075
|
|
|
6051
6076
|
const args = this._buildArgs([wireMessage], commitment);
|
|
6052
6077
|
|
|
@@ -9987,10 +10012,8 @@ class ValidatorInfo {
|
|
|
9987
10012
|
const configKeys = [];
|
|
9988
10013
|
|
|
9989
10014
|
for (let i = 0; i < 2; i++) {
|
|
9990
|
-
const publicKey = new PublicKey(byteArray
|
|
9991
|
-
|
|
9992
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9993
|
-
byteArray = byteArray.slice(1);
|
|
10015
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10016
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9994
10017
|
configKeys.push({
|
|
9995
10018
|
publicKey,
|
|
9996
10019
|
isSigner
|