@solana/web3.js 1.63.0 → 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.
package/lib/index.d.ts CHANGED
@@ -1562,10 +1562,10 @@ declare module '@solana/web3.js' {
1562
1562
  };
1563
1563
  export type GetAccountKeysArgs =
1564
1564
  | {
1565
- accountKeysFromLookups: AccountKeysFromLookups;
1565
+ accountKeysFromLookups?: AccountKeysFromLookups | null;
1566
1566
  }
1567
1567
  | {
1568
- addressLookupTableAccounts: AddressLookupTableAccount[];
1568
+ addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
1569
1569
  };
1570
1570
  export class MessageV0 {
1571
1571
  header: MessageHeader;
package/lib/index.esm.js CHANGED
@@ -737,6 +737,36 @@ class CompiledKeys {
737
737
 
738
738
  }
739
739
 
740
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
741
+ /**
742
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
743
+ */
744
+
745
+ function guardedShift(byteArray) {
746
+ if (byteArray.length === 0) {
747
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
748
+ }
749
+
750
+ return byteArray.shift();
751
+ }
752
+ /**
753
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
754
+ * the array.
755
+ */
756
+
757
+ function guardedSplice(byteArray, ...args) {
758
+ var _args$;
759
+
760
+ const [start] = args;
761
+
762
+ if (args.length === 2 // Implies that `deleteCount` was supplied
763
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
764
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
765
+ }
766
+
767
+ return byteArray.splice(...args);
768
+ }
769
+
740
770
  /**
741
771
  * An instruction to execute by a program
742
772
  *
@@ -888,37 +918,33 @@ class Message {
888
918
  static from(buffer) {
889
919
  // Slice up wire data
890
920
  let byteArray = [...buffer];
891
- const numRequiredSignatures = byteArray.shift();
921
+ const numRequiredSignatures = guardedShift(byteArray);
892
922
 
893
923
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
894
924
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
895
925
  }
896
926
 
897
- const numReadonlySignedAccounts = byteArray.shift();
898
- const numReadonlyUnsignedAccounts = byteArray.shift();
927
+ const numReadonlySignedAccounts = guardedShift(byteArray);
928
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
899
929
  const accountCount = decodeLength(byteArray);
900
930
  let accountKeys = [];
901
931
 
902
932
  for (let i = 0; i < accountCount; i++) {
903
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
904
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
933
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
905
934
  accountKeys.push(new PublicKey(Buffer.from(account)));
906
935
  }
907
936
 
908
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
909
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
937
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
910
938
  const instructionCount = decodeLength(byteArray);
911
939
  let instructions = [];
912
940
 
913
941
  for (let i = 0; i < instructionCount; i++) {
914
- const programIdIndex = byteArray.shift();
942
+ const programIdIndex = guardedShift(byteArray);
915
943
  const accountCount = decodeLength(byteArray);
916
- const accounts = byteArray.slice(0, accountCount);
917
- byteArray = byteArray.slice(accountCount);
944
+ const accounts = guardedSplice(byteArray, 0, accountCount);
918
945
  const dataLength = decodeLength(byteArray);
919
- const dataSlice = byteArray.slice(0, dataLength);
946
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
920
947
  const data = bs58.encode(Buffer.from(dataSlice));
921
- byteArray = byteArray.slice(dataLength);
922
948
  instructions.push({
923
949
  programIdIndex,
924
950
  accounts,
@@ -976,13 +1002,13 @@ class MessageV0 {
976
1002
  getAccountKeys(args) {
977
1003
  let accountKeysFromLookups;
978
1004
 
979
- if (args && 'accountKeysFromLookups' in args) {
1005
+ if (args && 'accountKeysFromLookups' in args && args.accountKeysFromLookups) {
980
1006
  if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
981
1007
  throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
982
1008
  }
983
1009
 
984
1010
  accountKeysFromLookups = args.accountKeysFromLookups;
985
- } else if (args && 'addressLookupTableAccounts' in args) {
1011
+ } else if (args && 'addressLookupTableAccounts' in args && args.addressLookupTableAccounts) {
986
1012
  accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
987
1013
  } else if (this.addressTableLookups.length > 0) {
988
1014
  throw new Error('Failed to get account keys because address table lookups were not resolved');
@@ -1154,33 +1180,33 @@ class MessageV0 {
1154
1180
 
1155
1181
  static deserialize(serializedMessage) {
1156
1182
  let byteArray = [...serializedMessage];
1157
- const prefix = byteArray.shift();
1183
+ const prefix = guardedShift(byteArray);
1158
1184
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1159
1185
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1160
1186
  const version = maskedPrefix;
1161
1187
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1162
1188
  const header = {
1163
- numRequiredSignatures: byteArray.shift(),
1164
- numReadonlySignedAccounts: byteArray.shift(),
1165
- numReadonlyUnsignedAccounts: byteArray.shift()
1189
+ numRequiredSignatures: guardedShift(byteArray),
1190
+ numReadonlySignedAccounts: guardedShift(byteArray),
1191
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1166
1192
  };
1167
1193
  const staticAccountKeys = [];
1168
1194
  const staticAccountKeysLength = decodeLength(byteArray);
1169
1195
 
1170
1196
  for (let i = 0; i < staticAccountKeysLength; i++) {
1171
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1197
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1172
1198
  }
1173
1199
 
1174
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1200
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1175
1201
  const instructionCount = decodeLength(byteArray);
1176
1202
  const compiledInstructions = [];
1177
1203
 
1178
1204
  for (let i = 0; i < instructionCount; i++) {
1179
- const programIdIndex = byteArray.shift();
1205
+ const programIdIndex = guardedShift(byteArray);
1180
1206
  const accountKeyIndexesLength = decodeLength(byteArray);
1181
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1207
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1182
1208
  const dataLength = decodeLength(byteArray);
1183
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1209
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1184
1210
  compiledInstructions.push({
1185
1211
  programIdIndex,
1186
1212
  accountKeyIndexes,
@@ -1192,11 +1218,11 @@ class MessageV0 {
1192
1218
  const addressTableLookups = [];
1193
1219
 
1194
1220
  for (let i = 0; i < addressTableLookupsCount; i++) {
1195
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1221
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1196
1222
  const writableIndexesLength = decodeLength(byteArray);
1197
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1223
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1198
1224
  const readonlyIndexesLength = decodeLength(byteArray);
1199
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1225
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1200
1226
  addressTableLookups.push({
1201
1227
  accountKey,
1202
1228
  writableIndexes,
@@ -1927,8 +1953,7 @@ class Transaction {
1927
1953
  let signatures = [];
1928
1954
 
1929
1955
  for (let i = 0; i < signatureCount; i++) {
1930
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1931
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1956
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1932
1957
  signatures.push(bs58.encode(Buffer.from(signature)));
1933
1958
  }
1934
1959
 
@@ -2126,7 +2151,7 @@ class VersionedTransaction {
2126
2151
  const signaturesLength = decodeLength(byteArray);
2127
2152
 
2128
2153
  for (let i = 0; i < signaturesLength; i++) {
2129
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2154
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2130
2155
  }
2131
2156
 
2132
2157
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4594,7 +4619,7 @@ const LogsNotificationResult = type({
4594
4619
 
4595
4620
  /** @internal */
4596
4621
  const COMMON_HTTP_HEADERS = {
4597
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4622
+ 'solana-client': `js/${(_process$env$npm_pack = "1.63.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4598
4623
  };
4599
4624
  /**
4600
4625
  * A connection to a fullnode JSON RPC endpoint
@@ -9511,10 +9536,8 @@ class ValidatorInfo {
9511
9536
  const configKeys = [];
9512
9537
 
9513
9538
  for (let i = 0; i < 2; i++) {
9514
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9515
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9516
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9517
- byteArray = byteArray.slice(1);
9539
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9540
+ const isSigner = guardedShift(byteArray) === 1;
9518
9541
  configKeys.push({
9519
9542
  publicKey,
9520
9543
  isSigner