@solana/web3.js 1.66.5 → 1.66.6

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.cjs.js CHANGED
@@ -771,6 +771,36 @@ class CompiledKeys {
771
771
 
772
772
  }
773
773
 
774
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
775
+ /**
776
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
777
+ */
778
+
779
+ function guardedShift(byteArray) {
780
+ if (byteArray.length === 0) {
781
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
782
+ }
783
+
784
+ return byteArray.shift();
785
+ }
786
+ /**
787
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
788
+ * the array.
789
+ */
790
+
791
+ function guardedSplice(byteArray, ...args) {
792
+ var _args$;
793
+
794
+ const [start] = args;
795
+
796
+ if (args.length === 2 // Implies that `deleteCount` was supplied
797
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
798
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
799
+ }
800
+
801
+ return byteArray.splice(...args);
802
+ }
803
+
774
804
  /**
775
805
  * An instruction to execute by a program
776
806
  *
@@ -922,37 +952,33 @@ class Message {
922
952
  static from(buffer$1) {
923
953
  // Slice up wire data
924
954
  let byteArray = [...buffer$1];
925
- const numRequiredSignatures = byteArray.shift();
955
+ const numRequiredSignatures = guardedShift(byteArray);
926
956
 
927
957
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
928
958
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
929
959
  }
930
960
 
931
- const numReadonlySignedAccounts = byteArray.shift();
932
- const numReadonlyUnsignedAccounts = byteArray.shift();
961
+ const numReadonlySignedAccounts = guardedShift(byteArray);
962
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
933
963
  const accountCount = decodeLength(byteArray);
934
964
  let accountKeys = [];
935
965
 
936
966
  for (let i = 0; i < accountCount; i++) {
937
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
938
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
967
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
939
968
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
940
969
  }
941
970
 
942
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
943
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
971
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
944
972
  const instructionCount = decodeLength(byteArray);
945
973
  let instructions = [];
946
974
 
947
975
  for (let i = 0; i < instructionCount; i++) {
948
- const programIdIndex = byteArray.shift();
976
+ const programIdIndex = guardedShift(byteArray);
949
977
  const accountCount = decodeLength(byteArray);
950
- const accounts = byteArray.slice(0, accountCount);
951
- byteArray = byteArray.slice(accountCount);
978
+ const accounts = guardedSplice(byteArray, 0, accountCount);
952
979
  const dataLength = decodeLength(byteArray);
953
- const dataSlice = byteArray.slice(0, dataLength);
980
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
954
981
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
955
- byteArray = byteArray.slice(dataLength);
956
982
  instructions.push({
957
983
  programIdIndex,
958
984
  accounts,
@@ -1188,33 +1214,33 @@ class MessageV0 {
1188
1214
 
1189
1215
  static deserialize(serializedMessage) {
1190
1216
  let byteArray = [...serializedMessage];
1191
- const prefix = byteArray.shift();
1217
+ const prefix = guardedShift(byteArray);
1192
1218
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1193
1219
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1194
1220
  const version = maskedPrefix;
1195
1221
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1196
1222
  const header = {
1197
- numRequiredSignatures: byteArray.shift(),
1198
- numReadonlySignedAccounts: byteArray.shift(),
1199
- numReadonlyUnsignedAccounts: byteArray.shift()
1223
+ numRequiredSignatures: guardedShift(byteArray),
1224
+ numReadonlySignedAccounts: guardedShift(byteArray),
1225
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1200
1226
  };
1201
1227
  const staticAccountKeys = [];
1202
1228
  const staticAccountKeysLength = decodeLength(byteArray);
1203
1229
 
1204
1230
  for (let i = 0; i < staticAccountKeysLength; i++) {
1205
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1231
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1206
1232
  }
1207
1233
 
1208
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1234
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1209
1235
  const instructionCount = decodeLength(byteArray);
1210
1236
  const compiledInstructions = [];
1211
1237
 
1212
1238
  for (let i = 0; i < instructionCount; i++) {
1213
- const programIdIndex = byteArray.shift();
1239
+ const programIdIndex = guardedShift(byteArray);
1214
1240
  const accountKeyIndexesLength = decodeLength(byteArray);
1215
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1241
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1216
1242
  const dataLength = decodeLength(byteArray);
1217
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1243
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1218
1244
  compiledInstructions.push({
1219
1245
  programIdIndex,
1220
1246
  accountKeyIndexes,
@@ -1226,11 +1252,11 @@ class MessageV0 {
1226
1252
  const addressTableLookups = [];
1227
1253
 
1228
1254
  for (let i = 0; i < addressTableLookupsCount; i++) {
1229
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1255
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1230
1256
  const writableIndexesLength = decodeLength(byteArray);
1231
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1257
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1232
1258
  const readonlyIndexesLength = decodeLength(byteArray);
1233
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1259
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1234
1260
  addressTableLookups.push({
1235
1261
  accountKey,
1236
1262
  writableIndexes,
@@ -1961,8 +1987,7 @@ class Transaction {
1961
1987
  let signatures = [];
1962
1988
 
1963
1989
  for (let i = 0; i < signatureCount; i++) {
1964
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1965
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1990
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1966
1991
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1967
1992
  }
1968
1993
 
@@ -2160,7 +2185,7 @@ class VersionedTransaction {
2160
2185
  const signaturesLength = decodeLength(byteArray);
2161
2186
 
2162
2187
  for (let i = 0; i < signaturesLength; i++) {
2163
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2188
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2164
2189
  }
2165
2190
 
2166
2191
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4650,7 +4675,7 @@ const LogsNotificationResult = superstruct.type({
4650
4675
 
4651
4676
  /** @internal */
4652
4677
  const COMMON_HTTP_HEADERS = {
4653
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4678
+ 'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4654
4679
  };
4655
4680
  /**
4656
4681
  * A connection to a fullnode JSON RPC endpoint
@@ -9755,10 +9780,8 @@ class ValidatorInfo {
9755
9780
  const configKeys = [];
9756
9781
 
9757
9782
  for (let i = 0; i < 2; i++) {
9758
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9759
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9760
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9761
- byteArray = byteArray.slice(1);
9783
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9784
+ const isSigner = guardedShift(byteArray) === 1;
9762
9785
  configKeys.push({
9763
9786
  publicKey,
9764
9787
  isSigner