@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.
package/lib/index.cjs.js CHANGED
@@ -707,6 +707,31 @@ class CompiledKeys {
707
707
  }
708
708
  }
709
709
 
710
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
711
+
712
+ /**
713
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
714
+ */
715
+ function guardedShift(byteArray) {
716
+ if (byteArray.length === 0) {
717
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
718
+ }
719
+ return byteArray.shift();
720
+ }
721
+
722
+ /**
723
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
724
+ * the array.
725
+ */
726
+ function guardedSplice(byteArray, ...args) {
727
+ const [start] = args;
728
+ if (args.length === 2 // Implies that `deleteCount` was supplied
729
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
730
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
731
+ }
732
+ return byteArray.splice(...args);
733
+ }
734
+
710
735
  /**
711
736
  * An instruction to execute by a program
712
737
  *
@@ -844,32 +869,28 @@ class Message {
844
869
  static from(buffer$1) {
845
870
  // Slice up wire data
846
871
  let byteArray = [...buffer$1];
847
- const numRequiredSignatures = byteArray.shift();
872
+ const numRequiredSignatures = guardedShift(byteArray);
848
873
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
849
874
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
850
875
  }
851
- const numReadonlySignedAccounts = byteArray.shift();
852
- const numReadonlyUnsignedAccounts = byteArray.shift();
876
+ const numReadonlySignedAccounts = guardedShift(byteArray);
877
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
853
878
  const accountCount = decodeLength(byteArray);
854
879
  let accountKeys = [];
855
880
  for (let i = 0; i < accountCount; i++) {
856
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
857
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
881
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
858
882
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
859
883
  }
860
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
861
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
884
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
862
885
  const instructionCount = decodeLength(byteArray);
863
886
  let instructions = [];
864
887
  for (let i = 0; i < instructionCount; i++) {
865
- const programIdIndex = byteArray.shift();
888
+ const programIdIndex = guardedShift(byteArray);
866
889
  const accountCount = decodeLength(byteArray);
867
- const accounts = byteArray.slice(0, accountCount);
868
- byteArray = byteArray.slice(accountCount);
890
+ const accounts = guardedSplice(byteArray, 0, accountCount);
869
891
  const dataLength = decodeLength(byteArray);
870
- const dataSlice = byteArray.slice(0, dataLength);
892
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
871
893
  const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
872
- byteArray = byteArray.slice(dataLength);
873
894
  instructions.push({
874
895
  programIdIndex,
875
896
  accounts,
@@ -1074,30 +1095,30 @@ class MessageV0 {
1074
1095
  }
1075
1096
  static deserialize(serializedMessage) {
1076
1097
  let byteArray = [...serializedMessage];
1077
- const prefix = byteArray.shift();
1098
+ const prefix = guardedShift(byteArray);
1078
1099
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1079
1100
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1080
1101
  const version = maskedPrefix;
1081
1102
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1082
1103
  const header = {
1083
- numRequiredSignatures: byteArray.shift(),
1084
- numReadonlySignedAccounts: byteArray.shift(),
1085
- numReadonlyUnsignedAccounts: byteArray.shift()
1104
+ numRequiredSignatures: guardedShift(byteArray),
1105
+ numReadonlySignedAccounts: guardedShift(byteArray),
1106
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1086
1107
  };
1087
1108
  const staticAccountKeys = [];
1088
1109
  const staticAccountKeysLength = decodeLength(byteArray);
1089
1110
  for (let i = 0; i < staticAccountKeysLength; i++) {
1090
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1111
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1091
1112
  }
1092
- const recentBlockhash = bs58__default.default.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1113
+ const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1093
1114
  const instructionCount = decodeLength(byteArray);
1094
1115
  const compiledInstructions = [];
1095
1116
  for (let i = 0; i < instructionCount; i++) {
1096
- const programIdIndex = byteArray.shift();
1117
+ const programIdIndex = guardedShift(byteArray);
1097
1118
  const accountKeyIndexesLength = decodeLength(byteArray);
1098
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1119
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1099
1120
  const dataLength = decodeLength(byteArray);
1100
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1121
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1101
1122
  compiledInstructions.push({
1102
1123
  programIdIndex,
1103
1124
  accountKeyIndexes,
@@ -1107,11 +1128,11 @@ class MessageV0 {
1107
1128
  const addressTableLookupsCount = decodeLength(byteArray);
1108
1129
  const addressTableLookups = [];
1109
1130
  for (let i = 0; i < addressTableLookupsCount; i++) {
1110
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1131
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1111
1132
  const writableIndexesLength = decodeLength(byteArray);
1112
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1133
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1113
1134
  const readonlyIndexesLength = decodeLength(byteArray);
1114
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1135
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1115
1136
  addressTableLookups.push({
1116
1137
  accountKey,
1117
1138
  writableIndexes,
@@ -1794,8 +1815,7 @@ class Transaction {
1794
1815
  const signatureCount = decodeLength(byteArray);
1795
1816
  let signatures = [];
1796
1817
  for (let i = 0; i < signatureCount; i++) {
1797
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1798
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1818
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1799
1819
  signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
1800
1820
  }
1801
1821
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1965,7 +1985,7 @@ class VersionedTransaction {
1965
1985
  const signatures = [];
1966
1986
  const signaturesLength = decodeLength(byteArray);
1967
1987
  for (let i = 0; i < signaturesLength; i++) {
1968
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1988
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1969
1989
  }
1970
1990
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1971
1991
  return new VersionedTransaction(message, signatures);
@@ -6993,7 +7013,7 @@ const LogsNotificationResult = superstruct.type({
6993
7013
 
6994
7014
  /** @internal */
6995
7015
  const COMMON_HTTP_HEADERS = {
6996
- 'solana-client': `js/${"0.0.0-development" }`
7016
+ 'solana-client': `js/${"1.77.4" }`
6997
7017
  };
6998
7018
 
6999
7019
  /**
@@ -11783,10 +11803,8 @@ class ValidatorInfo {
11783
11803
  if (configKeyCount !== 2) return null;
11784
11804
  const configKeys = [];
11785
11805
  for (let i = 0; i < 2; i++) {
11786
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
11787
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11788
- const isSigner = byteArray.slice(0, 1)[0] === 1;
11789
- byteArray = byteArray.slice(1);
11806
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11807
+ const isSigner = guardedShift(byteArray) === 1;
11790
11808
  configKeys.push({
11791
11809
  publicKey,
11792
11810
  isSigner