@solana/web3.js 1.66.5 → 1.66.6

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.
@@ -765,6 +765,36 @@ class CompiledKeys {
765
765
 
766
766
  }
767
767
 
768
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
769
+ /**
770
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
771
+ */
772
+
773
+ function guardedShift(byteArray) {
774
+ if (byteArray.length === 0) {
775
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
776
+ }
777
+
778
+ return byteArray.shift();
779
+ }
780
+ /**
781
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
782
+ * the array.
783
+ */
784
+
785
+ function guardedSplice(byteArray, ...args) {
786
+ var _args$;
787
+
788
+ const [start] = args;
789
+
790
+ if (args.length === 2 // Implies that `deleteCount` was supplied
791
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
792
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
793
+ }
794
+
795
+ return byteArray.splice(...args);
796
+ }
797
+
768
798
  /**
769
799
  * An instruction to execute by a program
770
800
  *
@@ -916,37 +946,33 @@ class Message {
916
946
  static from(buffer$1) {
917
947
  // Slice up wire data
918
948
  let byteArray = [...buffer$1];
919
- const numRequiredSignatures = byteArray.shift();
949
+ const numRequiredSignatures = guardedShift(byteArray);
920
950
 
921
951
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
922
952
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
923
953
  }
924
954
 
925
- const numReadonlySignedAccounts = byteArray.shift();
926
- const numReadonlyUnsignedAccounts = byteArray.shift();
955
+ const numReadonlySignedAccounts = guardedShift(byteArray);
956
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
927
957
  const accountCount = decodeLength(byteArray);
928
958
  let accountKeys = [];
929
959
 
930
960
  for (let i = 0; i < accountCount; i++) {
931
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
932
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
961
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
933
962
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
934
963
  }
935
964
 
936
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
937
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
965
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
938
966
  const instructionCount = decodeLength(byteArray);
939
967
  let instructions = [];
940
968
 
941
969
  for (let i = 0; i < instructionCount; i++) {
942
- const programIdIndex = byteArray.shift();
970
+ const programIdIndex = guardedShift(byteArray);
943
971
  const accountCount = decodeLength(byteArray);
944
- const accounts = byteArray.slice(0, accountCount);
945
- byteArray = byteArray.slice(accountCount);
972
+ const accounts = guardedSplice(byteArray, 0, accountCount);
946
973
  const dataLength = decodeLength(byteArray);
947
- const dataSlice = byteArray.slice(0, dataLength);
974
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
948
975
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
949
- byteArray = byteArray.slice(dataLength);
950
976
  instructions.push({
951
977
  programIdIndex,
952
978
  accounts,
@@ -1182,33 +1208,33 @@ class MessageV0 {
1182
1208
 
1183
1209
  static deserialize(serializedMessage) {
1184
1210
  let byteArray = [...serializedMessage];
1185
- const prefix = byteArray.shift();
1211
+ const prefix = guardedShift(byteArray);
1186
1212
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1187
1213
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1188
1214
  const version = maskedPrefix;
1189
1215
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1190
1216
  const header = {
1191
- numRequiredSignatures: byteArray.shift(),
1192
- numReadonlySignedAccounts: byteArray.shift(),
1193
- numReadonlyUnsignedAccounts: byteArray.shift()
1217
+ numRequiredSignatures: guardedShift(byteArray),
1218
+ numReadonlySignedAccounts: guardedShift(byteArray),
1219
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1194
1220
  };
1195
1221
  const staticAccountKeys = [];
1196
1222
  const staticAccountKeysLength = decodeLength(byteArray);
1197
1223
 
1198
1224
  for (let i = 0; i < staticAccountKeysLength; i++) {
1199
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1225
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1200
1226
  }
1201
1227
 
1202
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1228
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1203
1229
  const instructionCount = decodeLength(byteArray);
1204
1230
  const compiledInstructions = [];
1205
1231
 
1206
1232
  for (let i = 0; i < instructionCount; i++) {
1207
- const programIdIndex = byteArray.shift();
1233
+ const programIdIndex = guardedShift(byteArray);
1208
1234
  const accountKeyIndexesLength = decodeLength(byteArray);
1209
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1235
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1210
1236
  const dataLength = decodeLength(byteArray);
1211
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1237
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1212
1238
  compiledInstructions.push({
1213
1239
  programIdIndex,
1214
1240
  accountKeyIndexes,
@@ -1220,11 +1246,11 @@ class MessageV0 {
1220
1246
  const addressTableLookups = [];
1221
1247
 
1222
1248
  for (let i = 0; i < addressTableLookupsCount; i++) {
1223
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1249
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1224
1250
  const writableIndexesLength = decodeLength(byteArray);
1225
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1251
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1226
1252
  const readonlyIndexesLength = decodeLength(byteArray);
1227
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1253
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1228
1254
  addressTableLookups.push({
1229
1255
  accountKey,
1230
1256
  writableIndexes,
@@ -1955,8 +1981,7 @@ class Transaction {
1955
1981
  let signatures = [];
1956
1982
 
1957
1983
  for (let i = 0; i < signatureCount; i++) {
1958
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1959
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1984
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1960
1985
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1961
1986
  }
1962
1987
 
@@ -2154,7 +2179,7 @@ class VersionedTransaction {
2154
2179
  const signaturesLength = decodeLength(byteArray);
2155
2180
 
2156
2181
  for (let i = 0; i < signaturesLength; i++) {
2157
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2182
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2158
2183
  }
2159
2184
 
2160
2185
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4584,7 +4609,7 @@ const LogsNotificationResult = superstruct.type({
4584
4609
 
4585
4610
  /** @internal */
4586
4611
  const COMMON_HTTP_HEADERS = {
4587
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4612
+ 'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4588
4613
  };
4589
4614
  /**
4590
4615
  * A connection to a fullnode JSON RPC endpoint
@@ -9689,10 +9714,8 @@ class ValidatorInfo {
9689
9714
  const configKeys = [];
9690
9715
 
9691
9716
  for (let i = 0; i < 2; i++) {
9692
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9693
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9694
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9695
- byteArray = byteArray.slice(1);
9717
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9718
+ const isSigner = guardedShift(byteArray) === 1;
9696
9719
  configKeys.push({
9697
9720
  publicKey,
9698
9721
  isSigner