@solana/web3.js 1.75.0 → 1.75.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.cjs.js CHANGED
@@ -648,8 +648,8 @@ class CompiledKeys {
648
648
  getOrInsertDefault(ix.programId).isInvoked = true;
649
649
  for (const accountMeta of ix.keys) {
650
650
  const keyMeta = getOrInsertDefault(accountMeta.pubkey);
651
- keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
652
- keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
651
+ keyMeta.isSigner ||= accountMeta.isSigner;
652
+ keyMeta.isWritable ||= accountMeta.isWritable;
653
653
  }
654
654
  }
655
655
  return new CompiledKeys(payer, keyMetaMap);
@@ -714,6 +714,31 @@ class CompiledKeys {
714
714
  }
715
715
  }
716
716
 
717
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
718
+
719
+ /**
720
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
721
+ */
722
+ function guardedShift(byteArray) {
723
+ if (byteArray.length === 0) {
724
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
725
+ }
726
+ return byteArray.shift();
727
+ }
728
+
729
+ /**
730
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
731
+ * the array.
732
+ */
733
+ function guardedSplice(byteArray, ...args) {
734
+ const [start] = args;
735
+ if (args.length === 2 // Implies that `deleteCount` was supplied
736
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
737
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
738
+ }
739
+ return byteArray.splice(...args);
740
+ }
741
+
717
742
  /**
718
743
  * An instruction to execute by a program
719
744
  *
@@ -851,32 +876,28 @@ class Message {
851
876
  static from(buffer$1) {
852
877
  // Slice up wire data
853
878
  let byteArray = [...buffer$1];
854
- const numRequiredSignatures = byteArray.shift();
879
+ const numRequiredSignatures = guardedShift(byteArray);
855
880
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
856
881
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
857
882
  }
858
- const numReadonlySignedAccounts = byteArray.shift();
859
- const numReadonlyUnsignedAccounts = byteArray.shift();
883
+ const numReadonlySignedAccounts = guardedShift(byteArray);
884
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
860
885
  const accountCount = decodeLength(byteArray);
861
886
  let accountKeys = [];
862
887
  for (let i = 0; i < accountCount; i++) {
863
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
864
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
888
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
865
889
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
866
890
  }
867
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
868
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
891
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
869
892
  const instructionCount = decodeLength(byteArray);
870
893
  let instructions = [];
871
894
  for (let i = 0; i < instructionCount; i++) {
872
- const programIdIndex = byteArray.shift();
895
+ const programIdIndex = guardedShift(byteArray);
873
896
  const accountCount = decodeLength(byteArray);
874
- const accounts = byteArray.slice(0, accountCount);
875
- byteArray = byteArray.slice(accountCount);
897
+ const accounts = guardedSplice(byteArray, 0, accountCount);
876
898
  const dataLength = decodeLength(byteArray);
877
- const dataSlice = byteArray.slice(0, dataLength);
899
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
878
900
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
879
- byteArray = byteArray.slice(dataLength);
880
901
  instructions.push({
881
902
  programIdIndex,
882
903
  accounts,
@@ -1081,30 +1102,30 @@ class MessageV0 {
1081
1102
  }
1082
1103
  static deserialize(serializedMessage) {
1083
1104
  let byteArray = [...serializedMessage];
1084
- const prefix = byteArray.shift();
1105
+ const prefix = guardedShift(byteArray);
1085
1106
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1086
1107
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1087
1108
  const version = maskedPrefix;
1088
1109
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1089
1110
  const header = {
1090
- numRequiredSignatures: byteArray.shift(),
1091
- numReadonlySignedAccounts: byteArray.shift(),
1092
- numReadonlyUnsignedAccounts: byteArray.shift()
1111
+ numRequiredSignatures: guardedShift(byteArray),
1112
+ numReadonlySignedAccounts: guardedShift(byteArray),
1113
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1093
1114
  };
1094
1115
  const staticAccountKeys = [];
1095
1116
  const staticAccountKeysLength = decodeLength(byteArray);
1096
1117
  for (let i = 0; i < staticAccountKeysLength; i++) {
1097
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1118
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1098
1119
  }
1099
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1120
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1100
1121
  const instructionCount = decodeLength(byteArray);
1101
1122
  const compiledInstructions = [];
1102
1123
  for (let i = 0; i < instructionCount; i++) {
1103
- const programIdIndex = byteArray.shift();
1124
+ const programIdIndex = guardedShift(byteArray);
1104
1125
  const accountKeyIndexesLength = decodeLength(byteArray);
1105
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1126
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1106
1127
  const dataLength = decodeLength(byteArray);
1107
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1128
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1108
1129
  compiledInstructions.push({
1109
1130
  programIdIndex,
1110
1131
  accountKeyIndexes,
@@ -1114,11 +1135,11 @@ class MessageV0 {
1114
1135
  const addressTableLookupsCount = decodeLength(byteArray);
1115
1136
  const addressTableLookups = [];
1116
1137
  for (let i = 0; i < addressTableLookupsCount; i++) {
1117
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1138
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1118
1139
  const writableIndexesLength = decodeLength(byteArray);
1119
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1140
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1120
1141
  const readonlyIndexesLength = decodeLength(byteArray);
1121
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1142
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1122
1143
  addressTableLookups.push({
1123
1144
  accountKey,
1124
1145
  writableIndexes,
@@ -1793,8 +1814,7 @@ class Transaction {
1793
1814
  const signatureCount = decodeLength(byteArray);
1794
1815
  let signatures = [];
1795
1816
  for (let i = 0; i < signatureCount; i++) {
1796
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1797
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1817
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1798
1818
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1799
1819
  }
1800
1820
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1964,7 +1984,7 @@ class VersionedTransaction {
1964
1984
  const signatures = [];
1965
1985
  const signaturesLength = decodeLength(byteArray);
1966
1986
  for (let i = 0; i < signaturesLength; i++) {
1967
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1987
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1968
1988
  }
1969
1989
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1970
1990
  return new VersionedTransaction(message, signatures);
@@ -6964,7 +6984,7 @@ const LogsNotificationResult = superstruct.type({
6964
6984
 
6965
6985
  /** @internal */
6966
6986
  const COMMON_HTTP_HEADERS = {
6967
- 'solana-client': `js/${"0.0.0-development" }`
6987
+ 'solana-client': `js/${"1.75.1" }`
6968
6988
  };
6969
6989
 
6970
6990
  /**
@@ -9193,12 +9213,11 @@ class Connection {
9193
9213
  * @internal
9194
9214
  */
9195
9215
  _onSubscriptionStateChange(clientSubscriptionId, callback) {
9196
- var _this$_subscriptionSt;
9197
9216
  const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
9198
9217
  if (hash == null) {
9199
9218
  return () => {};
9200
9219
  }
9201
- const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
9220
+ const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
9202
9221
  stateChangeCallbacks.add(callback);
9203
9222
  return () => {
9204
9223
  stateChangeCallbacks.delete(callback);
@@ -11759,10 +11778,8 @@ class ValidatorInfo {
11759
11778
  if (configKeyCount !== 2) return null;
11760
11779
  const configKeys = [];
11761
11780
  for (let i = 0; i < 2; i++) {
11762
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
11763
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11764
- const isSigner = byteArray.slice(0, 1)[0] === 1;
11765
- byteArray = byteArray.slice(1);
11781
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11782
+ const isSigner = guardedShift(byteArray) === 1;
11766
11783
  configKeys.push({
11767
11784
  publicKey,
11768
11785
  isSigner