@solana/web3.js 1.69.0 → 1.69.1

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.esm.js CHANGED
@@ -753,6 +753,36 @@ class CompiledKeys {
753
753
 
754
754
  }
755
755
 
756
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
757
+ /**
758
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
759
+ */
760
+
761
+ function guardedShift(byteArray) {
762
+ if (byteArray.length === 0) {
763
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
764
+ }
765
+
766
+ return byteArray.shift();
767
+ }
768
+ /**
769
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
770
+ * the array.
771
+ */
772
+
773
+ function guardedSplice(byteArray, ...args) {
774
+ var _args$;
775
+
776
+ const [start] = args;
777
+
778
+ if (args.length === 2 // Implies that `deleteCount` was supplied
779
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
780
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
781
+ }
782
+
783
+ return byteArray.splice(...args);
784
+ }
785
+
756
786
  /**
757
787
  * An instruction to execute by a program
758
788
  *
@@ -904,37 +934,33 @@ class Message {
904
934
  static from(buffer) {
905
935
  // Slice up wire data
906
936
  let byteArray = [...buffer];
907
- const numRequiredSignatures = byteArray.shift();
937
+ const numRequiredSignatures = guardedShift(byteArray);
908
938
 
909
939
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
910
940
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
911
941
  }
912
942
 
913
- const numReadonlySignedAccounts = byteArray.shift();
914
- const numReadonlyUnsignedAccounts = byteArray.shift();
943
+ const numReadonlySignedAccounts = guardedShift(byteArray);
944
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
915
945
  const accountCount = decodeLength(byteArray);
916
946
  let accountKeys = [];
917
947
 
918
948
  for (let i = 0; i < accountCount; i++) {
919
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
920
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
949
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
921
950
  accountKeys.push(new PublicKey(Buffer.from(account)));
922
951
  }
923
952
 
924
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
925
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
953
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
926
954
  const instructionCount = decodeLength(byteArray);
927
955
  let instructions = [];
928
956
 
929
957
  for (let i = 0; i < instructionCount; i++) {
930
- const programIdIndex = byteArray.shift();
958
+ const programIdIndex = guardedShift(byteArray);
931
959
  const accountCount = decodeLength(byteArray);
932
- const accounts = byteArray.slice(0, accountCount);
933
- byteArray = byteArray.slice(accountCount);
960
+ const accounts = guardedSplice(byteArray, 0, accountCount);
934
961
  const dataLength = decodeLength(byteArray);
935
- const dataSlice = byteArray.slice(0, dataLength);
962
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
936
963
  const data = bs58.encode(Buffer.from(dataSlice));
937
- byteArray = byteArray.slice(dataLength);
938
964
  instructions.push({
939
965
  programIdIndex,
940
966
  accounts,
@@ -1170,33 +1196,33 @@ class MessageV0 {
1170
1196
 
1171
1197
  static deserialize(serializedMessage) {
1172
1198
  let byteArray = [...serializedMessage];
1173
- const prefix = byteArray.shift();
1199
+ const prefix = guardedShift(byteArray);
1174
1200
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1175
1201
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1176
1202
  const version = maskedPrefix;
1177
1203
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1178
1204
  const header = {
1179
- numRequiredSignatures: byteArray.shift(),
1180
- numReadonlySignedAccounts: byteArray.shift(),
1181
- numReadonlyUnsignedAccounts: byteArray.shift()
1205
+ numRequiredSignatures: guardedShift(byteArray),
1206
+ numReadonlySignedAccounts: guardedShift(byteArray),
1207
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1182
1208
  };
1183
1209
  const staticAccountKeys = [];
1184
1210
  const staticAccountKeysLength = decodeLength(byteArray);
1185
1211
 
1186
1212
  for (let i = 0; i < staticAccountKeysLength; i++) {
1187
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1213
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1188
1214
  }
1189
1215
 
1190
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1216
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1191
1217
  const instructionCount = decodeLength(byteArray);
1192
1218
  const compiledInstructions = [];
1193
1219
 
1194
1220
  for (let i = 0; i < instructionCount; i++) {
1195
- const programIdIndex = byteArray.shift();
1221
+ const programIdIndex = guardedShift(byteArray);
1196
1222
  const accountKeyIndexesLength = decodeLength(byteArray);
1197
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1223
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1198
1224
  const dataLength = decodeLength(byteArray);
1199
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1225
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1200
1226
  compiledInstructions.push({
1201
1227
  programIdIndex,
1202
1228
  accountKeyIndexes,
@@ -1208,11 +1234,11 @@ class MessageV0 {
1208
1234
  const addressTableLookups = [];
1209
1235
 
1210
1236
  for (let i = 0; i < addressTableLookupsCount; i++) {
1211
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1237
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1212
1238
  const writableIndexesLength = decodeLength(byteArray);
1213
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1239
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1214
1240
  const readonlyIndexesLength = decodeLength(byteArray);
1215
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1241
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1216
1242
  addressTableLookups.push({
1217
1243
  accountKey,
1218
1244
  writableIndexes,
@@ -1952,8 +1978,7 @@ class Transaction {
1952
1978
  let signatures = [];
1953
1979
 
1954
1980
  for (let i = 0; i < signatureCount; i++) {
1955
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1956
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1981
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1957
1982
  signatures.push(bs58.encode(Buffer.from(signature)));
1958
1983
  }
1959
1984
 
@@ -2151,7 +2176,7 @@ class VersionedTransaction {
2151
2176
  const signaturesLength = decodeLength(byteArray);
2152
2177
 
2153
2178
  for (let i = 0; i < signaturesLength; i++) {
2154
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2179
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2155
2180
  }
2156
2181
 
2157
2182
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4723,7 +4748,7 @@ const LogsNotificationResult = type({
4723
4748
 
4724
4749
  /** @internal */
4725
4750
  const COMMON_HTTP_HEADERS = {
4726
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4751
+ 'solana-client': `js/${(_process$env$npm_pack = "1.69.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4727
4752
  };
4728
4753
  /**
4729
4754
  * A connection to a fullnode JSON RPC endpoint
@@ -10139,10 +10164,8 @@ class ValidatorInfo {
10139
10164
  const configKeys = [];
10140
10165
 
10141
10166
  for (let i = 0; i < 2; i++) {
10142
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10143
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10144
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10145
- byteArray = byteArray.slice(1);
10167
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10168
+ const isSigner = guardedShift(byteArray) === 1;
10146
10169
  configKeys.push({
10147
10170
  publicKey,
10148
10171
  isSigner