@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.
package/lib/index.esm.js CHANGED
@@ -738,6 +738,36 @@ class CompiledKeys {
738
738
 
739
739
  }
740
740
 
741
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
742
+ /**
743
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
744
+ */
745
+
746
+ function guardedShift(byteArray) {
747
+ if (byteArray.length === 0) {
748
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
749
+ }
750
+
751
+ return byteArray.shift();
752
+ }
753
+ /**
754
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
755
+ * the array.
756
+ */
757
+
758
+ function guardedSplice(byteArray, ...args) {
759
+ var _args$;
760
+
761
+ const [start] = args;
762
+
763
+ if (args.length === 2 // Implies that `deleteCount` was supplied
764
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
765
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
766
+ }
767
+
768
+ return byteArray.splice(...args);
769
+ }
770
+
741
771
  /**
742
772
  * An instruction to execute by a program
743
773
  *
@@ -889,37 +919,33 @@ class Message {
889
919
  static from(buffer) {
890
920
  // Slice up wire data
891
921
  let byteArray = [...buffer];
892
- const numRequiredSignatures = byteArray.shift();
922
+ const numRequiredSignatures = guardedShift(byteArray);
893
923
 
894
924
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
895
925
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
896
926
  }
897
927
 
898
- const numReadonlySignedAccounts = byteArray.shift();
899
- const numReadonlyUnsignedAccounts = byteArray.shift();
928
+ const numReadonlySignedAccounts = guardedShift(byteArray);
929
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
900
930
  const accountCount = decodeLength(byteArray);
901
931
  let accountKeys = [];
902
932
 
903
933
  for (let i = 0; i < accountCount; i++) {
904
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
905
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
934
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
906
935
  accountKeys.push(new PublicKey(Buffer.from(account)));
907
936
  }
908
937
 
909
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
910
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
938
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
911
939
  const instructionCount = decodeLength(byteArray);
912
940
  let instructions = [];
913
941
 
914
942
  for (let i = 0; i < instructionCount; i++) {
915
- const programIdIndex = byteArray.shift();
943
+ const programIdIndex = guardedShift(byteArray);
916
944
  const accountCount = decodeLength(byteArray);
917
- const accounts = byteArray.slice(0, accountCount);
918
- byteArray = byteArray.slice(accountCount);
945
+ const accounts = guardedSplice(byteArray, 0, accountCount);
919
946
  const dataLength = decodeLength(byteArray);
920
- const dataSlice = byteArray.slice(0, dataLength);
947
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
921
948
  const data = bs58.encode(Buffer.from(dataSlice));
922
- byteArray = byteArray.slice(dataLength);
923
949
  instructions.push({
924
950
  programIdIndex,
925
951
  accounts,
@@ -1155,33 +1181,33 @@ class MessageV0 {
1155
1181
 
1156
1182
  static deserialize(serializedMessage) {
1157
1183
  let byteArray = [...serializedMessage];
1158
- const prefix = byteArray.shift();
1184
+ const prefix = guardedShift(byteArray);
1159
1185
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
1160
1186
  assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
1161
1187
  const version = maskedPrefix;
1162
1188
  assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
1163
1189
  const header = {
1164
- numRequiredSignatures: byteArray.shift(),
1165
- numReadonlySignedAccounts: byteArray.shift(),
1166
- numReadonlyUnsignedAccounts: byteArray.shift()
1190
+ numRequiredSignatures: guardedShift(byteArray),
1191
+ numReadonlySignedAccounts: guardedShift(byteArray),
1192
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
1167
1193
  };
1168
1194
  const staticAccountKeys = [];
1169
1195
  const staticAccountKeysLength = decodeLength(byteArray);
1170
1196
 
1171
1197
  for (let i = 0; i < staticAccountKeysLength; i++) {
1172
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
1198
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
1173
1199
  }
1174
1200
 
1175
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1201
+ const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1176
1202
  const instructionCount = decodeLength(byteArray);
1177
1203
  const compiledInstructions = [];
1178
1204
 
1179
1205
  for (let i = 0; i < instructionCount; i++) {
1180
- const programIdIndex = byteArray.shift();
1206
+ const programIdIndex = guardedShift(byteArray);
1181
1207
  const accountKeyIndexesLength = decodeLength(byteArray);
1182
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
1208
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
1183
1209
  const dataLength = decodeLength(byteArray);
1184
- const data = new Uint8Array(byteArray.splice(0, dataLength));
1210
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
1185
1211
  compiledInstructions.push({
1186
1212
  programIdIndex,
1187
1213
  accountKeyIndexes,
@@ -1193,11 +1219,11 @@ class MessageV0 {
1193
1219
  const addressTableLookups = [];
1194
1220
 
1195
1221
  for (let i = 0; i < addressTableLookupsCount; i++) {
1196
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
1222
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
1197
1223
  const writableIndexesLength = decodeLength(byteArray);
1198
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
1224
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
1199
1225
  const readonlyIndexesLength = decodeLength(byteArray);
1200
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
1226
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
1201
1227
  addressTableLookups.push({
1202
1228
  accountKey,
1203
1229
  writableIndexes,
@@ -1928,8 +1954,7 @@ class Transaction {
1928
1954
  let signatures = [];
1929
1955
 
1930
1956
  for (let i = 0; i < signatureCount; i++) {
1931
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
1932
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
1957
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
1933
1958
  signatures.push(bs58.encode(Buffer.from(signature)));
1934
1959
  }
1935
1960
 
@@ -2127,7 +2152,7 @@ class VersionedTransaction {
2127
2152
  const signaturesLength = decodeLength(byteArray);
2128
2153
 
2129
2154
  for (let i = 0; i < signaturesLength; i++) {
2130
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
2155
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
2131
2156
  }
2132
2157
 
2133
2158
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -4617,7 +4642,7 @@ const LogsNotificationResult = type({
4617
4642
 
4618
4643
  /** @internal */
4619
4644
  const COMMON_HTTP_HEADERS = {
4620
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4645
+ 'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
4621
4646
  };
4622
4647
  /**
4623
4648
  * A connection to a fullnode JSON RPC endpoint
@@ -5246,7 +5271,7 @@ class Connection {
5246
5271
  }
5247
5272
 
5248
5273
  assert(decodedSignature.length === 64, 'signature has invalid length');
5249
- const subscriptionCommitment = commitment || this.commitment;
5274
+ const confirmationCommitment = commitment || this.commitment;
5250
5275
  let timeoutId;
5251
5276
  let signatureSubscriptionId;
5252
5277
  let disposeSignatureSubscriptionStateChangeObserver;
@@ -5264,7 +5289,7 @@ class Connection {
5264
5289
  __type: TransactionStatus.PROCESSED,
5265
5290
  response
5266
5291
  });
5267
- }, subscriptionCommitment);
5292
+ }, confirmationCommitment);
5268
5293
  const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
5269
5294
  if (signatureSubscriptionId == null) {
5270
5295
  resolveSubscriptionSetup();
@@ -5292,11 +5317,41 @@ class Connection {
5292
5317
  value
5293
5318
  } = response;
5294
5319
 
5320
+ if (value == null) {
5321
+ return;
5322
+ }
5323
+
5295
5324
  if (value !== null && value !== void 0 && value.err) {
5296
5325
  reject(value.err);
5297
- }
5326
+ } else {
5327
+ switch (confirmationCommitment) {
5328
+ case 'confirmed':
5329
+ case 'single':
5330
+ case 'singleGossip':
5331
+ {
5332
+ if (value.confirmationStatus === 'processed') {
5333
+ return;
5334
+ }
5335
+
5336
+ break;
5337
+ }
5338
+
5339
+ case 'finalized':
5340
+ case 'max':
5341
+ case 'root':
5342
+ {
5343
+ if (value.confirmationStatus === 'processed' || value.confirmationStatus === 'confirmed') {
5344
+ return;
5345
+ }
5346
+
5347
+ break;
5348
+ }
5349
+ // exhaust enums to ensure full coverage
5350
+
5351
+ case 'processed':
5352
+ case 'recent':
5353
+ }
5298
5354
 
5299
- if (value) {
5300
5355
  done = true;
5301
5356
  resolve({
5302
5357
  __type: TransactionStatus.PROCESSED,
@@ -5315,7 +5370,7 @@ class Connection {
5315
5370
  if (typeof strategy === 'string') {
5316
5371
  let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
5317
5372
 
5318
- switch (subscriptionCommitment) {
5373
+ switch (confirmationCommitment) {
5319
5374
  case 'processed':
5320
5375
  case 'recent':
5321
5376
  case 'single':
@@ -9692,10 +9747,8 @@ class ValidatorInfo {
9692
9747
  const configKeys = [];
9693
9748
 
9694
9749
  for (let i = 0; i < 2; i++) {
9695
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
9696
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
9697
- const isSigner = byteArray.slice(0, 1)[0] === 1;
9698
- byteArray = byteArray.slice(1);
9750
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
9751
+ const isSigner = guardedShift(byteArray) === 1;
9699
9752
  configKeys.push({
9700
9753
  publicKey,
9701
9754
  isSigner