@solana/web3.js 1.70.3 → 1.70.4
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.cjs.js
CHANGED
|
@@ -787,6 +787,36 @@ class CompiledKeys {
|
|
|
787
787
|
|
|
788
788
|
}
|
|
789
789
|
|
|
790
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
791
|
+
/**
|
|
792
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
function guardedShift(byteArray) {
|
|
796
|
+
if (byteArray.length === 0) {
|
|
797
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return byteArray.shift();
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
804
|
+
* the array.
|
|
805
|
+
*/
|
|
806
|
+
|
|
807
|
+
function guardedSplice(byteArray, ...args) {
|
|
808
|
+
var _args$;
|
|
809
|
+
|
|
810
|
+
const [start] = args;
|
|
811
|
+
|
|
812
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
813
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
814
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
return byteArray.splice(...args);
|
|
818
|
+
}
|
|
819
|
+
|
|
790
820
|
/**
|
|
791
821
|
* An instruction to execute by a program
|
|
792
822
|
*
|
|
@@ -938,37 +968,33 @@ class Message {
|
|
|
938
968
|
static from(buffer$1) {
|
|
939
969
|
// Slice up wire data
|
|
940
970
|
let byteArray = [...buffer$1];
|
|
941
|
-
const numRequiredSignatures = byteArray
|
|
971
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
942
972
|
|
|
943
973
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
944
974
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
945
975
|
}
|
|
946
976
|
|
|
947
|
-
const numReadonlySignedAccounts = byteArray
|
|
948
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
977
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
978
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
949
979
|
const accountCount = decodeLength(byteArray);
|
|
950
980
|
let accountKeys = [];
|
|
951
981
|
|
|
952
982
|
for (let i = 0; i < accountCount; i++) {
|
|
953
|
-
const account = byteArray
|
|
954
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
983
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
955
984
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
956
985
|
}
|
|
957
986
|
|
|
958
|
-
const recentBlockhash = byteArray
|
|
959
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
987
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
960
988
|
const instructionCount = decodeLength(byteArray);
|
|
961
989
|
let instructions = [];
|
|
962
990
|
|
|
963
991
|
for (let i = 0; i < instructionCount; i++) {
|
|
964
|
-
const programIdIndex = byteArray
|
|
992
|
+
const programIdIndex = guardedShift(byteArray);
|
|
965
993
|
const accountCount = decodeLength(byteArray);
|
|
966
|
-
const accounts = byteArray
|
|
967
|
-
byteArray = byteArray.slice(accountCount);
|
|
994
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
968
995
|
const dataLength = decodeLength(byteArray);
|
|
969
|
-
const dataSlice = byteArray
|
|
996
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
970
997
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
971
|
-
byteArray = byteArray.slice(dataLength);
|
|
972
998
|
instructions.push({
|
|
973
999
|
programIdIndex,
|
|
974
1000
|
accounts,
|
|
@@ -1204,33 +1230,33 @@ class MessageV0 {
|
|
|
1204
1230
|
|
|
1205
1231
|
static deserialize(serializedMessage) {
|
|
1206
1232
|
let byteArray = [...serializedMessage];
|
|
1207
|
-
const prefix = byteArray
|
|
1233
|
+
const prefix = guardedShift(byteArray);
|
|
1208
1234
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1209
1235
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1210
1236
|
const version = maskedPrefix;
|
|
1211
1237
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1212
1238
|
const header = {
|
|
1213
|
-
numRequiredSignatures: byteArray
|
|
1214
|
-
numReadonlySignedAccounts: byteArray
|
|
1215
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1239
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1240
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1241
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1216
1242
|
};
|
|
1217
1243
|
const staticAccountKeys = [];
|
|
1218
1244
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1219
1245
|
|
|
1220
1246
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1221
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1247
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1222
1248
|
}
|
|
1223
1249
|
|
|
1224
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1250
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1225
1251
|
const instructionCount = decodeLength(byteArray);
|
|
1226
1252
|
const compiledInstructions = [];
|
|
1227
1253
|
|
|
1228
1254
|
for (let i = 0; i < instructionCount; i++) {
|
|
1229
|
-
const programIdIndex = byteArray
|
|
1255
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1230
1256
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1231
|
-
const accountKeyIndexes = byteArray
|
|
1257
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1232
1258
|
const dataLength = decodeLength(byteArray);
|
|
1233
|
-
const data = new Uint8Array(byteArray
|
|
1259
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1234
1260
|
compiledInstructions.push({
|
|
1235
1261
|
programIdIndex,
|
|
1236
1262
|
accountKeyIndexes,
|
|
@@ -1242,11 +1268,11 @@ class MessageV0 {
|
|
|
1242
1268
|
const addressTableLookups = [];
|
|
1243
1269
|
|
|
1244
1270
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1245
|
-
const accountKey = new PublicKey(byteArray
|
|
1271
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1246
1272
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1247
|
-
const writableIndexes = byteArray
|
|
1273
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1248
1274
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1249
|
-
const readonlyIndexes = byteArray
|
|
1275
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1250
1276
|
addressTableLookups.push({
|
|
1251
1277
|
accountKey,
|
|
1252
1278
|
writableIndexes,
|
|
@@ -1986,8 +2012,7 @@ class Transaction {
|
|
|
1986
2012
|
let signatures = [];
|
|
1987
2013
|
|
|
1988
2014
|
for (let i = 0; i < signatureCount; i++) {
|
|
1989
|
-
const signature = byteArray
|
|
1990
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
2015
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1991
2016
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1992
2017
|
}
|
|
1993
2018
|
|
|
@@ -2185,7 +2210,7 @@ class VersionedTransaction {
|
|
|
2185
2210
|
const signaturesLength = decodeLength(byteArray);
|
|
2186
2211
|
|
|
2187
2212
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2188
|
-
signatures.push(new Uint8Array(byteArray
|
|
2213
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2189
2214
|
}
|
|
2190
2215
|
|
|
2191
2216
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4702,7 +4727,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4702
4727
|
|
|
4703
4728
|
/** @internal */
|
|
4704
4729
|
const COMMON_HTTP_HEADERS = {
|
|
4705
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4730
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.70.4") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4706
4731
|
};
|
|
4707
4732
|
/**
|
|
4708
4733
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -10120,10 +10145,8 @@ class ValidatorInfo {
|
|
|
10120
10145
|
const configKeys = [];
|
|
10121
10146
|
|
|
10122
10147
|
for (let i = 0; i < 2; i++) {
|
|
10123
|
-
const publicKey = new PublicKey(byteArray
|
|
10124
|
-
|
|
10125
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10126
|
-
byteArray = byteArray.slice(1);
|
|
10148
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10149
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10127
10150
|
configKeys.push({
|
|
10128
10151
|
publicKey,
|
|
10129
10152
|
isSigner
|