@solana/web3.js 1.58.0 → 1.58.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.
@@ -754,6 +754,36 @@ class CompiledKeys {
754
754
 
755
755
  }
756
756
 
757
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
758
+ /**
759
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
760
+ */
761
+
762
+ function guardedShift(byteArray) {
763
+ if (byteArray.length === 0) {
764
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
765
+ }
766
+
767
+ return byteArray.shift();
768
+ }
769
+ /**
770
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
771
+ * the array.
772
+ */
773
+
774
+ function guardedSplice(byteArray, ...args) {
775
+ var _args$;
776
+
777
+ const [start] = args;
778
+
779
+ if (args.length === 2 // Implies that `deleteCount` was supplied
780
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
781
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
782
+ }
783
+
784
+ return byteArray.splice(...args);
785
+ }
786
+
757
787
  /**
758
788
  * An instruction to execute by a program
759
789
  *
@@ -895,37 +925,33 @@ class Message {
895
925
  static from(buffer$1) {
896
926
  // Slice up wire data
897
927
  let byteArray = [...buffer$1];
898
- const numRequiredSignatures = byteArray.shift();
928
+ const numRequiredSignatures = guardedShift(byteArray);
899
929
 
900
930
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
901
931
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
902
932
  }
903
933
 
904
- const numReadonlySignedAccounts = byteArray.shift();
905
- const numReadonlyUnsignedAccounts = byteArray.shift();
934
+ const numReadonlySignedAccounts = guardedShift(byteArray);
935
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
906
936
  const accountCount = decodeLength(byteArray);
907
937
  let accountKeys = [];
908
938
 
909
939
  for (let i = 0; i < accountCount; i++) {
910
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
911
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
940
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
912
941
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
913
942
  }
914
943
 
915
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
916
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
944
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
917
945
  const instructionCount = decodeLength(byteArray);
918
946
  let instructions = [];
919
947
 
920
948
  for (let i = 0; i < instructionCount; i++) {
921
- const programIdIndex = byteArray.shift();
949
+ const programIdIndex = guardedShift(byteArray);
922
950
  const accountCount = decodeLength(byteArray);
923
- const accounts = byteArray.slice(0, accountCount);
924
- byteArray = byteArray.slice(accountCount);
951
+ const accounts = guardedSplice(byteArray, 0, accountCount);
925
952
  const dataLength = decodeLength(byteArray);
926
- const dataSlice = byteArray.slice(0, dataLength);
953
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
927
954
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
928
- byteArray = byteArray.slice(dataLength);
929
955
  instructions.push({
930
956
  programIdIndex,
931
957
  accounts,
@@ -1138,33 +1164,33 @@ class MessageV0 {
1138
1164
 
1139
1165
  static deserialize(serializedMessage) {
1140
1166
  let byteArray = [...serializedMessage];
1141
- const prefix = byteArray.shift();
1167
+ const prefix = guardedShift(byteArray);
1142
1168
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1143
1169
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1144
1170
  const version = maskedPrefix;
1145
1171
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1146
1172
  const header = {
1147
- numRequiredSignatures: byteArray.shift(),
1148
- numReadonlySignedAccounts: byteArray.shift(),
1149
- numReadonlyUnsignedAccounts: byteArray.shift()
1173
+ numRequiredSignatures: guardedShift(byteArray),
1174
+ numReadonlySignedAccounts: guardedShift(byteArray),
1175
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1150
1176
  };
1151
1177
  const staticAccountKeys = [];
1152
1178
  const staticAccountKeysLength = decodeLength(byteArray);
1153
1179
 
1154
1180
  for (let i = 0; i < staticAccountKeysLength; i++) {
1155
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1181
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1156
1182
  }
1157
1183
 
1158
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1184
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1159
1185
  const instructionCount = decodeLength(byteArray);
1160
1186
  const compiledInstructions = [];
1161
1187
 
1162
1188
  for (let i = 0; i < instructionCount; i++) {
1163
- const programIdIndex = byteArray.shift();
1189
+ const programIdIndex = guardedShift(byteArray);
1164
1190
  const accountKeyIndexesLength = decodeLength(byteArray);
1165
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1191
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1166
1192
  const dataLength = decodeLength(byteArray);
1167
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1193
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1168
1194
  compiledInstructions.push({
1169
1195
  programIdIndex,
1170
1196
  accountKeyIndexes,
@@ -1176,11 +1202,11 @@ class MessageV0 {
1176
1202
  const addressTableLookups = [];
1177
1203
 
1178
1204
  for (let i = 0; i < addressTableLookupsCount; i++) {
1179
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1205
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1180
1206
  const writableIndexesLength = decodeLength(byteArray);
1181
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1207
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1182
1208
  const readonlyIndexesLength = decodeLength(byteArray);
1183
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1209
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1184
1210
  addressTableLookups.push({
1185
1211
  accountKey,
1186
1212
  writableIndexes,
@@ -1911,8 +1937,7 @@ class Transaction {
1911
1937
  let signatures = [];
1912
1938
 
1913
1939
  for (let i = 0; i < signatureCount; i++) {
1914
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1915
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1940
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1916
1941
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1917
1942
  }
1918
1943
 
@@ -2112,7 +2137,7 @@ class VersionedTransaction {
2112
2137
  const signaturesLength = decodeLength(byteArray);
2113
2138
 
2114
2139
  for (let i = 0; i < signaturesLength; i++) {
2115
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2140
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2116
2141
  }
2117
2142
 
2118
2143
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4511,7 +4536,7 @@ const LogsNotificationResult = superstruct.type({
4511
4536
 
4512
4537
  /** @internal */
4513
4538
  const COMMON_HTTP_HEADERS = {
4514
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4539
+ 'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4515
4540
  };
4516
4541
  /**
4517
4542
  * A connection to a fullnode JSON RPC endpoint
@@ -9351,10 +9376,8 @@ class ValidatorInfo {
9351
9376
  const configKeys = [];
9352
9377
 
9353
9378
  for (let i = 0; i < 2; i++) {
9354
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9355
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9356
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9357
- byteArray = byteArray.slice(1);
9379
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9380
+ const isSigner = guardedShift(byteArray) === 1;
9358
9381
  configKeys.push({
9359
9382
  publicKey,
9360
9383
  isSigner