@solana/web3.js 1.67.1 → 1.67.3

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.
@@ -780,6 +780,36 @@ class CompiledKeys {
780
780
 
781
781
  }
782
782
 
783
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
784
+ /**
785
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
786
+ */
787
+
788
+ function guardedShift(byteArray) {
789
+ if (byteArray.length === 0) {
790
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
791
+ }
792
+
793
+ return byteArray.shift();
794
+ }
795
+ /**
796
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
797
+ * the array.
798
+ */
799
+
800
+ function guardedSplice(byteArray, ...args) {
801
+ var _args$;
802
+
803
+ const [start] = args;
804
+
805
+ if (args.length === 2 // Implies that `deleteCount` was supplied
806
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
807
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
808
+ }
809
+
810
+ return byteArray.splice(...args);
811
+ }
812
+
783
813
  /**
784
814
  * An instruction to execute by a program
785
815
  *
@@ -931,37 +961,33 @@ class Message {
931
961
  static from(buffer$1) {
932
962
  // Slice up wire data
933
963
  let byteArray = [...buffer$1];
934
- const numRequiredSignatures = byteArray.shift();
964
+ const numRequiredSignatures = guardedShift(byteArray);
935
965
 
936
966
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
937
967
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
938
968
  }
939
969
 
940
- const numReadonlySignedAccounts = byteArray.shift();
941
- const numReadonlyUnsignedAccounts = byteArray.shift();
970
+ const numReadonlySignedAccounts = guardedShift(byteArray);
971
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
942
972
  const accountCount = decodeLength(byteArray);
943
973
  let accountKeys = [];
944
974
 
945
975
  for (let i = 0; i < accountCount; i++) {
946
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
947
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
976
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
948
977
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
949
978
  }
950
979
 
951
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
952
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
980
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
953
981
  const instructionCount = decodeLength(byteArray);
954
982
  let instructions = [];
955
983
 
956
984
  for (let i = 0; i < instructionCount; i++) {
957
- const programIdIndex = byteArray.shift();
985
+ const programIdIndex = guardedShift(byteArray);
958
986
  const accountCount = decodeLength(byteArray);
959
- const accounts = byteArray.slice(0, accountCount);
960
- byteArray = byteArray.slice(accountCount);
987
+ const accounts = guardedSplice(byteArray, 0, accountCount);
961
988
  const dataLength = decodeLength(byteArray);
962
- const dataSlice = byteArray.slice(0, dataLength);
989
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
963
990
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
964
- byteArray = byteArray.slice(dataLength);
965
991
  instructions.push({
966
992
  programIdIndex,
967
993
  accounts,
@@ -1197,33 +1223,33 @@ class MessageV0 {
1197
1223
 
1198
1224
  static deserialize(serializedMessage) {
1199
1225
  let byteArray = [...serializedMessage];
1200
- const prefix = byteArray.shift();
1226
+ const prefix = guardedShift(byteArray);
1201
1227
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1202
1228
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1203
1229
  const version = maskedPrefix;
1204
1230
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1205
1231
  const header = {
1206
- numRequiredSignatures: byteArray.shift(),
1207
- numReadonlySignedAccounts: byteArray.shift(),
1208
- numReadonlyUnsignedAccounts: byteArray.shift()
1232
+ numRequiredSignatures: guardedShift(byteArray),
1233
+ numReadonlySignedAccounts: guardedShift(byteArray),
1234
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1209
1235
  };
1210
1236
  const staticAccountKeys = [];
1211
1237
  const staticAccountKeysLength = decodeLength(byteArray);
1212
1238
 
1213
1239
  for (let i = 0; i < staticAccountKeysLength; i++) {
1214
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1240
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1215
1241
  }
1216
1242
 
1217
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1243
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1218
1244
  const instructionCount = decodeLength(byteArray);
1219
1245
  const compiledInstructions = [];
1220
1246
 
1221
1247
  for (let i = 0; i < instructionCount; i++) {
1222
- const programIdIndex = byteArray.shift();
1248
+ const programIdIndex = guardedShift(byteArray);
1223
1249
  const accountKeyIndexesLength = decodeLength(byteArray);
1224
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1250
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1225
1251
  const dataLength = decodeLength(byteArray);
1226
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1252
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1227
1253
  compiledInstructions.push({
1228
1254
  programIdIndex,
1229
1255
  accountKeyIndexes,
@@ -1235,11 +1261,11 @@ class MessageV0 {
1235
1261
  const addressTableLookups = [];
1236
1262
 
1237
1263
  for (let i = 0; i < addressTableLookupsCount; i++) {
1238
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1264
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1239
1265
  const writableIndexesLength = decodeLength(byteArray);
1240
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1266
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1241
1267
  const readonlyIndexesLength = decodeLength(byteArray);
1242
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1268
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1243
1269
  addressTableLookups.push({
1244
1270
  accountKey,
1245
1271
  writableIndexes,
@@ -1979,8 +2005,7 @@ class Transaction {
1979
2005
  let signatures = [];
1980
2006
 
1981
2007
  for (let i = 0; i < signatureCount; i++) {
1982
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1983
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
2008
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1984
2009
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1985
2010
  }
1986
2011
 
@@ -2178,7 +2203,7 @@ class VersionedTransaction {
2178
2203
  const signaturesLength = decodeLength(byteArray);
2179
2204
 
2180
2205
  for (let i = 0; i < signaturesLength; i++) {
2181
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2206
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2182
2207
  }
2183
2208
 
2184
2209
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4631,7 +4656,7 @@ const LogsNotificationResult = superstruct.type({
4631
4656
 
4632
4657
  /** @internal */
4633
4658
  const COMMON_HTTP_HEADERS = {
4634
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4659
+ 'solana-client': `js/${(_process$env$npm_pack = "1.67.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4635
4660
  };
4636
4661
  /**
4637
4662
  * A connection to a fullnode JSON RPC endpoint
@@ -6013,7 +6038,7 @@ class Connection {
6013
6038
 
6014
6039
 
6015
6040
  async getFeeForMessage(message, commitment) {
6016
- const wireMessage = message.serialize().toString('base64');
6041
+ const wireMessage = toBuffer(message.serialize()).toString('base64');
6017
6042
 
6018
6043
  const args = this._buildArgs([wireMessage], commitment);
6019
6044
 
@@ -9954,10 +9979,8 @@ class ValidatorInfo {
9954
9979
  const configKeys = [];
9955
9980
 
9956
9981
  for (let i = 0; i < 2; i++) {
9957
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9958
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9959
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9960
- byteArray = byteArray.slice(1);
9982
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9983
+ const isSigner = guardedShift(byteArray) === 1;
9961
9984
  configKeys.push({
9962
9985
  publicKey,
9963
9986
  isSigner