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