@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.
@@ -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
  *
@@ -885,37 +915,33 @@ class Message {
885
915
  static from(buffer) {
886
916
  // Slice up wire data
887
917
  let byteArray = [...buffer];
888
- const numRequiredSignatures = byteArray.shift();
918
+ const numRequiredSignatures = guardedShift(byteArray);
889
919
 
890
920
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
891
921
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
892
922
  }
893
923
 
894
- const numReadonlySignedAccounts = byteArray.shift();
895
- const numReadonlyUnsignedAccounts = byteArray.shift();
924
+ const numReadonlySignedAccounts = guardedShift(byteArray);
925
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
896
926
  const accountCount = decodeLength(byteArray);
897
927
  let accountKeys = [];
898
928
 
899
929
  for (let i = 0; i < accountCount; i++) {
900
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
901
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
930
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
902
931
  accountKeys.push(new PublicKey(Buffer.from(account)));
903
932
  }
904
933
 
905
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
906
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
934
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
907
935
  const instructionCount = decodeLength(byteArray);
908
936
  let instructions = [];
909
937
 
910
938
  for (let i = 0; i < instructionCount; i++) {
911
- const programIdIndex = byteArray.shift();
939
+ const programIdIndex = guardedShift(byteArray);
912
940
  const accountCount = decodeLength(byteArray);
913
- const accounts = byteArray.slice(0, accountCount);
914
- byteArray = byteArray.slice(accountCount);
941
+ const accounts = guardedSplice(byteArray, 0, accountCount);
915
942
  const dataLength = decodeLength(byteArray);
916
- const dataSlice = byteArray.slice(0, dataLength);
943
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
917
944
  const data = bs58.encode(Buffer.from(dataSlice));
918
- byteArray = byteArray.slice(dataLength);
919
945
  instructions.push({
920
946
  programIdIndex,
921
947
  accounts,
@@ -1151,33 +1177,33 @@ class MessageV0 {
1151
1177
 
1152
1178
  static deserialize(serializedMessage) {
1153
1179
  let byteArray = [...serializedMessage];
1154
- const prefix = byteArray.shift();
1180
+ const prefix = guardedShift(byteArray);
1155
1181
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1156
1182
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1157
1183
  const version = maskedPrefix;
1158
1184
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1159
1185
  const header = {
1160
- numRequiredSignatures: byteArray.shift(),
1161
- numReadonlySignedAccounts: byteArray.shift(),
1162
- numReadonlyUnsignedAccounts: byteArray.shift()
1186
+ numRequiredSignatures: guardedShift(byteArray),
1187
+ numReadonlySignedAccounts: guardedShift(byteArray),
1188
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1163
1189
  };
1164
1190
  const staticAccountKeys = [];
1165
1191
  const staticAccountKeysLength = decodeLength(byteArray);
1166
1192
 
1167
1193
  for (let i = 0; i < staticAccountKeysLength; i++) {
1168
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1194
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1169
1195
  }
1170
1196
 
1171
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1197
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1172
1198
  const instructionCount = decodeLength(byteArray);
1173
1199
  const compiledInstructions = [];
1174
1200
 
1175
1201
  for (let i = 0; i < instructionCount; i++) {
1176
- const programIdIndex = byteArray.shift();
1202
+ const programIdIndex = guardedShift(byteArray);
1177
1203
  const accountKeyIndexesLength = decodeLength(byteArray);
1178
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1204
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1179
1205
  const dataLength = decodeLength(byteArray);
1180
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1206
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1181
1207
  compiledInstructions.push({
1182
1208
  programIdIndex,
1183
1209
  accountKeyIndexes,
@@ -1189,11 +1215,11 @@ class MessageV0 {
1189
1215
  const addressTableLookups = [];
1190
1216
 
1191
1217
  for (let i = 0; i < addressTableLookupsCount; i++) {
1192
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1218
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1193
1219
  const writableIndexesLength = decodeLength(byteArray);
1194
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1220
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1195
1221
  const readonlyIndexesLength = decodeLength(byteArray);
1196
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1222
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1197
1223
  addressTableLookups.push({
1198
1224
  accountKey,
1199
1225
  writableIndexes,
@@ -1924,8 +1950,7 @@ class Transaction {
1924
1950
  let signatures = [];
1925
1951
 
1926
1952
  for (let i = 0; i < signatureCount; i++) {
1927
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1928
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1953
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1929
1954
  signatures.push(bs58.encode(Buffer.from(signature)));
1930
1955
  }
1931
1956
 
@@ -2123,7 +2148,7 @@ class VersionedTransaction {
2123
2148
  const signaturesLength = decodeLength(byteArray);
2124
2149
 
2125
2150
  for (let i = 0; i < signaturesLength; i++) {
2126
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2151
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2127
2152
  }
2128
2153
 
2129
2154
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4531,7 +4556,7 @@ const LogsNotificationResult = type({
4531
4556
 
4532
4557
  /** @internal */
4533
4558
  const COMMON_HTTP_HEADERS = {
4534
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4559
+ 'solana-client': `js/${(_process$env$npm_pack = "1.63.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4535
4560
  };
4536
4561
  /**
4537
4562
  * A connection to a fullnode JSON RPC endpoint
@@ -9448,10 +9473,8 @@ class ValidatorInfo {
9448
9473
  const configKeys = [];
9449
9474
 
9450
9475
  for (let i = 0; i < 2; i++) {
9451
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9452
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9453
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9454
- byteArray = byteArray.slice(1);
9476
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9477
+ const isSigner = guardedShift(byteArray) === 1;
9455
9478
  configKeys.push({
9456
9479
  publicKey,
9457
9480
  isSigner