@sun-protocol/tron-mcp-server 1.0.0-beta.1

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -0
  3. package/bin/cli.js +51 -0
  4. package/build/core/chains.d.ts +17 -0
  5. package/build/core/chains.js +55 -0
  6. package/build/core/chains.js.map +1 -0
  7. package/build/core/prompts.d.ts +16 -0
  8. package/build/core/prompts.js +268 -0
  9. package/build/core/prompts.js.map +1 -0
  10. package/build/core/resources.d.ts +14 -0
  11. package/build/core/resources.js +42 -0
  12. package/build/core/resources.js.map +1 -0
  13. package/build/core/services/address.d.ts +8 -0
  14. package/build/core/services/address.js +52 -0
  15. package/build/core/services/address.js.map +1 -0
  16. package/build/core/services/balance.d.ts +26 -0
  17. package/build/core/services/balance.js +60 -0
  18. package/build/core/services/balance.js.map +1 -0
  19. package/build/core/services/blocks.d.ts +16 -0
  20. package/build/core/services/blocks.js +46 -0
  21. package/build/core/services/blocks.js.map +1 -0
  22. package/build/core/services/clients.d.ts +9 -0
  23. package/build/core/services/clients.js +46 -0
  24. package/build/core/services/clients.js.map +1 -0
  25. package/build/core/services/contracts.d.ts +50 -0
  26. package/build/core/services/contracts.js +225 -0
  27. package/build/core/services/contracts.js.map +1 -0
  28. package/build/core/services/index.d.ts +119 -0
  29. package/build/core/services/index.js +39 -0
  30. package/build/core/services/index.js.map +1 -0
  31. package/build/core/services/multicall-abi.d.ts +55 -0
  32. package/build/core/services/multicall-abi.js +61 -0
  33. package/build/core/services/multicall-abi.js.map +1 -0
  34. package/build/core/services/tokens.d.ts +22 -0
  35. package/build/core/services/tokens.js +68 -0
  36. package/build/core/services/tokens.js.map +1 -0
  37. package/build/core/services/transactions.d.ts +16 -0
  38. package/build/core/services/transactions.js +42 -0
  39. package/build/core/services/transactions.js.map +1 -0
  40. package/build/core/services/transfer.d.ts +24 -0
  41. package/build/core/services/transfer.js +70 -0
  42. package/build/core/services/transfer.js.map +1 -0
  43. package/build/core/services/utils.d.ts +13 -0
  44. package/build/core/services/utils.js +39 -0
  45. package/build/core/services/utils.js.map +1 -0
  46. package/build/core/services/wallet.d.ts +33 -0
  47. package/build/core/services/wallet.js +113 -0
  48. package/build/core/services/wallet.js.map +1 -0
  49. package/build/core/tools.d.ts +16 -0
  50. package/build/core/tools.js +792 -0
  51. package/build/core/tools.js.map +1 -0
  52. package/build/index.d.ts +1 -0
  53. package/build/index.js +20 -0
  54. package/build/index.js.map +1 -0
  55. package/build/server/http-server.d.ts +1 -0
  56. package/build/server/http-server.js +197 -0
  57. package/build/server/http-server.js.map +1 -0
  58. package/build/server/server.d.ts +3 -0
  59. package/build/server/server.js +46 -0
  60. package/build/server/server.js.map +1 -0
  61. package/package.json +90 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../src/core/services/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,YAAoB,EACpB,UAAkB,SAAS;IAQ3B,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QAE3D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC9D,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE;YAC9B,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;YAChC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;YAClC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IA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;YACL,IAAI;YACJ,MAAM;YACN,QAAQ;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,YAAoB,EACpB,OAAe,EACf,UAAkB,SAAS;IAE3B,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAClE,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ type Transaction = any;
2
+ type TransactionInfo = any;
3
+ /**
4
+ * Get transaction details by transaction hash
5
+ */
6
+ export declare function getTransaction(txHash: string, network?: string): Promise<Transaction>;
7
+ /**
8
+ * Get transaction info (receipt equivalent)
9
+ */
10
+ export declare function getTransactionInfo(txHash: string, network?: string): Promise<TransactionInfo>;
11
+ export declare const getTransactionReceipt: typeof getTransactionInfo;
12
+ /**
13
+ * Wait for a transaction to be confirmed
14
+ */
15
+ export declare function waitForTransaction(txHash: string, network?: string): Promise<TransactionInfo>;
16
+ export {};
@@ -0,0 +1,42 @@
1
+ import { getTronWeb } from "./clients.js";
2
+ /**
3
+ * Get transaction details by transaction hash
4
+ */
5
+ export async function getTransaction(txHash, network = "mainnet") {
6
+ const tronWeb = getTronWeb(network);
7
+ const tx = await tronWeb.trx.getTransaction(txHash);
8
+ return tx;
9
+ }
10
+ /**
11
+ * Get transaction info (receipt equivalent)
12
+ */
13
+ export async function getTransactionInfo(txHash, network = "mainnet") {
14
+ const tronWeb = getTronWeb(network);
15
+ const info = await tronWeb.trx.getTransactionInfo(txHash);
16
+ return info;
17
+ }
18
+ // Alias for tools expecting 'receipt'
19
+ export const getTransactionReceipt = getTransactionInfo;
20
+ /**
21
+ * Wait for a transaction to be confirmed
22
+ */
23
+ export async function waitForTransaction(txHash, network = "mainnet") {
24
+ const tronWeb = getTronWeb(network);
25
+ // Poll for transaction info
26
+ const maxAttempts = 30;
27
+ const interval = 2000; // 2 seconds
28
+ for (let i = 0; i < maxAttempts; i++) {
29
+ try {
30
+ const info = await tronWeb.trx.getTransactionInfo(txHash);
31
+ if (info && info.id) {
32
+ return info;
33
+ }
34
+ }
35
+ catch (_e) {
36
+ // Ignore error and retry
37
+ }
38
+ await new Promise((resolve) => setTimeout(resolve, interval));
39
+ }
40
+ throw new Error(`Transaction ${txHash} not confirmed after ${maxAttempts * interval}ms`);
41
+ }
42
+ //# sourceMappingURL=transactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../../src/core/services/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc,EAAE,OAAO,GAAG,SAAS;IACtE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sCAAsC;AACtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEpC,4BAA4B;IAC5B,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,YAAY;IAEnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAC1D,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,yBAAyB;QAC3B,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,wBAAwB,WAAW,GAAG,QAAQ,IAAI,CAAC,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Transfer TRX to an address
3
+ */
4
+ export declare function transferTRX(privateKey: string, to: string, amount: string, // Amount in TRX (not Sun)
5
+ network?: string): Promise<any>;
6
+ /**
7
+ * Transfer TRC20 tokens
8
+ */
9
+ export declare function transferTRC20(tokenAddress: string, to: string, amount: string, // Raw amount (accounting for decimals)
10
+ privateKey: string, network?: string): Promise<{
11
+ txHash: any;
12
+ amount: {
13
+ raw: string;
14
+ formatted: string;
15
+ };
16
+ token: {
17
+ symbol: any;
18
+ decimals: number;
19
+ };
20
+ }>;
21
+ /**
22
+ * Approve token spending
23
+ */
24
+ export declare function approveTRC20(tokenAddress: string, spenderAddress: string, amount: string, privateKey: string, network?: string): Promise<any>;
@@ -0,0 +1,70 @@
1
+ import { getWallet } from "./clients.js";
2
+ import { utils } from "./utils.js";
3
+ /**
4
+ * Transfer TRX to an address
5
+ */
6
+ export async function transferTRX(privateKey, to, amount, // Amount in TRX (not Sun)
7
+ network = "mainnet") {
8
+ const tronWeb = getWallet(privateKey, network);
9
+ // Convert TRX to Sun
10
+ const amountSun = utils.toSun(amount);
11
+ const tx = await tronWeb.trx.sendTransaction(to, amountSun);
12
+ // If result is just true/false (older TronWeb), handle it?
13
+ // Newer TronWeb returns transaction object usually.
14
+ if (tx.result === true && tx.transaction) {
15
+ return tx.transaction.txID;
16
+ }
17
+ // If it returns the tx object directly
18
+ if (tx.txID) {
19
+ return tx.txID;
20
+ }
21
+ throw new Error(`Transaction failed: ${JSON.stringify(tx)}`);
22
+ }
23
+ /**
24
+ * Transfer TRC20 tokens
25
+ */
26
+ export async function transferTRC20(tokenAddress, to, amount, // Raw amount (accounting for decimals)
27
+ privateKey, network = "mainnet") {
28
+ const tronWeb = getWallet(privateKey, network);
29
+ try {
30
+ const contract = await tronWeb.contract().at(tokenAddress);
31
+ // TRC20 transfer(to, amount)
32
+ const txId = await contract.methods.transfer(to, amount).send();
33
+ // Fetch token info for return
34
+ const symbol = await contract.methods.symbol().call();
35
+ const decimals = await contract.methods.decimals().call();
36
+ // Basic formatting for return
37
+ const decimalsNum = Number(decimals);
38
+ const divisor = BigInt(10) ** BigInt(decimalsNum);
39
+ const formatted = (Number(BigInt(amount)) / Number(divisor)).toString();
40
+ return {
41
+ txHash: txId,
42
+ amount: {
43
+ raw: amount,
44
+ formatted: formatted,
45
+ },
46
+ token: {
47
+ symbol: symbol,
48
+ decimals: decimalsNum,
49
+ },
50
+ };
51
+ }
52
+ catch (error) {
53
+ throw new Error(`Failed to transfer TRC20: ${error.message}`);
54
+ }
55
+ }
56
+ /**
57
+ * Approve token spending
58
+ */
59
+ export async function approveTRC20(tokenAddress, spenderAddress, amount, privateKey, network = "mainnet") {
60
+ const tronWeb = getWallet(privateKey, network);
61
+ try {
62
+ const contract = await tronWeb.contract().at(tokenAddress);
63
+ const txId = await contract.methods.approve(spenderAddress, amount).send();
64
+ return txId;
65
+ }
66
+ catch (error) {
67
+ throw new Error(`Failed to approve TRC20: ${error.message}`);
68
+ }
69
+ }
70
+ //# sourceMappingURL=transfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../src/core/services/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,EAAU,EACV,MAAc,EAAE,0BAA0B;AAC1C,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE/C,qBAAqB;IACrB,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAa,CAAC,CAAC;IAE7C,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,EAAE,SAAgB,CAAC,CAAC;IAEnE,2DAA2D;IAC3D,oDAAoD;IACpD,IAAK,EAAU,CAAC,MAAM,KAAK,IAAI,IAAK,EAAU,CAAC,WAAW,EAAE,CAAC;QAC3D,OAAQ,EAAU,CAAC,WAAW,CAAC,IAAI,CAAC;IACtC,CAAC;IACD,uCAAuC;IACvC,IAAK,EAAU,CAAC,IA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;gBACL,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,WAAW;aACtB;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,YAAoB,EACpB,cAAsB,EACtB,MAAc,EACd,UAAkB,EAClB,OAAO,GAAG,SAAS;IAEnB,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE/C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QAC3D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Utility functions for formatting and parsing values
3
+ */
4
+ export declare const utils: {
5
+ toSun: (trx: number | string) => string;
6
+ fromSun: (sun: number | string | bigint) => string;
7
+ formatBigInt: (value: bigint | number) => string;
8
+ formatJson: (obj: unknown) => string;
9
+ formatNumber: (value: number | string) => string;
10
+ hexToNumber: (hex: string) => number;
11
+ numberToHex: (num: number) => string;
12
+ isAddress: (address: string) => boolean;
13
+ };
@@ -0,0 +1,39 @@
1
+ // Fix TypeScript error: TronWeb.fromSun returns string, but we can pass string to it (TronWeb types might be outdated or strict)
2
+ import { TronWeb } from "tronweb";
3
+ // Note: TronWeb handles most of these conversions internally or via utility methods.
4
+ // We are wrapping them here for consistent API usage across the application.
5
+ /**
6
+ * Utility functions for formatting and parsing values
7
+ */
8
+ export const utils = {
9
+ // Convert Tron (ether equivalent) to Sun (wei equivalent)
10
+ // 1 TRX = 1,000,000 SUN
11
+ toSun: (trx) => {
12
+ return TronWeb.toSun(trx).toString();
13
+ },
14
+ // Convert Sun to Tron
15
+ fromSun: (sun) => {
16
+ return TronWeb.fromSun(sun.toString()).toString();
17
+ },
18
+ // Format a bigint/number to a string
19
+ formatBigInt: (value) => value.toString(),
20
+ // Format an object to JSON with bigint handling
21
+ formatJson: (obj) => JSON.stringify(obj, (_, value) => (typeof value === "bigint" ? value.toString() : value), 2),
22
+ // Format a number with commas
23
+ formatNumber: (value) => {
24
+ return Number(value).toLocaleString();
25
+ },
26
+ // Convert a hex string to a number
27
+ hexToNumber: (hex) => {
28
+ return parseInt(hex, 16);
29
+ },
30
+ // Convert a number to a hex string
31
+ numberToHex: (num) => {
32
+ return "0x" + num.toString(16);
33
+ },
34
+ // Tron specific utils
35
+ isAddress: (address) => {
36
+ return TronWeb.isAddress(address);
37
+ },
38
+ };
39
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/services/utils.ts"],"names":[],"mappings":"AAAA,iIAAiI;AAEjI,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qFAAqF;AACrF,6EAA6E;AAE7E;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,0DAA0D;IAC1D,wBAAwB;IACxB,KAAK,EAAE,CAAC,GAAoB,EAAU,EAAE;QACtC,OAAO,OAAO,CAAC,KAAK,CAAC,GAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9C,CAAC;IAED,sBAAsB;IACtB,OAAO,EAAE,CAAC,GAA6B,EAAU,EAAE;QACjD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,CAAC;IAED,qCAAqC;IACrC,YAAY,EAAE,CAAC,KAAsB,EAAU,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE;IAElE,gDAAgD;IAChD,UAAU,EAAE,CAAC,GAAY,EAAU,EAAE,CACnC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE9F,8BAA8B;IAC9B,YAAY,EAAE,CAAC,KAAsB,EAAU,EAAE;QAC/C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED,mCAAmC;IACnC,WAAW,EAAE,CAAC,GAAW,EAAU,EAAE;QACnC,OAAO,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,mCAAmC;IACnC,WAAW,EAAE,CAAC,GAAW,EAAU,EAAE;QACnC,OAAO,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,sBAAsB;IACtB,SAAS,EAAE,CAAC,OAAe,EAAW,EAAE;QACtC,OAAO,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Get the configured account from environment (private key or mnemonic)
3
+ *
4
+ * Configuration options:
5
+ * - TRON_PRIVATE_KEY: Hex private key (with or without 0x prefix)
6
+ * - TRON_MNEMONIC: BIP-39 mnemonic phrase (12 or 24 words)
7
+ * - TRON_ACCOUNT_INDEX: Optional account index for HD wallet derivation (default: 0)
8
+ */
9
+ export interface ConfiguredWallet {
10
+ privateKey: string;
11
+ address: string;
12
+ }
13
+ export declare const getConfiguredWallet: () => ConfiguredWallet;
14
+ /**
15
+ * Helper to get the configured private key (for services that need it)
16
+ */
17
+ export declare const getConfiguredPrivateKey: () => string;
18
+ /**
19
+ * Helper to get wallet address
20
+ */
21
+ export declare const getWalletAddressFromKey: () => string;
22
+ /**
23
+ * Sign an arbitrary message using the configured wallet
24
+ * @param message The message to sign (can be a string or hex data)
25
+ * @returns The signature as a hex string
26
+ */
27
+ export declare const signMessage: (message: string) => Promise<string>;
28
+ /**
29
+ * Sign typed data (EIP-712 equivalent in Tron / TRON-712)
30
+ * Note: Tron support for EIP-712 is limited/specific.
31
+ * This implementation assumes standard EIP-712 compatible signing if supported by TronWeb version.
32
+ */
33
+ export declare const signTypedData: (domain: object, types: object, value: object) => Promise<string>;
@@ -0,0 +1,113 @@
1
+ import { TronWeb } from "tronweb";
2
+ import * as bip39 from "@scure/bip39";
3
+ import { wordlist } from "@scure/bip39/wordlists/english.js";
4
+ import { HDKey } from "@scure/bip32";
5
+ export const getConfiguredWallet = () => {
6
+ const privateKey = process.env.TRON_PRIVATE_KEY;
7
+ const mnemonic = process.env.TRON_MNEMONIC;
8
+ const accountIndexStr = process.env.TRON_ACCOUNT_INDEX || "0";
9
+ const accountIndex = parseInt(accountIndexStr, 10);
10
+ // Validate account index
11
+ if (isNaN(accountIndex) || accountIndex < 0 || !Number.isInteger(accountIndex)) {
12
+ throw new Error(`Invalid TRON_ACCOUNT_INDEX: "${accountIndexStr}". Must be a non-negative integer.`);
13
+ }
14
+ if (privateKey) {
15
+ // Use private key if provided
16
+ // TronWeb handles private keys without 0x prefix usually.
17
+ // If it has 0x, we strip it to be safe for TronWeb usage.
18
+ const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
19
+ const address = TronWeb.address.fromPrivateKey(cleanKey);
20
+ if (!address) {
21
+ throw new Error("Invalid private key provided in TRON_PRIVATE_KEY");
22
+ }
23
+ return {
24
+ privateKey: cleanKey,
25
+ address: address,
26
+ };
27
+ }
28
+ else if (mnemonic) {
29
+ // Derive from mnemonic
30
+ if (!bip39.validateMnemonic(mnemonic, wordlist)) {
31
+ throw new Error("Invalid mnemonic provided in TRON_MNEMONIC");
32
+ }
33
+ // Tron derivation path: m/44'/195'/0'/0/index
34
+ const seed = bip39.mnemonicToSeedSync(mnemonic);
35
+ const hdKey = HDKey.fromMasterSeed(seed);
36
+ const child = hdKey.derive(`m/44'/195'/0'/0/${accountIndex}`);
37
+ if (!child.privateKey) {
38
+ throw new Error("Failed to derive private key from mnemonic");
39
+ }
40
+ const privateKeyHex = Buffer.from(child.privateKey).toString("hex");
41
+ const address = TronWeb.address.fromPrivateKey(privateKeyHex);
42
+ return {
43
+ privateKey: privateKeyHex,
44
+ address: address, // TronWeb returns false or string
45
+ };
46
+ }
47
+ else {
48
+ throw new Error("Neither TRON_PRIVATE_KEY nor TRON_MNEMONIC environment variable is set. " +
49
+ "Configure one of them to enable write operations.\n" +
50
+ "- TRON_PRIVATE_KEY: Your private key in hex format\n" +
51
+ "- TRON_MNEMONIC: Your 12 or 24 word mnemonic phrase\n" +
52
+ "- TRON_ACCOUNT_INDEX: (Optional) Account index for HD wallet (default: 0)");
53
+ }
54
+ };
55
+ /**
56
+ * Helper to get the configured private key (for services that need it)
57
+ */
58
+ export const getConfiguredPrivateKey = () => {
59
+ const wallet = getConfiguredWallet();
60
+ return wallet.privateKey;
61
+ };
62
+ /**
63
+ * Helper to get wallet address
64
+ */
65
+ export const getWalletAddressFromKey = () => {
66
+ const wallet = getConfiguredWallet();
67
+ return wallet.address;
68
+ };
69
+ /**
70
+ * Sign an arbitrary message using the configured wallet
71
+ * @param message The message to sign (can be a string or hex data)
72
+ * @returns The signature as a hex string
73
+ */
74
+ export const signMessage = async (message) => {
75
+ const { privateKey } = getConfiguredWallet();
76
+ const apiKey = process.env.TRONGRID_API_KEY;
77
+ // Create a temporary TronWeb instance for signing (network doesn't matter for pure signing usually, but good practice)
78
+ // Actually we can use TronWeb.Trx.signString equivalent if available statically, or instance.
79
+ const tronWeb = new TronWeb({
80
+ fullHost: "https://api.trongrid.io", // Dummy host for signing
81
+ privateKey: privateKey,
82
+ headers: apiKey ? { "TRON-PRO-API-KEY": apiKey } : undefined,
83
+ });
84
+ // Sign the message
85
+ // Note: TronWeb signing usually prefixes with standard Tron message prefix
86
+ const signature = await tronWeb.trx.sign(message);
87
+ return signature;
88
+ };
89
+ /**
90
+ * Sign typed data (EIP-712 equivalent in Tron / TRON-712)
91
+ * Note: Tron support for EIP-712 is limited/specific.
92
+ * This implementation assumes standard EIP-712 compatible signing if supported by TronWeb version.
93
+ */
94
+ export const signTypedData = async (domain, types, value) => {
95
+ const { privateKey } = getConfiguredWallet();
96
+ const apiKey = process.env.TRONGRID_API_KEY;
97
+ // TronWeb might support _signTypedData or similar.
98
+ // For now, we'll use a generic implementation if TronWeb exposes it,
99
+ // otherwise we might need to construct the hash manually or use a specific library.
100
+ // Checking TronWeb docs, it supports signTypedData since recently.
101
+ const tronWeb = new TronWeb({
102
+ fullHost: "https://api.trongrid.io",
103
+ privateKey: privateKey,
104
+ headers: apiKey ? { "TRON-PRO-API-KEY": apiKey } : undefined,
105
+ });
106
+ // @ts-ignore - TronWeb types might be missing signTypedData
107
+ if (typeof tronWeb.trx._signTypedData === "function") {
108
+ // @ts-ignore
109
+ return await tronWeb.trx._signTypedData(domain, types, value);
110
+ }
111
+ throw new Error("signTypedData not supported by this TronWeb version or configuration");
112
+ };
113
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/services/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAgBrC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAqB,EAAE;IACxD,MAAM,UAA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
+ /**
3
+ * Register all TRON-related tools with the MCP server
4
+ *
5
+ * SECURITY: Either TRON_PRIVATE_KEY or TRON_MNEMONIC environment variable must be set for write operations.
6
+ * Private keys and mnemonics are never passed as tool arguments for security reasons.
7
+ * Tools will use the configured wallet for all transactions.
8
+ *
9
+ * Configuration options:
10
+ * - TRON_PRIVATE_KEY: Hex private key (with or without 0x prefix)
11
+ * - TRON_MNEMONIC: BIP-39 mnemonic phrase (12 or 24 words)
12
+ * - TRON_ACCOUNT_INDEX: Optional account index for HD wallet derivation (default: 0)
13
+ *
14
+ * @param server The MCP server instance
15
+ */
16
+ export declare function registerTRONTools(server: McpServer): void;