@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.
@@ -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
  *
@@ -905,37 +935,33 @@ class Message {
905
935
  static from(buffer$1) {
906
936
  // Slice up wire data
907
937
  let byteArray = [...buffer$1];
908
- const numRequiredSignatures = byteArray.shift();
938
+ const numRequiredSignatures = guardedShift(byteArray);
909
939
 
910
940
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
911
941
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
912
942
  }
913
943
 
914
- const numReadonlySignedAccounts = byteArray.shift();
915
- const numReadonlyUnsignedAccounts = byteArray.shift();
944
+ const numReadonlySignedAccounts = guardedShift(byteArray);
945
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
916
946
  const accountCount = decodeLength(byteArray);
917
947
  let accountKeys = [];
918
948
 
919
949
  for (let i = 0; i < accountCount; i++) {
920
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
921
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
950
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
922
951
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
923
952
  }
924
953
 
925
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
926
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
954
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
927
955
  const instructionCount = decodeLength(byteArray);
928
956
  let instructions = [];
929
957
 
930
958
  for (let i = 0; i < instructionCount; i++) {
931
- const programIdIndex = byteArray.shift();
959
+ const programIdIndex = guardedShift(byteArray);
932
960
  const accountCount = decodeLength(byteArray);
933
- const accounts = byteArray.slice(0, accountCount);
934
- byteArray = byteArray.slice(accountCount);
961
+ const accounts = guardedSplice(byteArray, 0, accountCount);
935
962
  const dataLength = decodeLength(byteArray);
936
- const dataSlice = byteArray.slice(0, dataLength);
963
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
937
964
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
938
- byteArray = byteArray.slice(dataLength);
939
965
  instructions.push({
940
966
  programIdIndex,
941
967
  accounts,
@@ -1148,33 +1174,33 @@ class MessageV0 {
1148
1174
 
1149
1175
  static deserialize(serializedMessage) {
1150
1176
  let byteArray = [...serializedMessage];
1151
- const prefix = byteArray.shift();
1177
+ const prefix = guardedShift(byteArray);
1152
1178
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1153
1179
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1154
1180
  const version = maskedPrefix;
1155
1181
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1156
1182
  const header = {
1157
- numRequiredSignatures: byteArray.shift(),
1158
- numReadonlySignedAccounts: byteArray.shift(),
1159
- numReadonlyUnsignedAccounts: byteArray.shift()
1183
+ numRequiredSignatures: guardedShift(byteArray),
1184
+ numReadonlySignedAccounts: guardedShift(byteArray),
1185
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1160
1186
  };
1161
1187
  const staticAccountKeys = [];
1162
1188
  const staticAccountKeysLength = decodeLength(byteArray);
1163
1189
 
1164
1190
  for (let i = 0; i < staticAccountKeysLength; i++) {
1165
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1191
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1166
1192
  }
1167
1193
 
1168
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1194
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1169
1195
  const instructionCount = decodeLength(byteArray);
1170
1196
  const compiledInstructions = [];
1171
1197
 
1172
1198
  for (let i = 0; i < instructionCount; i++) {
1173
- const programIdIndex = byteArray.shift();
1199
+ const programIdIndex = guardedShift(byteArray);
1174
1200
  const accountKeyIndexesLength = decodeLength(byteArray);
1175
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1201
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1176
1202
  const dataLength = decodeLength(byteArray);
1177
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1203
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1178
1204
  compiledInstructions.push({
1179
1205
  programIdIndex,
1180
1206
  accountKeyIndexes,
@@ -1186,11 +1212,11 @@ class MessageV0 {
1186
1212
  const addressTableLookups = [];
1187
1213
 
1188
1214
  for (let i = 0; i < addressTableLookupsCount; i++) {
1189
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1215
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1190
1216
  const writableIndexesLength = decodeLength(byteArray);
1191
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1217
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1192
1218
  const readonlyIndexesLength = decodeLength(byteArray);
1193
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1219
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1194
1220
  addressTableLookups.push({
1195
1221
  accountKey,
1196
1222
  writableIndexes,
@@ -1921,8 +1947,7 @@ class Transaction {
1921
1947
  let signatures = [];
1922
1948
 
1923
1949
  for (let i = 0; i < signatureCount; i++) {
1924
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1925
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1950
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1926
1951
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1927
1952
  }
1928
1953
 
@@ -1972,10 +1997,10 @@ class Transaction {
1972
1997
 
1973
1998
  class TransactionMessage {
1974
1999
  constructor(args) {
1975
- this.accountKeys = void 0;
2000
+ this.payerKey = void 0;
1976
2001
  this.instructions = void 0;
1977
2002
  this.recentBlockhash = void 0;
1978
- this.accountKeys = args.accountKeys;
2003
+ this.payerKey = args.payerKey;
1979
2004
  this.instructions = args.instructions;
1980
2005
  this.recentBlockhash = args.recentBlockhash;
1981
2006
  }
@@ -1996,6 +2021,12 @@ class TransactionMessage {
1996
2021
  const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
1997
2022
  assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
1998
2023
  const accountKeys = message.getAccountKeys(args);
2024
+ const payerKey = accountKeys.get(0);
2025
+
2026
+ if (payerKey === undefined) {
2027
+ throw new Error('Failed to decompile message because no account keys were found');
2028
+ }
2029
+
1999
2030
  const instructions = [];
2000
2031
 
2001
2032
  for (const compiledIx of compiledInstructions) {
@@ -2041,35 +2072,23 @@ class TransactionMessage {
2041
2072
  }
2042
2073
 
2043
2074
  return new TransactionMessage({
2044
- accountKeys,
2075
+ payerKey,
2045
2076
  instructions,
2046
2077
  recentBlockhash
2047
2078
  });
2048
2079
  }
2049
2080
 
2050
2081
  compileToLegacyMessage() {
2051
- const payerKey = this.accountKeys.get(0);
2052
-
2053
- if (payerKey === undefined) {
2054
- throw new Error('Failed to compile message because no account keys were found');
2055
- }
2056
-
2057
2082
  return Message.compile({
2058
- payerKey,
2083
+ payerKey: this.payerKey,
2059
2084
  recentBlockhash: this.recentBlockhash,
2060
2085
  instructions: this.instructions
2061
2086
  });
2062
2087
  }
2063
2088
 
2064
2089
  compileToV0Message(addressLookupTableAccounts) {
2065
- const payerKey = this.accountKeys.get(0);
2066
-
2067
- if (payerKey === undefined) {
2068
- throw new Error('Failed to compile message because no account keys were found');
2069
- }
2070
-
2071
2090
  return MessageV0.compile({
2072
- payerKey,
2091
+ payerKey: this.payerKey,
2073
2092
  recentBlockhash: this.recentBlockhash,
2074
2093
  instructions: this.instructions,
2075
2094
  addressLookupTableAccounts
@@ -2122,7 +2141,7 @@ class VersionedTransaction {
2122
2141
  const signaturesLength = decodeLength(byteArray);
2123
2142
 
2124
2143
  for (let i = 0; i < signaturesLength; i++) {
2125
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2144
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2126
2145
  }
2127
2146
 
2128
2147
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4521,7 +4540,7 @@ const LogsNotificationResult = superstruct.type({
4521
4540
 
4522
4541
  /** @internal */
4523
4542
  const COMMON_HTTP_HEADERS = {
4524
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4543
+ 'solana-client': `js/${(_process$env$npm_pack = "1.59.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4525
4544
  };
4526
4545
  /**
4527
4546
  * A connection to a fullnode JSON RPC endpoint
@@ -9435,10 +9454,8 @@ class ValidatorInfo {
9435
9454
  const configKeys = [];
9436
9455
 
9437
9456
  for (let i = 0; i < 2; i++) {
9438
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9439
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9440
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9441
- byteArray = byteArray.slice(1);
9457
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9458
+ const isSigner = guardedShift(byteArray) === 1;
9442
9459
  configKeys.push({
9443
9460
  publicKey,
9444
9461
  isSigner