@anywalletkit/wallet-tron 0.0.0-stage → 0.2.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.
- package/LICENSE +202 -0
- package/README.md +103 -2
- package/dist/chunk-4XN4VJDG.js +389 -0
- package/dist/chunk-4XN4VJDG.js.map +1 -0
- package/dist/history.cjs +394 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +160 -0
- package/dist/history.d.ts +160 -0
- package/dist/history.js +21 -0
- package/dist/history.js.map +1 -0
- package/dist/index.cjs +1845 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +636 -0
- package/dist/index.d.ts +636 -0
- package/dist/index.js +1467 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import { IWalletAccountReadOnly, TransferResult, IWalletAccount, Signer, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
2
|
+
export { FullNodeTxInfo, HistoryFetch, HistoryUnavailableError, TRANSFER_TOPIC, TronChainTx, TronGridTrc20, TronGridTx, TronHistoryCursor, TronHistoryOptions, TronHistoryPage, TronHistoryRaw, TronHistorySource, TronNetwork, createTronHistory, decodeCursor as decodeHistoryCursor, encodeCursor as encodeHistoryCursor, mapTransactionRow as mapHistoryTransactionRow, mapTrc20Only as mapHistoryTrc20Only, tronExplorerTxUrl } from './history.cjs';
|
|
3
|
+
|
|
4
|
+
/** JSON-RPC-ish HTTP transport: POST `path` with a JSON body, returns parsed JSON. */
|
|
5
|
+
type TronFetch = (path: string, body: unknown) => Promise<unknown>;
|
|
6
|
+
/** One full-node base url (e.g. "https://api.trongrid.io") or a ready transport. */
|
|
7
|
+
type TronProvider = string | TronFetch;
|
|
8
|
+
/**
|
|
9
|
+
* Options for a Tron wallet manager or account: full-node endpoints, network, fee limits and the
|
|
10
|
+
* pre-sign checks.
|
|
11
|
+
*/
|
|
12
|
+
interface TronConfig {
|
|
13
|
+
/** Full-node url(s) / transport(s). A list fails over in order. Omit for an offline (sign-only) wallet. */
|
|
14
|
+
provider?: TronProvider | TronProvider[];
|
|
15
|
+
/** Extra attempts across the provider list after the first failure (default 3). */
|
|
16
|
+
retries?: number;
|
|
17
|
+
/** Optional headers for every request (e.g. `TRON-PRO-API-KEY`). */
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** Max fee (sun) for `transfer`. */
|
|
20
|
+
transferMaxFee?: bigint | number;
|
|
21
|
+
/** Max fee (sun) for `sendTransaction` / `signTransaction`. */
|
|
22
|
+
transactionMaxFee?: bigint | number;
|
|
23
|
+
/** CAIP-2 suffix; default mainnet genesis "0x2b6653dc". */
|
|
24
|
+
network?: 'mainnet' | 'shasta' | 'nile' | string;
|
|
25
|
+
/** Run `simulateTransaction` before signing in `sendTransaction` / `transfer` (default true). */
|
|
26
|
+
simulate?: boolean;
|
|
27
|
+
/** Allow TRX / TRC-20 transfers to the zero address (default false — refused as a burn). */
|
|
28
|
+
allowBurn?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Native TRX transfer. `value` in sun. `memo` → `raw_data.data` (charged the memo fee). */
|
|
31
|
+
interface TronNativeTransfer {
|
|
32
|
+
to: string;
|
|
33
|
+
value: bigint | number | string;
|
|
34
|
+
memo?: string; /** 'hex' = binary memo given as 0x-hex (default 'utf8'). */
|
|
35
|
+
memoEncoding?: 'utf8' | 'hex';
|
|
36
|
+
}
|
|
37
|
+
/** Smart-contract call. */
|
|
38
|
+
interface TronContractCall {
|
|
39
|
+
contractAddress: string;
|
|
40
|
+
/** e.g. "transfer(address,uint256)" */
|
|
41
|
+
functionSelector: string;
|
|
42
|
+
parameters?: Array<{
|
|
43
|
+
type: string;
|
|
44
|
+
value: unknown;
|
|
45
|
+
}>;
|
|
46
|
+
options?: {
|
|
47
|
+
feeLimit?: number;
|
|
48
|
+
callValue?: number;
|
|
49
|
+
};
|
|
50
|
+
/** Attached as `raw_data.data` (e.g. a THORChain swap memo on a TRC-20 transfer). */
|
|
51
|
+
memo?: string;
|
|
52
|
+
/** 'hex' = binary memo given as 0x-hex, e.g. a Chainflip vault-swap note (default 'utf8'). */
|
|
53
|
+
memoEncoding?: 'utf8' | 'hex';
|
|
54
|
+
}
|
|
55
|
+
/** A transaction as the full node returns it (`/wallet/createtransaction`, `/wallet/triggersmartcontract`). */
|
|
56
|
+
interface TronRawTransaction {
|
|
57
|
+
txID: string;
|
|
58
|
+
raw_data_hex: string;
|
|
59
|
+
raw_data: {
|
|
60
|
+
contract: Array<{
|
|
61
|
+
type: string;
|
|
62
|
+
parameter: {
|
|
63
|
+
value: Record<string, unknown>;
|
|
64
|
+
type_url?: string;
|
|
65
|
+
};
|
|
66
|
+
}>;
|
|
67
|
+
ref_block_bytes?: string;
|
|
68
|
+
ref_block_hash?: string;
|
|
69
|
+
expiration?: number;
|
|
70
|
+
timestamp?: number;
|
|
71
|
+
fee_limit?: number;
|
|
72
|
+
/** Memo, hex-encoded. Charged `getMemoFee` when present. */
|
|
73
|
+
data?: string;
|
|
74
|
+
};
|
|
75
|
+
/** Execution result the node attaches (also returned by `triggerconstantcontract` on revert: `ret: 'FAILED'`). */
|
|
76
|
+
ret?: Array<{
|
|
77
|
+
ret?: string;
|
|
78
|
+
contractRet?: string;
|
|
79
|
+
}>;
|
|
80
|
+
visible?: boolean;
|
|
81
|
+
signature?: string[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Anything `sendTransaction` accepts: a TRX transfer, a contract call, or a transaction prebuilt by
|
|
85
|
+
* a provider.
|
|
86
|
+
*/
|
|
87
|
+
type TronTransaction = TronNativeTransfer | TronContractCall | TronRawTransaction;
|
|
88
|
+
/** A TRX or TRC-20 transfer. Amount in sun or the token's base units. */
|
|
89
|
+
interface TronTransferOptions {
|
|
90
|
+
/** TRC-20 contract (base58 T… or hex 41…). Omit for native TRX. */
|
|
91
|
+
token?: string;
|
|
92
|
+
/** Address that receives (base58 `T…` or hex `41…`). */
|
|
93
|
+
recipient: string;
|
|
94
|
+
amount: bigint | number | string;
|
|
95
|
+
/** Attached as `raw_data.data`; the network charges `getMemoFee` (1 TRX). */
|
|
96
|
+
memo?: string;
|
|
97
|
+
/** 'hex' = binary memo given as 0x-hex, e.g. a Chainflip vault-swap note (default 'utf8'). */
|
|
98
|
+
memoEncoding?: 'utf8' | 'hex';
|
|
99
|
+
}
|
|
100
|
+
/** What a transaction will cost, resource by resource. All sun values are what the SENDER burns. */
|
|
101
|
+
interface TronFeeBreakdown {
|
|
102
|
+
/** Free bandwidth points left on the account (`freeNetLimit − freeNetUsed`). */
|
|
103
|
+
bandwidthFree: number;
|
|
104
|
+
/** Staked bandwidth points left (`NetLimit − NetUsed`). */
|
|
105
|
+
bandwidthStaked: number;
|
|
106
|
+
/** Staked energy left (`EnergyLimit − EnergyUsed`). */
|
|
107
|
+
energyStaked: number;
|
|
108
|
+
/** sun per energy unit (`getEnergyFee`). */
|
|
109
|
+
energyPrice: bigint;
|
|
110
|
+
/** sun per bandwidth byte (`getTransactionFee`). */
|
|
111
|
+
bandwidthPrice: bigint;
|
|
112
|
+
/** sun burned for a memo (`getMemoFee`), 0 without one. */
|
|
113
|
+
memoFee: bigint;
|
|
114
|
+
/**
|
|
115
|
+
* sun burned to create the recipient account: `getCreateNewAccountFeeInSystemContract` (1 TRX)
|
|
116
|
+
* plus `getCreateAccountFee` (0.1 TRX) when staked bandwidth cannot cover the creation; 0 when it exists.
|
|
117
|
+
*/
|
|
118
|
+
accountCreationFee: bigint;
|
|
119
|
+
/** sun burned for bandwidth not covered by staked/free allowance. */
|
|
120
|
+
bandwidthBurn: bigint;
|
|
121
|
+
/** sun burned for energy not covered by staked energy. */
|
|
122
|
+
energyBurn: bigint;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resources a transaction consumes and the TRX burned for what the account's free bandwidth and
|
|
126
|
+
* staked energy do not cover.
|
|
127
|
+
*/
|
|
128
|
+
interface TronFeeEstimate {
|
|
129
|
+
/** Bandwidth points the transaction consumes (serialized size + signature + 64-byte result reserve). */
|
|
130
|
+
bandwidth: number;
|
|
131
|
+
/** Energy the call consumes (`energy_used` from a constant call); 0 for non-contract transactions. */
|
|
132
|
+
energy: number;
|
|
133
|
+
/** Total sun the sender pays on top of the amount. */
|
|
134
|
+
trxBurn: bigint;
|
|
135
|
+
breakdown: TronFeeBreakdown;
|
|
136
|
+
}
|
|
137
|
+
/** Fee of a transaction in sun (TRX burned), with the estimate behind it. */
|
|
138
|
+
interface TronQuote {
|
|
139
|
+
/** = `estimate.trxBurn`. */
|
|
140
|
+
fee: bigint;
|
|
141
|
+
/** = `estimate.breakdown.accountCreationFee` (TransferContract to a new account). */
|
|
142
|
+
activationFee: bigint;
|
|
143
|
+
estimate: TronFeeEstimate;
|
|
144
|
+
}
|
|
145
|
+
/** Outcome of a constant call (`/wallet/triggerconstantcontract`) or a balance pre-check. */
|
|
146
|
+
interface TronSimulation {
|
|
147
|
+
ok: boolean;
|
|
148
|
+
/** `energy_used` reported by the node (0 for non-contract transactions). */
|
|
149
|
+
energy: number;
|
|
150
|
+
/** Decoded revert reason / node message when `ok` is false. */
|
|
151
|
+
reason?: string;
|
|
152
|
+
/** Raw `constant_result` entries. */
|
|
153
|
+
constantResult?: string[] | undefined;
|
|
154
|
+
}
|
|
155
|
+
/** What a Tron transaction does. */
|
|
156
|
+
type TronTxKind = 'trx-transfer' | 'trc10-transfer' | 'trc20-transfer' | 'trc20-approve' | 'contract-call' | 'freeze' | 'unfreeze' | 'unknown';
|
|
157
|
+
/** Problems a Tron description is flagged with. */
|
|
158
|
+
type TronTxWarningCode = 'unlimited-approve' | 'zero-address' | 'unactivated-recipient' | 'memo-fee' | 'expired'
|
|
159
|
+
/** Prebuilt transaction without `raw_data_hex`: described from the unsigned JSON copy, cannot be signed. */
|
|
160
|
+
| 'no-raw-hex'
|
|
161
|
+
/** `raw_data_hex` is not a well-formed Transaction.raw: nothing can be said about it. */
|
|
162
|
+
| 'raw-undecodable'
|
|
163
|
+
/** A contract type or parameter fields the wallet has no decoder for: only the raw bytes are known. */
|
|
164
|
+
| 'undecoded'
|
|
165
|
+
/** More than one contract in the transaction (the node refuses these; the wallet does too). */
|
|
166
|
+
| 'multi-contract'
|
|
167
|
+
/** AccountPermissionUpdateContract: changes who controls the account. */
|
|
168
|
+
| 'account-permission';
|
|
169
|
+
/** One flagged problem, with a sentence a wallet can show. */
|
|
170
|
+
interface TronTxWarning {
|
|
171
|
+
code: TronTxWarningCode;
|
|
172
|
+
message: string;
|
|
173
|
+
}
|
|
174
|
+
/** What a transaction does, decoded offline (see `describeTransaction`). Addresses are base58. */
|
|
175
|
+
interface TronTxDescription {
|
|
176
|
+
/** What it does. */
|
|
177
|
+
kind: TronTxKind;
|
|
178
|
+
warnings: TronTxWarning[];
|
|
179
|
+
/** Sender (owner_address) when known. */
|
|
180
|
+
from?: string;
|
|
181
|
+
/** TRX / TRC-20 recipient. */
|
|
182
|
+
to?: string;
|
|
183
|
+
/** sun (TRX) or token base units (TRC-20) or frozen/unfrozen sun. */
|
|
184
|
+
amount?: bigint;
|
|
185
|
+
/** TRC-20 contract. */
|
|
186
|
+
token?: string;
|
|
187
|
+
/** Spender of a TRC-20 approval. */
|
|
188
|
+
spender?: string;
|
|
189
|
+
/** Called contract (contract-call). */
|
|
190
|
+
contract?: string;
|
|
191
|
+
/** 4-byte selector, hex. */
|
|
192
|
+
selector?: string;
|
|
193
|
+
/** sun attached to the call. */
|
|
194
|
+
callValue?: bigint;
|
|
195
|
+
feeLimit?: number;
|
|
196
|
+
/** Decoded memo (`raw_data.data`). */
|
|
197
|
+
memo?: string;
|
|
198
|
+
/** Freeze / unfreeze resource. */
|
|
199
|
+
resource?: 'BANDWIDTH' | 'ENERGY';
|
|
200
|
+
expiration?: number;
|
|
201
|
+
}
|
|
202
|
+
/** Outcome of a confirmed Tron transaction. */
|
|
203
|
+
interface TronReceipt {
|
|
204
|
+
hash: string;
|
|
205
|
+
/** 1 success, 0 failed. */
|
|
206
|
+
status: 0 | 1;
|
|
207
|
+
blockNumber: bigint;
|
|
208
|
+
fee: bigint;
|
|
209
|
+
/** Raw `/wallet/gettransactioninfobyid` payload. */
|
|
210
|
+
raw: Record<string, unknown>;
|
|
211
|
+
}
|
|
212
|
+
/** CAIP-2 ids of the Tron networks, by name. */
|
|
213
|
+
declare const CAIP2_GENESIS: Record<string, string>;
|
|
214
|
+
|
|
215
|
+
/** Why a transaction was refused before signing. */
|
|
216
|
+
type UnsafeTransactionCode = 'expired' | 'expiration-too-far' | 'missing-ref-block' | 'owner-mismatch' | 'zero-address' | 'fee-limit' | 'multi-contract' | 'memo'
|
|
217
|
+
/** `txID` is not sha256(raw_data_hex). */
|
|
218
|
+
| 'txid-mismatch'
|
|
219
|
+
/** The JSON `raw_data` disagrees with the bytes that would be signed. */
|
|
220
|
+
| 'raw-mismatch'
|
|
221
|
+
/** No `raw_data_hex`, or bytes that are not a well-formed Transaction.raw. */
|
|
222
|
+
| 'raw-undecodable'
|
|
223
|
+
/** Bytes a strict protobuf reader would not produce (over-long tag, non-minimal varint, repeated singular field, parameter that does not re-encode to itself): java-tron could read them differently. */
|
|
224
|
+
| 'raw-noncanonical'
|
|
225
|
+
/** A node-built transaction is not what was requested (type, owner, recipient, amount, contract, calldata, call value, fee limit, extra fields) — scan F7. */
|
|
226
|
+
| 'build-mismatch';
|
|
227
|
+
/** A transaction failed a hard check and was not signed. */
|
|
228
|
+
declare class UnsafeTransactionError extends Error {
|
|
229
|
+
readonly code: UnsafeTransactionCode;
|
|
230
|
+
constructor(code: UnsafeTransactionCode, message: string);
|
|
231
|
+
}
|
|
232
|
+
/** A constant call (or balance pre-check) predicted failure; nothing was signed or broadcast. */
|
|
233
|
+
declare class SimulationError extends Error {
|
|
234
|
+
readonly reason: string;
|
|
235
|
+
readonly energy: number;
|
|
236
|
+
constructor(reason: string, energy?: number);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Compressed secp256k1 pubkey → base58 T… address (keccak of X||Y, last 20 bytes, 0x41 prefix, sha256d checksum). */
|
|
240
|
+
declare function addressFromPublicKey(compressed: Uint8Array): string;
|
|
241
|
+
/** True for a hex Tron address (`41` plus 20 bytes, optional `0x`). */
|
|
242
|
+
declare function isHexAddress(a: string): boolean;
|
|
243
|
+
/** Any accepted form → 21-byte hex "41…" (lowercase, no 0x). */
|
|
244
|
+
declare function toHexAddress(address: string): string;
|
|
245
|
+
/** Any accepted form → base58 T… */
|
|
246
|
+
declare function toBase58Address(address: string): string;
|
|
247
|
+
|
|
248
|
+
/** 4-byte selector of "name(type,…)". */
|
|
249
|
+
declare function selector(signature: string): string;
|
|
250
|
+
/** Minimal static ABI encoder: address, uintN/intN, bool, bytes32. Enough for TRC-20 calls. */
|
|
251
|
+
declare function encodeParameters(params: Array<{
|
|
252
|
+
type: string;
|
|
253
|
+
value: unknown;
|
|
254
|
+
}>): string;
|
|
255
|
+
/** A hex word as a bigint (empty hex is 0). */
|
|
256
|
+
declare function decodeUint(hex: string): bigint;
|
|
257
|
+
/** 32-byte ABI word → 21-byte Tron hex address ("41" + last 20 bytes). */
|
|
258
|
+
declare function decodeAddressWord(word: string): string;
|
|
259
|
+
/** Split calldata hex into selector + 32-byte words (partial trailing word dropped). */
|
|
260
|
+
declare function splitCalldata(data: string): {
|
|
261
|
+
selector: string;
|
|
262
|
+
words: string[];
|
|
263
|
+
};
|
|
264
|
+
/** ABI-decode `Error(string)` / `Panic(uint256)` revert data; falls back to the hex itself. */
|
|
265
|
+
declare function decodeRevertReason(hex: string | undefined): string | undefined;
|
|
266
|
+
/** Hex → UTF-8 text when it decodes cleanly, else the hex. */
|
|
267
|
+
declare function hexToText(hex: string): string;
|
|
268
|
+
|
|
269
|
+
/** One transport, or a failover transport over the list. */
|
|
270
|
+
declare function createClient(config: TronConfig): TronFetch | undefined;
|
|
271
|
+
|
|
272
|
+
/** Type guard: a transaction prebuilt by a node or provider (has `txID`). */
|
|
273
|
+
declare const isPrebuilt: (tx: unknown) => tx is TronRawTransaction;
|
|
274
|
+
/** Type guard: a contract call (`functionSelector`). */
|
|
275
|
+
declare const isContractCall: (tx: unknown) => tx is TronContractCall;
|
|
276
|
+
|
|
277
|
+
/** Tron's zero address (20 zero bytes behind the 0x41 prefix). */
|
|
278
|
+
declare const ZERO_ADDRESS = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
279
|
+
/** The all-zero Tron address in hex; value sent there is lost. */
|
|
280
|
+
declare const ZERO_ADDRESS_HEX: string;
|
|
281
|
+
/** What an offline description can be told to sharpen its warnings. */
|
|
282
|
+
interface DescribeContext {
|
|
283
|
+
/**
|
|
284
|
+
* Whether the recipient account already exists on chain. Offline callers do not know;
|
|
285
|
+
* `WalletAccountReadOnlyTron.describeTransactionOnline` fills it from `/wallet/getaccount`.
|
|
286
|
+
*/
|
|
287
|
+
recipientExists?: boolean;
|
|
288
|
+
/** Unix ms "now" for the expiry warning (default Date.now()). */
|
|
289
|
+
now?: number;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* What a transaction does — decoded offline, no network. Works on the three input shapes
|
|
293
|
+
* (`{to, value}`, contract call, node-built raw transaction). Only the `unactivated-recipient`
|
|
294
|
+
* warning needs the chain; pass `ctx.recipientExists` or use `describeTransactionOnline`.
|
|
295
|
+
*/
|
|
296
|
+
declare function describeTransaction(tx: TronTransaction, ctx?: DescribeContext): TronTxDescription;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Fee limit for contract calls when no estimate is available (the simulation itself
|
|
300
|
+
* failed and the caller gave none) — `buildTransaction` otherwise derives it from energy.
|
|
301
|
+
*/
|
|
302
|
+
declare const DEFAULT_FEE_LIMIT_SUN = 15000000;
|
|
303
|
+
/** Head-room over the simulated energy cost when deriving `fee_limit` (×1.2). */
|
|
304
|
+
declare const FEE_LIMIT_MARGIN = 1.2;
|
|
305
|
+
/**
|
|
306
|
+
* Bandwidth points a transaction consumes: its serialized size with signatures plus the 64-byte
|
|
307
|
+
* result reserve.
|
|
308
|
+
*/
|
|
309
|
+
declare function bandwidthPoints(rawDataHex: string, signatures?: number): number;
|
|
310
|
+
interface Resources {
|
|
311
|
+
freeNetLimit?: number;
|
|
312
|
+
freeNetUsed?: number;
|
|
313
|
+
NetLimit?: number;
|
|
314
|
+
NetUsed?: number;
|
|
315
|
+
EnergyLimit?: number;
|
|
316
|
+
EnergyUsed?: number;
|
|
317
|
+
}
|
|
318
|
+
interface ConstantCallResponse {
|
|
319
|
+
Error?: string;
|
|
320
|
+
constant_result?: string[];
|
|
321
|
+
energy_used?: number;
|
|
322
|
+
transaction?: TronRawTransaction;
|
|
323
|
+
result?: {
|
|
324
|
+
result?: boolean;
|
|
325
|
+
code?: string;
|
|
326
|
+
message?: string;
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
/** keccak256("\x19TRON Signed Message:\n" + byteLength + message) — TIP-191 (tronweb `signMessageV2`). */
|
|
330
|
+
declare function hashMessage(message: string | Uint8Array): Uint8Array;
|
|
331
|
+
/** Address that produced a TIP-191 signature (`0x` + r||s||v, v = 27|28 or 0|1), or undefined. */
|
|
332
|
+
declare function recoverMessageAddress(message: string | Uint8Array, signature: string): string | undefined;
|
|
333
|
+
/**
|
|
334
|
+
* A Tron address without a key: TRX and TRC-20 balances, allowances, resources, fee estimates,
|
|
335
|
+
* simulation, receipts and signature checks.
|
|
336
|
+
*/
|
|
337
|
+
declare class WalletAccountReadOnlyTron implements IWalletAccountReadOnly {
|
|
338
|
+
/** base58 T… */
|
|
339
|
+
readonly address: string;
|
|
340
|
+
/** Hex form (`41…`). */
|
|
341
|
+
readonly addressHex: string;
|
|
342
|
+
readonly chain: string;
|
|
343
|
+
protected readonly _config: TronConfig;
|
|
344
|
+
protected readonly _client: TronFetch | undefined;
|
|
345
|
+
constructor(address: string, config?: TronConfig);
|
|
346
|
+
protected requireClient(what: string): TronFetch;
|
|
347
|
+
protected post<T>(path: string, body: unknown, what: string): Promise<T>;
|
|
348
|
+
/** The base58 address. */
|
|
349
|
+
getAddress(): Promise<string>;
|
|
350
|
+
/** TRX balance in sun; 0 for an account that does not exist yet. */
|
|
351
|
+
getBalance(): Promise<bigint>;
|
|
352
|
+
/** Read-only contract call. Returns constant_result hex strings. */
|
|
353
|
+
protected constantCall(contract: string, functionSelector: string, parameters: Array<{
|
|
354
|
+
type: string;
|
|
355
|
+
value: unknown;
|
|
356
|
+
}>, what: string, extra?: Record<string, unknown>): Promise<ConstantCallResponse>;
|
|
357
|
+
/** TRC-20 `balanceOf` in the token's base units. */
|
|
358
|
+
getTokenBalance(token: string): Promise<bigint>;
|
|
359
|
+
/** Several TRC-20 balances in parallel, keyed by the tokens as given. */
|
|
360
|
+
getTokenBalances(tokens: string[]): Promise<Record<string, bigint>>;
|
|
361
|
+
/** TRC-20 `allowance(owner, spender)` in base units. */
|
|
362
|
+
getAllowance(token: string, spender: string): Promise<bigint>;
|
|
363
|
+
/** Does an account exist on chain (`/wallet/getaccount` non-empty)? */
|
|
364
|
+
accountExists(address: string): Promise<boolean>;
|
|
365
|
+
/**
|
|
366
|
+
* Ask the node for `raw_data`. Contract calls are simulated first so `fee_limit`
|
|
367
|
+
* can be derived from the energy they need (×1.2, capped at `transactionMaxFee`)
|
|
368
|
+
* when the caller gives none; the simulation rides along so nobody pays for a second one.
|
|
369
|
+
*/
|
|
370
|
+
protected buildWithSimulation(tx: TronTransaction): Promise<{
|
|
371
|
+
built: TronRawTransaction;
|
|
372
|
+
sim?: TronSimulation;
|
|
373
|
+
}>;
|
|
374
|
+
protected buildTransaction(tx: TronTransaction): Promise<TronRawTransaction>;
|
|
375
|
+
/** Constant call by selector + params (unbuilt contract call). Never throws on a revert. */
|
|
376
|
+
protected simulateCall(tx: TronContractCall): Promise<TronSimulation>;
|
|
377
|
+
private constantSimulation;
|
|
378
|
+
/**
|
|
379
|
+
* Predict the outcome without signing: contract calls run through
|
|
380
|
+
* `/wallet/triggerconstantcontract` (revert reason ABI-decoded); TRX transfers check
|
|
381
|
+
* that the balance covers amount + fees. Transport failures throw, predicted failures don't.
|
|
382
|
+
*/
|
|
383
|
+
simulateTransaction(tx: TronTransaction): Promise<TronSimulation>;
|
|
384
|
+
protected simulateRaw(tx: TronRawTransaction): Promise<TronSimulation>;
|
|
385
|
+
private simulateNativeTransfer;
|
|
386
|
+
protected getResources(): Promise<Resources>;
|
|
387
|
+
protected getChainParameters(): Promise<Record<string, bigint>>;
|
|
388
|
+
protected getChainParameter(key: string): Promise<bigint>;
|
|
389
|
+
/**
|
|
390
|
+
* Resource-by-resource cost of a node-built transaction. `energy` comes from a
|
|
391
|
+
* constant call unless the caller already has one (`sim`).
|
|
392
|
+
*/
|
|
393
|
+
protected estimateRaw(tx: TronRawTransaction, sim?: TronSimulation): Promise<TronFeeEstimate>;
|
|
394
|
+
/** Build (if needed) and price a transaction: bandwidth, energy and the sun the sender burns. */
|
|
395
|
+
estimateFee(tx: TronTransaction): Promise<TronFeeEstimate>;
|
|
396
|
+
protected quoteTransaction(tx: TronRawTransaction, sim?: TronSimulation): Promise<TronQuote>;
|
|
397
|
+
/** `fee` = the sun the sender burns, after staked / free resources. */
|
|
398
|
+
quoteSendTransaction(tx: TronTransaction): Promise<TronQuote>;
|
|
399
|
+
protected trc20TransferParams(recipient: string, amount: bigint | number | string): ({
|
|
400
|
+
type: string;
|
|
401
|
+
value: string;
|
|
402
|
+
} | {
|
|
403
|
+
type: string;
|
|
404
|
+
value: bigint;
|
|
405
|
+
})[];
|
|
406
|
+
protected asTransaction(o: TronTransferOptions): TronTransaction;
|
|
407
|
+
/** Fee of a transfer in sun, including account activation when the recipient is new. */
|
|
408
|
+
quoteTransfer(o: TronTransferOptions): Promise<TronQuote>;
|
|
409
|
+
/** `describeTransaction` plus the `unactivated-recipient` check against the node. */
|
|
410
|
+
describeTransactionOnline(tx: TronTransaction, ctx?: DescribeContext): Promise<TronTxDescription>;
|
|
411
|
+
/** The receipt, or `undefined` while the transaction is unconfirmed. */
|
|
412
|
+
getTransactionReceipt(hash: string): Promise<TronReceipt | undefined>;
|
|
413
|
+
/** Verify a TIP-191 signature produced by `sign` (0x + r||s||v, v = 27|28 or 0|1). */
|
|
414
|
+
verify(message: string | Uint8Array, signature: string): Promise<boolean>;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
interface TronTransferResult extends TransferResult {
|
|
418
|
+
/** Account creation fee included in `fee` (TRX transfer to a new account). */
|
|
419
|
+
activationFee?: bigint;
|
|
420
|
+
estimate?: TronFeeEstimate;
|
|
421
|
+
}
|
|
422
|
+
/** Longest expiration the node accepts for a transaction (`Constant.MAXIMUM_TIME_UNTIL_EXPIRATION`). */
|
|
423
|
+
declare const MAX_EXPIRATION_MS: number;
|
|
424
|
+
/**
|
|
425
|
+
* Signing Tron account. The key lives in a secp256k1 {@link Signer} (a local key
|
|
426
|
+
* zeroized by `dispose()`, or an external hardware / MPC / backend signer). The
|
|
427
|
+
* full node builds `raw_data`; we check it, simulate it, have the signer sign
|
|
428
|
+
* `txID` (= sha256(raw_data)) as recoverable ECDSA (context `tron-tx`) and broadcast.
|
|
429
|
+
*/
|
|
430
|
+
declare class WalletAccountTron extends WalletAccountReadOnlyTron implements IWalletAccount {
|
|
431
|
+
/** ref block / expiration come from the node, so building needs the network. */
|
|
432
|
+
readonly needsNetwork = true;
|
|
433
|
+
/** Derivation path, or `external` for an external signer. */
|
|
434
|
+
readonly path: string;
|
|
435
|
+
/** Compressed secp256k1 key (33 bytes); needed synchronously for the address. */
|
|
436
|
+
readonly publicKey: Uint8Array;
|
|
437
|
+
/** The signer that holds the key. */
|
|
438
|
+
readonly signer: Signer;
|
|
439
|
+
private _disposed;
|
|
440
|
+
private _readOnly;
|
|
441
|
+
constructor(signer: Signer, publicKey: Uint8Array, path: string, config?: TronConfig);
|
|
442
|
+
/** Wrap a raw derived key (takes ownership; zeroized on dispose). Kept for callers that derive themselves. */
|
|
443
|
+
static fromPrivateKey(privateKey: Uint8Array, publicKey: Uint8Array, path: string, config?: TronConfig): WalletAccountTron;
|
|
444
|
+
/** Account index for the standard m/44'/195'/0'/0/i path. */
|
|
445
|
+
get index(): number | undefined;
|
|
446
|
+
private key;
|
|
447
|
+
/** Recoverable secp256k1 signature over a 32-byte digest from the signer: r‖s‖recovery (recovery 0/1). */
|
|
448
|
+
private signDigest;
|
|
449
|
+
/** TIP-191 message signature: 0x + r||s||(27 + recovery) hex (tronweb `signMessageV2` encoding). */
|
|
450
|
+
sign(message: string | Uint8Array): Promise<string>;
|
|
451
|
+
/**
|
|
452
|
+
* Sign a prebuilt transaction (ours or a dApp's) and attach `signature: [r||s||recovery]`
|
|
453
|
+
* (recovery as 00/01, tronweb encoding). The signature covers `sha256(raw_data_hex)`, so
|
|
454
|
+
* that is what is checked and signed: `txID` must equal it, the JSON `raw_data` must agree
|
|
455
|
+
* with the bytes field by field, and the hard checks ({@link assertSafe}) run on the bytes.
|
|
456
|
+
* A transaction whose JSON says "1 TRX to me" while the bytes say otherwise is refused
|
|
457
|
+
* (`raw-mismatch`), as is a `txID` that does not belong to the bytes (`txid-mismatch`).
|
|
458
|
+
*/
|
|
459
|
+
signRaw(tx: TronRawTransaction): Promise<TronRawTransaction>;
|
|
460
|
+
/**
|
|
461
|
+
* Refuse to sign what cannot be right: a foreign owner, a missing or expired
|
|
462
|
+
* (or >24h) expiration, no ref block, more than one contract, a TRX / TRC-20
|
|
463
|
+
* transfer to the zero address (unless `allowBurn`), a `fee_limit` above
|
|
464
|
+
* `transactionMaxFee`.
|
|
465
|
+
*/
|
|
466
|
+
protected assertSafe(tx: TronRawTransaction, now?: number): void;
|
|
467
|
+
private maxFeeCheck;
|
|
468
|
+
/** Build → hard checks → simulate → estimate → fee cap. Shared by sign / send / transfer. */
|
|
469
|
+
private prepare;
|
|
470
|
+
/** Build (via the node), check, simulate and sign; returns broadcast-ready transaction JSON. */
|
|
471
|
+
signTransaction(tx: TronTransaction): Promise<string>;
|
|
472
|
+
private broadcast;
|
|
473
|
+
sendTransaction(tx: TronTransaction | string): Promise<TronTransferResult>;
|
|
474
|
+
/** TRX (no `token`) or TRC-20 `transfer(address,uint256)`. */
|
|
475
|
+
transfer(o: TronTransferOptions): Promise<TronTransferResult>;
|
|
476
|
+
/** The same address as a {@link WalletAccountReadOnlyTron}. */
|
|
477
|
+
toReadOnlyAccount(): IWalletAccountReadOnly;
|
|
478
|
+
/** Dispose the signer (zeroizes a local key). Idempotent. */
|
|
479
|
+
dispose(): void;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Base derivation path; account `i` is at `m/44'/195'/0'/0/i` (TronLink). */
|
|
483
|
+
declare const TRON_BASE_PATH = "m/44'/195'";
|
|
484
|
+
/** The account branch `getAccount(i)` indexes: m/44'/195'/0'/0/i (TronLink default). */
|
|
485
|
+
declare const TRON_ACCOUNT_BRANCH = "m/44'/195'/0'/0";
|
|
486
|
+
/**
|
|
487
|
+
* One seed → Tron accounts at m/44'/195'/0'/0/i (BIP-44; TronLink default).
|
|
488
|
+
* Paths may be relative to m/44'/195' ("0'/0/3") or full.
|
|
489
|
+
*
|
|
490
|
+
* Built with a secp256k1 `Signer` instead of a seed, the manager wraps it:
|
|
491
|
+
* - a derivable `SeedSigner` sitting at `m/44'/195'/0'/0` yields `getAccount(i)` children;
|
|
492
|
+
* - a `SeedSigner` at a leaf, or any external signer, is `getAccount(0)` (path = the
|
|
493
|
+
* signer's path, or 'external'); other indexes/paths throw.
|
|
494
|
+
*/
|
|
495
|
+
declare class WalletManagerTron extends WalletManager<WalletAccountTron, TronConfig> {
|
|
496
|
+
constructor(seedOrSigner: string | Uint8Array | Signer, config?: TronConfig);
|
|
497
|
+
getAccount(index?: number): Promise<WalletAccountTron>;
|
|
498
|
+
getAccountByPath(path: string): Promise<WalletAccountTron>;
|
|
499
|
+
/** Resolve `path` against an injected signer: the signer itself, or a child when it can derive there. */
|
|
500
|
+
private fromSigner;
|
|
501
|
+
/** A read-only account for any address, with this manager's config. */
|
|
502
|
+
getReadOnlyAccount(address: string): WalletAccountReadOnlyTron;
|
|
503
|
+
/** getTransactionFee chain parameter; normal = ×1.1, fast = ×2.0; slow = ×1.0. */
|
|
504
|
+
getFeeRates(): Promise<FeeRates>;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Memo = `Transaction.raw.data` (protobuf field 10, bytes). The full node builds
|
|
509
|
+
* `raw_data_hex` for us; we splice the field in ourselves rather than re-encoding
|
|
510
|
+
* the contracts.
|
|
511
|
+
*
|
|
512
|
+
* Where it goes matters: java-tron recomputes `txID` as sha256 of the raw_data it
|
|
513
|
+
* re-serializes from the parsed message, and protobuf-java writes fields in
|
|
514
|
+
* field-number order. A memo appended after `contract` (field 11) would therefore
|
|
515
|
+
* hash differently on the node than what we signed. So the record is inserted at
|
|
516
|
+
* its canonical position — after every field numbered ≤ 10, before the first > 10
|
|
517
|
+
* (ref_block_bytes 1 … expiration 8, auths 9, DATA 10, contract 11, scripts 12,
|
|
518
|
+
* timestamp 14, fee_limit 18). The JSON we broadcast carries the same bytes as
|
|
519
|
+
* `raw_data.data` (hex), the way tronweb's `addUpdateData` does.
|
|
520
|
+
*/
|
|
521
|
+
declare const MEMO_FIELD = 10;
|
|
522
|
+
/** Upper bound we enforce on a memo (UTF-8 bytes). java-tron bounds only the whole transaction (500 KB); 512 keeps memos cheap and sane. */
|
|
523
|
+
declare const MAX_MEMO_BYTES = 512;
|
|
524
|
+
/**
|
|
525
|
+
* How a memo string becomes `raw_data.data` bytes: 'utf8' (a text memo — THORChain, exchanges) or 'hex' (binary
|
|
526
|
+
* payloads — a Chainflip vault swap's SCALE-encoded note, given as 0x-hex).
|
|
527
|
+
*/
|
|
528
|
+
type MemoEncoding = 'utf8' | 'hex';
|
|
529
|
+
/**
|
|
530
|
+
* Bytes of a memo, from UTF-8 text or `0x` hex.
|
|
531
|
+
*
|
|
532
|
+
* @throws `UnsafeTransactionError` `memo` for invalid hex.
|
|
533
|
+
*/
|
|
534
|
+
declare function memoBytes(memo: string, encoding?: MemoEncoding): Uint8Array;
|
|
535
|
+
/** The wire bytes of a memo record: tag (field 10, length-delimited = 0x52) ‖ varint(len) ‖ the memo bytes. */
|
|
536
|
+
declare function encodeMemoRecord(memo: string, encoding?: MemoEncoding): Uint8Array;
|
|
537
|
+
/**
|
|
538
|
+
* Splice `memo` into a node-built transaction: canonical-position `raw_data` field 10,
|
|
539
|
+
* fresh `txID` = sha256(raw_data), and `raw_data.data` (hex) for the JSON broadcast.
|
|
540
|
+
* A transaction that already carries a memo is refused (the node's own `data` would
|
|
541
|
+
* have to be re-signed anyway and we cannot know which the caller meant).
|
|
542
|
+
*/
|
|
543
|
+
declare function attachMemo(tx: TronRawTransaction, memo: string, encoding?: MemoEncoding): TronRawTransaction;
|
|
544
|
+
|
|
545
|
+
interface Field {
|
|
546
|
+
number: number;
|
|
547
|
+
wire: number;
|
|
548
|
+
value: bigint | Uint8Array;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Bytes that a strict protobuf reader would not produce or that java-tron would read
|
|
552
|
+
* differently from this codec (scan F4). The wallet refuses them rather than guess:
|
|
553
|
+
* protobuf-java keeps only the low 32 bits of an over-long tag, so a field this codec
|
|
554
|
+
* would call "unknown 536870916" is `data` to the node.
|
|
555
|
+
*/
|
|
556
|
+
declare class NonCanonicalError extends Error {
|
|
557
|
+
constructor(message: string);
|
|
558
|
+
}
|
|
559
|
+
/** Every top-level field of a protobuf message, in wire order. Throws on malformed or non-canonical input. */
|
|
560
|
+
declare function readFields(bytes: Uint8Array): Field[];
|
|
561
|
+
/** `protocol.Transaction.Contract.ContractType`. */
|
|
562
|
+
declare const CONTRACT_TYPES: Record<number, string>;
|
|
563
|
+
/** One decoded `Transaction.Contract`. `value` has the node's JSON keys (hex addresses, hex bytes, numbers as JSON numbers or decimal strings). */
|
|
564
|
+
interface TronDecodedContract {
|
|
565
|
+
type: string;
|
|
566
|
+
parameter: {
|
|
567
|
+
value: Record<string, unknown>;
|
|
568
|
+
type_url: string;
|
|
569
|
+
};
|
|
570
|
+
Permission_id?: number;
|
|
571
|
+
/** Field numbers inside the parameter the wallet has no schema for (or the whole parameter when the type is unknown). */
|
|
572
|
+
undecoded: number[];
|
|
573
|
+
}
|
|
574
|
+
/** A transaction's `raw_data`, decoded from its protobuf bytes. */
|
|
575
|
+
interface TronDecodedRaw {
|
|
576
|
+
raw_data: Omit<TronRawTransaction['raw_data'], 'contract'> & {
|
|
577
|
+
contract: TronDecodedContract[];
|
|
578
|
+
ref_block_num?: number;
|
|
579
|
+
};
|
|
580
|
+
/** Top-level `Transaction.raw` field numbers this codec does not know. */
|
|
581
|
+
unknownFields: number[];
|
|
582
|
+
}
|
|
583
|
+
/** Whether the wallet decodes this contract type field by field (otherwise only its owner and raw bytes are known). */
|
|
584
|
+
declare function isDecodedContractType(type: string): boolean;
|
|
585
|
+
/** Decode `Transaction.raw` bytes (or hex). Throws a plain `Error` on malformed input; callers wrap it. */
|
|
586
|
+
declare function decodeRawData(raw: Uint8Array | string): TronDecodedRaw;
|
|
587
|
+
/**
|
|
588
|
+
* Serialize a `raw_data` object the way java-tron does (fields in number order, proto3
|
|
589
|
+
* defaults omitted). Round-trips with {@link decodeRawData}; `sha256` of the result is the txID.
|
|
590
|
+
*/
|
|
591
|
+
declare function encodeRawData(raw: TronRawTransaction['raw_data'] & {
|
|
592
|
+
ref_block_num?: number;
|
|
593
|
+
}): Uint8Array;
|
|
594
|
+
/** Decoded `raw_data` with the exact bytes that are signed and their hash. */
|
|
595
|
+
interface VerifiedRaw extends TronDecodedRaw {
|
|
596
|
+
/** The bytes that get hashed and signed. */
|
|
597
|
+
bytes: Uint8Array;
|
|
598
|
+
/** Lowercase hex sha256 of `bytes` (= the txID the signature is over). */
|
|
599
|
+
txID: string;
|
|
600
|
+
}
|
|
601
|
+
/** First material difference between the dApp's JSON `raw_data` and what the bytes say, or `null`. */
|
|
602
|
+
declare function rawMismatch(json: TronRawTransaction['raw_data'] | undefined, decoded: TronDecodedRaw['raw_data']): string | null;
|
|
603
|
+
/**
|
|
604
|
+
* Everything that must hold before a prebuilt transaction is signed or shown:
|
|
605
|
+
* `raw_data_hex` present and well-formed, `txID == sha256(raw_data_hex)`, and the
|
|
606
|
+
* JSON copy (when there is one) agreeing with the bytes field by field. Returns the
|
|
607
|
+
* decoded bytes; the description and the hard checks run on that, never on the JSON.
|
|
608
|
+
*/
|
|
609
|
+
declare function verifyRawTransaction(tx: TronRawTransaction): VerifiedRaw;
|
|
610
|
+
|
|
611
|
+
/** What the wallet asked the node to build. Addresses in any form; numbers in sun. */
|
|
612
|
+
type ExpectedBuild = {
|
|
613
|
+
type: 'TransferContract';
|
|
614
|
+
owner: string;
|
|
615
|
+
to: string;
|
|
616
|
+
amount: bigint;
|
|
617
|
+
} | {
|
|
618
|
+
type: 'TriggerSmartContract';
|
|
619
|
+
owner: string;
|
|
620
|
+
contract: string;
|
|
621
|
+
/** selector ‖ ABI-encoded parameters, hex (0x optional, any case). */
|
|
622
|
+
data: string;
|
|
623
|
+
callValue: bigint;
|
|
624
|
+
/** The `fee_limit` actually POSTed to `/wallet/triggersmartcontract`. */
|
|
625
|
+
feeLimit: bigint;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Refuse a node-built transaction unless its bytes are exactly one contract of the
|
|
629
|
+
* expected type with the expected owner, recipient / contract, amount / calldata,
|
|
630
|
+
* call value and fee limit — no Permission_id, no TRC-10 token on the call, no second
|
|
631
|
+
* contract, no field the request did not produce. `memo` = the bytes the wallet spliced
|
|
632
|
+
* into `raw_data.data` (none → the field must be absent).
|
|
633
|
+
*/
|
|
634
|
+
declare function assertNodeBuild(tx: TronRawTransaction, expected: ExpectedBuild, memo?: Uint8Array): void;
|
|
635
|
+
|
|
636
|
+
export { CAIP2_GENESIS, CONTRACT_TYPES, DEFAULT_FEE_LIMIT_SUN, type DescribeContext, type ExpectedBuild, FEE_LIMIT_MARGIN, MAX_EXPIRATION_MS, MAX_MEMO_BYTES, MEMO_FIELD, type MemoEncoding, NonCanonicalError, SimulationError, TRON_ACCOUNT_BRANCH, TRON_BASE_PATH, type TronConfig, type TronContractCall, type TronDecodedContract, type TronDecodedRaw, type TronFeeBreakdown, type TronFeeEstimate, type TronFetch, type TronNativeTransfer, type TronProvider, type TronQuote, type TronRawTransaction, type TronReceipt, type TronSimulation, type TronTransaction, type TronTransferOptions, type TronTransferResult, type TronTxDescription, type TronTxKind, type TronTxWarning, type TronTxWarningCode, type UnsafeTransactionCode, UnsafeTransactionError, type VerifiedRaw, WalletAccountReadOnlyTron, WalletAccountTron, WalletManagerTron, ZERO_ADDRESS, ZERO_ADDRESS_HEX, addressFromPublicKey, assertNodeBuild, attachMemo, bandwidthPoints, createClient, decodeAddressWord, decodeRawData, decodeRevertReason, decodeUint, WalletManagerTron as default, describeTransaction, encodeMemoRecord, encodeParameters, encodeRawData, hashMessage, hexToText, isContractCall, isDecodedContractType, isHexAddress, isPrebuilt, memoBytes, rawMismatch, readFields, recoverMessageAddress, selector, splitCalldata, toBase58Address, toHexAddress, verifyRawTransaction };
|