@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.d.ts CHANGED
@@ -3191,7 +3191,7 @@ export class Connection {
3191
3191
  *
3192
3192
  * @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
3193
3193
  */
3194
- getProgramAccounts(programId: PublicKey, configOrCommitment?: GetProgramAccountsConfig & Readonly<{
3194
+ getProgramAccounts(programId: PublicKey, configOrCommitment: GetProgramAccountsConfig & Readonly<{
3195
3195
  withContext: true;
3196
3196
  }>): Promise<RpcResponseAndContext<GetProgramAccountsResponse>>;
3197
3197
  getProgramAccounts(programId: PublicKey, configOrCommitment?: GetProgramAccountsConfig | Commitment): Promise<GetProgramAccountsResponse>;
package/lib/index.esm.js CHANGED
@@ -672,6 +672,31 @@ class CompiledKeys {
672
672
  }
673
673
  }
674
674
 
675
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
676
+
677
+ /**
678
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
679
+ */
680
+ function guardedShift(byteArray) {
681
+ if (byteArray.length === 0) {
682
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
683
+ }
684
+ return byteArray.shift();
685
+ }
686
+
687
+ /**
688
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
689
+ * the array.
690
+ */
691
+ function guardedSplice(byteArray, ...args) {
692
+ const [start] = args;
693
+ if (args.length === 2 // Implies that `deleteCount` was supplied
694
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
695
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
696
+ }
697
+ return byteArray.splice(...args);
698
+ }
699
+
675
700
  /**
676
701
  * An instruction to execute by a program
677
702
  *
@@ -809,32 +834,28 @@ class Message {
809
834
  static from(buffer) {
810
835
  // Slice up wire data
811
836
  let byteArray = [...buffer];
812
- const numRequiredSignatures = byteArray.shift();
837
+ const numRequiredSignatures = guardedShift(byteArray);
813
838
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
814
839
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
815
840
  }
816
- const numReadonlySignedAccounts = byteArray.shift();
817
- const numReadonlyUnsignedAccounts = byteArray.shift();
841
+ const numReadonlySignedAccounts = guardedShift(byteArray);
842
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
818
843
  const accountCount = decodeLength(byteArray);
819
844
  let accountKeys = [];
820
845
  for (let i = 0; i < accountCount; i++) {
821
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
822
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
846
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
823
847
  accountKeys.push(new PublicKey(Buffer.from(account)));
824
848
  }
825
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
826
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
849
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
827
850
  const instructionCount = decodeLength(byteArray);
828
851
  let instructions = [];
829
852
  for (let i = 0; i < instructionCount; i++) {
830
- const programIdIndex = byteArray.shift();
853
+ const programIdIndex = guardedShift(byteArray);
831
854
  const accountCount = decodeLength(byteArray);
832
- const accounts = byteArray.slice(0, accountCount);
833
- byteArray = byteArray.slice(accountCount);
855
+ const accounts = guardedSplice(byteArray, 0, accountCount);
834
856
  const dataLength = decodeLength(byteArray);
835
- const dataSlice = byteArray.slice(0, dataLength);
857
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
836
858
  const data = bs58.encode(Buffer.from(dataSlice));
837
- byteArray = byteArray.slice(dataLength);
838
859
  instructions.push({
839
860
  programIdIndex,
840
861
  accounts,
@@ -1039,30 +1060,30 @@ class MessageV0 {
1039
1060
  }
1040
1061
  static deserialize(serializedMessage) {
1041
1062
  let byteArray = [...serializedMessage];
1042
- const prefix = byteArray.shift();
1063
+ const prefix = guardedShift(byteArray);
1043
1064
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1044
1065
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1045
1066
  const version = maskedPrefix;
1046
1067
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1047
1068
  const header = {
1048
- numRequiredSignatures: byteArray.shift(),
1049
- numReadonlySignedAccounts: byteArray.shift(),
1050
- numReadonlyUnsignedAccounts: byteArray.shift()
1069
+ numRequiredSignatures: guardedShift(byteArray),
1070
+ numReadonlySignedAccounts: guardedShift(byteArray),
1071
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1051
1072
  };
1052
1073
  const staticAccountKeys = [];
1053
1074
  const staticAccountKeysLength = decodeLength(byteArray);
1054
1075
  for (let i = 0; i < staticAccountKeysLength; i++) {
1055
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1076
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1056
1077
  }
1057
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1078
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1058
1079
  const instructionCount = decodeLength(byteArray);
1059
1080
  const compiledInstructions = [];
1060
1081
  for (let i = 0; i < instructionCount; i++) {
1061
- const programIdIndex = byteArray.shift();
1082
+ const programIdIndex = guardedShift(byteArray);
1062
1083
  const accountKeyIndexesLength = decodeLength(byteArray);
1063
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1084
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1064
1085
  const dataLength = decodeLength(byteArray);
1065
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1086
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1066
1087
  compiledInstructions.push({
1067
1088
  programIdIndex,
1068
1089
  accountKeyIndexes,
@@ -1072,11 +1093,11 @@ class MessageV0 {
1072
1093
  const addressTableLookupsCount = decodeLength(byteArray);
1073
1094
  const addressTableLookups = [];
1074
1095
  for (let i = 0; i < addressTableLookupsCount; i++) {
1075
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1096
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1076
1097
  const writableIndexesLength = decodeLength(byteArray);
1077
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1098
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1078
1099
  const readonlyIndexesLength = decodeLength(byteArray);
1079
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1100
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1080
1101
  addressTableLookups.push({
1081
1102
  accountKey,
1082
1103
  writableIndexes,
@@ -1759,8 +1780,7 @@ class Transaction {
1759
1780
  const signatureCount = decodeLength(byteArray);
1760
1781
  let signatures = [];
1761
1782
  for (let i = 0; i < signatureCount; i++) {
1762
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1763
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1783
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1764
1784
  signatures.push(bs58.encode(Buffer.from(signature)));
1765
1785
  }
1766
1786
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1930,7 +1950,7 @@ class VersionedTransaction {
1930
1950
  const signatures = [];
1931
1951
  const signaturesLength = decodeLength(byteArray);
1932
1952
  for (let i = 0; i < signaturesLength; i++) {
1933
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1953
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1934
1954
  }
1935
1955
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1936
1956
  return new VersionedTransaction(message, signatures);
@@ -6958,7 +6978,7 @@ const LogsNotificationResult = type({
6958
6978
 
6959
6979
  /** @internal */
6960
6980
  const COMMON_HTTP_HEADERS = {
6961
- 'solana-client': `js/${"0.0.0-development" }`
6981
+ 'solana-client': `js/${"1.77.4" }`
6962
6982
  };
6963
6983
 
6964
6984
  /**
@@ -11748,10 +11768,8 @@ class ValidatorInfo {
11748
11768
  if (configKeyCount !== 2) return null;
11749
11769
  const configKeys = [];
11750
11770
  for (let i = 0; i < 2; i++) {
11751
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
11752
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11753
- const isSigner = byteArray.slice(0, 1)[0] === 1;
11754
- byteArray = byteArray.slice(1);
11771
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11772
+ const isSigner = guardedShift(byteArray) === 1;
11755
11773
  configKeys.push({
11756
11774
  publicKey,
11757
11775
  isSigner