@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.
package/lib/index.esm.js CHANGED
@@ -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';
@@ -12,7 +11,7 @@ import RpcClient from 'jayson/lib/client/browser';
12
11
  import http from 'http';
13
12
  import https from 'https';
14
13
  import secp256k1 from 'secp256k1';
15
- import { keccak_256 } from 'js-sha3';
14
+ import sha3 from 'js-sha3';
16
15
 
17
16
  const toBuffer = arr => {
18
17
  if (Buffer.isBuffer(arr)) {
@@ -1806,6 +1805,10 @@ class PublicKey extends Struct {
1806
1805
  toBase58() {
1807
1806
  return bs58.encode(this.toBytes());
1808
1807
  }
1808
+
1809
+ toJSON() {
1810
+ return this.toBase58();
1811
+ }
1809
1812
  /**
1810
1813
  * Return the byte array representation of the public key
1811
1814
  */
@@ -1925,7 +1928,7 @@ SOLANA_SCHEMA.set(PublicKey, {
1925
1928
  fields: [['_bn', 'u256']]
1926
1929
  }); // @ts-ignore
1927
1930
 
1928
- let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
1931
+ let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
1929
1932
  // This function and its dependents were sourced from:
1930
1933
  // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
1931
1934
 
@@ -2445,8 +2448,9 @@ class Transaction {
2445
2448
  }); // Sort. Prioritizing first by signer, then by writable
2446
2449
 
2447
2450
  accountMetas.sort(function (x, y) {
2451
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2448
2452
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2449
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2453
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2450
2454
  return checkSigner || checkWritable;
2451
2455
  }); // Cull duplicate account metas
2452
2456
 
@@ -2700,7 +2704,7 @@ class Transaction {
2700
2704
  _partialSign(message, ...signers) {
2701
2705
  const signData = message.serialize();
2702
2706
  signers.forEach(signer => {
2703
- const signature = nacl__default.sign.detached(signData, signer.secretKey);
2707
+ const signature = nacl.sign.detached(signData, signer.secretKey);
2704
2708
 
2705
2709
  this._addSignature(signer.publicKey, toBuffer(signature));
2706
2710
  });
@@ -2756,7 +2760,7 @@ class Transaction {
2756
2760
  return false;
2757
2761
  }
2758
2762
  } else {
2759
- if (!nacl__default.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
2763
+ if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
2760
2764
  return false;
2761
2765
  }
2762
2766
  }
@@ -2902,11 +2906,14 @@ class Transaction {
2902
2906
  }
2903
2907
 
2904
2908
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2909
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2910
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2905
2911
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2906
2912
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2907
2913
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2914
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2915
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2908
2916
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2909
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2910
2917
 
2911
2918
  /**
2912
2919
  * Sign, send and confirm a transaction.
@@ -2922,7 +2929,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
2922
2929
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2923
2930
  const sendOptions = options && {
2924
2931
  skipPreflight: options.skipPreflight,
2925
- preflightCommitment: options.preflightCommitment || options.commitment
2932
+ preflightCommitment: options.preflightCommitment || options.commitment,
2933
+ maxRetries: options.maxRetries
2926
2934
  };
2927
2935
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2928
2936
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -4324,16 +4332,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4324
4332
  let fetchWithMiddleware;
4325
4333
 
4326
4334
  if (fetchMiddleware) {
4327
- fetchWithMiddleware = (url, options) => {
4328
- return new Promise((resolve, reject) => {
4329
- fetchMiddleware(url, options, async (url, options) => {
4330
- try {
4331
- resolve(await fetch(url, options));
4332
- } catch (error) {
4333
- reject(error);
4334
- }
4335
- });
4335
+ fetchWithMiddleware = async (url, options) => {
4336
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4337
+ try {
4338
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4339
+ } catch (error) {
4340
+ reject(error);
4341
+ }
4336
4342
  });
4343
+ return await fetch(...modifiedFetchArgs);
4337
4344
  };
4338
4345
  }
4339
4346
 
@@ -4827,6 +4834,7 @@ const ParsedConfirmedTransactionResult = type({
4827
4834
  const TokenBalanceResult = type({
4828
4835
  accountIndex: number(),
4829
4836
  mint: string(),
4837
+ owner: optional(string()),
4830
4838
  uiTokenAmount: TokenAmountResult
4831
4839
  });
4832
4840
  /**
@@ -4867,8 +4875,31 @@ const ParsedConfirmedTransactionMetaResult = type({
4867
4875
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
4868
4876
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
4869
4877
  });
4878
+ /**
4879
+ * Expected JSON RPC response for the "getBlock" message
4880
+ */
4881
+
4882
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
4883
+ blockhash: string(),
4884
+ previousBlockhash: string(),
4885
+ parentSlot: number(),
4886
+ transactions: array(type({
4887
+ transaction: ConfirmedTransactionResult,
4888
+ meta: nullable(ConfirmedTransactionMetaResult)
4889
+ })),
4890
+ rewards: optional(array(type({
4891
+ pubkey: string(),
4892
+ lamports: number(),
4893
+ postBalance: nullable(number()),
4894
+ rewardType: nullable(string())
4895
+ }))),
4896
+ blockTime: nullable(number()),
4897
+ blockHeight: nullable(number())
4898
+ })));
4870
4899
  /**
4871
4900
  * Expected JSON RPC response for the "getConfirmedBlock" message
4901
+ *
4902
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
4872
4903
  */
4873
4904
 
4874
4905
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -4888,10 +4919,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
4888
4919
  blockTime: nullable(number())
4889
4920
  })));
4890
4921
  /**
4891
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
4922
+ * Expected JSON RPC response for the "getBlock" message
4892
4923
  */
4893
4924
 
4894
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4925
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4895
4926
  blockhash: string(),
4896
4927
  previousBlockhash: string(),
4897
4928
  parentSlot: number(),
@@ -4899,20 +4930,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4899
4930
  blockTime: nullable(number())
4900
4931
  })));
4901
4932
  /**
4902
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4933
+ * Expected JSON RPC response for the "getTransaction" message
4903
4934
  */
4904
4935
 
4905
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4936
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
4906
4937
  slot: number(),
4907
4938
  meta: ConfirmedTransactionMetaResult,
4908
4939
  blockTime: optional(nullable(number())),
4909
4940
  transaction: ConfirmedTransactionResult
4910
4941
  })));
4911
4942
  /**
4912
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4943
+ * Expected parsed JSON RPC response for the "getTransaction" message
4913
4944
  */
4914
4945
 
4915
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4946
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
4916
4947
  slot: number(),
4917
4948
  transaction: ParsedConfirmedTransactionResult,
4918
4949
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -4920,6 +4951,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4920
4951
  })));
4921
4952
  /**
4922
4953
  * Expected JSON RPC response for the "getRecentBlockhash" message
4954
+ *
4955
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
4923
4956
  */
4924
4957
 
4925
4958
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -4928,6 +4961,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
4928
4961
  lamportsPerSignature: number()
4929
4962
  })
4930
4963
  }));
4964
+ /**
4965
+ * Expected JSON RPC response for the "getLatestBlockhash" message
4966
+ */
4967
+
4968
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
4969
+ blockhash: string(),
4970
+ lastValidBlockHeight: number()
4971
+ }));
4931
4972
  const PerfSampleResult = type({
4932
4973
  slot: number(),
4933
4974
  numTransactions: number(),
@@ -5430,13 +5471,25 @@ class Connection {
5430
5471
  */
5431
5472
 
5432
5473
 
5433
- async getMultipleAccountsInfo(publicKeys, commitment) {
5474
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5434
5475
  const keys = publicKeys.map(key => key.toBase58());
5476
+ let commitment;
5477
+ let encoding = 'base64';
5435
5478
 
5436
- const args = this._buildArgs([keys], commitment, 'base64');
5479
+ if (configOrCommitment) {
5480
+ if (typeof configOrCommitment === 'string') {
5481
+ commitment = configOrCommitment;
5482
+ encoding = 'base64';
5483
+ } else {
5484
+ commitment = configOrCommitment.commitment;
5485
+ encoding = configOrCommitment.encoding || 'base64';
5486
+ }
5487
+ }
5488
+
5489
+ const args = this._buildArgs([keys], commitment, encoding);
5437
5490
 
5438
5491
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5439
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5492
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
5440
5493
 
5441
5494
  if ('error' in res) {
5442
5495
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -5860,6 +5913,8 @@ class Connection {
5860
5913
  /**
5861
5914
  * Fetch a recent blockhash from the cluster, return with context
5862
5915
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
5916
+ *
5917
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5863
5918
  */
5864
5919
 
5865
5920
 
@@ -5895,6 +5950,8 @@ class Connection {
5895
5950
  }
5896
5951
  /**
5897
5952
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
5953
+ *
5954
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
5898
5955
  */
5899
5956
 
5900
5957
 
@@ -5917,9 +5974,34 @@ class Connection {
5917
5974
  value: value !== null ? value.feeCalculator : null
5918
5975
  };
5919
5976
  }
5977
+ /**
5978
+ * Fetch the fee for a message from the cluster, return with context
5979
+ */
5980
+
5981
+
5982
+ async getFeeForMessage(message, commitment) {
5983
+ const wireMessage = message.serialize().toString('base64');
5984
+
5985
+ const args = this._buildArgs([wireMessage], commitment);
5986
+
5987
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
5988
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
5989
+
5990
+ if ('error' in res) {
5991
+ throw new Error('failed to get slot: ' + res.error.message);
5992
+ }
5993
+
5994
+ if (res.result === null) {
5995
+ throw new Error('invalid blockhash');
5996
+ }
5997
+
5998
+ return res.result;
5999
+ }
5920
6000
  /**
5921
6001
  * Fetch a recent blockhash from the cluster
5922
6002
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6003
+ *
6004
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5923
6005
  */
5924
6006
 
5925
6007
 
@@ -5931,6 +6013,38 @@ class Connection {
5931
6013
  throw new Error('failed to get recent blockhash: ' + e);
5932
6014
  }
5933
6015
  }
6016
+ /**
6017
+ * Fetch the latest blockhash from the cluster
6018
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6019
+ */
6020
+
6021
+
6022
+ async getLatestBlockhash(commitment) {
6023
+ try {
6024
+ const res = await this.getLatestBlockhashAndContext(commitment);
6025
+ return res.value;
6026
+ } catch (e) {
6027
+ throw new Error('failed to get recent blockhash: ' + e);
6028
+ }
6029
+ }
6030
+ /**
6031
+ * Fetch the latest blockhash from the cluster
6032
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6033
+ */
6034
+
6035
+
6036
+ async getLatestBlockhashAndContext(commitment) {
6037
+ const args = this._buildArgs([], commitment);
6038
+
6039
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6040
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6041
+
6042
+ if ('error' in res) {
6043
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6044
+ }
6045
+
6046
+ return res.result;
6047
+ }
5934
6048
  /**
5935
6049
  * Fetch the node version
5936
6050
  */
@@ -5969,8 +6083,8 @@ class Connection {
5969
6083
  async getBlock(slot, opts) {
5970
6084
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
5971
6085
 
5972
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
5973
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6086
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6087
+ const res = create(unsafeRes, GetBlockRpcResult);
5974
6088
 
5975
6089
  if ('error' in res) {
5976
6090
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -5994,18 +6108,18 @@ class Connection {
5994
6108
  };
5995
6109
  }
5996
6110
  /**
5997
- * Fetch a processed transaction from the cluster.
6111
+ * Fetch a confirmed or finalized transaction from the cluster.
5998
6112
  */
5999
6113
 
6000
6114
 
6001
6115
  async getTransaction(signature, opts) {
6002
6116
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6003
6117
 
6004
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6005
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
6118
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6119
+ const res = create(unsafeRes, GetTransactionRpcResult);
6006
6120
 
6007
6121
  if ('error' in res) {
6008
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6122
+ throw new Error('failed to get transaction: ' + res.error.message);
6009
6123
  }
6010
6124
 
6011
6125
  const result = res.result;
@@ -6016,6 +6130,49 @@ class Connection {
6016
6130
  }
6017
6131
  };
6018
6132
  }
6133
+ /**
6134
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6135
+ */
6136
+
6137
+
6138
+ async getParsedTransaction(signature, commitment) {
6139
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6140
+
6141
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6142
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6143
+
6144
+ if ('error' in res) {
6145
+ throw new Error('failed to get transaction: ' + res.error.message);
6146
+ }
6147
+
6148
+ return res.result;
6149
+ }
6150
+ /**
6151
+ * Fetch parsed transaction details for a batch of confirmed transactions
6152
+ */
6153
+
6154
+
6155
+ async getParsedTransactions(signatures, commitment) {
6156
+ const batch = signatures.map(signature => {
6157
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6158
+
6159
+ return {
6160
+ methodName: 'getTransaction',
6161
+ args
6162
+ };
6163
+ });
6164
+ const unsafeRes = await this._rpcBatchRequest(batch);
6165
+ const res = unsafeRes.map(unsafeRes => {
6166
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6167
+
6168
+ if ('error' in res) {
6169
+ throw new Error('failed to get transactions: ' + res.error.message);
6170
+ }
6171
+
6172
+ return res.result;
6173
+ });
6174
+ return res;
6175
+ }
6019
6176
  /**
6020
6177
  * Fetch a list of Transactions and transaction statuses from the cluster
6021
6178
  * for a confirmed block.
@@ -6025,18 +6182,39 @@ class Connection {
6025
6182
 
6026
6183
 
6027
6184
  async getConfirmedBlock(slot, commitment) {
6028
- const result = await this.getBlock(slot, {
6029
- commitment
6030
- });
6185
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6186
+
6187
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6188
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6189
+
6190
+ if ('error' in res) {
6191
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6192
+ }
6193
+
6194
+ const result = res.result;
6031
6195
 
6032
6196
  if (!result) {
6033
6197
  throw new Error('Confirmed block ' + slot + ' not found');
6034
6198
  }
6035
6199
 
6036
- return { ...result,
6200
+ const block = { ...result,
6037
6201
  transactions: result.transactions.map(({
6038
6202
  transaction,
6039
6203
  meta
6204
+ }) => {
6205
+ const message = new Message(transaction.message);
6206
+ return {
6207
+ meta,
6208
+ transaction: { ...transaction,
6209
+ message
6210
+ }
6211
+ };
6212
+ })
6213
+ };
6214
+ return { ...block,
6215
+ transactions: block.transactions.map(({
6216
+ transaction,
6217
+ meta
6040
6218
  }) => {
6041
6219
  return {
6042
6220
  meta,
@@ -6053,7 +6231,7 @@ class Connection {
6053
6231
  async getBlocks(startSlot, endSlot, commitment) {
6054
6232
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6055
6233
 
6056
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6234
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6057
6235
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6058
6236
 
6059
6237
  if ('error' in res) {
@@ -6062,8 +6240,36 @@ class Connection {
6062
6240
 
6063
6241
  return res.result;
6064
6242
  }
6243
+ /**
6244
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6245
+ */
6246
+
6247
+
6248
+ async getBlockSignatures(slot, commitment) {
6249
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6250
+ transactionDetails: 'signatures',
6251
+ rewards: false
6252
+ });
6253
+
6254
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6255
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6256
+
6257
+ if ('error' in res) {
6258
+ throw new Error('failed to get block: ' + res.error.message);
6259
+ }
6260
+
6261
+ const result = res.result;
6262
+
6263
+ if (!result) {
6264
+ throw new Error('Block ' + slot + ' not found');
6265
+ }
6266
+
6267
+ return result;
6268
+ }
6065
6269
  /**
6066
6270
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6271
+ *
6272
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6067
6273
  */
6068
6274
 
6069
6275
 
@@ -6074,7 +6280,7 @@ class Connection {
6074
6280
  });
6075
6281
 
6076
6282
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6077
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6283
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6078
6284
 
6079
6285
  if ('error' in res) {
6080
6286
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6090,24 +6296,33 @@ class Connection {
6090
6296
  }
6091
6297
  /**
6092
6298
  * Fetch a transaction details for a confirmed transaction
6299
+ *
6300
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6093
6301
  */
6094
6302
 
6095
6303
 
6096
6304
  async getConfirmedTransaction(signature, commitment) {
6097
- const result = await this.getTransaction(signature, {
6098
- commitment
6099
- });
6305
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6306
+
6307
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6308
+ const res = create(unsafeRes, GetTransactionRpcResult);
6309
+
6310
+ if ('error' in res) {
6311
+ throw new Error('failed to get transaction: ' + res.error.message);
6312
+ }
6313
+
6314
+ const result = res.result;
6100
6315
  if (!result) return result;
6101
- const {
6102
- message,
6103
- signatures
6104
- } = result.transaction;
6316
+ const message = new Message(result.transaction.message);
6317
+ const signatures = result.transaction.signatures;
6105
6318
  return { ...result,
6106
6319
  transaction: Transaction.populate(message, signatures)
6107
6320
  };
6108
6321
  }
6109
6322
  /**
6110
6323
  * Fetch parsed transaction details for a confirmed transaction
6324
+ *
6325
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6111
6326
  */
6112
6327
 
6113
6328
 
@@ -6115,7 +6330,7 @@ class Connection {
6115
6330
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6116
6331
 
6117
6332
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6118
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6333
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6119
6334
 
6120
6335
  if ('error' in res) {
6121
6336
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6125,6 +6340,8 @@ class Connection {
6125
6340
  }
6126
6341
  /**
6127
6342
  * Fetch parsed transaction details for a batch of confirmed transactions
6343
+ *
6344
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6128
6345
  */
6129
6346
 
6130
6347
 
@@ -6139,7 +6356,7 @@ class Connection {
6139
6356
  });
6140
6357
  const unsafeRes = await this._rpcBatchRequest(batch);
6141
6358
  const res = unsafeRes.map(unsafeRes => {
6142
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6359
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6143
6360
 
6144
6361
  if ('error' in res) {
6145
6362
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -6529,6 +6746,10 @@ class Connection {
6529
6746
  const skipPreflight = options && options.skipPreflight;
6530
6747
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
6531
6748
 
6749
+ if (options && options.maxRetries) {
6750
+ config.maxRetries = options.maxRetries;
6751
+ }
6752
+
6532
6753
  if (skipPreflight) {
6533
6754
  config.skipPreflight = skipPreflight;
6534
6755
  }
@@ -6683,7 +6904,14 @@ class Connection {
6683
6904
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
6684
6905
  this._rpcWebSocketIdleTimeout = null;
6685
6906
 
6686
- this._rpcWebSocket.close();
6907
+ try {
6908
+ this._rpcWebSocket.close();
6909
+ } catch (err) {
6910
+ // swallow error if socket has already been closed.
6911
+ if (err instanceof Error) {
6912
+ console.log(`Error when closing socket connection: ${err.message}`);
6913
+ }
6914
+ }
6687
6915
  }, 500);
6688
6916
  }
6689
6917
 
@@ -7397,7 +7625,7 @@ class Ed25519Program {
7397
7625
  try {
7398
7626
  const keypair = Keypair.fromSecretKey(privateKey);
7399
7627
  const publicKey = keypair.publicKey.toBytes();
7400
- const signature = nacl__default.sign.detached(message, keypair.secretKey);
7628
+ const signature = nacl.sign.detached(message, keypair.secretKey);
7401
7629
  return this.createInstructionWithPublicKey({
7402
7630
  publicKey,
7403
7631
  message,
@@ -8194,7 +8422,7 @@ class Secp256k1Program {
8194
8422
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
8195
8423
 
8196
8424
  try {
8197
- return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8425
+ return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8198
8426
  } catch (error) {
8199
8427
  throw new Error(`Error constructing Ethereum address: ${error}`);
8200
8428
  }
@@ -8292,7 +8520,7 @@ class Secp256k1Program {
8292
8520
  const privateKey = toBuffer(pkey);
8293
8521
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
8294
8522
 
8295
- const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
8523
+ const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
8296
8524
  const {
8297
8525
  signature,
8298
8526
  recid: recoveryId
@@ -8396,9 +8624,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8396
8624
  *
8397
8625
  * @internal
8398
8626
  */
8399
- const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8400
- 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
8401
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits')]);
8627
+ const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8628
+ 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
8629
+ 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
8630
+ 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')]);
8402
8631
 
8403
8632
  /**
8404
8633
  * VoteAccount class
@@ -8409,25 +8638,23 @@ class VoteAccount {
8409
8638
  */
8410
8639
  constructor(args) {
8411
8640
  this.nodePubkey = void 0;
8412
- this.authorizedVoterPubkey = void 0;
8413
- this.authorizedWithdrawerPubkey = void 0;
8641
+ this.authorizedWithdrawer = void 0;
8414
8642
  this.commission = void 0;
8415
- this.votes = void 0;
8416
8643
  this.rootSlot = void 0;
8417
- this.epoch = void 0;
8418
- this.credits = void 0;
8419
- this.lastEpochCredits = void 0;
8644
+ this.votes = void 0;
8645
+ this.authorizedVoters = void 0;
8646
+ this.priorVoters = void 0;
8420
8647
  this.epochCredits = void 0;
8648
+ this.lastTimestamp = void 0;
8421
8649
  this.nodePubkey = args.nodePubkey;
8422
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8423
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
8650
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8424
8651
  this.commission = args.commission;
8425
- this.votes = args.votes;
8426
8652
  this.rootSlot = args.rootSlot;
8427
- this.epoch = args.epoch;
8428
- this.credits = args.credits;
8429
- this.lastEpochCredits = args.lastEpochCredits;
8653
+ this.votes = args.votes;
8654
+ this.authorizedVoters = args.authorizedVoters;
8655
+ this.priorVoters = args.priorVoters;
8430
8656
  this.epochCredits = args.epochCredits;
8657
+ this.lastTimestamp = args.lastTimestamp;
8431
8658
  }
8432
8659
  /**
8433
8660
  * Deserialize VoteAccount from the account data.
@@ -8438,7 +8665,8 @@ class VoteAccount {
8438
8665
 
8439
8666
 
8440
8667
  static fromAccountData(buffer) {
8441
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
8668
+ const versionOffset = 4;
8669
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8442
8670
  let rootSlot = va.rootSlot;
8443
8671
 
8444
8672
  if (!va.rootSlotValid) {
@@ -8447,20 +8675,53 @@ class VoteAccount {
8447
8675
 
8448
8676
  return new VoteAccount({
8449
8677
  nodePubkey: new PublicKey(va.nodePubkey),
8450
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8451
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
8678
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8452
8679
  commission: va.commission,
8453
8680
  votes: va.votes,
8454
8681
  rootSlot,
8455
- epoch: va.epoch,
8456
- credits: va.credits,
8457
- lastEpochCredits: va.lastEpochCredits,
8458
- epochCredits: va.epochCredits
8682
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
8683
+ priorVoters: getPriorVoters(va.priorVoters),
8684
+ epochCredits: va.epochCredits,
8685
+ lastTimestamp: va.lastTimestamp
8459
8686
  });
8460
8687
  }
8461
8688
 
8462
8689
  }
8463
8690
 
8691
+ function parseAuthorizedVoter({
8692
+ epoch,
8693
+ authorizedVoter
8694
+ }) {
8695
+ return {
8696
+ epoch,
8697
+ authorizedVoter: new PublicKey(authorizedVoter)
8698
+ };
8699
+ }
8700
+
8701
+ function parsePriorVoters({
8702
+ authorizedPubkey,
8703
+ epochOfLastAuthorizedSwitch,
8704
+ targetEpoch
8705
+ }) {
8706
+ return {
8707
+ authorizedPubkey: new PublicKey(authorizedPubkey),
8708
+ epochOfLastAuthorizedSwitch,
8709
+ targetEpoch
8710
+ };
8711
+ }
8712
+
8713
+ function getPriorVoters({
8714
+ buf,
8715
+ idx,
8716
+ isEmpty
8717
+ }) {
8718
+ if (isEmpty) {
8719
+ return [];
8720
+ }
8721
+
8722
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8723
+ }
8724
+
8464
8725
  /**
8465
8726
  * Send and confirm a raw transaction
8466
8727
  *
@@ -8490,12 +8751,12 @@ const endpoint = {
8490
8751
  http: {
8491
8752
  devnet: 'http://api.devnet.solana.com',
8492
8753
  testnet: 'http://api.testnet.solana.com',
8493
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
8754
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
8494
8755
  },
8495
8756
  https: {
8496
8757
  devnet: 'https://api.devnet.solana.com',
8497
8758
  testnet: 'https://api.testnet.solana.com',
8498
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
8759
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
8499
8760
  }
8500
8761
  };
8501
8762
 
@@ -8524,5 +8785,5 @@ function clusterApiUrl(cluster, tls) {
8524
8785
 
8525
8786
  const LAMPORTS_PER_SOL = 1000000000;
8526
8787
 
8527
- 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 };
8788
+ 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 };
8528
8789
  //# sourceMappingURL=index.esm.js.map