@solana/web3.js 1.61.0 → 1.61.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.
@@ -734,6 +734,36 @@ class CompiledKeys {
734
734
 
735
735
  }
736
736
 
737
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
738
+ /**
739
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
740
+ */
741
+
742
+ function guardedShift(byteArray) {
743
+ if (byteArray.length === 0) {
744
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
745
+ }
746
+
747
+ return byteArray.shift();
748
+ }
749
+ /**
750
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
751
+ * the array.
752
+ */
753
+
754
+ function guardedSplice(byteArray, ...args) {
755
+ var _args$;
756
+
757
+ const [start] = args;
758
+
759
+ if (args.length === 2 // Implies that `deleteCount` was supplied
760
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
761
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
762
+ }
763
+
764
+ return byteArray.splice(...args);
765
+ }
766
+
737
767
  /**
738
768
  * An instruction to execute by a program
739
769
  *
@@ -875,37 +905,33 @@ class Message {
875
905
  static from(buffer) {
876
906
  // Slice up wire data
877
907
  let byteArray = [...buffer];
878
- const numRequiredSignatures = byteArray.shift();
908
+ const numRequiredSignatures = guardedShift(byteArray);
879
909
 
880
910
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
881
911
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
882
912
  }
883
913
 
884
- const numReadonlySignedAccounts = byteArray.shift();
885
- const numReadonlyUnsignedAccounts = byteArray.shift();
914
+ const numReadonlySignedAccounts = guardedShift(byteArray);
915
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
886
916
  const accountCount = decodeLength(byteArray);
887
917
  let accountKeys = [];
888
918
 
889
919
  for (let i = 0; i < accountCount; i++) {
890
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
891
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
920
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
892
921
  accountKeys.push(new PublicKey(Buffer.from(account)));
893
922
  }
894
923
 
895
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
896
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
924
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
897
925
  const instructionCount = decodeLength(byteArray);
898
926
  let instructions = [];
899
927
 
900
928
  for (let i = 0; i < instructionCount; i++) {
901
- const programIdIndex = byteArray.shift();
929
+ const programIdIndex = guardedShift(byteArray);
902
930
  const accountCount = decodeLength(byteArray);
903
- const accounts = byteArray.slice(0, accountCount);
904
- byteArray = byteArray.slice(accountCount);
931
+ const accounts = guardedSplice(byteArray, 0, accountCount);
905
932
  const dataLength = decodeLength(byteArray);
906
- const dataSlice = byteArray.slice(0, dataLength);
933
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
907
934
  const data = bs58.encode(Buffer.from(dataSlice));
908
- byteArray = byteArray.slice(dataLength);
909
935
  instructions.push({
910
936
  programIdIndex,
911
937
  accounts,
@@ -1118,33 +1144,33 @@ class MessageV0 {
1118
1144
 
1119
1145
  static deserialize(serializedMessage) {
1120
1146
  let byteArray = [...serializedMessage];
1121
- const prefix = byteArray.shift();
1147
+ const prefix = guardedShift(byteArray);
1122
1148
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1123
1149
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1124
1150
  const version = maskedPrefix;
1125
1151
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1126
1152
  const header = {
1127
- numRequiredSignatures: byteArray.shift(),
1128
- numReadonlySignedAccounts: byteArray.shift(),
1129
- numReadonlyUnsignedAccounts: byteArray.shift()
1153
+ numRequiredSignatures: guardedShift(byteArray),
1154
+ numReadonlySignedAccounts: guardedShift(byteArray),
1155
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1130
1156
  };
1131
1157
  const staticAccountKeys = [];
1132
1158
  const staticAccountKeysLength = decodeLength(byteArray);
1133
1159
 
1134
1160
  for (let i = 0; i < staticAccountKeysLength; i++) {
1135
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1161
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1136
1162
  }
1137
1163
 
1138
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1164
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1139
1165
  const instructionCount = decodeLength(byteArray);
1140
1166
  const compiledInstructions = [];
1141
1167
 
1142
1168
  for (let i = 0; i < instructionCount; i++) {
1143
- const programIdIndex = byteArray.shift();
1169
+ const programIdIndex = guardedShift(byteArray);
1144
1170
  const accountKeyIndexesLength = decodeLength(byteArray);
1145
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1171
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1146
1172
  const dataLength = decodeLength(byteArray);
1147
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1173
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1148
1174
  compiledInstructions.push({
1149
1175
  programIdIndex,
1150
1176
  accountKeyIndexes,
@@ -1156,11 +1182,11 @@ class MessageV0 {
1156
1182
  const addressTableLookups = [];
1157
1183
 
1158
1184
  for (let i = 0; i < addressTableLookupsCount; i++) {
1159
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1185
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1160
1186
  const writableIndexesLength = decodeLength(byteArray);
1161
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1187
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1162
1188
  const readonlyIndexesLength = decodeLength(byteArray);
1163
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1189
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1164
1190
  addressTableLookups.push({
1165
1191
  accountKey,
1166
1192
  writableIndexes,
@@ -1891,8 +1917,7 @@ class Transaction {
1891
1917
  let signatures = [];
1892
1918
 
1893
1919
  for (let i = 0; i < signatureCount; i++) {
1894
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1895
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1920
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1896
1921
  signatures.push(bs58.encode(Buffer.from(signature)));
1897
1922
  }
1898
1923
 
@@ -2090,7 +2115,7 @@ class VersionedTransaction {
2090
2115
  const signaturesLength = decodeLength(byteArray);
2091
2116
 
2092
2117
  for (let i = 0; i < signaturesLength; i++) {
2093
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2118
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2094
2119
  }
2095
2120
 
2096
2121
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -3474,7 +3499,7 @@ class AddressLookupTableAccount {
3474
3499
  }
3475
3500
 
3476
3501
  isActive() {
3477
- const U64_MAX = 2n ** 64n - 1n;
3502
+ const U64_MAX = 18446744073709551615n;
3478
3503
  return this.state.deactivationSlot === U64_MAX;
3479
3504
  }
3480
3505
 
@@ -4490,7 +4515,7 @@ const LogsNotificationResult = type({
4490
4515
 
4491
4516
  /** @internal */
4492
4517
  const COMMON_HTTP_HEADERS = {
4493
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4518
+ 'solana-client': `js/${(_process$env$npm_pack = "1.61.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4494
4519
  };
4495
4520
  /**
4496
4521
  * A connection to a fullnode JSON RPC endpoint
@@ -9407,10 +9432,8 @@ class ValidatorInfo {
9407
9432
  const configKeys = [];
9408
9433
 
9409
9434
  for (let i = 0; i < 2; i++) {
9410
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9411
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9412
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9413
- byteArray = byteArray.slice(1);
9435
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9436
+ const isSigner = guardedShift(byteArray) === 1;
9414
9437
  configKeys.push({
9415
9438
  publicKey,
9416
9439
  isSigner