@tatumio/tron 2.0.1-alpha.231

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/package.json +28 -0
  2. package/src/index.d.ts +1 -0
  3. package/src/index.js +5 -0
  4. package/src/index.js.map +1 -0
  5. package/src/lib/services/tron.custodial.d.ts +59 -0
  6. package/src/lib/services/tron.custodial.js +131 -0
  7. package/src/lib/services/tron.custodial.js.map +1 -0
  8. package/src/lib/services/tron.record.d.ts +17 -0
  9. package/src/lib/services/tron.record.js +24 -0
  10. package/src/lib/services/tron.record.js.map +1 -0
  11. package/src/lib/services/tron.trc10.d.ts +39 -0
  12. package/src/lib/services/tron.trc10.js +105 -0
  13. package/src/lib/services/tron.trc10.js.map +1 -0
  14. package/src/lib/services/tron.trc20.d.ts +45 -0
  15. package/src/lib/services/tron.trc20.js +133 -0
  16. package/src/lib/services/tron.trc20.js.map +1 -0
  17. package/src/lib/services/tron.trc721.d.ts +127 -0
  18. package/src/lib/services/tron.trc721.js +396 -0
  19. package/src/lib/services/tron.trc721.js.map +1 -0
  20. package/src/lib/services/tron.tx.d.ts +150 -0
  21. package/src/lib/services/tron.tx.js +236 -0
  22. package/src/lib/services/tron.tx.js.map +1 -0
  23. package/src/lib/services/tron.utils.d.ts +1 -0
  24. package/src/lib/services/tron.utils.js +82 -0
  25. package/src/lib/services/tron.utils.js.map +1 -0
  26. package/src/lib/services/tron.wallet.d.ts +49 -0
  27. package/src/lib/services/tron.wallet.js +76 -0
  28. package/src/lib/services/tron.wallet.js.map +1 -0
  29. package/src/lib/services/tron.web.d.ts +5 -0
  30. package/src/lib/services/tron.web.js +27 -0
  31. package/src/lib/services/tron.web.js.map +1 -0
  32. package/src/lib/tron.sdk.d.ts +230 -0
  33. package/src/lib/tron.sdk.js +25 -0
  34. package/src/lib/tron.sdk.js.map +1 -0
@@ -0,0 +1,150 @@
1
+ import { CallSmartContractMethod, CallSmartContractMethodKMS, FreezeTron, FreezeTronKMS, GenerateCustodialWalletTron, GenerateCustodialWalletTronKMS, GenerateMarketplaceTron, GenerateMarketplaceTronKMS, TransferTronBlockchain, TransferTronBlockchainKMS } from '@tatumio/api-client';
2
+ import { ITronWeb } from './tron.web';
3
+ export declare const tronTx: (args: {
4
+ tronWeb: ITronWeb;
5
+ }) => {
6
+ trc10: {
7
+ prepare: {
8
+ signedTransaction: (body: import("@tatumio/api-client").TransferTronTrc10Blockchain | import("@tatumio/api-client").TransferTronTrc10BlockchainKMS, precision?: number, provider?: string) => Promise<string>;
9
+ createSignedTransaction: (body: import("@tatumio/api-client").CreateTronTrc10Blockchain | import("@tatumio/api-client").CreateTronTrc10BlockchainKMS, provider?: string) => Promise<string>;
10
+ };
11
+ send: {
12
+ signedTransaction: (body: import("@tatumio/api-client").TransferTronTrc10Blockchain | import("@tatumio/api-client").TransferTronTrc10BlockchainKMS, precision?: number, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
13
+ createSignedTransaction: (body: import("@tatumio/api-client").CreateTronTrc10Blockchain | import("@tatumio/api-client").CreateTronTrc10BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
14
+ };
15
+ };
16
+ trc20: {
17
+ getAccountTrc20Address: (address: string, contractAddress: string, provider?: string) => Promise<any>;
18
+ getTrc20ContractDecimals: (contractAddress: string, provider?: string) => Promise<any>;
19
+ prepare: {
20
+ signedTransaction: (body: import("@tatumio/api-client").TransferTronTrc20Blockchain | import("@tatumio/api-client").TransferTronTrc20BlockchainKMS, provider?: string) => Promise<string>;
21
+ createSignedTransaction: (body: import("@tatumio/api-client").CreateTronTrc20Blockchain | import("@tatumio/api-client").CreateTronTrc20BlockchainKMS, provider?: string) => Promise<string>;
22
+ };
23
+ send: {
24
+ signedTransaction: (body: import("@tatumio/api-client").TransferTronTrc20Blockchain | import("@tatumio/api-client").TransferTronTrc20BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
25
+ createSignedTransaction: (body: import("@tatumio/api-client").CreateTronTrc20Blockchain | import("@tatumio/api-client").CreateTronTrc20BlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
26
+ };
27
+ };
28
+ trc721: {
29
+ prepare: {
30
+ deploySignedTransaction: (body: (import("@tatumio/api-client").DeployNftTronKMS & {
31
+ from: string;
32
+ }) | import("@tatumio/api-client").DeployNftTron, provider?: string) => Promise<string>;
33
+ mintCashbackSignedTransaction: (body: (import("@tatumio/api-client").MintNftKMSTron & {
34
+ from: string;
35
+ }) | import("@tatumio/api-client").MintNftTron, provider?: string) => Promise<string>;
36
+ mintSignedTransaction: (body: (import("@tatumio/api-client").MintNftKMSTron & {
37
+ from: string;
38
+ }) | import("@tatumio/api-client").MintNftTron, provider?: string) => Promise<string>;
39
+ transferSignedTransaction: (body: (import("@tatumio/api-client").TransferNftKMSTron & {
40
+ from: string;
41
+ }) | import("@tatumio/api-client").TransferNftTron, provider?: string) => Promise<string>;
42
+ burnSignedTransaction: (body: (import("@tatumio/api-client").BurnNftKMSTron & {
43
+ from: string;
44
+ }) | import("@tatumio/api-client").BurnNftTron, provider?: string) => Promise<string>;
45
+ mintMultipleSignedTransaction: (body: (import("@tatumio/api-client").MintMultipleNftKMSTron & {
46
+ from: string;
47
+ }) | import("@tatumio/api-client").MintMultipleNftTron, provider?: string) => Promise<string>;
48
+ updateCashbackValueForAuthorSignedTransaction: (body: (import("@tatumio/api-client").UpdateCashbackValueForAuthorNftKMSTron & {
49
+ from: string;
50
+ }) | import("@tatumio/api-client").UpdateCashbackValueForAuthorNftTron, provider?: string) => Promise<string>;
51
+ };
52
+ send: {
53
+ deploySignedTransaction: (body: (import("@tatumio/api-client").DeployNftTronKMS & {
54
+ from: string;
55
+ }) | import("@tatumio/api-client").DeployNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
56
+ mintCashbackSignedTransaction: (body: (import("@tatumio/api-client").MintNftKMSTron & {
57
+ from: string;
58
+ }) | import("@tatumio/api-client").MintNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
59
+ mintSignedTransaction: (body: (import("@tatumio/api-client").MintNftKMSTron & {
60
+ from: string;
61
+ }) | import("@tatumio/api-client").MintNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
62
+ transferSignedTransaction: (body: (import("@tatumio/api-client").TransferNftKMSTron & {
63
+ from: string;
64
+ }) | import("@tatumio/api-client").TransferNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
65
+ burnSignedTransaction: (body: (import("@tatumio/api-client").BurnNftKMSTron & {
66
+ from: string;
67
+ }) | import("@tatumio/api-client").BurnNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
68
+ mintMultipleSignedTransaction: (body: (import("@tatumio/api-client").MintMultipleNftKMSTron & {
69
+ from: string;
70
+ }) | import("@tatumio/api-client").MintMultipleNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
71
+ updateCashbackValueForAuthorSignedTransaction: (body: (import("@tatumio/api-client").UpdateCashbackValueForAuthorNftKMSTron & {
72
+ from: string;
73
+ }) | import("@tatumio/api-client").UpdateCashbackValueForAuthorNftTron, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
74
+ };
75
+ };
76
+ prepare: {
77
+ /**
78
+ * Sign Tron transaction with private keys locally. Nothing is broadcast to the blockchain.
79
+ * @param body content of the transaction to broadcast
80
+ * @param provider
81
+ * @returns transaction data to be broadcast to blockchain.
82
+ */
83
+ signedTransaction: (body: TransferTronBlockchain | TransferTronBlockchainKMS, provider?: string) => Promise<string>;
84
+ /**
85
+ * Sign Tron Freeze balance transaction with private keys locally. Nothing is broadcast to the blockchain.
86
+ * @param body content of the transaction to broadcast
87
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
88
+ * @returns transaction data to be broadcast to blockchain.
89
+ */
90
+ freezeTransaction: (body: FreezeTron | FreezeTronKMS, provider?: string) => Promise<string>;
91
+ /**
92
+ * Sign Tron custodial transfer transaction with private keys locally. Nothing is broadcast to the blockchain.
93
+ * @param body content of the transaction to broadcast
94
+ * @param provider
95
+ * @returns transaction data to be broadcast to blockchain.
96
+ */
97
+ smartContractInvocation: (body: CallSmartContractMethod | CallSmartContractMethodKMS, provider?: string) => Promise<string>;
98
+ /**
99
+ * Sign Tron custodial transfer batch transaction with private keys locally. Nothing is broadcast to the blockchain.
100
+ * @param body content of the transaction to broadcast
101
+ * @param provider
102
+ * @returns transaction data to be broadcast to blockchain.
103
+ */
104
+ custodialTransferBatch: (body: CallSmartContractMethod | CallSmartContractMethodKMS, provider?: string) => Promise<string>;
105
+ /**
106
+ * Sign Tron generate custodial wallet transaction with private keys locally. Nothing is broadcast to the blockchain.
107
+ * @param body content of the transaction to broadcast
108
+ * @param provider
109
+ * @returns transaction data to be broadcast to blockchain.
110
+ */
111
+ generateCustodialWalletSignedTransaction: (body: GenerateCustodialWalletTron | GenerateCustodialWalletTronKMS, provider?: string) => Promise<string>;
112
+ /**
113
+ * Sign TRON deploy new smart contract for NFT marketplace transaction. Smart contract enables marketplace operator to create new listing for NFT (ERC-721/1155).
114
+ * @param body request data
115
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
116
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
117
+ */
118
+ deployMarketplaceListingSignedTransaction: (body: GenerateMarketplaceTron | GenerateMarketplaceTronKMS, tronWeb: ITronWeb, provider?: string) => Promise<string>;
119
+ };
120
+ send: {
121
+ /**
122
+ * Send Tron transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
123
+ * This operation is irreversible.
124
+ * @param body content of the transaction to broadcast
125
+ * @returns transaction id of the transaction in the blockchain
126
+ */
127
+ signedTransaction: (body: TransferTronBlockchain | TransferTronBlockchainKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
128
+ /**
129
+ * Send Tron Freeze balance transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
130
+ * This operation is irreversible.
131
+ * @param body content of the transaction to broadcast
132
+ * @returns transaction id of the transaction in the blockchain
133
+ */
134
+ freezeTransaction: (body: FreezeTron | FreezeTronKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
135
+ /**
136
+ * Send Tron generate custodial wallet transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
137
+ * This operation is irreversible.
138
+ * @param body content of the transaction to broadcast
139
+ * @returns transaction id of the transaction in the blockchain
140
+ */
141
+ generateCustodialWalletSignedTransaction: (body: GenerateCustodialWalletTron | GenerateCustodialWalletTronKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
142
+ /**
143
+ * Deploy new smart contract for NFT marketplace logic. Smart contract enables marketplace operator to create new listing for NFT (ERC-721/1155).
144
+ * @param body request data
145
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
146
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
147
+ */
148
+ deployMarketplaceListingSignedTransaction: (body: GenerateMarketplaceTron | GenerateMarketplaceTronKMS, tronWeb: ITronWeb, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
149
+ };
150
+ };
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronTx = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const api_client_1 = require("@tatumio/api-client");
6
+ const shared_blockchain_evm_based_1 = require("@tatumio/shared-blockchain-evm-based");
7
+ const tron_trc10_1 = require("./tron.trc10");
8
+ const tron_trc20_1 = require("./tron.trc20");
9
+ const tron_trc721_1 = require("./tron.trc721");
10
+ function isTransferTronBlockchainKMS(input) {
11
+ return input.signatureId !== undefined;
12
+ }
13
+ const prepareSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
14
+ const { to, amount } = body;
15
+ const client = tronWeb.getClient(provider);
16
+ if (isTransferTronBlockchainKMS(body)) {
17
+ const tx = yield client.transactionBuilder.sendTrx(to, client.toSun(amount), body.from);
18
+ return JSON.stringify(tx);
19
+ }
20
+ else {
21
+ const tx = yield client.transactionBuilder.sendTrx(to, client.toSun(amount), client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey)));
22
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
23
+ }
24
+ });
25
+ function isFreezeTronKMS(input) {
26
+ return input.signatureId !== undefined;
27
+ }
28
+ const prepareFreezeTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
29
+ const { receiver, amount, resource, duration } = body;
30
+ const client = tronWeb.getClient(provider);
31
+ if (isFreezeTronKMS(body)) {
32
+ const tx = yield client.transactionBuilder.freezeBalance(client.toSun(parseFloat(amount)), duration, resource, body.from, receiver);
33
+ return JSON.stringify(tx);
34
+ }
35
+ else {
36
+ const tx = yield client.transactionBuilder.freezeBalance(client.toSun(parseFloat(amount)), duration, resource, client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey)), receiver);
37
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
38
+ }
39
+ });
40
+ function isCallSmartContractMethodKMS(input) {
41
+ return input.signatureId !== undefined;
42
+ }
43
+ const prepareSmartContractInvocation = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
44
+ var _a;
45
+ const { amount, contractAddress, methodName, params } = body;
46
+ const client = tronWeb.getClient(provider);
47
+ client.setAddress(contractAddress);
48
+ const contractAddressHex = client.address.toHex(contractAddress);
49
+ const sender = isCallSmartContractMethodKMS(body)
50
+ ? body.signatureId
51
+ : client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey));
52
+ const { transaction } = yield client.transactionBuilder.triggerSmartContract(contractAddressHex, methodName, {
53
+ feeLimit: client.toSun((_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit),
54
+ from: sender,
55
+ callValue: client.toSun(amount || 0),
56
+ }, params, sender);
57
+ if (isCallSmartContractMethodKMS(body)) {
58
+ return JSON.stringify(transaction);
59
+ }
60
+ return JSON.stringify(yield client.trx.sign(transaction, body.fromPrivateKey));
61
+ });
62
+ const prepareCustodialTransferBatch = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
63
+ const { contractAddress, fee } = body;
64
+ const client = tronWeb.getClient(provider);
65
+ client.setAddress(contractAddress);
66
+ const contractAddressHex = client.address.toHex(contractAddress);
67
+ const sender = isCallSmartContractMethodKMS(body)
68
+ ? body.signatureId
69
+ : client.address.fromHex(client.address.fromPrivateKey(body.fromPrivateKey));
70
+ const methodName = 'transferBatch(address[],uint256[],address[],uint256[],uint256[])';
71
+ const { transaction } = yield client.transactionBuilder.triggerSmartContract(contractAddressHex, methodName, {
72
+ feeLimit: client.toSun(fee === null || fee === void 0 ? void 0 : fee.gasLimit),
73
+ from: sender,
74
+ }, [
75
+ { type: 'address[]', value: body.params[0].map(client.address.toHex) },
76
+ { type: 'uint256[]', value: body.params[1] },
77
+ { type: 'address[]', value: body.params[2].map(client.address.toHex) },
78
+ { type: 'uint256[]', value: body.params[3] },
79
+ { type: 'uint256[]', value: body.params[4] },
80
+ ], sender);
81
+ if (isCallSmartContractMethodKMS(body)) {
82
+ return JSON.stringify(transaction);
83
+ }
84
+ return JSON.stringify(yield client.trx.sign(transaction, body.fromPrivateKey));
85
+ });
86
+ function isGenerateCustodialWalletTronKMS(input) {
87
+ return input.signatureId !== undefined;
88
+ }
89
+ const prepareGenerateCustodialWalletSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
90
+ const client = tronWeb.getClient(provider);
91
+ // TODO: implement obtainCustodialAddressType
92
+ const { abi, code } = {};
93
+ const sender = isGenerateCustodialWalletTronKMS(body)
94
+ ? body.from
95
+ : client.address.fromPrivateKey(body.fromPrivateKey);
96
+ const tx = yield client.transactionBuilder.createSmartContract({
97
+ feeLimit: client.toSun(body.feeLimit || 100),
98
+ callValue: 0,
99
+ userFeePercentage: 100,
100
+ originEnergyLimit: 1,
101
+ abi: JSON.stringify(abi),
102
+ bytecode: code,
103
+ parameters: [],
104
+ name: 'CustodialWallet',
105
+ }, sender);
106
+ if (isGenerateCustodialWalletTronKMS(body)) {
107
+ return JSON.stringify(tx);
108
+ }
109
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
110
+ });
111
+ function isGenerateMarketplaceTronKMS(input) {
112
+ return input.signatureId !== undefined;
113
+ }
114
+ const prepareDeployMarketplaceListingSignedTransaction = (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
115
+ const client = tronWeb.getClient(provider);
116
+ const sender = isGenerateMarketplaceTronKMS(body)
117
+ ? body.from
118
+ : client.address.fromPrivateKey(body.fromPrivateKey);
119
+ const tx = yield client.transactionBuilder.createSmartContract({
120
+ feeLimit: client.toSun(body.feeLimit || 300),
121
+ callValue: 0,
122
+ userFeePercentage: 100,
123
+ originEnergyLimit: 1,
124
+ abi: JSON.stringify(shared_blockchain_evm_based_1.ListingSmartContract.abi),
125
+ bytecode: shared_blockchain_evm_based_1.ListingSmartContract.bytecode,
126
+ parameters: [body.marketplaceFee, body.feeRecipient],
127
+ name: 'CustodialWallet',
128
+ }, sender);
129
+ if (isGenerateMarketplaceTronKMS(body)) {
130
+ return JSON.stringify(tx);
131
+ }
132
+ return JSON.stringify(yield client.trx.sign(tx, body.fromPrivateKey));
133
+ });
134
+ const tronTx = (args) => {
135
+ return {
136
+ trc10: (0, tron_trc10_1.tronTrc10)(args),
137
+ trc20: (0, tron_trc20_1.tronTrc20)(args),
138
+ trc721: (0, tron_trc721_1.tronTrc721)(args),
139
+ prepare: {
140
+ /**
141
+ * Sign Tron transaction with private keys locally. Nothing is broadcast to the blockchain.
142
+ * @param body content of the transaction to broadcast
143
+ * @param provider
144
+ * @returns transaction data to be broadcast to blockchain.
145
+ */
146
+ signedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareSignedTransaction(body, args.tronWeb, provider); }),
147
+ /**
148
+ * Sign Tron Freeze balance transaction with private keys locally. Nothing is broadcast to the blockchain.
149
+ * @param body content of the transaction to broadcast
150
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
151
+ * @returns transaction data to be broadcast to blockchain.
152
+ */
153
+ freezeTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareFreezeTransaction(body, args.tronWeb, provider); }),
154
+ /**
155
+ * Sign Tron custodial transfer transaction with private keys locally. Nothing is broadcast to the blockchain.
156
+ * @param body content of the transaction to broadcast
157
+ * @param provider
158
+ * @returns transaction data to be broadcast to blockchain.
159
+ */
160
+ smartContractInvocation: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareSmartContractInvocation(body, args.tronWeb, provider); }),
161
+ /**
162
+ * Sign Tron custodial transfer batch transaction with private keys locally. Nothing is broadcast to the blockchain.
163
+ * @param body content of the transaction to broadcast
164
+ * @param provider
165
+ * @returns transaction data to be broadcast to blockchain.
166
+ */
167
+ custodialTransferBatch: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareCustodialTransferBatch(body, args.tronWeb, provider); }),
168
+ /**
169
+ * Sign Tron generate custodial wallet transaction with private keys locally. Nothing is broadcast to the blockchain.
170
+ * @param body content of the transaction to broadcast
171
+ * @param provider
172
+ * @returns transaction data to be broadcast to blockchain.
173
+ */
174
+ generateCustodialWalletSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareGenerateCustodialWalletSignedTransaction(body, args.tronWeb, provider); }),
175
+ /**
176
+ * Sign TRON deploy new smart contract for NFT marketplace transaction. Smart contract enables marketplace operator to create new listing for NFT (ERC-721/1155).
177
+ * @param body request data
178
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
179
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
180
+ */
181
+ deployMarketplaceListingSignedTransaction: (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { return prepareDeployMarketplaceListingSignedTransaction(body, args.tronWeb, provider); }),
182
+ },
183
+ send: {
184
+ /**
185
+ * Send Tron transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
186
+ * This operation is irreversible.
187
+ * @param body content of the transaction to broadcast
188
+ * @returns transaction id of the transaction in the blockchain
189
+ */
190
+ signedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
191
+ return api_client_1.BlockchainTronService.tronBroadcast({
192
+ txData: yield prepareSignedTransaction(body, args.tronWeb, provider),
193
+ // TODO: SignatureID is missing in OpenApi
194
+ });
195
+ }),
196
+ /**
197
+ * Send Tron Freeze balance transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
198
+ * This operation is irreversible.
199
+ * @param body content of the transaction to broadcast
200
+ * @returns transaction id of the transaction in the blockchain
201
+ */
202
+ freezeTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
203
+ return api_client_1.BlockchainTronService.tronBroadcast({
204
+ txData: yield prepareFreezeTransaction(body, args.tronWeb, provider),
205
+ // TODO: SignatureID is missing in OpenApi
206
+ });
207
+ }),
208
+ /**
209
+ * Send Tron generate custodial wallet transaction to the blockchain. This method broadcasts signed transaction to the blockchain.
210
+ * This operation is irreversible.
211
+ * @param body content of the transaction to broadcast
212
+ * @returns transaction id of the transaction in the blockchain
213
+ */
214
+ generateCustodialWalletSignedTransaction: (body, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
215
+ return api_client_1.BlockchainTronService.tronBroadcast({
216
+ txData: yield prepareGenerateCustodialWalletSignedTransaction(body, args.tronWeb, provider),
217
+ // TODO: SignatureID is missing in OpenApi
218
+ });
219
+ }),
220
+ /**
221
+ * Deploy new smart contract for NFT marketplace logic. Smart contract enables marketplace operator to create new listing for NFT (ERC-721/1155).
222
+ * @param body request data
223
+ * @param provider optional provider to enter. if not present, Tatum provider will be used.
224
+ * @returns {txId: string} Transaction ID of the operation, or signatureID in case of Tatum KMS
225
+ */
226
+ deployMarketplaceListingSignedTransaction: (body, tronWeb, provider) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
227
+ return api_client_1.BlockchainTronService.tronBroadcast({
228
+ txData: yield prepareDeployMarketplaceListingSignedTransaction(body, args.tronWeb, provider),
229
+ // TODO: SignatureID is missing in OpenApi
230
+ });
231
+ }),
232
+ },
233
+ };
234
+ };
235
+ exports.tronTx = tronTx;
236
+ //# sourceMappingURL=tron.tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.tx.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.tx.ts"],"names":[],"mappings":";;;;AAAA,oDAY4B;AAC5B,sFAA2E;AAC3E,6CAAwC;AACxC,6CAAwC;AACxC,+CAA0C;AAG1C,SAAS,2BAA2B,CAClC,KAAyD;IAEzD,OAAQ,KAAmC,CAAC,WAAW,KAAK,SAAS,CAAA;AACvE,CAAC;AAED,MAAM,wBAAwB,GAAG,CAC/B,IAAwD,EACxD,OAAiB,EACjB,QAAiB,EACjB,EAAE;IACF,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,2BAA2B,CAAC,IAAI,CAAC,EAAE;QACrC,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAEvF,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;KAC1B;SAAM;QACL,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAChD,EAAE,EACF,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EACpB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC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,EAAE,QAAQ,CAAC;oBAC5F,0CAA0C;iBAC3C,CAAC,CAAA;cAAA;SACL;KACF,CAAA;AACH,CAAC,CAAA;AA3HY,QAAA,MAAM,UA2HlB"}
@@ -0,0 +1 @@
1
+ export declare const generateAddress: (publicKey: Buffer) => string;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateAddress = void 0;
4
+ const elliptic_1 = require("elliptic");
5
+ const js_sha3_1 = require("js-sha3");
6
+ const hexChar2byte = (c) => {
7
+ let d = 0;
8
+ if (c >= 'A' && c <= 'F')
9
+ d = c.charCodeAt(0) - 'A'.charCodeAt(0) + 10;
10
+ else if (c >= 'a' && c <= 'f')
11
+ d = c.charCodeAt(0) - 'a'.charCodeAt(0) + 10;
12
+ else if (c >= '0' && c <= '9')
13
+ d = c.charCodeAt(0) - '0'.charCodeAt(0);
14
+ return d;
15
+ };
16
+ const isHexChar = (c) => {
17
+ if ((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9')) {
18
+ return 1;
19
+ }
20
+ return 0;
21
+ };
22
+ // TODO: should return Uint8Array
23
+ const hexStr2byteArray = (str) => {
24
+ const byteArray = [];
25
+ let d = 0;
26
+ let j = 0;
27
+ let k = 0;
28
+ for (let i = 0; i < str.length; i++) {
29
+ const c = str.charAt(i);
30
+ if (isHexChar(c)) {
31
+ d <<= 4;
32
+ d += hexChar2byte(c);
33
+ j++;
34
+ if (0 === j % 2) {
35
+ byteArray[k++] = d;
36
+ d = 0;
37
+ }
38
+ }
39
+ }
40
+ return byteArray;
41
+ };
42
+ // @ts-ignore
43
+ const byte2hexStr = (byte) => {
44
+ const hexByteMap = '0123456789ABCDEF';
45
+ let str = '';
46
+ str += hexByteMap.charAt(byte >> 4);
47
+ str += hexByteMap.charAt(byte & 0x0f);
48
+ return str;
49
+ };
50
+ const byteArray2hexStr = (byteArray) => {
51
+ let str = '';
52
+ for (const byte of byteArray) {
53
+ str += byte2hexStr(byte);
54
+ }
55
+ return str;
56
+ };
57
+ const computeAddress = (pubBytes) => {
58
+ if (pubBytes.length === 65)
59
+ pubBytes = pubBytes.slice(1);
60
+ const hash = (0, js_sha3_1.keccak_256)(pubBytes).toString();
61
+ const addressHex = '41' + hash.substring(24);
62
+ return hexStr2byteArray(addressHex);
63
+ };
64
+ const generatePubKey = (bytes) => {
65
+ const ec = new elliptic_1.ec('secp256k1');
66
+ const key = ec.keyFromPublic(bytes, 'bytes');
67
+ const pubkey = key.getPublic();
68
+ const x = pubkey.getX();
69
+ const y = pubkey.getY();
70
+ let xHex = x.toString('hex');
71
+ while (xHex.length < 64) {
72
+ xHex = '0' + xHex;
73
+ }
74
+ let yHex = y.toString('hex');
75
+ while (yHex.length < 64) {
76
+ yHex = '0' + yHex;
77
+ }
78
+ return '04' + xHex + yHex;
79
+ };
80
+ const generateAddress = (publicKey) => byteArray2hexStr(computeAddress(hexStr2byteArray(generatePubKey(publicKey))));
81
+ exports.generateAddress = generateAddress;
82
+ //# sourceMappingURL=tron.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.utils.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.utils.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AACnC,qCAAoC;AAEpC,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE;IACjC,IAAI,CAAC,GAAG,CAAC,CAAA;IAET,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG;QAAE,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;SACjE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG;QAAE,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;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CAAC,IAAI,EAAE,CAAA;IACvB,IAAI,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5B,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;KAClB;IACD,IAAI,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5B,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE;QACvB,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;KAClB;IACD,OAAO,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC3B,CAAC,CAAA;AAEM,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,EAAE,CACnD,gBAAgB,CAAC,cAAc,CAAC,gBAAgB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AADlE,QAAA,eAAe,mBACmD"}
@@ -0,0 +1,49 @@
1
+ import { TronWallet } from '@tatumio/api-client';
2
+ import { ITronWeb } from './tron.web';
3
+ export declare const tronWallet: (args: {
4
+ tronWeb: ITronWeb;
5
+ }) => {
6
+ /**
7
+ * Generate Tron wallet
8
+ * @returns mnemonic for the wallet
9
+ */
10
+ generateBlockchainWallet: (mnem: string) => Promise<TronWallet>;
11
+ /**
12
+ * Generate wallet
13
+ * @param mnemonic optional mnemonic seed to use. If not present, new one will be generated
14
+ * @returns wallet or a combination of address and private key
15
+ */
16
+ generateWallet(mnemonic?: string): Promise<TronWallet>;
17
+ /**
18
+ * Generate address
19
+ * @param xpub extended public key to generate address from
20
+ * @param i derivation index of address to generate. Up to 2^31 addresses can be generated.
21
+ * @returns blockchain address
22
+ */
23
+ generateAddressFromXPub(xpub: string, i: number): string;
24
+ /**
25
+ * Generate private key from mnemonic seed
26
+ * @param mnemonic mnemonic to generate private key from
27
+ * @param i derivation index of private key to generate.
28
+ * @returns blockchain private key to the address
29
+ */
30
+ generatePrivateKeyFromMnemonic(mnemonic: string, i: number): Promise<string>;
31
+ /**
32
+ * Generate address from private key
33
+ * @param privateKey private key to use
34
+ * @returns blockchain private key to the address
35
+ */
36
+ generateAddressFromPrivatekey(privateKey: string): string;
37
+ custodial: {
38
+ prepare: {
39
+ custodialWallet: (body: import("@tatumio/api-client").GenerateCustodialWalletTron | import("@tatumio/api-client").GenerateCustodialWalletTronKMS, provider?: string) => Promise<string>;
40
+ transferFromCustodialWallet: (body: import("@tatumio/api-client").TransferCustodialWalletTron | import("@tatumio/api-client").TransferCustodialWalletTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<string>;
41
+ batchTransferFromCustodialWallet: (body: import("@tatumio/api-client").TransferCustodialWalletBatchTron | import("@tatumio/api-client").TransferCustodialWalletBatchTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<string>;
42
+ };
43
+ send: {
44
+ custodialWallet: (body: import("@tatumio/api-client").GenerateCustodialWalletTron | import("@tatumio/api-client").GenerateCustodialWalletTronKMS, provider?: string) => Promise<import("@tatumio/api-client").TransactionHash>;
45
+ transferFromCustodialWallet: (body: import("@tatumio/api-client").TransferCustodialWalletTron | import("@tatumio/api-client").TransferCustodialWalletTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<import("@tatumio/api-client").TransactionHash>;
46
+ batchTransferFromCustodialWallet: (body: import("@tatumio/api-client").TransferCustodialWalletBatchTron | import("@tatumio/api-client").TransferCustodialWalletBatchTronKMS, getContractDecimals: (contractAddress: string, provider?: string, testnet?: boolean) => Promise<number>, provider?: string, decimals?: number, testnet?: boolean) => Promise<import("@tatumio/api-client").TransactionHash>;
47
+ };
48
+ };
49
+ };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tronWallet = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const shared_core_1 = require("@tatumio/shared-core");
6
+ const bip32_1 = require("bip32");
7
+ const bip39_1 = require("bip39");
8
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
9
+ const tron_utils_1 = require("./tron.utils");
10
+ // tronweb lib dont have any typings (not even in @types)
11
+ // @ts-ignore
12
+ const tronweb_1 = (0, tslib_1.__importDefault)(require("tronweb"));
13
+ const tron_custodial_1 = require("./tron.custodial");
14
+ const generateBlockchainWallet = (mnem) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
15
+ const w = bitcoinjs_lib_1.bip32.fromSeed(yield (0, bip39_1.mnemonicToSeed)(mnem));
16
+ const bip32Interface = w.derivePath(shared_core_1.DERIVATION_PATH[shared_core_1.Blockchain.TRON]);
17
+ return {
18
+ mnemonic: mnem,
19
+ xpub: bip32Interface.publicKey.toString('hex') + bip32Interface.chainCode.toString('hex'),
20
+ };
21
+ });
22
+ const tronWallet = (args) => {
23
+ return {
24
+ /**
25
+ * Generate Tron wallet
26
+ * @returns mnemonic for the wallet
27
+ */
28
+ generateBlockchainWallet,
29
+ /**
30
+ * Generate wallet
31
+ * @param mnemonic optional mnemonic seed to use. If not present, new one will be generated
32
+ * @returns wallet or a combination of address and private key
33
+ */
34
+ generateWallet(mnemonic) {
35
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
36
+ return generateBlockchainWallet(mnemonic !== null && mnemonic !== void 0 ? mnemonic : (0, bip39_1.generateMnemonic)(256));
37
+ });
38
+ },
39
+ /**
40
+ * Generate address
41
+ * @param xpub extended public key to generate address from
42
+ * @param i derivation index of address to generate. Up to 2^31 addresses can be generated.
43
+ * @returns blockchain address
44
+ */
45
+ generateAddressFromXPub(xpub, i) {
46
+ const w = (0, bip32_1.fromPublicKey)(Buffer.from(xpub.slice(0, 66), 'hex'), Buffer.from(xpub.slice(-64), 'hex'));
47
+ return tronweb_1.default.address.fromHex((0, tron_utils_1.generateAddress)(w.derive(i).publicKey));
48
+ },
49
+ /**
50
+ * Generate private key from mnemonic seed
51
+ * @param mnemonic mnemonic to generate private key from
52
+ * @param i derivation index of private key to generate.
53
+ * @returns blockchain private key to the address
54
+ */
55
+ generatePrivateKeyFromMnemonic(mnemonic, i) {
56
+ var _a, _b;
57
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
58
+ return ((_b = (_a = (0, bip32_1.fromSeed)(yield (0, bip39_1.mnemonicToSeed)(mnemonic))
59
+ .derivePath(shared_core_1.DERIVATION_PATH[shared_core_1.Blockchain.TRON])
60
+ .derive(i)
61
+ .privateKey) === null || _a === void 0 ? void 0 : _a.toString('hex')) !== null && _b !== void 0 ? _b : '');
62
+ });
63
+ },
64
+ /**
65
+ * Generate address from private key
66
+ * @param privateKey private key to use
67
+ * @returns blockchain private key to the address
68
+ */
69
+ generateAddressFromPrivatekey(privateKey) {
70
+ return tronweb_1.default.address.fromPrivateKey(privateKey);
71
+ },
72
+ custodial: (0, tron_custodial_1.tronCustodial)(args),
73
+ };
74
+ };
75
+ exports.tronWallet = tronWallet;
76
+ //# sourceMappingURL=tron.wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.wallet.js","sourceRoot":"","sources":["../../../../../../../packages/blockchain/tron/src/lib/services/tron.wallet.ts"],"names":[],"mappings":";;;;AACA,sDAAkE;AAClE,iCAA+C;AAC/C,iCAAwD;AACxD,iDAAqC;AACrC,6CAA8C;AAE9C,yDAAyD;AACzD,aAAa;AACb,mEAA6B;AAC7B,qDAAgD;AAGhD,MAAM,wBAAwB,GAAG,CAAO,IAAY,EAAuB,EAAE;IAC3E,MAAM,CAAC,GAAG,qBAAK,CAAC,QAAQ,CAAC,MAAM,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC,CAAA;IACpD,MAAM,cAAc,GAAG,CAAC,CAAC,UAAU,CAAC,6BAAe,CAAC,wBAAU,CAAC,IAAI,CAAC,CAAC,CAAA;IAErE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A6B,CAAC,UAAkB;YAC9C,OAAO,iBAAO,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;QACnD,CAAC;QACD,SAAS,EAAE,IAAA,8BAAa,EAAC,IAAI,CAAC;KAC/B,CAAA;AACH,CAAC,CAAA;AAjDY,QAAA,UAAU,cAiDtB"}
@@ -0,0 +1,5 @@
1
+ export declare type TronWebClient = any;
2
+ export interface ITronWeb {
3
+ getClient(provider?: string): TronWebClient;
4
+ }
5
+ export declare const tronWeb: () => ITronWeb;