@solana/web3.js 1.63.1 → 1.63.2

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.
@@ -764,6 +764,36 @@ class CompiledKeys {
764
764
 
765
765
  }
766
766
 
767
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
768
+ /**
769
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
770
+ */
771
+
772
+ function guardedShift(byteArray) {
773
+ if (byteArray.length === 0) {
774
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
775
+ }
776
+
777
+ return byteArray.shift();
778
+ }
779
+ /**
780
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
781
+ * the array.
782
+ */
783
+
784
+ function guardedSplice(byteArray, ...args) {
785
+ var _args$;
786
+
787
+ const [start] = args;
788
+
789
+ if (args.length === 2 // Implies that `deleteCount` was supplied
790
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
791
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
792
+ }
793
+
794
+ return byteArray.splice(...args);
795
+ }
796
+
767
797
  /**
768
798
  * An instruction to execute by a program
769
799
  *
@@ -915,37 +945,33 @@ class Message {
915
945
  static from(buffer$1) {
916
946
  // Slice up wire data
917
947
  let byteArray = [...buffer$1];
918
- const numRequiredSignatures = byteArray.shift();
948
+ const numRequiredSignatures = guardedShift(byteArray);
919
949
 
920
950
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
921
951
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
922
952
  }
923
953
 
924
- const numReadonlySignedAccounts = byteArray.shift();
925
- const numReadonlyUnsignedAccounts = byteArray.shift();
954
+ const numReadonlySignedAccounts = guardedShift(byteArray);
955
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
926
956
  const accountCount = decodeLength(byteArray);
927
957
  let accountKeys = [];
928
958
 
929
959
  for (let i = 0; i < accountCount; i++) {
930
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
931
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
960
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
932
961
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
933
962
  }
934
963
 
935
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
936
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
964
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
937
965
  const instructionCount = decodeLength(byteArray);
938
966
  let instructions = [];
939
967
 
940
968
  for (let i = 0; i < instructionCount; i++) {
941
- const programIdIndex = byteArray.shift();
969
+ const programIdIndex = guardedShift(byteArray);
942
970
  const accountCount = decodeLength(byteArray);
943
- const accounts = byteArray.slice(0, accountCount);
944
- byteArray = byteArray.slice(accountCount);
971
+ const accounts = guardedSplice(byteArray, 0, accountCount);
945
972
  const dataLength = decodeLength(byteArray);
946
- const dataSlice = byteArray.slice(0, dataLength);
973
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
947
974
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
948
- byteArray = byteArray.slice(dataLength);
949
975
  instructions.push({
950
976
  programIdIndex,
951
977
  accounts,
@@ -1181,33 +1207,33 @@ class MessageV0 {
1181
1207
 
1182
1208
  static deserialize(serializedMessage) {
1183
1209
  let byteArray = [...serializedMessage];
1184
- const prefix = byteArray.shift();
1210
+ const prefix = guardedShift(byteArray);
1185
1211
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1186
1212
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1187
1213
  const version = maskedPrefix;
1188
1214
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1189
1215
  const header = {
1190
- numRequiredSignatures: byteArray.shift(),
1191
- numReadonlySignedAccounts: byteArray.shift(),
1192
- numReadonlyUnsignedAccounts: byteArray.shift()
1216
+ numRequiredSignatures: guardedShift(byteArray),
1217
+ numReadonlySignedAccounts: guardedShift(byteArray),
1218
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1193
1219
  };
1194
1220
  const staticAccountKeys = [];
1195
1221
  const staticAccountKeysLength = decodeLength(byteArray);
1196
1222
 
1197
1223
  for (let i = 0; i < staticAccountKeysLength; i++) {
1198
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1224
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1199
1225
  }
1200
1226
 
1201
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1227
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1202
1228
  const instructionCount = decodeLength(byteArray);
1203
1229
  const compiledInstructions = [];
1204
1230
 
1205
1231
  for (let i = 0; i < instructionCount; i++) {
1206
- const programIdIndex = byteArray.shift();
1232
+ const programIdIndex = guardedShift(byteArray);
1207
1233
  const accountKeyIndexesLength = decodeLength(byteArray);
1208
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1234
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1209
1235
  const dataLength = decodeLength(byteArray);
1210
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1236
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1211
1237
  compiledInstructions.push({
1212
1238
  programIdIndex,
1213
1239
  accountKeyIndexes,
@@ -1219,11 +1245,11 @@ class MessageV0 {
1219
1245
  const addressTableLookups = [];
1220
1246
 
1221
1247
  for (let i = 0; i < addressTableLookupsCount; i++) {
1222
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1248
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1223
1249
  const writableIndexesLength = decodeLength(byteArray);
1224
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1250
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1225
1251
  const readonlyIndexesLength = decodeLength(byteArray);
1226
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1252
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1227
1253
  addressTableLookups.push({
1228
1254
  accountKey,
1229
1255
  writableIndexes,
@@ -1954,8 +1980,7 @@ class Transaction {
1954
1980
  let signatures = [];
1955
1981
 
1956
1982
  for (let i = 0; i < signatureCount; i++) {
1957
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1958
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1983
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1959
1984
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1960
1985
  }
1961
1986
 
@@ -2153,7 +2178,7 @@ class VersionedTransaction {
2153
2178
  const signaturesLength = decodeLength(byteArray);
2154
2179
 
2155
2180
  for (let i = 0; i < signaturesLength; i++) {
2156
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2181
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2157
2182
  }
2158
2183
 
2159
2184
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4561,7 +4586,7 @@ const LogsNotificationResult = superstruct.type({
4561
4586
 
4562
4587
  /** @internal */
4563
4588
  const COMMON_HTTP_HEADERS = {
4564
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4589
+ 'solana-client': `js/${(_process$env$npm_pack = "1.63.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4565
4590
  };
4566
4591
  /**
4567
4592
  * A connection to a fullnode JSON RPC endpoint
@@ -9478,10 +9503,8 @@ class ValidatorInfo {
9478
9503
  const configKeys = [];
9479
9504
 
9480
9505
  for (let i = 0; i < 2; i++) {
9481
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9482
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9483
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9484
- byteArray = byteArray.slice(1);
9506
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9507
+ const isSigner = guardedShift(byteArray) === 1;
9485
9508
  configKeys.push({
9486
9509
  publicKey,
9487
9510
  isSigner