@solana/web3.js 1.59.0 → 1.59.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
@@ -1847,7 +1847,7 @@ declare module '@solana/web3.js' {
1847
1847
  }
1848
1848
 
1849
1849
  export type TransactionMessageArgs = {
1850
- accountKeys: MessageAccountKeys;
1850
+ payerKey: PublicKey;
1851
1851
  instructions: Array<TransactionInstruction>;
1852
1852
  recentBlockhash: Blockhash;
1853
1853
  };
@@ -1859,7 +1859,7 @@ declare module '@solana/web3.js' {
1859
1859
  addressLookupTableAccounts: AddressLookupTableAccount[];
1860
1860
  };
1861
1861
  export class TransactionMessage {
1862
- accountKeys: MessageAccountKeys;
1862
+ payerKey: PublicKey;
1863
1863
  instructions: Array<TransactionInstruction>;
1864
1864
  recentBlockhash: Blockhash;
1865
1865
  constructor(args: TransactionMessageArgs);
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
  *
@@ -878,37 +908,33 @@ class Message {
878
908
  static from(buffer) {
879
909
  // Slice up wire data
880
910
  let byteArray = [...buffer];
881
- const numRequiredSignatures = byteArray.shift();
911
+ const numRequiredSignatures = guardedShift(byteArray);
882
912
 
883
913
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
884
914
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
885
915
  }
886
916
 
887
- const numReadonlySignedAccounts = byteArray.shift();
888
- const numReadonlyUnsignedAccounts = byteArray.shift();
917
+ const numReadonlySignedAccounts = guardedShift(byteArray);
918
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
889
919
  const accountCount = decodeLength(byteArray);
890
920
  let accountKeys = [];
891
921
 
892
922
  for (let i = 0; i < accountCount; i++) {
893
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
894
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
923
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
895
924
  accountKeys.push(new PublicKey(Buffer.from(account)));
896
925
  }
897
926
 
898
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
899
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
927
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
900
928
  const instructionCount = decodeLength(byteArray);
901
929
  let instructions = [];
902
930
 
903
931
  for (let i = 0; i < instructionCount; i++) {
904
- const programIdIndex = byteArray.shift();
932
+ const programIdIndex = guardedShift(byteArray);
905
933
  const accountCount = decodeLength(byteArray);
906
- const accounts = byteArray.slice(0, accountCount);
907
- byteArray = byteArray.slice(accountCount);
934
+ const accounts = guardedSplice(byteArray, 0, accountCount);
908
935
  const dataLength = decodeLength(byteArray);
909
- const dataSlice = byteArray.slice(0, dataLength);
936
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
910
937
  const data = bs58.encode(Buffer.from(dataSlice));
911
- byteArray = byteArray.slice(dataLength);
912
938
  instructions.push({
913
939
  programIdIndex,
914
940
  accounts,
@@ -1121,33 +1147,33 @@ class MessageV0 {
1121
1147
 
1122
1148
  static deserialize(serializedMessage) {
1123
1149
  let byteArray = [...serializedMessage];
1124
- const prefix = byteArray.shift();
1150
+ const prefix = guardedShift(byteArray);
1125
1151
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1126
1152
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1127
1153
  const version = maskedPrefix;
1128
1154
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1129
1155
  const header = {
1130
- numRequiredSignatures: byteArray.shift(),
1131
- numReadonlySignedAccounts: byteArray.shift(),
1132
- numReadonlyUnsignedAccounts: byteArray.shift()
1156
+ numRequiredSignatures: guardedShift(byteArray),
1157
+ numReadonlySignedAccounts: guardedShift(byteArray),
1158
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1133
1159
  };
1134
1160
  const staticAccountKeys = [];
1135
1161
  const staticAccountKeysLength = decodeLength(byteArray);
1136
1162
 
1137
1163
  for (let i = 0; i < staticAccountKeysLength; i++) {
1138
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1164
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1139
1165
  }
1140
1166
 
1141
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1167
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1142
1168
  const instructionCount = decodeLength(byteArray);
1143
1169
  const compiledInstructions = [];
1144
1170
 
1145
1171
  for (let i = 0; i < instructionCount; i++) {
1146
- const programIdIndex = byteArray.shift();
1172
+ const programIdIndex = guardedShift(byteArray);
1147
1173
  const accountKeyIndexesLength = decodeLength(byteArray);
1148
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1174
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1149
1175
  const dataLength = decodeLength(byteArray);
1150
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1176
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1151
1177
  compiledInstructions.push({
1152
1178
  programIdIndex,
1153
1179
  accountKeyIndexes,
@@ -1159,11 +1185,11 @@ class MessageV0 {
1159
1185
  const addressTableLookups = [];
1160
1186
 
1161
1187
  for (let i = 0; i < addressTableLookupsCount; i++) {
1162
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1188
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1163
1189
  const writableIndexesLength = decodeLength(byteArray);
1164
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1190
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1165
1191
  const readonlyIndexesLength = decodeLength(byteArray);
1166
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1192
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1167
1193
  addressTableLookups.push({
1168
1194
  accountKey,
1169
1195
  writableIndexes,
@@ -1894,8 +1920,7 @@ class Transaction {
1894
1920
  let signatures = [];
1895
1921
 
1896
1922
  for (let i = 0; i < signatureCount; i++) {
1897
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1898
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1923
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1899
1924
  signatures.push(bs58.encode(Buffer.from(signature)));
1900
1925
  }
1901
1926
 
@@ -1945,10 +1970,10 @@ class Transaction {
1945
1970
 
1946
1971
  class TransactionMessage {
1947
1972
  constructor(args) {
1948
- this.accountKeys = void 0;
1973
+ this.payerKey = void 0;
1949
1974
  this.instructions = void 0;
1950
1975
  this.recentBlockhash = void 0;
1951
- this.accountKeys = args.accountKeys;
1976
+ this.payerKey = args.payerKey;
1952
1977
  this.instructions = args.instructions;
1953
1978
  this.recentBlockhash = args.recentBlockhash;
1954
1979
  }
@@ -1969,6 +1994,12 @@ class TransactionMessage {
1969
1994
  const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
1970
1995
  assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
1971
1996
  const accountKeys = message.getAccountKeys(args);
1997
+ const payerKey = accountKeys.get(0);
1998
+
1999
+ if (payerKey === undefined) {
2000
+ throw new Error('Failed to decompile message because no account keys were found');
2001
+ }
2002
+
1972
2003
  const instructions = [];
1973
2004
 
1974
2005
  for (const compiledIx of compiledInstructions) {
@@ -2014,35 +2045,23 @@ class TransactionMessage {
2014
2045
  }
2015
2046
 
2016
2047
  return new TransactionMessage({
2017
- accountKeys,
2048
+ payerKey,
2018
2049
  instructions,
2019
2050
  recentBlockhash
2020
2051
  });
2021
2052
  }
2022
2053
 
2023
2054
  compileToLegacyMessage() {
2024
- const payerKey = this.accountKeys.get(0);
2025
-
2026
- if (payerKey === undefined) {
2027
- throw new Error('Failed to compile message because no account keys were found');
2028
- }
2029
-
2030
2055
  return Message.compile({
2031
- payerKey,
2056
+ payerKey: this.payerKey,
2032
2057
  recentBlockhash: this.recentBlockhash,
2033
2058
  instructions: this.instructions
2034
2059
  });
2035
2060
  }
2036
2061
 
2037
2062
  compileToV0Message(addressLookupTableAccounts) {
2038
- const payerKey = this.accountKeys.get(0);
2039
-
2040
- if (payerKey === undefined) {
2041
- throw new Error('Failed to compile message because no account keys were found');
2042
- }
2043
-
2044
2063
  return MessageV0.compile({
2045
- payerKey,
2064
+ payerKey: this.payerKey,
2046
2065
  recentBlockhash: this.recentBlockhash,
2047
2066
  instructions: this.instructions,
2048
2067
  addressLookupTableAccounts
@@ -2095,7 +2114,7 @@ class VersionedTransaction {
2095
2114
  const signaturesLength = decodeLength(byteArray);
2096
2115
 
2097
2116
  for (let i = 0; i < signaturesLength; i++) {
2098
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2117
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2099
2118
  }
2100
2119
 
2101
2120
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4554,7 +4573,7 @@ const LogsNotificationResult = type({
4554
4573
 
4555
4574
  /** @internal */
4556
4575
  const COMMON_HTTP_HEADERS = {
4557
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4576
+ 'solana-client': `js/${(_process$env$npm_pack = "1.59.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4558
4577
  };
4559
4578
  /**
4560
4579
  * A connection to a fullnode JSON RPC endpoint
@@ -9468,10 +9487,8 @@ class ValidatorInfo {
9468
9487
  const configKeys = [];
9469
9488
 
9470
9489
  for (let i = 0; i < 2; i++) {
9471
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9472
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9473
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9474
- byteArray = byteArray.slice(1);
9490
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9491
+ const isSigner = guardedShift(byteArray) === 1;
9475
9492
  configKeys.push({
9476
9493
  publicKey,
9477
9494
  isSigner