@solana/web3.js 1.70.2 → 1.70.4

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.
@@ -224,7 +224,8 @@ class PublicKey extends Struct {
224
224
 
225
225
 
226
226
  toBytes() {
227
- return this.toBuffer();
227
+ const buf = this.toBuffer();
228
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
228
229
  }
229
230
  /**
230
231
  * Return the Buffer representation of the public key in big endian
@@ -786,6 +787,36 @@ class CompiledKeys {
786
787
 
787
788
  }
788
789
 
790
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
791
+ /**
792
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
793
+ */
794
+
795
+ function guardedShift(byteArray) {
796
+ if (byteArray.length === 0) {
797
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
798
+ }
799
+
800
+ return byteArray.shift();
801
+ }
802
+ /**
803
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
804
+ * the array.
805
+ */
806
+
807
+ function guardedSplice(byteArray, ...args) {
808
+ var _args$;
809
+
810
+ const [start] = args;
811
+
812
+ if (args.length === 2 // Implies that `deleteCount` was supplied
813
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
814
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
815
+ }
816
+
817
+ return byteArray.splice(...args);
818
+ }
819
+
789
820
  /**
790
821
  * An instruction to execute by a program
791
822
  *
@@ -937,37 +968,33 @@ class Message {
937
968
  static from(buffer$1) {
938
969
  // Slice up wire data
939
970
  let byteArray = [...buffer$1];
940
- const numRequiredSignatures = byteArray.shift();
971
+ const numRequiredSignatures = guardedShift(byteArray);
941
972
 
942
973
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
943
974
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
944
975
  }
945
976
 
946
- const numReadonlySignedAccounts = byteArray.shift();
947
- const numReadonlyUnsignedAccounts = byteArray.shift();
977
+ const numReadonlySignedAccounts = guardedShift(byteArray);
978
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
948
979
  const accountCount = decodeLength(byteArray);
949
980
  let accountKeys = [];
950
981
 
951
982
  for (let i = 0; i < accountCount; i++) {
952
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
953
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
983
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
954
984
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
955
985
  }
956
986
 
957
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
958
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
987
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
959
988
  const instructionCount = decodeLength(byteArray);
960
989
  let instructions = [];
961
990
 
962
991
  for (let i = 0; i < instructionCount; i++) {
963
- const programIdIndex = byteArray.shift();
992
+ const programIdIndex = guardedShift(byteArray);
964
993
  const accountCount = decodeLength(byteArray);
965
- const accounts = byteArray.slice(0, accountCount);
966
- byteArray = byteArray.slice(accountCount);
994
+ const accounts = guardedSplice(byteArray, 0, accountCount);
967
995
  const dataLength = decodeLength(byteArray);
968
- const dataSlice = byteArray.slice(0, dataLength);
996
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
969
997
  const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
970
- byteArray = byteArray.slice(dataLength);
971
998
  instructions.push({
972
999
  programIdIndex,
973
1000
  accounts,
@@ -1203,33 +1230,33 @@ class MessageV0 {
1203
1230
 
1204
1231
  static deserialize(serializedMessage) {
1205
1232
  let byteArray = [...serializedMessage];
1206
- const prefix = byteArray.shift();
1233
+ const prefix = guardedShift(byteArray);
1207
1234
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1208
1235
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1209
1236
  const version = maskedPrefix;
1210
1237
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1211
1238
  const header = {
1212
- numRequiredSignatures: byteArray.shift(),
1213
- numReadonlySignedAccounts: byteArray.shift(),
1214
- numReadonlyUnsignedAccounts: byteArray.shift()
1239
+ numRequiredSignatures: guardedShift(byteArray),
1240
+ numReadonlySignedAccounts: guardedShift(byteArray),
1241
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1215
1242
  };
1216
1243
  const staticAccountKeys = [];
1217
1244
  const staticAccountKeysLength = decodeLength(byteArray);
1218
1245
 
1219
1246
  for (let i = 0; i < staticAccountKeysLength; i++) {
1220
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1247
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1221
1248
  }
1222
1249
 
1223
- const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1250
+ const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1224
1251
  const instructionCount = decodeLength(byteArray);
1225
1252
  const compiledInstructions = [];
1226
1253
 
1227
1254
  for (let i = 0; i < instructionCount; i++) {
1228
- const programIdIndex = byteArray.shift();
1255
+ const programIdIndex = guardedShift(byteArray);
1229
1256
  const accountKeyIndexesLength = decodeLength(byteArray);
1230
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1257
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1231
1258
  const dataLength = decodeLength(byteArray);
1232
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1259
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1233
1260
  compiledInstructions.push({
1234
1261
  programIdIndex,
1235
1262
  accountKeyIndexes,
@@ -1241,11 +1268,11 @@ class MessageV0 {
1241
1268
  const addressTableLookups = [];
1242
1269
 
1243
1270
  for (let i = 0; i < addressTableLookupsCount; i++) {
1244
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1271
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1245
1272
  const writableIndexesLength = decodeLength(byteArray);
1246
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1273
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1247
1274
  const readonlyIndexesLength = decodeLength(byteArray);
1248
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1275
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1249
1276
  addressTableLookups.push({
1250
1277
  accountKey,
1251
1278
  writableIndexes,
@@ -1985,8 +2012,7 @@ class Transaction {
1985
2012
  let signatures = [];
1986
2013
 
1987
2014
  for (let i = 0; i < signatureCount; i++) {
1988
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1989
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
2015
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1990
2016
  signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
1991
2017
  }
1992
2018
 
@@ -2184,7 +2210,7 @@ class VersionedTransaction {
2184
2210
  const signaturesLength = decodeLength(byteArray);
2185
2211
 
2186
2212
  for (let i = 0; i < signaturesLength; i++) {
2187
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2213
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2188
2214
  }
2189
2215
 
2190
2216
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4701,7 +4727,7 @@ const LogsNotificationResult = superstruct.type({
4701
4727
 
4702
4728
  /** @internal */
4703
4729
  const COMMON_HTTP_HEADERS = {
4704
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4730
+ 'solana-client': `js/${(_process$env$npm_pack = "1.70.4") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4705
4731
  };
4706
4732
  /**
4707
4733
  * A connection to a fullnode JSON RPC endpoint
@@ -10119,10 +10145,8 @@ class ValidatorInfo {
10119
10145
  const configKeys = [];
10120
10146
 
10121
10147
  for (let i = 0; i < 2; i++) {
10122
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10123
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10124
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10125
- byteArray = byteArray.slice(1);
10148
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10149
+ const isSigner = guardedShift(byteArray) === 1;
10126
10150
  configKeys.push({
10127
10151
  publicKey,
10128
10152
  isSigner
@@ -10287,7 +10311,7 @@ function clusterApiUrl(cluster, tls) {
10287
10311
  *
10288
10312
  * @param {Connection} connection
10289
10313
  * @param {Buffer} rawTransaction
10290
- * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
10314
+ * @param {TransactionConfirmationStrategy} confirmationStrategy
10291
10315
  * @param {ConfirmOptions} [options]
10292
10316
  * @returns {Promise<TransactionSignature>}
10293
10317
  */