@solana/web3.js 1.76.0 → 1.76.1

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.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,
@@ -1751,8 +1772,7 @@ class Transaction {
1751
1772
  const signatureCount = decodeLength(byteArray);
1752
1773
  let signatures = [];
1753
1774
  for (let i = 0; i < signatureCount; i++) {
1754
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1755
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1775
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1756
1776
  signatures.push(bs58.encode(Buffer.from(signature)));
1757
1777
  }
1758
1778
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1922,7 +1942,7 @@ class VersionedTransaction {
1922
1942
  const signatures = [];
1923
1943
  const signaturesLength = decodeLength(byteArray);
1924
1944
  for (let i = 0; i < signaturesLength; i++) {
1925
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1945
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1926
1946
  }
1927
1947
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1928
1948
  return new VersionedTransaction(message, signatures);
@@ -6922,7 +6942,7 @@ const LogsNotificationResult = type({
6922
6942
 
6923
6943
  /** @internal */
6924
6944
  const COMMON_HTTP_HEADERS = {
6925
- 'solana-client': `js/${"0.0.0-development" }`
6945
+ 'solana-client': `js/${"1.76.1" }`
6926
6946
  };
6927
6947
 
6928
6948
  /**
@@ -11709,10 +11729,8 @@ class ValidatorInfo {
11709
11729
  if (configKeyCount !== 2) return null;
11710
11730
  const configKeys = [];
11711
11731
  for (let i = 0; i < 2; i++) {
11712
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
11713
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11714
- const isSigner = byteArray.slice(0, 1)[0] === 1;
11715
- byteArray = byteArray.slice(1);
11732
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11733
+ const isSigner = guardedShift(byteArray) === 1;
11716
11734
  configKeys.push({
11717
11735
  publicKey,
11718
11736
  isSigner