@solana/web3.js 1.66.4 → 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.
@@ -735,6 +735,36 @@ class CompiledKeys {
735
735
 
736
736
  }
737
737
 
738
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
739
+ /**
740
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
741
+ */
742
+
743
+ function guardedShift(byteArray) {
744
+ if (byteArray.length === 0) {
745
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
746
+ }
747
+
748
+ return byteArray.shift();
749
+ }
750
+ /**
751
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
752
+ * the array.
753
+ */
754
+
755
+ function guardedSplice(byteArray, ...args) {
756
+ var _args$;
757
+
758
+ const [start] = args;
759
+
760
+ if (args.length === 2 // Implies that `deleteCount` was supplied
761
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
762
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
763
+ }
764
+
765
+ return byteArray.splice(...args);
766
+ }
767
+
738
768
  /**
739
769
  * An instruction to execute by a program
740
770
  *
@@ -886,37 +916,33 @@ class Message {
886
916
  static from(buffer) {
887
917
  // Slice up wire data
888
918
  let byteArray = [...buffer];
889
- const numRequiredSignatures = byteArray.shift();
919
+ const numRequiredSignatures = guardedShift(byteArray);
890
920
 
891
921
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
892
922
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
893
923
  }
894
924
 
895
- const numReadonlySignedAccounts = byteArray.shift();
896
- const numReadonlyUnsignedAccounts = byteArray.shift();
925
+ const numReadonlySignedAccounts = guardedShift(byteArray);
926
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
897
927
  const accountCount = decodeLength(byteArray);
898
928
  let accountKeys = [];
899
929
 
900
930
  for (let i = 0; i < accountCount; i++) {
901
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
902
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
931
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
903
932
  accountKeys.push(new PublicKey(Buffer.from(account)));
904
933
  }
905
934
 
906
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
907
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
935
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
908
936
  const instructionCount = decodeLength(byteArray);
909
937
  let instructions = [];
910
938
 
911
939
  for (let i = 0; i < instructionCount; i++) {
912
- const programIdIndex = byteArray.shift();
940
+ const programIdIndex = guardedShift(byteArray);
913
941
  const accountCount = decodeLength(byteArray);
914
- const accounts = byteArray.slice(0, accountCount);
915
- byteArray = byteArray.slice(accountCount);
942
+ const accounts = guardedSplice(byteArray, 0, accountCount);
916
943
  const dataLength = decodeLength(byteArray);
917
- const dataSlice = byteArray.slice(0, dataLength);
944
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
918
945
  const data = bs58.encode(Buffer.from(dataSlice));
919
- byteArray = byteArray.slice(dataLength);
920
946
  instructions.push({
921
947
  programIdIndex,
922
948
  accounts,
@@ -1152,33 +1178,33 @@ class MessageV0 {
1152
1178
 
1153
1179
  static deserialize(serializedMessage) {
1154
1180
  let byteArray = [...serializedMessage];
1155
- const prefix = byteArray.shift();
1181
+ const prefix = guardedShift(byteArray);
1156
1182
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1157
1183
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1158
1184
  const version = maskedPrefix;
1159
1185
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1160
1186
  const header = {
1161
- numRequiredSignatures: byteArray.shift(),
1162
- numReadonlySignedAccounts: byteArray.shift(),
1163
- numReadonlyUnsignedAccounts: byteArray.shift()
1187
+ numRequiredSignatures: guardedShift(byteArray),
1188
+ numReadonlySignedAccounts: guardedShift(byteArray),
1189
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1164
1190
  };
1165
1191
  const staticAccountKeys = [];
1166
1192
  const staticAccountKeysLength = decodeLength(byteArray);
1167
1193
 
1168
1194
  for (let i = 0; i < staticAccountKeysLength; i++) {
1169
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1195
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1170
1196
  }
1171
1197
 
1172
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1198
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1173
1199
  const instructionCount = decodeLength(byteArray);
1174
1200
  const compiledInstructions = [];
1175
1201
 
1176
1202
  for (let i = 0; i < instructionCount; i++) {
1177
- const programIdIndex = byteArray.shift();
1203
+ const programIdIndex = guardedShift(byteArray);
1178
1204
  const accountKeyIndexesLength = decodeLength(byteArray);
1179
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1205
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1180
1206
  const dataLength = decodeLength(byteArray);
1181
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1207
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1182
1208
  compiledInstructions.push({
1183
1209
  programIdIndex,
1184
1210
  accountKeyIndexes,
@@ -1190,11 +1216,11 @@ class MessageV0 {
1190
1216
  const addressTableLookups = [];
1191
1217
 
1192
1218
  for (let i = 0; i < addressTableLookupsCount; i++) {
1193
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1219
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1194
1220
  const writableIndexesLength = decodeLength(byteArray);
1195
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1221
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1196
1222
  const readonlyIndexesLength = decodeLength(byteArray);
1197
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1223
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1198
1224
  addressTableLookups.push({
1199
1225
  accountKey,
1200
1226
  writableIndexes,
@@ -1925,8 +1951,7 @@ class Transaction {
1925
1951
  let signatures = [];
1926
1952
 
1927
1953
  for (let i = 0; i < signatureCount; i++) {
1928
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1929
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1954
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1930
1955
  signatures.push(bs58.encode(Buffer.from(signature)));
1931
1956
  }
1932
1957
 
@@ -2124,7 +2149,7 @@ class VersionedTransaction {
2124
2149
  const signaturesLength = decodeLength(byteArray);
2125
2150
 
2126
2151
  for (let i = 0; i < signaturesLength; i++) {
2127
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2152
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2128
2153
  }
2129
2154
 
2130
2155
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4554,7 +4579,7 @@ const LogsNotificationResult = type({
4554
4579
 
4555
4580
  /** @internal */
4556
4581
  const COMMON_HTTP_HEADERS = {
4557
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4582
+ 'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4558
4583
  };
4559
4584
  /**
4560
4585
  * A connection to a fullnode JSON RPC endpoint
@@ -5183,7 +5208,7 @@ class Connection {
5183
5208
  }
5184
5209
 
5185
5210
  assert(decodedSignature.length === 64, 'signature has invalid length');
5186
- const subscriptionCommitment = commitment || this.commitment;
5211
+ const confirmationCommitment = commitment || this.commitment;
5187
5212
  let timeoutId;
5188
5213
  let signatureSubscriptionId;
5189
5214
  let disposeSignatureSubscriptionStateChangeObserver;
@@ -5201,7 +5226,7 @@ class Connection {
5201
5226
  __type: TransactionStatus.PROCESSED,
5202
5227
  response
5203
5228
  });
5204
- }, subscriptionCommitment);
5229
+ }, confirmationCommitment);
5205
5230
  const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
5206
5231
  if (signatureSubscriptionId == null) {
5207
5232
  resolveSubscriptionSetup();
@@ -5229,11 +5254,41 @@ class Connection {
5229
5254
  value
5230
5255
  } = response;
5231
5256
 
5257
+ if (value == null) {
5258
+ return;
5259
+ }
5260
+
5232
5261
  if (value !== null && value !== void 0 && value.err) {
5233
5262
  reject(value.err);
5234
- }
5263
+ } else {
5264
+ switch (confirmationCommitment) {
5265
+ case 'confirmed':
5266
+ case 'single':
5267
+ case 'singleGossip':
5268
+ {
5269
+ if (value.confirmationStatus === 'processed') {
5270
+ return;
5271
+ }
5272
+
5273
+ break;
5274
+ }
5275
+
5276
+ case 'finalized':
5277
+ case 'max':
5278
+ case 'root':
5279
+ {
5280
+ if (value.confirmationStatus === 'processed' || value.confirmationStatus === 'confirmed') {
5281
+ return;
5282
+ }
5283
+
5284
+ break;
5285
+ }
5286
+ // exhaust enums to ensure full coverage
5287
+
5288
+ case 'processed':
5289
+ case 'recent':
5290
+ }
5235
5291
 
5236
- if (value) {
5237
5292
  done = true;
5238
5293
  resolve({
5239
5294
  __type: TransactionStatus.PROCESSED,
@@ -5252,7 +5307,7 @@ class Connection {
5252
5307
  if (typeof strategy === 'string') {
5253
5308
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
5254
5309
 
5255
- switch (subscriptionCommitment) {
5310
+ switch (confirmationCommitment) {
5256
5311
  case 'processed':
5257
5312
  case 'recent':
5258
5313
  case 'single':
@@ -9629,10 +9684,8 @@ class ValidatorInfo {
9629
9684
  const configKeys = [];
9630
9685
 
9631
9686
  for (let i = 0; i < 2; i++) {
9632
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9633
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9634
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9635
- byteArray = byteArray.slice(1);
9687
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9688
+ const isSigner = guardedShift(byteArray) === 1;
9636
9689
  configKeys.push({
9637
9690
  publicKey,
9638
9691
  isSigner