@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.
@@ -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.shift();
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.shift();
918
- const numReadonlyUnsignedAccounts = byteArray.shift();
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.slice(0, PUBLIC_KEY_LENGTH);
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.slice(0, PUBLIC_KEY_LENGTH);
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.shift();
962
+ const programIdIndex = guardedShift(byteArray);
935
963
  const accountCount = decodeLength(byteArray);
936
- const accounts = byteArray.slice(0, accountCount);
937
- byteArray = byteArray.slice(accountCount);
964
+ const accounts = guardedSplice(byteArray, 0, accountCount);
938
965
  const dataLength = decodeLength(byteArray);
939
- const dataSlice = byteArray.slice(0, dataLength);
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.shift();
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.shift(),
1184
- numReadonlySignedAccounts: byteArray.shift(),
1185
- numReadonlyUnsignedAccounts: byteArray.shift()
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.splice(0, PUBLIC_KEY_LENGTH)));
1217
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1192
1218
  }
1193
1219
 
1194
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
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.shift();
1225
+ const programIdIndex = guardedShift(byteArray);
1200
1226
  const accountKeyIndexesLength = decodeLength(byteArray);
1201
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1227
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1202
1228
  const dataLength = decodeLength(byteArray);
1203
- const data = new Uint8Array(byteArray.splice(0, dataLength));
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.splice(0, PUBLIC_KEY_LENGTH));
1241
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1216
1242
  const writableIndexesLength = decodeLength(byteArray);
1217
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1243
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1218
1244
  const readonlyIndexesLength = decodeLength(byteArray);
1219
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1245
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1220
1246
  addressTableLookups.push({
1221
1247
  accountKey,
1222
1248
  writableIndexes,
@@ -1956,8 +1982,7 @@ class Transaction {
1956
1982
  let signatures = [];
1957
1983
 
1958
1984
  for (let i = 0; i < signatureCount; i++) {
1959
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1960
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1985
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1961
1986
  signatures.push(bs58.encode(Buffer.from(signature)));
1962
1987
  }
1963
1988
 
@@ -2155,7 +2180,7 @@ class VersionedTransaction {
2155
2180
  const signaturesLength = decodeLength(byteArray);
2156
2181
 
2157
2182
  for (let i = 0; i < signaturesLength; i++) {
2158
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2183
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2159
2184
  }
2160
2185
 
2161
2186
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4672,7 +4697,7 @@ const LogsNotificationResult = type({
4672
4697
 
4673
4698
  /** @internal */
4674
4699
  const COMMON_HTTP_HEADERS = {
4675
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4700
+ 'solana-client': `js/${(_process$env$npm_pack = "1.70.4") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4676
4701
  };
4677
4702
  /**
4678
4703
  * A connection to a fullnode JSON RPC endpoint
@@ -10090,10 +10115,8 @@ class ValidatorInfo {
10090
10115
  const configKeys = [];
10091
10116
 
10092
10117
  for (let i = 0; i < 2; i++) {
10093
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10094
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10095
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10096
- byteArray = byteArray.slice(1);
10118
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10119
+ const isSigner = guardedShift(byteArray) === 1;
10097
10120
  configKeys.push({
10098
10121
  publicKey,
10099
10122
  isSigner