@solana/web3.js 1.90.1 → 1.90.2

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
@@ -708,6 +708,31 @@ class CompiledKeys {
708
708
  }
709
709
  }
710
710
 
711
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
712
+
713
+ /**
714
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
715
+ */
716
+ function guardedShift(byteArray) {
717
+ if (byteArray.length === 0) {
718
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
719
+ }
720
+ return byteArray.shift();
721
+ }
722
+
723
+ /**
724
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
725
+ * the array.
726
+ */
727
+ function guardedSplice(byteArray, ...args) {
728
+ const [start] = args;
729
+ if (args.length === 2 // Implies that `deleteCount` was supplied
730
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
731
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
732
+ }
733
+ return byteArray.splice(...args);
734
+ }
735
+
711
736
  /**
712
737
  * An instruction to execute by a program
713
738
  *
@@ -849,32 +874,28 @@ class Message {
849
874
  static from(buffer$1) {
850
875
  // Slice up wire data
851
876
  let byteArray = [...buffer$1];
852
- const numRequiredSignatures = byteArray.shift();
877
+ const numRequiredSignatures = guardedShift(byteArray);
853
878
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
854
879
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
855
880
  }
856
- const numReadonlySignedAccounts = byteArray.shift();
857
- const numReadonlyUnsignedAccounts = byteArray.shift();
881
+ const numReadonlySignedAccounts = guardedShift(byteArray);
882
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
858
883
  const accountCount = decodeLength(byteArray);
859
884
  let accountKeys = [];
860
885
  for (let i = 0; i < accountCount; i++) {
861
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
862
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
886
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
863
887
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
864
888
  }
865
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
866
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
889
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
867
890
  const instructionCount = decodeLength(byteArray);
868
891
  let instructions = [];
869
892
  for (let i = 0; i < instructionCount; i++) {
870
- const programIdIndex = byteArray.shift();
893
+ const programIdIndex = guardedShift(byteArray);
871
894
  const accountCount = decodeLength(byteArray);
872
- const accounts = byteArray.slice(0, accountCount);
873
- byteArray = byteArray.slice(accountCount);
895
+ const accounts = guardedSplice(byteArray, 0, accountCount);
874
896
  const dataLength = decodeLength(byteArray);
875
- const dataSlice = byteArray.slice(0, dataLength);
897
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
876
898
  const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
877
- byteArray = byteArray.slice(dataLength);
878
899
  instructions.push({
879
900
  programIdIndex,
880
901
  accounts,
@@ -1079,30 +1100,30 @@ class MessageV0 {
1079
1100
  }
1080
1101
  static deserialize(serializedMessage) {
1081
1102
  let byteArray = [...serializedMessage];
1082
- const prefix = byteArray.shift();
1103
+ const prefix = guardedShift(byteArray);
1083
1104
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1084
1105
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1085
1106
  const version = maskedPrefix;
1086
1107
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1087
1108
  const header = {
1088
- numRequiredSignatures: byteArray.shift(),
1089
- numReadonlySignedAccounts: byteArray.shift(),
1090
- numReadonlyUnsignedAccounts: byteArray.shift()
1109
+ numRequiredSignatures: guardedShift(byteArray),
1110
+ numReadonlySignedAccounts: guardedShift(byteArray),
1111
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1091
1112
  };
1092
1113
  const staticAccountKeys = [];
1093
1114
  const staticAccountKeysLength = decodeLength(byteArray);
1094
1115
  for (let i = 0; i < staticAccountKeysLength; i++) {
1095
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1116
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1096
1117
  }
1097
- const recentBlockhash = bs58__default.default.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1118
+ const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1098
1119
  const instructionCount = decodeLength(byteArray);
1099
1120
  const compiledInstructions = [];
1100
1121
  for (let i = 0; i < instructionCount; i++) {
1101
- const programIdIndex = byteArray.shift();
1122
+ const programIdIndex = guardedShift(byteArray);
1102
1123
  const accountKeyIndexesLength = decodeLength(byteArray);
1103
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1124
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1104
1125
  const dataLength = decodeLength(byteArray);
1105
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1126
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1106
1127
  compiledInstructions.push({
1107
1128
  programIdIndex,
1108
1129
  accountKeyIndexes,
@@ -1112,11 +1133,11 @@ class MessageV0 {
1112
1133
  const addressTableLookupsCount = decodeLength(byteArray);
1113
1134
  const addressTableLookups = [];
1114
1135
  for (let i = 0; i < addressTableLookupsCount; i++) {
1115
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1136
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1116
1137
  const writableIndexesLength = decodeLength(byteArray);
1117
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1138
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1118
1139
  const readonlyIndexesLength = decodeLength(byteArray);
1119
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1140
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1120
1141
  addressTableLookups.push({
1121
1142
  accountKey,
1122
1143
  writableIndexes,
@@ -1907,8 +1928,7 @@ class Transaction {
1907
1928
  const signatureCount = decodeLength(byteArray);
1908
1929
  let signatures = [];
1909
1930
  for (let i = 0; i < signatureCount; i++) {
1910
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1911
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1931
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1912
1932
  signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
1913
1933
  }
1914
1934
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -2083,7 +2103,7 @@ class VersionedTransaction {
2083
2103
  const signatures = [];
2084
2104
  const signaturesLength = decodeLength(byteArray);
2085
2105
  for (let i = 0; i < signaturesLength; i++) {
2086
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2106
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2087
2107
  }
2088
2108
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
2089
2109
  return new VersionedTransaction(message, signatures);
@@ -5823,7 +5843,7 @@ const LogsNotificationResult = superstruct.type({
5823
5843
 
5824
5844
  /** @internal */
5825
5845
  const COMMON_HTTP_HEADERS = {
5826
- 'solana-client': `js/${"0.0.0-development" }`
5846
+ 'solana-client': `js/${"1.90.2" }`
5827
5847
  };
5828
5848
 
5829
5849
  /**
@@ -10783,10 +10803,8 @@ class ValidatorInfo {
10783
10803
  if (configKeyCount !== 2) return null;
10784
10804
  const configKeys = [];
10785
10805
  for (let i = 0; i < 2; i++) {
10786
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10787
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10788
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10789
- byteArray = byteArray.slice(1);
10806
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10807
+ const isSigner = guardedShift(byteArray) === 1;
10790
10808
  configKeys.push({
10791
10809
  publicKey,
10792
10810
  isSigner