@layerzerolabs/lz-corekit-tron 3.0.14 → 3.0.16

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