@solana/web3.js 1.71.0 → 1.71.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.
@@ -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.shift();
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.shift();
948
- const numReadonlyUnsignedAccounts = byteArray.shift();
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.slice(0, PUBLIC_KEY_LENGTH);
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.slice(0, PUBLIC_KEY_LENGTH);
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.shift();
992
+ const programIdIndex = guardedShift(byteArray);
965
993
  const accountCount = decodeLength(byteArray);
966
- const accounts = byteArray.slice(0, accountCount);
967
- byteArray = byteArray.slice(accountCount);
994
+ const accounts = guardedSplice(byteArray, 0, accountCount);
968
995
  const dataLength = decodeLength(byteArray);
969
- const dataSlice = byteArray.slice(0, dataLength);
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.shift();
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.shift(),
1214
- numReadonlySignedAccounts: byteArray.shift(),
1215
- numReadonlyUnsignedAccounts: byteArray.shift()
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.splice(0, PUBLIC_KEY_LENGTH)));
1247
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1222
1248
  }
1223
1249
 
1224
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
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.shift();
1255
+ const programIdIndex = guardedShift(byteArray);
1230
1256
  const accountKeyIndexesLength = decodeLength(byteArray);
1231
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1257
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1232
1258
  const dataLength = decodeLength(byteArray);
1233
- const data = new Uint8Array(byteArray.splice(0, dataLength));
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.splice(0, PUBLIC_KEY_LENGTH));
1271
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1246
1272
  const writableIndexesLength = decodeLength(byteArray);
1247
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1273
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1248
1274
  const readonlyIndexesLength = decodeLength(byteArray);
1249
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1275
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1250
1276
  addressTableLookups.push({
1251
1277
  accountKey,
1252
1278
  writableIndexes,
@@ -1988,8 +2014,7 @@ class Transaction {
1988
2014
  let signatures = [];
1989
2015
 
1990
2016
  for (let i = 0; i < signatureCount; i++) {
1991
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1992
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
2017
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1993
2018
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1994
2019
  }
1995
2020
 
@@ -2187,7 +2212,7 @@ class VersionedTransaction {
2187
2212
  const signaturesLength = decodeLength(byteArray);
2188
2213
 
2189
2214
  for (let i = 0; i < signaturesLength; i++) {
2190
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2215
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2191
2216
  }
2192
2217
 
2193
2218
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4704,7 +4729,7 @@ const LogsNotificationResult = superstruct.type({
4704
4729
 
4705
4730
  /** @internal */
4706
4731
  const COMMON_HTTP_HEADERS = {
4707
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4732
+ 'solana-client': `js/${(_process$env$npm_pack = "1.71.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4708
4733
  };
4709
4734
  /**
4710
4735
  * 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.slice(0, PUBLIC_KEY_LENGTH));
10126
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
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