@solana/web3.js 1.87.5 → 1.87.7

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.
@@ -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
  *
@@ -841,32 +866,28 @@ class Message {
841
866
  static from(buffer$1) {
842
867
  // Slice up wire data
843
868
  let byteArray = [...buffer$1];
844
- const numRequiredSignatures = byteArray.shift();
869
+ const numRequiredSignatures = guardedShift(byteArray);
845
870
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
846
871
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
847
872
  }
848
- const numReadonlySignedAccounts = byteArray.shift();
849
- const numReadonlyUnsignedAccounts = byteArray.shift();
873
+ const numReadonlySignedAccounts = guardedShift(byteArray);
874
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
850
875
  const accountCount = decodeLength(byteArray);
851
876
  let accountKeys = [];
852
877
  for (let i = 0; i < accountCount; i++) {
853
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
854
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
878
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
855
879
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
856
880
  }
857
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
858
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
881
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
859
882
  const instructionCount = decodeLength(byteArray);
860
883
  let instructions = [];
861
884
  for (let i = 0; i < instructionCount; i++) {
862
- const programIdIndex = byteArray.shift();
885
+ const programIdIndex = guardedShift(byteArray);
863
886
  const accountCount = decodeLength(byteArray);
864
- const accounts = byteArray.slice(0, accountCount);
865
- byteArray = byteArray.slice(accountCount);
887
+ const accounts = guardedSplice(byteArray, 0, accountCount);
866
888
  const dataLength = decodeLength(byteArray);
867
- const dataSlice = byteArray.slice(0, dataLength);
889
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
868
890
  const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
869
- byteArray = byteArray.slice(dataLength);
870
891
  instructions.push({
871
892
  programIdIndex,
872
893
  accounts,
@@ -1071,30 +1092,30 @@ class MessageV0 {
1071
1092
  }
1072
1093
  static deserialize(serializedMessage) {
1073
1094
  let byteArray = [...serializedMessage];
1074
- const prefix = byteArray.shift();
1095
+ const prefix = guardedShift(byteArray);
1075
1096
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1076
1097
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1077
1098
  const version = maskedPrefix;
1078
1099
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1079
1100
  const header = {
1080
- numRequiredSignatures: byteArray.shift(),
1081
- numReadonlySignedAccounts: byteArray.shift(),
1082
- numReadonlyUnsignedAccounts: byteArray.shift()
1101
+ numRequiredSignatures: guardedShift(byteArray),
1102
+ numReadonlySignedAccounts: guardedShift(byteArray),
1103
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1083
1104
  };
1084
1105
  const staticAccountKeys = [];
1085
1106
  const staticAccountKeysLength = decodeLength(byteArray);
1086
1107
  for (let i = 0; i < staticAccountKeysLength; i++) {
1087
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1108
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1088
1109
  }
1089
- const recentBlockhash = bs58__default.default.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1110
+ const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1090
1111
  const instructionCount = decodeLength(byteArray);
1091
1112
  const compiledInstructions = [];
1092
1113
  for (let i = 0; i < instructionCount; i++) {
1093
- const programIdIndex = byteArray.shift();
1114
+ const programIdIndex = guardedShift(byteArray);
1094
1115
  const accountKeyIndexesLength = decodeLength(byteArray);
1095
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1116
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1096
1117
  const dataLength = decodeLength(byteArray);
1097
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1118
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1098
1119
  compiledInstructions.push({
1099
1120
  programIdIndex,
1100
1121
  accountKeyIndexes,
@@ -1104,11 +1125,11 @@ class MessageV0 {
1104
1125
  const addressTableLookupsCount = decodeLength(byteArray);
1105
1126
  const addressTableLookups = [];
1106
1127
  for (let i = 0; i < addressTableLookupsCount; i++) {
1107
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1128
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1108
1129
  const writableIndexesLength = decodeLength(byteArray);
1109
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1130
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1110
1131
  const readonlyIndexesLength = decodeLength(byteArray);
1111
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1132
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1112
1133
  addressTableLookups.push({
1113
1134
  accountKey,
1114
1135
  writableIndexes,
@@ -1880,8 +1901,7 @@ class Transaction {
1880
1901
  const signatureCount = decodeLength(byteArray);
1881
1902
  let signatures = [];
1882
1903
  for (let i = 0; i < signatureCount; i++) {
1883
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1884
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1904
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1885
1905
  signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
1886
1906
  }
1887
1907
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -2056,7 +2076,7 @@ class VersionedTransaction {
2056
2076
  const signatures = [];
2057
2077
  const signaturesLength = decodeLength(byteArray);
2058
2078
  for (let i = 0; i < signaturesLength; i++) {
2059
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2079
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2060
2080
  }
2061
2081
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
2062
2082
  return new VersionedTransaction(message, signatures);
@@ -3563,7 +3583,7 @@ function makeWebsocketUrl(endpoint) {
3563
3583
  const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
3564
3584
  const websocketPort =
3565
3585
  // Only shift the port by +1 as a convention for ws(s) only if given endpoint
3566
- // is explictly specifying the endpoint port (HTTP-based RPC), assuming
3586
+ // is explicitly specifying the endpoint port (HTTP-based RPC), assuming
3567
3587
  // we're directly trying to connect to solana-validator's ws listening port.
3568
3588
  // When the endpoint omits the port, we're connecting to the protocol
3569
3589
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
@@ -5078,7 +5098,7 @@ const LogsNotificationResult = superstruct.type({
5078
5098
 
5079
5099
  /** @internal */
5080
5100
  const COMMON_HTTP_HEADERS = {
5081
- 'solana-client': `js/${"0.0.0-development" }`
5101
+ 'solana-client': `js/${"1.87.7" }`
5082
5102
  };
5083
5103
 
5084
5104
  /**
@@ -10013,10 +10033,8 @@ class ValidatorInfo {
10013
10033
  if (configKeyCount !== 2) return null;
10014
10034
  const configKeys = [];
10015
10035
  for (let i = 0; i < 2; i++) {
10016
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10017
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10018
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10019
- byteArray = byteArray.slice(1);
10036
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10037
+ const isSigner = guardedShift(byteArray) === 1;
10020
10038
  configKeys.push({
10021
10039
  publicKey,
10022
10040
  isSigner