@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.
@@ -194,7 +194,8 @@ class PublicKey extends Struct {
194
194
 
195
195
 
196
196
  toBytes() {
197
- return this.toBuffer();
197
+ const buf = this.toBuffer();
198
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
198
199
  }
199
200
  /**
200
201
  * Return the Buffer representation of the public key in big endian
@@ -756,6 +757,36 @@ class CompiledKeys {
756
757
 
757
758
  }
758
759
 
760
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
761
+ /**
762
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
763
+ */
764
+
765
+ function guardedShift(byteArray) {
766
+ if (byteArray.length === 0) {
767
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
768
+ }
769
+
770
+ return byteArray.shift();
771
+ }
772
+ /**
773
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
774
+ * the array.
775
+ */
776
+
777
+ function guardedSplice(byteArray, ...args) {
778
+ var _args$;
779
+
780
+ const [start] = args;
781
+
782
+ if (args.length === 2 // Implies that `deleteCount` was supplied
783
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
784
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
785
+ }
786
+
787
+ return byteArray.splice(...args);
788
+ }
789
+
759
790
  /**
760
791
  * An instruction to execute by a program
761
792
  *
@@ -907,37 +938,33 @@ class Message {
907
938
  static from(buffer) {
908
939
  // Slice up wire data
909
940
  let byteArray = [...buffer];
910
- const numRequiredSignatures = byteArray.shift();
941
+ const numRequiredSignatures = guardedShift(byteArray);
911
942
 
912
943
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
913
944
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
914
945
  }
915
946
 
916
- const numReadonlySignedAccounts = byteArray.shift();
917
- const numReadonlyUnsignedAccounts = byteArray.shift();
947
+ const numReadonlySignedAccounts = guardedShift(byteArray);
948
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
918
949
  const accountCount = decodeLength(byteArray);
919
950
  let accountKeys = [];
920
951
 
921
952
  for (let i = 0; i < accountCount; i++) {
922
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
923
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
953
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
924
954
  accountKeys.push(new PublicKey(Buffer.from(account)));
925
955
  }
926
956
 
927
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
928
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
957
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
929
958
  const instructionCount = decodeLength(byteArray);
930
959
  let instructions = [];
931
960
 
932
961
  for (let i = 0; i < instructionCount; i++) {
933
- const programIdIndex = byteArray.shift();
962
+ const programIdIndex = guardedShift(byteArray);
934
963
  const accountCount = decodeLength(byteArray);
935
- const accounts = byteArray.slice(0, accountCount);
936
- byteArray = byteArray.slice(accountCount);
964
+ const accounts = guardedSplice(byteArray, 0, accountCount);
937
965
  const dataLength = decodeLength(byteArray);
938
- const dataSlice = byteArray.slice(0, dataLength);
966
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
939
967
  const data = bs58.encode(Buffer.from(dataSlice));
940
- byteArray = byteArray.slice(dataLength);
941
968
  instructions.push({
942
969
  programIdIndex,
943
970
  accounts,
@@ -1173,33 +1200,33 @@ class MessageV0 {
1173
1200
 
1174
1201
  static deserialize(serializedMessage) {
1175
1202
  let byteArray = [...serializedMessage];
1176
- const prefix = byteArray.shift();
1203
+ const prefix = guardedShift(byteArray);
1177
1204
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1178
1205
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1179
1206
  const version = maskedPrefix;
1180
1207
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1181
1208
  const header = {
1182
- numRequiredSignatures: byteArray.shift(),
1183
- numReadonlySignedAccounts: byteArray.shift(),
1184
- numReadonlyUnsignedAccounts: byteArray.shift()
1209
+ numRequiredSignatures: guardedShift(byteArray),
1210
+ numReadonlySignedAccounts: guardedShift(byteArray),
1211
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1185
1212
  };
1186
1213
  const staticAccountKeys = [];
1187
1214
  const staticAccountKeysLength = decodeLength(byteArray);
1188
1215
 
1189
1216
  for (let i = 0; i < staticAccountKeysLength; i++) {
1190
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1217
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1191
1218
  }
1192
1219
 
1193
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1220
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1194
1221
  const instructionCount = decodeLength(byteArray);
1195
1222
  const compiledInstructions = [];
1196
1223
 
1197
1224
  for (let i = 0; i < instructionCount; i++) {
1198
- const programIdIndex = byteArray.shift();
1225
+ const programIdIndex = guardedShift(byteArray);
1199
1226
  const accountKeyIndexesLength = decodeLength(byteArray);
1200
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1227
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1201
1228
  const dataLength = decodeLength(byteArray);
1202
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1229
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1203
1230
  compiledInstructions.push({
1204
1231
  programIdIndex,
1205
1232
  accountKeyIndexes,
@@ -1211,11 +1238,11 @@ class MessageV0 {
1211
1238
  const addressTableLookups = [];
1212
1239
 
1213
1240
  for (let i = 0; i < addressTableLookupsCount; i++) {
1214
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1241
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1215
1242
  const writableIndexesLength = decodeLength(byteArray);
1216
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1243
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1217
1244
  const readonlyIndexesLength = decodeLength(byteArray);
1218
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1245
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1219
1246
  addressTableLookups.push({
1220
1247
  accountKey,
1221
1248
  writableIndexes,
@@ -1955,8 +1982,7 @@ class Transaction {
1955
1982
  let signatures = [];
1956
1983
 
1957
1984
  for (let i = 0; i < signatureCount; i++) {
1958
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1959
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1985
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1960
1986
  signatures.push(bs58.encode(Buffer.from(signature)));
1961
1987
  }
1962
1988
 
@@ -2154,7 +2180,7 @@ class VersionedTransaction {
2154
2180
  const signaturesLength = decodeLength(byteArray);
2155
2181
 
2156
2182
  for (let i = 0; i < signaturesLength; i++) {
2157
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2183
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2158
2184
  }
2159
2185
 
2160
2186
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4671,7 +4697,7 @@ const LogsNotificationResult = type({
4671
4697
 
4672
4698
  /** @internal */
4673
4699
  const COMMON_HTTP_HEADERS = {
4674
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4700
+ 'solana-client': `js/${(_process$env$npm_pack = "1.70.4") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4675
4701
  };
4676
4702
  /**
4677
4703
  * A connection to a fullnode JSON RPC endpoint
@@ -10089,10 +10115,8 @@ class ValidatorInfo {
10089
10115
  const configKeys = [];
10090
10116
 
10091
10117
  for (let i = 0; i < 2; i++) {
10092
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10093
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10094
- const isSigner = byteArray.slice(0, 1)[0] === 1;
10095
- byteArray = byteArray.slice(1);
10118
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
10119
+ const isSigner = guardedShift(byteArray) === 1;
10096
10120
  configKeys.push({
10097
10121
  publicKey,
10098
10122
  isSigner
@@ -10257,7 +10281,7 @@ function clusterApiUrl(cluster, tls) {
10257
10281
  *
10258
10282
  * @param {Connection} connection
10259
10283
  * @param {Buffer} rawTransaction
10260
- * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
10284
+ * @param {TransactionConfirmationStrategy} confirmationStrategy
10261
10285
  * @param {ConfirmOptions} [options]
10262
10286
  * @returns {Promise<TransactionSignature>}
10263
10287
  */