@solana/web3.js 1.77.2 → 1.77.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.
@@ -693,6 +693,31 @@ class CompiledKeys {
693
693
  }
694
694
  }
695
695
 
696
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
697
+
698
+ /**
699
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
700
+ */
701
+ function guardedShift(byteArray) {
702
+ if (byteArray.length === 0) {
703
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
704
+ }
705
+ return byteArray.shift();
706
+ }
707
+
708
+ /**
709
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
710
+ * the array.
711
+ */
712
+ function guardedSplice(byteArray, ...args) {
713
+ const [start] = args;
714
+ if (args.length === 2 // Implies that `deleteCount` was supplied
715
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
716
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
717
+ }
718
+ return byteArray.splice(...args);
719
+ }
720
+
696
721
  /**
697
722
  * An instruction to execute by a program
698
723
  *
@@ -830,32 +855,28 @@ class Message {
830
855
  static from(buffer$1) {
831
856
  // Slice up wire data
832
857
  let byteArray = [...buffer$1];
833
- const numRequiredSignatures = byteArray.shift();
858
+ const numRequiredSignatures = guardedShift(byteArray);
834
859
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
835
860
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
836
861
  }
837
- const numReadonlySignedAccounts = byteArray.shift();
838
- const numReadonlyUnsignedAccounts = byteArray.shift();
862
+ const numReadonlySignedAccounts = guardedShift(byteArray);
863
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
839
864
  const accountCount = decodeLength(byteArray);
840
865
  let accountKeys = [];
841
866
  for (let i = 0; i < accountCount; i++) {
842
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
843
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
867
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
844
868
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
845
869
  }
846
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
847
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
870
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
848
871
  const instructionCount = decodeLength(byteArray);
849
872
  let instructions = [];
850
873
  for (let i = 0; i < instructionCount; i++) {
851
- const programIdIndex = byteArray.shift();
874
+ const programIdIndex = guardedShift(byteArray);
852
875
  const accountCount = decodeLength(byteArray);
853
- const accounts = byteArray.slice(0, accountCount);
854
- byteArray = byteArray.slice(accountCount);
876
+ const accounts = guardedSplice(byteArray, 0, accountCount);
855
877
  const dataLength = decodeLength(byteArray);
856
- const dataSlice = byteArray.slice(0, dataLength);
878
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
857
879
  const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
858
- byteArray = byteArray.slice(dataLength);
859
880
  instructions.push({
860
881
  programIdIndex,
861
882
  accounts,
@@ -1060,30 +1081,30 @@ class MessageV0 {
1060
1081
  }
1061
1082
  static deserialize(serializedMessage) {
1062
1083
  let byteArray = [...serializedMessage];
1063
- const prefix = byteArray.shift();
1084
+ const prefix = guardedShift(byteArray);
1064
1085
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1065
1086
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1066
1087
  const version = maskedPrefix;
1067
1088
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1068
1089
  const header = {
1069
- numRequiredSignatures: byteArray.shift(),
1070
- numReadonlySignedAccounts: byteArray.shift(),
1071
- numReadonlyUnsignedAccounts: byteArray.shift()
1090
+ numRequiredSignatures: guardedShift(byteArray),
1091
+ numReadonlySignedAccounts: guardedShift(byteArray),
1092
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1072
1093
  };
1073
1094
  const staticAccountKeys = [];
1074
1095
  const staticAccountKeysLength = decodeLength(byteArray);
1075
1096
  for (let i = 0; i < staticAccountKeysLength; i++) {
1076
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1097
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1077
1098
  }
1078
- const recentBlockhash = bs58__default.default.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1099
+ const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1079
1100
  const instructionCount = decodeLength(byteArray);
1080
1101
  const compiledInstructions = [];
1081
1102
  for (let i = 0; i < instructionCount; i++) {
1082
- const programIdIndex = byteArray.shift();
1103
+ const programIdIndex = guardedShift(byteArray);
1083
1104
  const accountKeyIndexesLength = decodeLength(byteArray);
1084
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1105
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1085
1106
  const dataLength = decodeLength(byteArray);
1086
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1107
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1087
1108
  compiledInstructions.push({
1088
1109
  programIdIndex,
1089
1110
  accountKeyIndexes,
@@ -1093,11 +1114,11 @@ class MessageV0 {
1093
1114
  const addressTableLookupsCount = decodeLength(byteArray);
1094
1115
  const addressTableLookups = [];
1095
1116
  for (let i = 0; i < addressTableLookupsCount; i++) {
1096
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1117
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1097
1118
  const writableIndexesLength = decodeLength(byteArray);
1098
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1119
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1099
1120
  const readonlyIndexesLength = decodeLength(byteArray);
1100
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1121
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1101
1122
  addressTableLookups.push({
1102
1123
  accountKey,
1103
1124
  writableIndexes,
@@ -1780,8 +1801,7 @@ class Transaction {
1780
1801
  const signatureCount = decodeLength(byteArray);
1781
1802
  let signatures = [];
1782
1803
  for (let i = 0; i < signatureCount; i++) {
1783
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1784
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1804
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1785
1805
  signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
1786
1806
  }
1787
1807
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1951,7 +1971,7 @@ class VersionedTransaction {
1951
1971
  const signatures = [];
1952
1972
  const signaturesLength = decodeLength(byteArray);
1953
1973
  for (let i = 0; i < signaturesLength; i++) {
1954
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1974
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1955
1975
  }
1956
1976
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1957
1977
  return new VersionedTransaction(message, signatures);
@@ -4469,7 +4489,7 @@ const LogsNotificationResult = superstruct.type({
4469
4489
 
4470
4490
  /** @internal */
4471
4491
  const COMMON_HTTP_HEADERS = {
4472
- 'solana-client': `js/${"0.0.0-development" }`
4492
+ 'solana-client': `js/${"1.77.4" }`
4473
4493
  };
4474
4494
 
4475
4495
  /**
@@ -9259,10 +9279,8 @@ class ValidatorInfo {
9259
9279
  if (configKeyCount !== 2) return null;
9260
9280
  const configKeys = [];
9261
9281
  for (let i = 0; i < 2; i++) {
9262
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9263
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9264
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9265
- byteArray = byteArray.slice(1);
9282
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9283
+ const isSigner = guardedShift(byteArray) === 1;
9266
9284
  configKeys.push({
9267
9285
  publicKey,
9268
9286
  isSigner