@solana/web3.js 1.30.2 → 1.32.2

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.
@@ -1,5 +1,4 @@
1
- import * as nacl from 'tweetnacl';
2
- import nacl__default from 'tweetnacl';
1
+ import nacl from 'tweetnacl';
3
2
  import { Buffer } from 'buffer';
4
3
  import BN from 'bn.js';
5
4
  import bs58 from 'bs58';
@@ -9,7 +8,7 @@ import { coerce, instance, string, tuple, literal, unknown, union, type, optiona
9
8
  import { Client } from 'rpc-websockets';
10
9
  import RpcClient from 'jayson/lib/client/browser';
11
10
  import secp256k1 from 'secp256k1';
12
- import { keccak_256 } from 'js-sha3';
11
+ import sha3 from 'js-sha3';
13
12
 
14
13
  const toBuffer = arr => {
15
14
  if (Buffer.isBuffer(arr)) {
@@ -1799,6 +1798,10 @@ class PublicKey extends Struct {
1799
1798
  toBase58() {
1800
1799
  return bs58.encode(this.toBytes());
1801
1800
  }
1801
+
1802
+ toJSON() {
1803
+ return this.toBase58();
1804
+ }
1802
1805
  /**
1803
1806
  * Return the byte array representation of the public key
1804
1807
  */
@@ -1918,7 +1921,7 @@ SOLANA_SCHEMA.set(PublicKey, {
1918
1921
  fields: [['_bn', 'u256']]
1919
1922
  }); // @ts-ignore
1920
1923
 
1921
- let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
1924
+ let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
1922
1925
  // This function and its dependents were sourced from:
1923
1926
  // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
1924
1927
 
@@ -2438,8 +2441,9 @@ class Transaction {
2438
2441
  }); // Sort. Prioritizing first by signer, then by writable
2439
2442
 
2440
2443
  accountMetas.sort(function (x, y) {
2444
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2441
2445
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2442
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2446
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2443
2447
  return checkSigner || checkWritable;
2444
2448
  }); // Cull duplicate account metas
2445
2449
 
@@ -2693,7 +2697,7 @@ class Transaction {
2693
2697
  _partialSign(message, ...signers) {
2694
2698
  const signData = message.serialize();
2695
2699
  signers.forEach(signer => {
2696
- const signature = nacl__default.sign.detached(signData, signer.secretKey);
2700
+ const signature = nacl.sign.detached(signData, signer.secretKey);
2697
2701
 
2698
2702
  this._addSignature(signer.publicKey, toBuffer(signature));
2699
2703
  });
@@ -2749,7 +2753,7 @@ class Transaction {
2749
2753
  return false;
2750
2754
  }
2751
2755
  } else {
2752
- if (!nacl__default.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
2756
+ if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
2753
2757
  return false;
2754
2758
  }
2755
2759
  }
@@ -2895,11 +2899,14 @@ class Transaction {
2895
2899
  }
2896
2900
 
2897
2901
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2902
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2903
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2898
2904
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2899
2905
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2900
2906
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2907
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2908
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2901
2909
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2902
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2903
2910
 
2904
2911
  /**
2905
2912
  * Sign, send and confirm a transaction.
@@ -2915,7 +2922,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
2915
2922
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2916
2923
  const sendOptions = options && {
2917
2924
  skipPreflight: options.skipPreflight,
2918
- preflightCommitment: options.preflightCommitment || options.commitment
2925
+ preflightCommitment: options.preflightCommitment || options.commitment,
2926
+ maxRetries: options.maxRetries
2919
2927
  };
2920
2928
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2921
2929
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -4824,16 +4832,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4824
4832
  let fetchWithMiddleware;
4825
4833
 
4826
4834
  if (fetchMiddleware) {
4827
- fetchWithMiddleware = (url, options) => {
4828
- return new Promise((resolve, reject) => {
4829
- fetchMiddleware(url, options, async (url, options) => {
4830
- try {
4831
- resolve(await fetch(url, options));
4832
- } catch (error) {
4833
- reject(error);
4834
- }
4835
- });
4835
+ fetchWithMiddleware = async (url, options) => {
4836
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4837
+ try {
4838
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4839
+ } catch (error) {
4840
+ reject(error);
4841
+ }
4836
4842
  });
4843
+ return await fetch(...modifiedFetchArgs);
4837
4844
  };
4838
4845
  }
4839
4846
 
@@ -5326,6 +5333,7 @@ const ParsedConfirmedTransactionResult = type({
5326
5333
  const TokenBalanceResult = type({
5327
5334
  accountIndex: number(),
5328
5335
  mint: string(),
5336
+ owner: optional(string()),
5329
5337
  uiTokenAmount: TokenAmountResult
5330
5338
  });
5331
5339
  /**
@@ -5366,8 +5374,31 @@ const ParsedConfirmedTransactionMetaResult = type({
5366
5374
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
5367
5375
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
5368
5376
  });
5377
+ /**
5378
+ * Expected JSON RPC response for the "getBlock" message
5379
+ */
5380
+
5381
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
5382
+ blockhash: string(),
5383
+ previousBlockhash: string(),
5384
+ parentSlot: number(),
5385
+ transactions: array(type({
5386
+ transaction: ConfirmedTransactionResult,
5387
+ meta: nullable(ConfirmedTransactionMetaResult)
5388
+ })),
5389
+ rewards: optional(array(type({
5390
+ pubkey: string(),
5391
+ lamports: number(),
5392
+ postBalance: nullable(number()),
5393
+ rewardType: nullable(string())
5394
+ }))),
5395
+ blockTime: nullable(number()),
5396
+ blockHeight: nullable(number())
5397
+ })));
5369
5398
  /**
5370
5399
  * Expected JSON RPC response for the "getConfirmedBlock" message
5400
+ *
5401
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
5371
5402
  */
5372
5403
 
5373
5404
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -5387,10 +5418,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
5387
5418
  blockTime: nullable(number())
5388
5419
  })));
5389
5420
  /**
5390
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
5421
+ * Expected JSON RPC response for the "getBlock" message
5391
5422
  */
5392
5423
 
5393
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5424
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5394
5425
  blockhash: string(),
5395
5426
  previousBlockhash: string(),
5396
5427
  parentSlot: number(),
@@ -5398,20 +5429,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5398
5429
  blockTime: nullable(number())
5399
5430
  })));
5400
5431
  /**
5401
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5432
+ * Expected JSON RPC response for the "getTransaction" message
5402
5433
  */
5403
5434
 
5404
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5435
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
5405
5436
  slot: number(),
5406
5437
  meta: ConfirmedTransactionMetaResult,
5407
5438
  blockTime: optional(nullable(number())),
5408
5439
  transaction: ConfirmedTransactionResult
5409
5440
  })));
5410
5441
  /**
5411
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5442
+ * Expected parsed JSON RPC response for the "getTransaction" message
5412
5443
  */
5413
5444
 
5414
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5445
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
5415
5446
  slot: number(),
5416
5447
  transaction: ParsedConfirmedTransactionResult,
5417
5448
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -5419,6 +5450,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5419
5450
  })));
5420
5451
  /**
5421
5452
  * Expected JSON RPC response for the "getRecentBlockhash" message
5453
+ *
5454
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
5422
5455
  */
5423
5456
 
5424
5457
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -5427,6 +5460,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
5427
5460
  lamportsPerSignature: number()
5428
5461
  })
5429
5462
  }));
5463
+ /**
5464
+ * Expected JSON RPC response for the "getLatestBlockhash" message
5465
+ */
5466
+
5467
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
5468
+ blockhash: string(),
5469
+ lastValidBlockHeight: number()
5470
+ }));
5430
5471
  const PerfSampleResult = type({
5431
5472
  slot: number(),
5432
5473
  numTransactions: number(),
@@ -5929,13 +5970,25 @@ class Connection {
5929
5970
  */
5930
5971
 
5931
5972
 
5932
- async getMultipleAccountsInfo(publicKeys, commitment) {
5973
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5933
5974
  const keys = publicKeys.map(key => key.toBase58());
5975
+ let commitment;
5976
+ let encoding = 'base64';
5934
5977
 
5935
- const args = this._buildArgs([keys], commitment, 'base64');
5978
+ if (configOrCommitment) {
5979
+ if (typeof configOrCommitment === 'string') {
5980
+ commitment = configOrCommitment;
5981
+ encoding = 'base64';
5982
+ } else {
5983
+ commitment = configOrCommitment.commitment;
5984
+ encoding = configOrCommitment.encoding || 'base64';
5985
+ }
5986
+ }
5987
+
5988
+ const args = this._buildArgs([keys], commitment, encoding);
5936
5989
 
5937
5990
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5938
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5991
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
5939
5992
 
5940
5993
  if ('error' in res) {
5941
5994
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -6359,6 +6412,8 @@ class Connection {
6359
6412
  /**
6360
6413
  * Fetch a recent blockhash from the cluster, return with context
6361
6414
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
6415
+ *
6416
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6362
6417
  */
6363
6418
 
6364
6419
 
@@ -6394,6 +6449,8 @@ class Connection {
6394
6449
  }
6395
6450
  /**
6396
6451
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
6452
+ *
6453
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
6397
6454
  */
6398
6455
 
6399
6456
 
@@ -6416,9 +6473,34 @@ class Connection {
6416
6473
  value: value !== null ? value.feeCalculator : null
6417
6474
  };
6418
6475
  }
6476
+ /**
6477
+ * Fetch the fee for a message from the cluster, return with context
6478
+ */
6479
+
6480
+
6481
+ async getFeeForMessage(message, commitment) {
6482
+ const wireMessage = message.serialize().toString('base64');
6483
+
6484
+ const args = this._buildArgs([wireMessage], commitment);
6485
+
6486
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
6487
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
6488
+
6489
+ if ('error' in res) {
6490
+ throw new Error('failed to get slot: ' + res.error.message);
6491
+ }
6492
+
6493
+ if (res.result === null) {
6494
+ throw new Error('invalid blockhash');
6495
+ }
6496
+
6497
+ return res.result;
6498
+ }
6419
6499
  /**
6420
6500
  * Fetch a recent blockhash from the cluster
6421
6501
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6502
+ *
6503
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6422
6504
  */
6423
6505
 
6424
6506
 
@@ -6430,6 +6512,38 @@ class Connection {
6430
6512
  throw new Error('failed to get recent blockhash: ' + e);
6431
6513
  }
6432
6514
  }
6515
+ /**
6516
+ * Fetch the latest blockhash from the cluster
6517
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6518
+ */
6519
+
6520
+
6521
+ async getLatestBlockhash(commitment) {
6522
+ try {
6523
+ const res = await this.getLatestBlockhashAndContext(commitment);
6524
+ return res.value;
6525
+ } catch (e) {
6526
+ throw new Error('failed to get recent blockhash: ' + e);
6527
+ }
6528
+ }
6529
+ /**
6530
+ * Fetch the latest blockhash from the cluster
6531
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6532
+ */
6533
+
6534
+
6535
+ async getLatestBlockhashAndContext(commitment) {
6536
+ const args = this._buildArgs([], commitment);
6537
+
6538
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6539
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6540
+
6541
+ if ('error' in res) {
6542
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6543
+ }
6544
+
6545
+ return res.result;
6546
+ }
6433
6547
  /**
6434
6548
  * Fetch the node version
6435
6549
  */
@@ -6468,8 +6582,8 @@ class Connection {
6468
6582
  async getBlock(slot, opts) {
6469
6583
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
6470
6584
 
6471
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6472
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6585
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6586
+ const res = create(unsafeRes, GetBlockRpcResult);
6473
6587
 
6474
6588
  if ('error' in res) {
6475
6589
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6493,18 +6607,18 @@ class Connection {
6493
6607
  };
6494
6608
  }
6495
6609
  /**
6496
- * Fetch a processed transaction from the cluster.
6610
+ * Fetch a confirmed or finalized transaction from the cluster.
6497
6611
  */
6498
6612
 
6499
6613
 
6500
6614
  async getTransaction(signature, opts) {
6501
6615
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6502
6616
 
6503
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6504
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
6617
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6618
+ const res = create(unsafeRes, GetTransactionRpcResult);
6505
6619
 
6506
6620
  if ('error' in res) {
6507
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6621
+ throw new Error('failed to get transaction: ' + res.error.message);
6508
6622
  }
6509
6623
 
6510
6624
  const result = res.result;
@@ -6515,6 +6629,49 @@ class Connection {
6515
6629
  }
6516
6630
  };
6517
6631
  }
6632
+ /**
6633
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6634
+ */
6635
+
6636
+
6637
+ async getParsedTransaction(signature, commitment) {
6638
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6639
+
6640
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6641
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6642
+
6643
+ if ('error' in res) {
6644
+ throw new Error('failed to get transaction: ' + res.error.message);
6645
+ }
6646
+
6647
+ return res.result;
6648
+ }
6649
+ /**
6650
+ * Fetch parsed transaction details for a batch of confirmed transactions
6651
+ */
6652
+
6653
+
6654
+ async getParsedTransactions(signatures, commitment) {
6655
+ const batch = signatures.map(signature => {
6656
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6657
+
6658
+ return {
6659
+ methodName: 'getTransaction',
6660
+ args
6661
+ };
6662
+ });
6663
+ const unsafeRes = await this._rpcBatchRequest(batch);
6664
+ const res = unsafeRes.map(unsafeRes => {
6665
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6666
+
6667
+ if ('error' in res) {
6668
+ throw new Error('failed to get transactions: ' + res.error.message);
6669
+ }
6670
+
6671
+ return res.result;
6672
+ });
6673
+ return res;
6674
+ }
6518
6675
  /**
6519
6676
  * Fetch a list of Transactions and transaction statuses from the cluster
6520
6677
  * for a confirmed block.
@@ -6524,18 +6681,39 @@ class Connection {
6524
6681
 
6525
6682
 
6526
6683
  async getConfirmedBlock(slot, commitment) {
6527
- const result = await this.getBlock(slot, {
6528
- commitment
6529
- });
6684
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6685
+
6686
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6687
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6688
+
6689
+ if ('error' in res) {
6690
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6691
+ }
6692
+
6693
+ const result = res.result;
6530
6694
 
6531
6695
  if (!result) {
6532
6696
  throw new Error('Confirmed block ' + slot + ' not found');
6533
6697
  }
6534
6698
 
6535
- return { ...result,
6699
+ const block = { ...result,
6536
6700
  transactions: result.transactions.map(({
6537
6701
  transaction,
6538
6702
  meta
6703
+ }) => {
6704
+ const message = new Message(transaction.message);
6705
+ return {
6706
+ meta,
6707
+ transaction: { ...transaction,
6708
+ message
6709
+ }
6710
+ };
6711
+ })
6712
+ };
6713
+ return { ...block,
6714
+ transactions: block.transactions.map(({
6715
+ transaction,
6716
+ meta
6539
6717
  }) => {
6540
6718
  return {
6541
6719
  meta,
@@ -6552,7 +6730,7 @@ class Connection {
6552
6730
  async getBlocks(startSlot, endSlot, commitment) {
6553
6731
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6554
6732
 
6555
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6733
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6556
6734
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6557
6735
 
6558
6736
  if ('error' in res) {
@@ -6561,8 +6739,36 @@ class Connection {
6561
6739
 
6562
6740
  return res.result;
6563
6741
  }
6742
+ /**
6743
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6744
+ */
6745
+
6746
+
6747
+ async getBlockSignatures(slot, commitment) {
6748
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6749
+ transactionDetails: 'signatures',
6750
+ rewards: false
6751
+ });
6752
+
6753
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6754
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6755
+
6756
+ if ('error' in res) {
6757
+ throw new Error('failed to get block: ' + res.error.message);
6758
+ }
6759
+
6760
+ const result = res.result;
6761
+
6762
+ if (!result) {
6763
+ throw new Error('Block ' + slot + ' not found');
6764
+ }
6765
+
6766
+ return result;
6767
+ }
6564
6768
  /**
6565
6769
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6770
+ *
6771
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6566
6772
  */
6567
6773
 
6568
6774
 
@@ -6573,7 +6779,7 @@ class Connection {
6573
6779
  });
6574
6780
 
6575
6781
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6576
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6782
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6577
6783
 
6578
6784
  if ('error' in res) {
6579
6785
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6589,24 +6795,33 @@ class Connection {
6589
6795
  }
6590
6796
  /**
6591
6797
  * Fetch a transaction details for a confirmed transaction
6798
+ *
6799
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6592
6800
  */
6593
6801
 
6594
6802
 
6595
6803
  async getConfirmedTransaction(signature, commitment) {
6596
- const result = await this.getTransaction(signature, {
6597
- commitment
6598
- });
6804
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6805
+
6806
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6807
+ const res = create(unsafeRes, GetTransactionRpcResult);
6808
+
6809
+ if ('error' in res) {
6810
+ throw new Error('failed to get transaction: ' + res.error.message);
6811
+ }
6812
+
6813
+ const result = res.result;
6599
6814
  if (!result) return result;
6600
- const {
6601
- message,
6602
- signatures
6603
- } = result.transaction;
6815
+ const message = new Message(result.transaction.message);
6816
+ const signatures = result.transaction.signatures;
6604
6817
  return { ...result,
6605
6818
  transaction: Transaction.populate(message, signatures)
6606
6819
  };
6607
6820
  }
6608
6821
  /**
6609
6822
  * Fetch parsed transaction details for a confirmed transaction
6823
+ *
6824
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6610
6825
  */
6611
6826
 
6612
6827
 
@@ -6614,7 +6829,7 @@ class Connection {
6614
6829
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6615
6830
 
6616
6831
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6617
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6832
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6618
6833
 
6619
6834
  if ('error' in res) {
6620
6835
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6624,6 +6839,8 @@ class Connection {
6624
6839
  }
6625
6840
  /**
6626
6841
  * Fetch parsed transaction details for a batch of confirmed transactions
6842
+ *
6843
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6627
6844
  */
6628
6845
 
6629
6846
 
@@ -6638,7 +6855,7 @@ class Connection {
6638
6855
  });
6639
6856
  const unsafeRes = await this._rpcBatchRequest(batch);
6640
6857
  const res = unsafeRes.map(unsafeRes => {
6641
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6858
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6642
6859
 
6643
6860
  if ('error' in res) {
6644
6861
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -7028,6 +7245,10 @@ class Connection {
7028
7245
  const skipPreflight = options && options.skipPreflight;
7029
7246
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
7030
7247
 
7248
+ if (options && options.maxRetries) {
7249
+ config.maxRetries = options.maxRetries;
7250
+ }
7251
+
7031
7252
  if (skipPreflight) {
7032
7253
  config.skipPreflight = skipPreflight;
7033
7254
  }
@@ -7182,7 +7403,14 @@ class Connection {
7182
7403
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
7183
7404
  this._rpcWebSocketIdleTimeout = null;
7184
7405
 
7185
- this._rpcWebSocket.close();
7406
+ try {
7407
+ this._rpcWebSocket.close();
7408
+ } catch (err) {
7409
+ // swallow error if socket has already been closed.
7410
+ if (err instanceof Error) {
7411
+ console.log(`Error when closing socket connection: ${err.message}`);
7412
+ }
7413
+ }
7186
7414
  }, 500);
7187
7415
  }
7188
7416
 
@@ -7896,7 +8124,7 @@ class Ed25519Program {
7896
8124
  try {
7897
8125
  const keypair = Keypair.fromSecretKey(privateKey);
7898
8126
  const publicKey = keypair.publicKey.toBytes();
7899
- const signature = nacl__default.sign.detached(message, keypair.secretKey);
8127
+ const signature = nacl.sign.detached(message, keypair.secretKey);
7900
8128
  return this.createInstructionWithPublicKey({
7901
8129
  publicKey,
7902
8130
  message,
@@ -8693,7 +8921,7 @@ class Secp256k1Program {
8693
8921
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
8694
8922
 
8695
8923
  try {
8696
- return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8924
+ return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8697
8925
  } catch (error) {
8698
8926
  throw new Error(`Error constructing Ethereum address: ${error}`);
8699
8927
  }
@@ -8791,7 +9019,7 @@ class Secp256k1Program {
8791
9019
  const privateKey = toBuffer(pkey);
8792
9020
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
8793
9021
 
8794
- const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
9022
+ const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
8795
9023
  const {
8796
9024
  signature,
8797
9025
  recid: recoveryId
@@ -8895,9 +9123,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8895
9123
  *
8896
9124
  * @internal
8897
9125
  */
8898
- const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8899
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('lastEpochCredits'), BufferLayout.nu64(), // epochCredits.length
8900
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits')]);
9126
+ const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
9127
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
9128
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
9129
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
8901
9130
 
8902
9131
  /**
8903
9132
  * VoteAccount class
@@ -8908,25 +9137,23 @@ class VoteAccount {
8908
9137
  */
8909
9138
  constructor(args) {
8910
9139
  this.nodePubkey = void 0;
8911
- this.authorizedVoterPubkey = void 0;
8912
- this.authorizedWithdrawerPubkey = void 0;
9140
+ this.authorizedWithdrawer = void 0;
8913
9141
  this.commission = void 0;
8914
- this.votes = void 0;
8915
9142
  this.rootSlot = void 0;
8916
- this.epoch = void 0;
8917
- this.credits = void 0;
8918
- this.lastEpochCredits = void 0;
9143
+ this.votes = void 0;
9144
+ this.authorizedVoters = void 0;
9145
+ this.priorVoters = void 0;
8919
9146
  this.epochCredits = void 0;
9147
+ this.lastTimestamp = void 0;
8920
9148
  this.nodePubkey = args.nodePubkey;
8921
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8922
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
9149
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8923
9150
  this.commission = args.commission;
8924
- this.votes = args.votes;
8925
9151
  this.rootSlot = args.rootSlot;
8926
- this.epoch = args.epoch;
8927
- this.credits = args.credits;
8928
- this.lastEpochCredits = args.lastEpochCredits;
9152
+ this.votes = args.votes;
9153
+ this.authorizedVoters = args.authorizedVoters;
9154
+ this.priorVoters = args.priorVoters;
8929
9155
  this.epochCredits = args.epochCredits;
9156
+ this.lastTimestamp = args.lastTimestamp;
8930
9157
  }
8931
9158
  /**
8932
9159
  * Deserialize VoteAccount from the account data.
@@ -8937,7 +9164,8 @@ class VoteAccount {
8937
9164
 
8938
9165
 
8939
9166
  static fromAccountData(buffer) {
8940
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
9167
+ const versionOffset = 4;
9168
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8941
9169
  let rootSlot = va.rootSlot;
8942
9170
 
8943
9171
  if (!va.rootSlotValid) {
@@ -8946,20 +9174,53 @@ class VoteAccount {
8946
9174
 
8947
9175
  return new VoteAccount({
8948
9176
  nodePubkey: new PublicKey(va.nodePubkey),
8949
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8950
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
9177
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8951
9178
  commission: va.commission,
8952
9179
  votes: va.votes,
8953
9180
  rootSlot,
8954
- epoch: va.epoch,
8955
- credits: va.credits,
8956
- lastEpochCredits: va.lastEpochCredits,
8957
- epochCredits: va.epochCredits
9181
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
9182
+ priorVoters: getPriorVoters(va.priorVoters),
9183
+ epochCredits: va.epochCredits,
9184
+ lastTimestamp: va.lastTimestamp
8958
9185
  });
8959
9186
  }
8960
9187
 
8961
9188
  }
8962
9189
 
9190
+ function parseAuthorizedVoter({
9191
+ epoch,
9192
+ authorizedVoter
9193
+ }) {
9194
+ return {
9195
+ epoch,
9196
+ authorizedVoter: new PublicKey(authorizedVoter)
9197
+ };
9198
+ }
9199
+
9200
+ function parsePriorVoters({
9201
+ authorizedPubkey,
9202
+ epochOfLastAuthorizedSwitch,
9203
+ targetEpoch
9204
+ }) {
9205
+ return {
9206
+ authorizedPubkey: new PublicKey(authorizedPubkey),
9207
+ epochOfLastAuthorizedSwitch,
9208
+ targetEpoch
9209
+ };
9210
+ }
9211
+
9212
+ function getPriorVoters({
9213
+ buf,
9214
+ idx,
9215
+ isEmpty
9216
+ }) {
9217
+ if (isEmpty) {
9218
+ return [];
9219
+ }
9220
+
9221
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
9222
+ }
9223
+
8963
9224
  /**
8964
9225
  * Send and confirm a raw transaction
8965
9226
  *
@@ -8989,12 +9250,12 @@ const endpoint = {
8989
9250
  http: {
8990
9251
  devnet: 'http://api.devnet.solana.com',
8991
9252
  testnet: 'http://api.testnet.solana.com',
8992
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
9253
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
8993
9254
  },
8994
9255
  https: {
8995
9256
  devnet: 'https://api.devnet.solana.com',
8996
9257
  testnet: 'https://api.testnet.solana.com',
8997
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
9258
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
8998
9259
  }
8999
9260
  };
9000
9261
 
@@ -9023,5 +9284,5 @@ function clusterApiUrl(cluster, tls) {
9023
9284
 
9024
9285
  const LAMPORTS_PER_SOL = 1000000000;
9025
9286
 
9026
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9287
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9027
9288
  //# sourceMappingURL=index.browser.esm.js.map