@solana/web3.js 1.73.4 → 1.73.5

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.
@@ -634,8 +634,8 @@ class CompiledKeys {
634
634
  getOrInsertDefault(ix.programId).isInvoked = true;
635
635
  for (const accountMeta of ix.keys) {
636
636
  const keyMeta = getOrInsertDefault(accountMeta.pubkey);
637
- keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
638
- keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
637
+ keyMeta.isSigner ||= accountMeta.isSigner;
638
+ keyMeta.isWritable ||= accountMeta.isWritable;
639
639
  }
640
640
  }
641
641
  return new CompiledKeys(payer, keyMetaMap);
@@ -700,6 +700,31 @@ class CompiledKeys {
700
700
  }
701
701
  }
702
702
 
703
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
704
+
705
+ /**
706
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
707
+ */
708
+ function guardedShift(byteArray) {
709
+ if (byteArray.length === 0) {
710
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
711
+ }
712
+ return byteArray.shift();
713
+ }
714
+
715
+ /**
716
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
717
+ * the array.
718
+ */
719
+ function guardedSplice(byteArray, ...args) {
720
+ const [start] = args;
721
+ if (args.length === 2 // Implies that `deleteCount` was supplied
722
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
723
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
724
+ }
725
+ return byteArray.splice(...args);
726
+ }
727
+
703
728
  /**
704
729
  * An instruction to execute by a program
705
730
  *
@@ -837,32 +862,28 @@ class Message {
837
862
  static from(buffer$1) {
838
863
  // Slice up wire data
839
864
  let byteArray = [...buffer$1];
840
- const numRequiredSignatures = byteArray.shift();
865
+ const numRequiredSignatures = guardedShift(byteArray);
841
866
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
842
867
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
843
868
  }
844
- const numReadonlySignedAccounts = byteArray.shift();
845
- const numReadonlyUnsignedAccounts = byteArray.shift();
869
+ const numReadonlySignedAccounts = guardedShift(byteArray);
870
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
846
871
  const accountCount = decodeLength(byteArray);
847
872
  let accountKeys = [];
848
873
  for (let i = 0; i < accountCount; i++) {
849
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
850
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
874
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
851
875
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
852
876
  }
853
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
854
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
877
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
855
878
  const instructionCount = decodeLength(byteArray);
856
879
  let instructions = [];
857
880
  for (let i = 0; i < instructionCount; i++) {
858
- const programIdIndex = byteArray.shift();
881
+ const programIdIndex = guardedShift(byteArray);
859
882
  const accountCount = decodeLength(byteArray);
860
- const accounts = byteArray.slice(0, accountCount);
861
- byteArray = byteArray.slice(accountCount);
883
+ const accounts = guardedSplice(byteArray, 0, accountCount);
862
884
  const dataLength = decodeLength(byteArray);
863
- const dataSlice = byteArray.slice(0, dataLength);
885
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
864
886
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
865
- byteArray = byteArray.slice(dataLength);
866
887
  instructions.push({
867
888
  programIdIndex,
868
889
  accounts,
@@ -1067,30 +1088,30 @@ class MessageV0 {
1067
1088
  }
1068
1089
  static deserialize(serializedMessage) {
1069
1090
  let byteArray = [...serializedMessage];
1070
- const prefix = byteArray.shift();
1091
+ const prefix = guardedShift(byteArray);
1071
1092
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1072
1093
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1073
1094
  const version = maskedPrefix;
1074
1095
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1075
1096
  const header = {
1076
- numRequiredSignatures: byteArray.shift(),
1077
- numReadonlySignedAccounts: byteArray.shift(),
1078
- numReadonlyUnsignedAccounts: byteArray.shift()
1097
+ numRequiredSignatures: guardedShift(byteArray),
1098
+ numReadonlySignedAccounts: guardedShift(byteArray),
1099
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1079
1100
  };
1080
1101
  const staticAccountKeys = [];
1081
1102
  const staticAccountKeysLength = decodeLength(byteArray);
1082
1103
  for (let i = 0; i < staticAccountKeysLength; i++) {
1083
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1104
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1084
1105
  }
1085
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1106
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1086
1107
  const instructionCount = decodeLength(byteArray);
1087
1108
  const compiledInstructions = [];
1088
1109
  for (let i = 0; i < instructionCount; i++) {
1089
- const programIdIndex = byteArray.shift();
1110
+ const programIdIndex = guardedShift(byteArray);
1090
1111
  const accountKeyIndexesLength = decodeLength(byteArray);
1091
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1112
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1092
1113
  const dataLength = decodeLength(byteArray);
1093
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1114
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1094
1115
  compiledInstructions.push({
1095
1116
  programIdIndex,
1096
1117
  accountKeyIndexes,
@@ -1100,11 +1121,11 @@ class MessageV0 {
1100
1121
  const addressTableLookupsCount = decodeLength(byteArray);
1101
1122
  const addressTableLookups = [];
1102
1123
  for (let i = 0; i < addressTableLookupsCount; i++) {
1103
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1124
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1104
1125
  const writableIndexesLength = decodeLength(byteArray);
1105
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1126
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1106
1127
  const readonlyIndexesLength = decodeLength(byteArray);
1107
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1128
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1108
1129
  addressTableLookups.push({
1109
1130
  accountKey,
1110
1131
  writableIndexes,
@@ -1779,8 +1800,7 @@ class Transaction {
1779
1800
  const signatureCount = decodeLength(byteArray);
1780
1801
  let signatures = [];
1781
1802
  for (let i = 0; i < signatureCount; i++) {
1782
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1783
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1803
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1784
1804
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1785
1805
  }
1786
1806
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -1950,7 +1970,7 @@ class VersionedTransaction {
1950
1970
  const signatures = [];
1951
1971
  const signaturesLength = decodeLength(byteArray);
1952
1972
  for (let i = 0; i < signaturesLength; i++) {
1953
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
1973
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
1954
1974
  }
1955
1975
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
1956
1976
  return new VersionedTransaction(message, signatures);
@@ -4428,7 +4448,7 @@ const LogsNotificationResult = superstruct.type({
4428
4448
 
4429
4449
  /** @internal */
4430
4450
  const COMMON_HTTP_HEADERS = {
4431
- 'solana-client': `js/${"0.0.0-development" }`
4451
+ 'solana-client': `js/${"1.73.5" }`
4432
4452
  };
4433
4453
 
4434
4454
  /**
@@ -6633,12 +6653,11 @@ class Connection {
6633
6653
  * @internal
6634
6654
  */
6635
6655
  _onSubscriptionStateChange(clientSubscriptionId, callback) {
6636
- var _this$_subscriptionSt;
6637
6656
  const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
6638
6657
  if (hash == null) {
6639
6658
  return () => {};
6640
6659
  }
6641
- const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
6660
+ const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
6642
6661
  stateChangeCallbacks.add(callback);
6643
6662
  return () => {
6644
6663
  stateChangeCallbacks.delete(callback);
@@ -9199,10 +9218,8 @@ class ValidatorInfo {
9199
9218
  if (configKeyCount !== 2) return null;
9200
9219
  const configKeys = [];
9201
9220
  for (let i = 0; i < 2; i++) {
9202
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9203
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9204
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9205
- byteArray = byteArray.slice(1);
9221
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9222
+ const isSigner = guardedShift(byteArray) === 1;
9206
9223
  configKeys.push({
9207
9224
  publicKey,
9208
9225
  isSigner