@layerzerolabs/lz-corekit-tron 3.0.15 → 3.0.17

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/dist/index.cjs CHANGED
@@ -1,18 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  var ethers = require('ethers');
4
- var mem = require('mem');
5
4
  var TronWeb5 = require('tronweb');
6
5
  var lzCore = require('@layerzerolabs/lz-core');
7
- var tronUtilities = require('@layerzerolabs/tron-utilities');
8
6
  var lzUtilities = require('@layerzerolabs/lz-utilities');
7
+ var tronUtilities = require('@layerzerolabs/tron-utilities');
9
8
 
10
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
10
 
12
- var mem__default = /*#__PURE__*/_interopDefault(mem);
13
11
  var TronWeb5__default = /*#__PURE__*/_interopDefault(TronWeb5);
14
12
 
15
- // src/providers/tron.ts
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __decorateClass = (decorators, target, key, kind) => {
16
+ var result = __getOwnPropDesc(target, key) ;
17
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
18
+ if (decorator = decorators[i])
19
+ result = (decorator(target, key, result) ) || result;
20
+ if (result) __defProp(target, key, result);
21
+ return result;
22
+ };
16
23
  function ensureJsonRpcUrlPostfix(url) {
17
24
  const value = url.trim().replace(/\/*$/, "");
18
25
  if (!value.endsWith("/jsonrpc")) {
@@ -39,37 +46,13 @@ function toValidHash(txHash) {
39
46
  // src/providers/tron.ts
40
47
  var TronProvider = class {
41
48
  /**
49
+ * Creates an instance of TronProvider.
42
50
  *
43
- * @param url RPC endpoint of the Tron full node, e.g. 'https://api.trongrid.io'
44
- * @param apiKey
51
+ * @param {string} url - RPC endpoint of the Tron full node, e.g. 'https://api.trongrid.io'
52
+ * @param {string} [apiKey] - The API key for accessing the Tron full node (optional).
45
53
  */
46
54
  constructor(url, apiKey) {
47
55
  this.url = url;
48
- this.buildTronWebFrom = mem__default.default(
49
- (provider) => {
50
- if (provider instanceof ethers.ethers.providers.JsonRpcProvider) {
51
- const { url } = provider.connection;
52
- const apiKey = provider.connection.headers?.["TRON-PRO-API-KEY"];
53
- return new TronWeb5__default.default({
54
- privateKey: void 0,
55
- fullHost: tronUtilities.StrategyFactory.get(url).asREST(url),
56
- headers: { ...apiKey !== void 0 ? { "TRON-PRO-API-KEY": apiKey } : {} }
57
- });
58
- }
59
- throw new Error(`The nativeSigner is not supported.`);
60
- },
61
- {
62
- cacheKey: (arguments_) => {
63
- const provider = arguments_[0];
64
- if (provider instanceof ethers.ethers.providers.JsonRpcProvider) {
65
- const { url } = provider.connection;
66
- const apiKey = provider.connection.headers?.["TRON-PRO-API-KEY"];
67
- return JSON.stringify({ url, apiKey });
68
- }
69
- return JSON.stringify(provider);
70
- }
71
- }
72
- );
73
56
  this.nativeProvider = new ethers.ethers.providers.StaticJsonRpcProvider({
74
57
  url: tronUtilities.StrategyFactory.get(url).asJSONRPC(url),
75
58
  headers: {
@@ -78,6 +61,14 @@ var TronProvider = class {
78
61
  }
79
62
  });
80
63
  }
64
+ /**
65
+ * Creates an instance of TronProvider from the given source.
66
+ *
67
+ * @param {string | TronWeb} source - The source to create the provider from.
68
+ * @param {string} [apiKey] - The API key for accessing the Tron node (optional).
69
+ * @returns {TronProvider} The created TronProvider instance.
70
+ * @throws {Error} If the parameters are invalid.
71
+ */
81
72
  static from(source, apiKey) {
82
73
  if (typeof source === "string") {
83
74
  return new this(source, apiKey);
@@ -89,65 +80,170 @@ var TronProvider = class {
89
80
  }
90
81
  }
91
82
  /**
92
- * Returns the native provider
83
+ * Returns the native provider.
84
+ *
85
+ * @returns {unknown} The native provider.
93
86
  */
94
87
  get native() {
95
88
  return this.nativeProvider;
96
89
  }
90
+ buildTronWebFrom(provider) {
91
+ if (provider instanceof ethers.ethers.providers.JsonRpcProvider) {
92
+ const { url } = provider.connection;
93
+ const apiKey = provider.connection.headers?.["TRON-PRO-API-KEY"];
94
+ return new TronWeb5__default.default({
95
+ privateKey: void 0,
96
+ fullHost: tronUtilities.StrategyFactory.get(url).asREST(url),
97
+ headers: { ...apiKey !== void 0 ? { "TRON-PRO-API-KEY": apiKey } : {} }
98
+ });
99
+ }
100
+ throw new Error(`The nativeSigner is not supported.`);
101
+ }
102
+ /**
103
+ * Gets the balance of the specified address.
104
+ *
105
+ * @param {string} address - The address to get the balance of.
106
+ * @returns {Promise<string>} A promise that resolves to the balance of the address.
107
+ */
97
108
  async getBalance(address) {
98
109
  return this.nativeProvider.getBalance(toEtherFormat(address)).then((balance) => balance.toString());
99
110
  }
111
+ /**
112
+ * Gets the block specified by blockTag.
113
+ *
114
+ * @param {BlockTag} blockTag - The block tag to specify the block.
115
+ * @returns {Promise<Block>} A promise that resolves to the block.
116
+ */
100
117
  async getBlock(blockTag) {
101
118
  const response = await this.nativeProvider.getBlock(blockTag);
102
119
  return lzCore.Block.from(response);
103
120
  }
121
+ /**
122
+ * Gets the block with transactions specified by blockTag.
123
+ *
124
+ * @param {BlockTag} blockTag - The block tag to specify the block.
125
+ * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
126
+ */
104
127
  async getBlockWithTransactions(blockTag) {
105
128
  const response = await this.nativeProvider.getBlockWithTransactions(blockTag);
106
129
  return lzCore.BlockWithTransactions.from(response);
107
130
  }
131
+ /**
132
+ * Gets the current block number.
133
+ *
134
+ * @returns {Promise<number>} A promise that resolves to the current block number.
135
+ */
108
136
  async getBlockNumber() {
109
137
  return this.nativeProvider.getBlockNumber();
110
138
  }
139
+ /**
140
+ * Gets the UNIX timestamp for the block identified by blockTag.
141
+ *
142
+ * @param {BlockTag} blockTag - The block tag to specify the block.
143
+ * @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block.
144
+ */
111
145
  async getBlockTimestamp(blockTag) {
112
146
  return this.nativeProvider.getBlock(blockTag).then((block) => block.timestamp);
113
147
  }
148
+ /**
149
+ * Gets the current slot number for commitment, not suitable for Tron.
150
+ *
151
+ * @param {Finality} [finality] - The commitment level (optional).
152
+ * @returns {Promise<number>} A promise that resolves to the current slot number.
153
+ * @throws {Error} Method not implemented.
154
+ */
114
155
  async getSlot(_finality) {
115
156
  await Promise.resolve();
116
157
  throw new Error("Method not implemented.");
117
158
  }
159
+ /**
160
+ * Gets information about a transaction.
161
+ *
162
+ * @param {string} txHash - The hash of the transaction.
163
+ * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
164
+ */
118
165
  async getTransaction(txHash) {
119
166
  const response = await this.nativeProvider.getTransaction(toValidHash(txHash));
120
167
  return lzCore.TransactionResponse.from(response);
121
168
  }
169
+ /**
170
+ * Gets the receipt of a transaction.
171
+ *
172
+ * @param {string} txHash - The hash of the transaction.
173
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
174
+ */
122
175
  async getTransactionReceipt(txHash) {
123
176
  const response = await this.nativeProvider.getTransactionReceipt(toValidHash(txHash));
124
177
  return lzCore.TransactionReceipt.from(response);
125
178
  }
179
+ /**
180
+ * Gets the number of transactions sent from the specified address.
181
+ *
182
+ * @param {string | Promise<string>} _addressOrName - The address to get the number of transactions from.
183
+ * @param {BlockTag | Promise<BlockTag>} [_blockTag] - The block tag to get the number of transactions from (optional).
184
+ * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
185
+ * @throws {Error} Method not supported in Tron.
186
+ */
126
187
  async getTransactionCount(_addressOrName, _blockTag) {
127
188
  await Promise.resolve();
128
189
  throw new Error("Method not supported in Tron.");
129
190
  }
191
+ /**
192
+ * Sends a signed transaction to the blockchain.
193
+ *
194
+ * @param {SignedTransaction} transaction - The signed transaction to send.
195
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
196
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
197
+ */
130
198
  async sendTransaction(transaction, _sendOptions) {
131
199
  const stx = transaction.signed;
132
200
  const client = this.buildTronWebFrom(this.nativeProvider);
133
201
  const response = await tronUtilities.sendTronTransaction(stx, client);
134
202
  return lzCore.TransactionPending.from(response);
135
203
  }
204
+ /**
205
+ * Confirms a pending transaction.
206
+ *
207
+ * @param {TransactionPending} pending - The pending transaction to confirm.
208
+ * @param {object} [opts] - Optional parameters for the confirmation.
209
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
210
+ */
136
211
  async confirmTransaction(pending, _opts) {
137
212
  const nativePending = pending.pending;
138
213
  const response = await nativePending.wait();
139
214
  return lzCore.TransactionReceipt.from(response);
140
215
  }
216
+ /**
217
+ * Sends a signed transaction and waits for confirmation.
218
+ *
219
+ * @param {SignedTransaction} transaction - The signed transaction to send.
220
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
221
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
222
+ */
141
223
  async sendAndConfirm(transaction, opts) {
142
224
  const pending = await this.sendTransaction(transaction, opts);
143
225
  return this.confirmTransaction(pending, opts);
144
226
  }
145
227
  };
228
+ __decorateClass([
229
+ lzUtilities.Memoizee({
230
+ normalizer: (args) => {
231
+ const provider = args[0];
232
+ if (provider instanceof ethers.ethers.providers.JsonRpcProvider) {
233
+ const { url } = provider.connection;
234
+ const apiKey = provider.connection.headers?.["TRON-PRO-API-KEY"];
235
+ return JSON.stringify({ url, apiKey });
236
+ }
237
+ return JSON.stringify(provider);
238
+ }
239
+ })
240
+ ], TronProvider.prototype, "buildTronWebFrom");
146
241
  var TronWebProvider = class {
147
242
  /**
148
- * Create a new TronProvider
149
- * @param url RPC endpoint of the Tron full node, e.g. 'https://api.trongrid.io'
150
- * @param apiKey
243
+ * Creates a new TronWebProvider.
244
+ *
245
+ * @param {string} url - The RPC endpoint of the Tron full node, e.g., 'https://api.trongrid.io'.
246
+ * @param {string} [apiKey] - The API key for accessing the Tron full node (optional).
151
247
  */
152
248
  constructor(url, apiKey) {
153
249
  this.url = url;
@@ -160,6 +256,14 @@ var TronWebProvider = class {
160
256
  }
161
257
  });
162
258
  }
259
+ /**
260
+ * Creates an instance of TronWebProvider from the given source.
261
+ *
262
+ * @param {string} source - The source to create the provider from.
263
+ * @param {string} [apiKey] - The API key for accessing the Tron node (optional).
264
+ * @returns {TronWebProvider} The created TronWebProvider instance.
265
+ * @throws {Error} If the parameters are invalid.
266
+ */
163
267
  static from(source, apiKey) {
164
268
  if (typeof source === "string") {
165
269
  return new this(source, apiKey);
@@ -167,20 +271,48 @@ var TronWebProvider = class {
167
271
  throw new Error("Invalid parameters");
168
272
  }
169
273
  }
274
+ /**
275
+ * Gets the native TronWeb provider instance.
276
+ *
277
+ * @returns {TronWeb} The native TronWeb provider instance.
278
+ */
170
279
  get native() {
171
280
  return this.nativeProvider;
172
281
  }
282
+ /**
283
+ * Gets the balance of the specified address.
284
+ *
285
+ * @param {string} address - The address to get the balance of.
286
+ * @returns {Promise<string>} A promise that resolves to the balance of the address.
287
+ */
173
288
  async getBalance(address) {
174
289
  return this.nativeProvider.trx.getBalance(address).then((balance) => balance.toString());
175
290
  }
291
+ /**
292
+ * Gets the block specified by blockTag.
293
+ *
294
+ * @param {BlockTag} blockTag - The block tag to specify the block.
295
+ * @returns {Promise<Block>} A promise that resolves to the block.
296
+ */
176
297
  async getBlock(blockTag) {
177
298
  const response = await this.nativeProvider.trx.getBlock(blockTag);
178
299
  return lzCore.Block.from(response);
179
300
  }
301
+ /**
302
+ * Gets the block with transactions specified by blockTag.
303
+ *
304
+ * @param {BlockTag} blockTag - The block tag to specify the block.
305
+ * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
306
+ */
180
307
  async getBlockWithTransactions(blockTag) {
181
308
  const response = await this.nativeProvider.trx.getBlock(blockTag);
182
309
  return lzCore.BlockWithTransactions.from(response);
183
310
  }
311
+ /**
312
+ * Gets the current block number.
313
+ *
314
+ * @returns {Promise<number>} A promise that resolves to the current block number.
315
+ */
184
316
  async getBlockNumber() {
185
317
  return this.nativeProvider.trx.getBlock("latest").then((block) => {
186
318
  if (block.block_header.raw_data.number === void 0) {
@@ -189,6 +321,12 @@ var TronWebProvider = class {
189
321
  return block.block_header.raw_data.number;
190
322
  });
191
323
  }
324
+ /**
325
+ * Gets the UNIX timestamp for the block identified by blockTag.
326
+ *
327
+ * @param {BlockTag} blockTag - The block tag to specify the block.
328
+ * @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block.
329
+ */
192
330
  async getBlockTimestamp(blockTag) {
193
331
  return this.nativeProvider.trx.getBlock(blockTag).then((block) => {
194
332
  if (block.block_header.raw_data.timestamp === void 0) {
@@ -197,22 +335,56 @@ var TronWebProvider = class {
197
335
  return block.block_header.raw_data.timestamp;
198
336
  });
199
337
  }
338
+ /**
339
+ * Gets the current slot number for commitment, not suitable for Tron.
340
+ *
341
+ * @param {Finality} [finality] - The commitment level (optional).
342
+ * @returns {Promise<number>} A promise that resolves to the current slot number.
343
+ * @throws {Error} Method not implemented.
344
+ */
200
345
  async getSlot(_finality) {
201
346
  await Promise.resolve();
202
347
  throw new Error("Method not implemented.");
203
348
  }
349
+ /**
350
+ * Gets information about a transaction.
351
+ *
352
+ * @param {string} txHash - The hash of the transaction.
353
+ * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
354
+ */
204
355
  async getTransaction(txHash) {
205
356
  const response = await this.nativeProvider.trx.getTransaction(txHash);
206
357
  return lzCore.TransactionResponse.from(response);
207
358
  }
359
+ /**
360
+ * Gets the receipt of a transaction.
361
+ *
362
+ * @param {string} txHash - The hash of the transaction.
363
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
364
+ */
208
365
  async getTransactionReceipt(txHash) {
209
366
  const response = await this.nativeProvider.trx.getTransactionInfo(txHash);
210
367
  return lzCore.TransactionReceipt.from(response);
211
368
  }
369
+ /**
370
+ * Gets the number of transactions sent from the specified address.
371
+ *
372
+ * @param {string | Promise<string>} _addressOrName - The address to get the number of transactions from.
373
+ * @param {BlockTag | Promise<BlockTag>} [_blockTag] - The block tag to get the number of transactions from (optional).
374
+ * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
375
+ * @throws {Error} Method not supported in Tron.
376
+ */
212
377
  async getTransactionCount(_addressOrName, _blockTag) {
213
378
  await Promise.resolve();
214
379
  throw new Error("Method not supported in Tron.");
215
380
  }
381
+ /**
382
+ * Sends a signed transaction to the blockchain.
383
+ *
384
+ * @param {SignedTransaction} transaction - The signed transaction to send.
385
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
386
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
387
+ */
216
388
  async sendTransaction(transaction, sendOptions) {
217
389
  const stx = transaction.signed;
218
390
  const response = await this.nativeProvider.trx.sendRawTransaction(stx, sendOptions);
@@ -228,6 +400,13 @@ var TronWebProvider = class {
228
400
  }
229
401
  return lzCore.TransactionPending.from(response);
230
402
  }
403
+ /**
404
+ * Confirms a pending transaction.
405
+ *
406
+ * @param {TransactionPending} pending - The pending transaction to confirm.
407
+ * @param {object} [opts] - Optional parameters for the confirmation.
408
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
409
+ */
231
410
  async confirmTransaction(pending, opts) {
232
411
  const nativePending = pending.pending;
233
412
  const txHash = nativePending.txid;
@@ -259,15 +438,35 @@ var TronWebProvider = class {
259
438
  }
260
439
  throw new Error(`Transaction not confirmed, txHash: ${txHash}`);
261
440
  }
441
+ /**
442
+ * Sends a signed transaction and waits for confirmation.
443
+ *
444
+ * @param {SignedTransaction} transaction - The signed transaction to send.
445
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
446
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
447
+ */
262
448
  async sendAndConfirm(transaction, opts) {
263
449
  const pending = await this.sendTransaction(transaction, opts);
264
450
  return this.confirmTransaction(pending, opts);
265
451
  }
266
452
  };
267
453
  var _TronSigner = class _TronSigner {
454
+ /**
455
+ * Creates an instance of TronSigner.
456
+ *
457
+ * @param {ethers.Signer} signer - The Ethers signer to use.
458
+ */
268
459
  constructor(signer) {
269
460
  this.nativeSigner = signer;
270
461
  }
462
+ /**
463
+ * Creates an instance of TronSigner from the given source.
464
+ *
465
+ * @param {ethers.Signer | TronWeb | string} source - The source to create the TronSigner from.
466
+ * @param {string} [path] - The derivation path (optional).
467
+ * @returns {Signer} The created TronSigner instance.
468
+ * @throws {Error} If the parameters are invalid.
469
+ */
271
470
  static from(source, path) {
272
471
  if (source instanceof ethers.ethers.Signer) {
273
472
  return new this(source);
@@ -286,9 +485,22 @@ var _TronSigner = class _TronSigner {
286
485
  throw new Error("Invalid parameters");
287
486
  }
288
487
  }
488
+ /**
489
+ * Gets the native signer instance.
490
+ *
491
+ * @returns {unknown} The native signer instance.
492
+ */
289
493
  get native() {
290
494
  return this.nativeSigner;
291
495
  }
496
+ /**
497
+ * Connects the signer to a provider.
498
+ * IMPORTANT: native provider must be an instance of ethers.providers.JsonRpcProvider.
499
+ *
500
+ * @param {Provider} provider - The provider to connect to.
501
+ * @returns {Signer} The connected signer.
502
+ * @throws {Error} If the provider is not an instance of JsonRpcProvider.
503
+ */
292
504
  connect(provider) {
293
505
  if (!(provider.native instanceof ethers.ethers.providers.JsonRpcProvider)) {
294
506
  throw new Error("Only JsonRpcProvider is supported.");
@@ -297,6 +509,14 @@ var _TronSigner = class _TronSigner {
297
509
  ethers.ethers.utils.defineReadOnly(this, "nativeSigner", signer);
298
510
  return this;
299
511
  }
512
+ /**
513
+ * Builds a TronWeb instance from the given signer.
514
+ * IMPORTANT: signer must be an instance of ethers.Wallet.
515
+ *
516
+ * @param {ethers.Signer} signer - The signer to build the TronWeb instance from.
517
+ * @returns {TronWeb} The built TronWeb instance.
518
+ * @throws {Error} If the signer is not supported.
519
+ */
300
520
  static buildTronWebFrom(signer) {
301
521
  if (signer instanceof ethers.ethers.Wallet) {
302
522
  if (signer.provider instanceof ethers.ethers.providers.JsonRpcProvider) {
@@ -306,15 +526,41 @@ var _TronSigner = class _TronSigner {
306
526
  }
307
527
  throw new Error(`The nativeSigner is not supported.`);
308
528
  }
529
+ static createTronWeb(url, privateKey, apiKey) {
530
+ return new TronWeb5__default.default({
531
+ privateKey: lzUtilities.trim0x(privateKey),
532
+ fullHost: removeJsonRpcUrlPostfix(url),
533
+ headers: { ...apiKey !== void 0 ? { "TRON-PRO-API-KEY": apiKey } : {} }
534
+ });
535
+ }
536
+ /**
537
+ * Gets the address of the signer.
538
+ *
539
+ * @returns {Promise<string>} A promise that resolves to the address of the signer.
540
+ */
309
541
  async getAddress() {
310
542
  return this.nativeSigner.getAddress();
311
543
  }
544
+ /**
545
+ * Sends a signed transaction and waits for confirmation.
546
+ *
547
+ * @param {SignedTransaction} transaction - The signed transaction to send.
548
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
549
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
550
+ */
312
551
  async sendAndConfirm(transaction, _opts) {
313
552
  const pending = (await this.sendTransaction(transaction)).pending;
314
553
  await pending.wait();
315
554
  const response = await this.nativeSigner.provider?.getTransactionReceipt(toValidHash(pending.txId));
316
555
  return lzCore.TransactionReceipt.from(response);
317
556
  }
557
+ /**
558
+ * Signs a transaction.
559
+ *
560
+ * @param {TransactionRequest} transaction - The transaction request to sign.
561
+ * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
562
+ * @throws {Error} If the transaction is invalid.
563
+ */
318
564
  async signTransaction(transaction) {
319
565
  const tx = transaction.request;
320
566
  if (tx.data === void 0 || tx.to === void 0) {
@@ -335,41 +581,66 @@ var _TronSigner = class _TronSigner {
335
581
  );
336
582
  return lzCore.SignedTransaction.from(response);
337
583
  }
584
+ /**
585
+ * Sends a signed transaction.
586
+ *
587
+ * @param {SignedTransaction} transaction - The signed transaction to send.
588
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
589
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
590
+ */
338
591
  async sendTransaction(transaction, _sendOptions) {
339
592
  const stx = transaction.signed;
340
593
  const tronWeb = _TronSigner.buildTronWebFrom(this.nativeSigner);
341
594
  const response = await tronUtilities.sendTronTransaction(stx, tronWeb);
342
595
  return lzCore.TransactionPending.from(response);
343
596
  }
597
+ /**
598
+ * Signs a buffer (e.g., a message hash) using the native Tron signer.
599
+ *
600
+ * @param {Uint8Array} buffer - The buffer to sign.
601
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
602
+ */
344
603
  async signBuffer(buffer) {
345
604
  const signedMessage = await this.nativeSigner.signMessage(buffer);
346
605
  return ethers.ethers.utils.arrayify(signedMessage);
347
606
  }
607
+ /**
608
+ * Validates a transaction.
609
+ *
610
+ * @param {ethers.PopulatedTransaction} transaction - The transaction to validate.
611
+ * @returns {boolean} True if the transaction is valid, false otherwise.
612
+ * @throws {Error} If the transaction is invalid.
613
+ */
348
614
  static validateTransaction(transaction) {
349
615
  if (transaction.data === void 0 || transaction.to === void 0) {
350
616
  throw new Error("Invalid transaction, missing data or to");
351
617
  }
352
618
  return true;
353
619
  }
354
- async buildTransaction(buildTxRequest) {
355
- return Promise.reject(new Error("Method not implemented."));
356
- }
357
620
  };
358
- _TronSigner.createTronWeb = mem__default.default(
359
- (url, privateKey, apiKey) => {
360
- return new TronWeb5__default.default({
361
- privateKey: lzUtilities.trim0x(privateKey),
362
- fullHost: removeJsonRpcUrlPostfix(url),
363
- headers: { ...apiKey !== void 0 ? { "TRON-PRO-API-KEY": apiKey } : {} }
364
- });
365
- },
366
- { cacheKey: (arguments_) => JSON.stringify(arguments_) }
367
- );
621
+ __decorateClass([
622
+ lzUtilities.Memoizee({
623
+ normalizer: (args) => JSON.stringify(args)
624
+ })
625
+ ], _TronSigner, "createTronWeb");
368
626
  var TronSigner = _TronSigner;
369
627
  var TronWebSigner = class _TronWebSigner {
628
+ /**
629
+ * Creates an instance of TronWebSigner.
630
+ *
631
+ * @param {TronWeb} signer - The TronWeb signer to use.
632
+ */
370
633
  constructor(signer) {
371
634
  this.nativeSigner = signer;
372
635
  }
636
+ /**
637
+ * Creates an instance of TronWebSigner from the given source.
638
+ *
639
+ * @param {TronWeb | string} source - The source to create the TronWebSigner from.
640
+ * @param {string} [path] - The derivation path (optional).
641
+ * @returns {Signer} The created TronWebSigner instance.
642
+ * @throws {Error} If the parameters are invalid.
643
+ */
373
644
  static from(source, path) {
374
645
  const fullHost = "https://api.trongrid.io";
375
646
  if (source instanceof TronWeb5__default.default) {
@@ -384,9 +655,20 @@ var TronWebSigner = class _TronWebSigner {
384
655
  throw new Error("Invalid parameters");
385
656
  }
386
657
  }
658
+ /**
659
+ * Gets the native TronWeb signer instance.
660
+ *
661
+ * @returns {unknown} The native TronWeb signer instance.
662
+ */
387
663
  get native() {
388
664
  return this.nativeSigner;
389
665
  }
666
+ /**
667
+ * Connects the signer to a provider.
668
+ *
669
+ * @param {Provider} provider - The provider to connect to.
670
+ * @returns {Signer} The connected signer.
671
+ */
390
672
  connect(provider) {
391
673
  const nativeProvider = provider.native;
392
674
  const { fullNode, solidityNode, eventServer } = nativeProvider.currentProviders();
@@ -395,6 +677,11 @@ var TronWebSigner = class _TronWebSigner {
395
677
  this.nativeSigner.setEventServer(eventServer);
396
678
  return this;
397
679
  }
680
+ /**
681
+ * Gets the address of the signer.
682
+ *
683
+ * @returns {Promise<string>} A promise that resolves to the address of the signer.
684
+ */
398
685
  async getAddress() {
399
686
  if (typeof this.nativeSigner.defaultAddress.hex !== "string") {
400
687
  throw new Error("Invalid address");
@@ -402,11 +689,25 @@ var TronWebSigner = class _TronWebSigner {
402
689
  const retval = this.nativeSigner.defaultAddress.hex.replace(/^41/, "0x");
403
690
  return Promise.resolve(retval);
404
691
  }
692
+ /**
693
+ * Sends a signed transaction and waits for confirmation.
694
+ *
695
+ * @param {SignedTransaction} transaction - The signed transaction to send.
696
+ * @param {object} [sendOptions] - Optional parameters for sending and confirming the transaction.
697
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
698
+ */
405
699
  async sendAndConfirm(transaction, _sendOptions) {
406
700
  const pending = (await this.sendTransaction(transaction)).pending;
407
701
  const response = await pending.wait();
408
702
  return lzCore.TransactionReceipt.from(response);
409
703
  }
704
+ /**
705
+ * Signs a transaction.
706
+ *
707
+ * @param {TransactionRequest} transaction - The transaction request to sign.
708
+ * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
709
+ * @throws {Error} If the transaction is invalid.
710
+ */
410
711
  async signTransaction(transaction) {
411
712
  const tx = transaction.request;
412
713
  if (tx.data === void 0 || tx.to === void 0) {
@@ -426,6 +727,13 @@ var TronWebSigner = class _TronWebSigner {
426
727
  );
427
728
  return lzCore.SignedTransaction.from(response);
428
729
  }
730
+ /**
731
+ * Sends a signed transaction.
732
+ *
733
+ * @param {SignedTransaction} transaction - The signed transaction to send.
734
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
735
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
736
+ */
429
737
  async sendTransaction(transaction, _sendOptions) {
430
738
  const stx = transaction.signed;
431
739
  const response = await tronUtilities.sendTronTransaction(stx, this.nativeSigner);
@@ -438,8 +746,10 @@ var TronWebSigner = class _TronWebSigner {
438
746
  * the message length is 32 bytes, the signature will be the same as the ethereum signature.
439
747
  * you can find the signString function here:
440
748
  * https://github.com/tronprotocol/tronweb/blob/master/src/lib/trx.js
441
- * @param buffer
442
- * @returns
749
+ *
750
+ * @param {Uint8Array} buffer - The buffer to sign.
751
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
752
+ * @throws {Error} If the private key is invalid.
443
753
  */
444
754
  async signBuffer(buffer) {
445
755
  if (typeof this.nativeSigner.defaultPrivateKey !== "string") {
@@ -453,20 +763,24 @@ var TronWebSigner = class _TronWebSigner {
453
763
  const retval = ethers.ethers.utils.arrayify(signedMessage);
454
764
  return Promise.resolve(retval);
455
765
  }
766
+ /**
767
+ * Validates a transaction.
768
+ *
769
+ * @param {ethers.PopulatedTransaction} transaction - The transaction to validate.
770
+ * @returns {boolean} True if the transaction is valid, false otherwise.
771
+ * @throws {Error} If the transaction is invalid.
772
+ */
456
773
  static validateTransaction(transaction) {
457
774
  if (transaction.data === void 0 || transaction.to === void 0) {
458
775
  throw new Error("Invalid transaction, missing data or to");
459
776
  }
460
777
  return true;
461
778
  }
462
- async buildTransaction(buildTxRequest) {
463
- return Promise.reject(new Error("Method not implemented."));
464
- }
465
779
  };
466
780
 
467
781
  exports.TronProvider = TronProvider;
468
782
  exports.TronSigner = TronSigner;
469
783
  exports.TronWebProvider = TronWebProvider;
470
784
  exports.TronWebSigner = TronWebSigner;
471
- //# sourceMappingURL=out.js.map
785
+ //# sourceMappingURL=index.cjs.map
472
786
  //# sourceMappingURL=index.cjs.map