@dynamic-labs-wallet/node-tron 0.0.0 → 1.1.43
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/index.cjs +1182 -0
- package/index.d.ts +1 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +1159 -0
- package/package.json +36 -1
- package/src/client/client.d.ts +178 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/constants.d.ts +37 -0
- package/src/client/constants.d.ts.map +1 -0
- package/src/client/index.d.ts +3 -0
- package/src/client/index.d.ts.map +1 -0
- package/src/index.d.ts +6 -0
- package/src/index.d.ts.map +1 -0
- package/src/types.d.ts +21 -0
- package/src/types.d.ts.map +1 -0
- package/src/utils/deriveTronAddress/deriveTronAddress.d.ts +39 -0
- package/src/utils/deriveTronAddress/deriveTronAddress.d.ts.map +1 -0
- package/src/utils/deriveTronAddress/index.d.ts +2 -0
- package/src/utils/deriveTronAddress/index.d.ts.map +1 -0
- package/src/utils/formatTronMessage/formatTronMessage.d.ts +35 -0
- package/src/utils/formatTronMessage/formatTronMessage.d.ts.map +1 -0
- package/src/utils/formatTronMessage/index.d.ts +2 -0
- package/src/utils/formatTronMessage/index.d.ts.map +1 -0
- package/src/utils/getTronTxId/getTronTxId.d.ts +17 -0
- package/src/utils/getTronTxId/getTronTxId.d.ts.map +1 -0
- package/src/utils/getTronTxId/index.d.ts +2 -0
- package/src/utils/getTronTxId/index.d.ts.map +1 -0
- package/src/utils/index.d.ts +5 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/serializeECDSASignature/index.d.ts +2 -0
- package/src/utils/serializeECDSASignature/index.d.ts.map +1 -0
- package/src/utils/serializeECDSASignature/serializeECDSASignature.d.ts +13 -0
- package/src/utils/serializeECDSASignature/serializeECDSASignature.d.ts.map +1 -0
package/package.json
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs-wallet/node-tron",
|
|
3
|
+
"version": "1.1.43",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@dynamic-labs-wallet/node": "1.1.43",
|
|
8
|
+
"@noble/hashes": "1.7.1",
|
|
9
|
+
"bs58": "^6.0.0"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"nx": {
|
|
15
|
+
"sourceRoot": "packages/node-tron/src",
|
|
16
|
+
"projectType": "library",
|
|
17
|
+
"name": "node-tron",
|
|
18
|
+
"targets": {
|
|
19
|
+
"build": {}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "./index.cjs",
|
|
23
|
+
"module": "./index.esm.js",
|
|
24
|
+
"types": "./index.esm.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./index.esm.d.ts",
|
|
29
|
+
"import": "./index.esm.js",
|
|
30
|
+
"require": "./index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/http-errors": "^2.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { DynamicWalletClient, type DynamicWalletClientProps, type EcdsaKeygenResult, type EcdsaPublicKey, type Ed25519KeygenResult, type ServerKeyShare, type SignMessageContext, type ThresholdSignatureScheme, type WalletApiKeyCreationResult, type WalletMetadata } from '@dynamic-labs-wallet/node';
|
|
2
|
+
import type { TronTransaction } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wallet client for TRON (SLIP-44 coin type 195, secp256k1 / ECDSA).
|
|
5
|
+
*
|
|
6
|
+
* V1 surface: create / signMessage (TIP-191, aka signMessageV2) /
|
|
7
|
+
* signTransaction / importPrivateKey / exportPrivateKey.
|
|
8
|
+
*
|
|
9
|
+
* Networks (Mainnet / Shasta / Nile) share the same address format and
|
|
10
|
+
* keyshare namespace; the network is selected at the broadcast layer via the
|
|
11
|
+
* raw_data the caller assembles against the full node of their choice. See
|
|
12
|
+
* `TRON_NETWORKS` in `./constants`.
|
|
13
|
+
*
|
|
14
|
+
* Address derivation: keccak256 of the uncompressed secp256k1 public key
|
|
15
|
+
* (minus the 0x04 prefix), last 20 bytes, prefixed with 0x41, encoded as
|
|
16
|
+
* Base58Check (`T...`).
|
|
17
|
+
*
|
|
18
|
+
* Transaction signing: SHA-256 of `raw_data_hex` is the digest, sent through
|
|
19
|
+
* the sign path as a pre-hashed (`isFormatted: true`) payload.
|
|
20
|
+
*
|
|
21
|
+
* Message signing (TIP-191): keccak256 of `\x19TRON Signed Message:\n<len><msg>`.
|
|
22
|
+
*/
|
|
23
|
+
export declare class DynamicTronWalletClient extends DynamicWalletClient {
|
|
24
|
+
readonly chainName = "TRON";
|
|
25
|
+
constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, debug, enableMPCAccelerator, logger, }: DynamicWalletClientProps);
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new wallet account.
|
|
28
|
+
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
|
|
29
|
+
* @param password - The password to use for the wallet.
|
|
30
|
+
* @param onError - The function to call if an error occurs.
|
|
31
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service. By default, it is false.
|
|
32
|
+
* @returns The walletMetadata, public key hex, raw public key, and external server key shares.
|
|
33
|
+
*/
|
|
34
|
+
createWalletAccount({ thresholdSignatureScheme, password, onError, backUpToDynamic, }: {
|
|
35
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
36
|
+
password?: string;
|
|
37
|
+
onError?: (error: Error) => void;
|
|
38
|
+
backUpToDynamic?: boolean;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
walletMetadata: WalletMetadata;
|
|
41
|
+
publicKeyHex: string;
|
|
42
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
43
|
+
externalServerKeyShares: ServerKeyShare[];
|
|
44
|
+
externalKeySharesWithBackupStatus: Array<{
|
|
45
|
+
share: ServerKeyShare;
|
|
46
|
+
backedUpToClientKeyShareService: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
} & WalletApiKeyCreationResult>;
|
|
49
|
+
/**
|
|
50
|
+
* TIP-191 personal-sign for TRON. This is the `signMessageV2` surface — there
|
|
51
|
+
* is no V1 legacy message-sign path for TRON.
|
|
52
|
+
*
|
|
53
|
+
* The TIP-191 prefix + keccak256 hashing happens client-side; the resulting
|
|
54
|
+
* 32-byte digest goes through the sign path as `isFormatted: true` (matches
|
|
55
|
+
* the browser TRON client and the EVM pre-hashed contract).
|
|
56
|
+
*
|
|
57
|
+
* @returns `0x`-prefixed `r || s || v` signature with v normalized to 0/1.
|
|
58
|
+
*/
|
|
59
|
+
signMessage({ message, walletMetadata, password, externalServerKeyShares, context, onError, }: {
|
|
60
|
+
message: string;
|
|
61
|
+
walletMetadata: WalletMetadata;
|
|
62
|
+
password?: string;
|
|
63
|
+
externalServerKeyShares?: ServerKeyShare[];
|
|
64
|
+
context?: SignMessageContext;
|
|
65
|
+
onError?: (error: Error) => void;
|
|
66
|
+
}): Promise<`0x${string}`>;
|
|
67
|
+
/**
|
|
68
|
+
* Alias for {@link signMessage} — the TIP-191 sign surface is the only
|
|
69
|
+
* TRON message-sign path (there is no V1 variant for this chain).
|
|
70
|
+
*/
|
|
71
|
+
signMessageV2(args: Parameters<DynamicTronWalletClient['signMessage']>[0]): Promise<`0x${string}`>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the `0x`-prefixed TIP-191 digest that `signMessage` sends to the
|
|
74
|
+
* signer — mirrors the browser client's `prepareSignMessage`.
|
|
75
|
+
*/
|
|
76
|
+
prepareSignMessage({ message }: {
|
|
77
|
+
message: string;
|
|
78
|
+
}): string;
|
|
79
|
+
/**
|
|
80
|
+
* Sign a TRON transaction.
|
|
81
|
+
*
|
|
82
|
+
* The caller supplies the unsigned `raw_data_hex` produced by a TRON full
|
|
83
|
+
* node (e.g. `/wallet/createtransaction` or `/wallet/triggersmartcontract`),
|
|
84
|
+
* either as a parsed `TronTransaction` object or as the JSON string that
|
|
85
|
+
* came back from the full node. The signer hashes those bytes with SHA-256
|
|
86
|
+
* (the TRON `txID`) and signs the digest.
|
|
87
|
+
*
|
|
88
|
+
* Returns the entire signed transaction (with the new signature appended to
|
|
89
|
+
* `transaction.signature[]`) as a JSON string, ready to be passed to the
|
|
90
|
+
* full-node `/wallet/broadcasttransaction` endpoint.
|
|
91
|
+
*/
|
|
92
|
+
signTransaction({ walletMetadata, transaction, password, externalServerKeyShares, context, onError, }: {
|
|
93
|
+
walletMetadata: WalletMetadata;
|
|
94
|
+
transaction: TronTransaction | string;
|
|
95
|
+
password?: string;
|
|
96
|
+
externalServerKeyShares?: ServerKeyShare[];
|
|
97
|
+
context?: SignMessageContext;
|
|
98
|
+
onError?: (error: Error) => void;
|
|
99
|
+
}): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Exports the private key for a given wallet.
|
|
102
|
+
* @returns `0x`-prefixed 32-byte hex private key (tronweb / TronLink format).
|
|
103
|
+
*/
|
|
104
|
+
exportPrivateKey({ walletMetadata, password, externalServerKeyShares, }: {
|
|
105
|
+
walletMetadata: WalletMetadata;
|
|
106
|
+
password?: string;
|
|
107
|
+
externalServerKeyShares?: ServerKeyShare[];
|
|
108
|
+
}): Promise<`0x${string}`>;
|
|
109
|
+
/**
|
|
110
|
+
* `derivationPath` is the JSON-serialized index map that
|
|
111
|
+
* `walletMetadata.derivationPath` carries (e.g. `'{"0":44,"1":195,"2":0,"3":0,"4":0}'`
|
|
112
|
+
* or `'[44,195,0,0,0]'`). BIP-32 strings such as `"m/44'/195'/0'/0/0"` are rejected.
|
|
113
|
+
* Omit it to export without path derivation.
|
|
114
|
+
*/
|
|
115
|
+
offlineExportPrivateKey({ keyShares, derivationPath, }: {
|
|
116
|
+
keyShares: (EcdsaKeygenResult | Ed25519KeygenResult)[];
|
|
117
|
+
derivationPath?: string;
|
|
118
|
+
}): Promise<{
|
|
119
|
+
derivedPrivateKey: string | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Imports a private key.
|
|
123
|
+
* @param privateKey - The private key to import (hex, with or without 0x).
|
|
124
|
+
* @param chainName - The chain name to use for the wallet.
|
|
125
|
+
* @param thresholdSignatureScheme - The threshold signature scheme to use for the wallet.
|
|
126
|
+
* @param password - The password to use for the wallet.
|
|
127
|
+
* @param onError - The function to call if an error occurs.
|
|
128
|
+
* @param backUpToDynamic - Whether to back up the external server key shares to the client share service. By default, it is false.
|
|
129
|
+
* @param publicAddressCheck - Optional TRON address to verify the imported key against.
|
|
130
|
+
* @returns The walletMetadata, public key hex, raw public key, and external server key shares.
|
|
131
|
+
*/
|
|
132
|
+
importPrivateKey({ privateKey, thresholdSignatureScheme, password, backUpToDynamic, onError, publicAddressCheck, }: {
|
|
133
|
+
privateKey: string;
|
|
134
|
+
/** Ignored — imports always create TRON shares. Kept for parity with sibling clients. */
|
|
135
|
+
chainName?: string;
|
|
136
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
137
|
+
password?: string;
|
|
138
|
+
backUpToDynamic?: boolean;
|
|
139
|
+
onError?: (error: Error) => void;
|
|
140
|
+
publicAddressCheck?: string;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
walletMetadata: WalletMetadata;
|
|
143
|
+
publicKeyHex: string;
|
|
144
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
145
|
+
externalServerKeyShares: ServerKeyShare[];
|
|
146
|
+
externalKeySharesWithBackupStatus: Array<{
|
|
147
|
+
share: ServerKeyShare;
|
|
148
|
+
backedUpToClientKeyShareService: boolean;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Derives the TRON Base58Check address from an MPC ECDSA public key.
|
|
153
|
+
*/
|
|
154
|
+
deriveAccountAddress({ rawPublicKey }: {
|
|
155
|
+
rawPublicKey: EcdsaPublicKey;
|
|
156
|
+
}): {
|
|
157
|
+
accountAddress: string;
|
|
158
|
+
publicKeyHex: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Gets all TRON wallets.
|
|
162
|
+
* @returns Array of TRON wallets
|
|
163
|
+
*/
|
|
164
|
+
getTronWallets(): Promise<{
|
|
165
|
+
walletId: string;
|
|
166
|
+
chainName: string;
|
|
167
|
+
accountAddress: string;
|
|
168
|
+
externalServerKeySharesBackupInfo: import("@dynamic-labs-wallet/core").KeyShareBackupInfo;
|
|
169
|
+
externalServerKeyShares: never[];
|
|
170
|
+
derivationPath: string | undefined;
|
|
171
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
172
|
+
}[]>;
|
|
173
|
+
/**
|
|
174
|
+
* Check if the raw public key is a valid ECDSA public key instance.
|
|
175
|
+
*/
|
|
176
|
+
private checkRawPublicKeyInstance;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEnB,KAAK,mBAAmB,EAIxB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,cAAc,EAEpB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAyBnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,uBAAwB,SAAQ,mBAAmB;IAC9D,QAAQ,CAAC,SAAS,UAAU;gBAEhB,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,oBA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,CAAC,EAAE,OAAO,CAAC;QAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,cAAc,CAAC;QAC/B,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;QAC/D,uBAAuB,EAAE,cAAc,EAAE,CAAC;QAC1C,iCAAiC,EAAE,KAAK,CAAC;YACvC,KAAK,EAAE,cAAc,CAAC;YACtB,+BAA+B,EAAE,OAAO,CAAC;SAC1C,CAAC,CAAC;KACJ,CAAC;IAyFF;;OAEG;IACH,oBAAoB,CAAC,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,cAAc,CAAA;KAAE,GAAG;QACxE,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;KACtB;IAQD;;;OAGG;IACG,cAAc;;;;;;;;;IAMpB;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAUlC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const ERROR_KEYGEN_FAILED = "Error with keygen";
|
|
2
|
+
export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating TRON wallet account";
|
|
3
|
+
export declare const ERROR_IMPORT_PRIVATE_KEY = "Error importing private key";
|
|
4
|
+
export declare const ERROR_EXPORT_PRIVATE_KEY = "Error exporting private key";
|
|
5
|
+
export declare const ERROR_SIGN_MESSAGE = "Error signing message";
|
|
6
|
+
export declare const ERROR_SIGN_TRANSACTION = "Error signing transaction";
|
|
7
|
+
export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
|
|
8
|
+
export declare const ERROR_RAW_DATA_HEX_REQUIRED = "Transaction raw_data_hex is required";
|
|
9
|
+
export declare const ERROR_INVALID_RAW_PUBLIC_KEY = "Invalid raw public key instance";
|
|
10
|
+
/**
|
|
11
|
+
* TRON network identifiers.
|
|
12
|
+
*
|
|
13
|
+
* Mainnet, Shasta, and Nile share the same address format and the same MPC
|
|
14
|
+
* keyshare namespace (SLIP-44 coin type 195). They only differ at the RPC /
|
|
15
|
+
* full-node URL level, so the wallet client itself is network-agnostic; the
|
|
16
|
+
* network passes through transactions via the raw_data the caller assembled
|
|
17
|
+
* against the appropriate full-node endpoint.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TRON_NETWORKS: {
|
|
20
|
+
readonly MAINNET: {
|
|
21
|
+
readonly name: "Mainnet";
|
|
22
|
+
readonly rpcUrl: "https://api.trongrid.io";
|
|
23
|
+
readonly chainId: "0x2b6653dc";
|
|
24
|
+
};
|
|
25
|
+
readonly SHASTA: {
|
|
26
|
+
readonly name: "Shasta";
|
|
27
|
+
readonly rpcUrl: "https://api.shasta.trongrid.io";
|
|
28
|
+
readonly chainId: "0x94a9059e";
|
|
29
|
+
};
|
|
30
|
+
readonly NILE: {
|
|
31
|
+
readonly name: "Nile";
|
|
32
|
+
readonly rpcUrl: "https://nile.trongrid.io";
|
|
33
|
+
readonly chainId: "0xcd8690dc";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type TronNetwork = keyof typeof TRON_NETWORKS;
|
|
37
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AAEvD,eAAO,MAAM,2BAA2B,uCAAuC,CAAC;AAEhF,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AAEtE,eAAO,MAAM,wBAAwB,gCAAgC,CAAC;AAEtE,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,eAAO,MAAM,sBAAsB,8BAA8B,CAAC;AAElE,eAAO,MAAM,8BAA8B,gCAAgC,CAAC;AAE5E,eAAO,MAAM,2BAA2B,yCAAyC,CAAC;AAElF,eAAO,MAAM,4BAA4B,oCAAoC,CAAC;AAE9E;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;CAIhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DynamicTronWalletClient } from './client/index.js';
|
|
2
|
+
export { ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_CREATE_WALLET_ACCOUNT, ERROR_EXPORT_PRIVATE_KEY, ERROR_IMPORT_PRIVATE_KEY, ERROR_INVALID_RAW_PUBLIC_KEY, ERROR_KEYGEN_FAILED, ERROR_RAW_DATA_HEX_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_SIGN_TRANSACTION, TRON_NETWORKS, } from './client/index.js';
|
|
3
|
+
export type { TronNetwork } from './client/index.js';
|
|
4
|
+
export { TRON_ADDRESS_PREFIX, deriveTronAddress, isValidTronAddress, decodeTronAddress, tronAddressToHex, TRON_SIGN_MESSAGE_PREFIX, toTronMessageBytes, formatTronMessage, getTronTxId, getTronTxIdHex, serializeECDSASignature, } from './utils/index.js';
|
|
5
|
+
export type { TronTransaction } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unsigned TRON transaction shape, matching the JSON returned by full-node
|
|
3
|
+
* endpoints like `/wallet/createtransaction` or `/wallet/triggersmartcontract`.
|
|
4
|
+
*
|
|
5
|
+
* The wallet client only needs `raw_data_hex` to sign — the rest of the
|
|
6
|
+
* fields are forwarded back to the caller (and on to a TRON full node) so
|
|
7
|
+
* the signed transaction can be broadcast unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export interface TronTransaction {
|
|
10
|
+
/** Pre-computed by the TRON full node; SHA256 of `raw_data_hex` */
|
|
11
|
+
txID?: string;
|
|
12
|
+
/** JSON view of the protobuf raw_data — passthrough for the consumer */
|
|
13
|
+
raw_data?: any;
|
|
14
|
+
/** Hex-encoded protobuf-serialized raw_data (this is what we sign) */
|
|
15
|
+
raw_data_hex: string;
|
|
16
|
+
/** Signatures already attached to the transaction (multi-sig flows) */
|
|
17
|
+
signature?: string[];
|
|
18
|
+
/** Visible flag for TRON address auto-conversion */
|
|
19
|
+
visible?: boolean;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../packages/src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mainnet address prefix byte for TRON addresses. Shasta and Nile testnets
|
|
3
|
+
* use the same prefix; the network is disambiguated at the node/relay layer
|
|
4
|
+
* (TRON does not embed a network byte into the address).
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/tronprotocol/tips/blob/master/tip-21.md
|
|
7
|
+
*/
|
|
8
|
+
export declare const TRON_ADDRESS_PREFIX = 65;
|
|
9
|
+
/**
|
|
10
|
+
* Derive a TRON Base58Check ("T...") address from a secp256k1 public key.
|
|
11
|
+
*
|
|
12
|
+
* TRON addresses are the keccak256 hash of the uncompressed public key
|
|
13
|
+
* (with the leading 0x04 byte stripped), taking the last 20 bytes, prefixed
|
|
14
|
+
* with 0x41, then encoded as Base58Check (SHA256d checksum).
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.com/tronprotocol/tips/blob/master/tip-21.md
|
|
17
|
+
*/
|
|
18
|
+
export declare const deriveTronAddress: ({ publicKeyHex }: {
|
|
19
|
+
publicKeyHex: string;
|
|
20
|
+
}) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Validate a TRON Base58Check address.
|
|
23
|
+
*
|
|
24
|
+
* Performs the full decode + checksum + prefix check, so it rejects EVM
|
|
25
|
+
* `0x...` addresses, malformed Base58, and addresses whose checksum was
|
|
26
|
+
* tampered with.
|
|
27
|
+
*/
|
|
28
|
+
export declare const isValidTronAddress: (address: string) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Decode a TRON Base58Check address to its 21-byte payload (prefix + 20-byte
|
|
31
|
+
* hash). Throws if the checksum doesn't validate.
|
|
32
|
+
*/
|
|
33
|
+
export declare const decodeTronAddress: (address: string) => Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Convert a TRON Base58Check address to its 0x41-prefixed hex form (used in
|
|
36
|
+
* raw transactions).
|
|
37
|
+
*/
|
|
38
|
+
export declare const tronAddressToHex: (address: string) => string;
|
|
39
|
+
//# sourceMappingURL=deriveTronAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deriveTronAddress.d.ts","sourceRoot":"","sources":["../../../src/utils/deriveTronAddress/deriveTronAddress.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,KAAO,CAAC;AAkBxC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,qBAAsB;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,KAAG,MA+B9E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,KAAG,OAsBpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,UAKnD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAa,MAAM,KAAG,MAGlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/deriveTronAddress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TIP-191 personal-sign prefix used by TRON for signed messages.
|
|
3
|
+
*
|
|
4
|
+
* The hash that gets signed is:
|
|
5
|
+
* keccak256("\x19TRON Signed Message:\n" || len(message) || message)
|
|
6
|
+
*
|
|
7
|
+
* where `message` is the raw bytes the user agreed to sign.
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/tronprotocol/tips/blob/master/tip-191.md
|
|
10
|
+
*/
|
|
11
|
+
export declare const TRON_SIGN_MESSAGE_PREFIX = "\u0019TRON Signed Message:\n";
|
|
12
|
+
/**
|
|
13
|
+
* Convert a user-supplied message into the bytes that TIP-191 expects to be
|
|
14
|
+
* hashed.
|
|
15
|
+
*
|
|
16
|
+
* - `string` starting with `0x` → treated as hex bytes
|
|
17
|
+
* - `string` otherwise → treated as utf-8 bytes
|
|
18
|
+
* - `Uint8Array` → passed through
|
|
19
|
+
* - `{ raw: ... }` → mirrors viem's `{ raw }` escape hatch for already-hashed payloads
|
|
20
|
+
*/
|
|
21
|
+
export declare const toTronMessageBytes: (message: string | Uint8Array | {
|
|
22
|
+
raw: string | Uint8Array;
|
|
23
|
+
}) => Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Apply the TIP-191 prefix and return the keccak256 hash that should be
|
|
26
|
+
* signed by the MPC ECDSA flow.
|
|
27
|
+
*
|
|
28
|
+
* Returns a `Uint8Array` (32 bytes). The wallet client hands this to
|
|
29
|
+
* `sign(...)` with `isFormatted: true` so the forward-MPC path sees a
|
|
30
|
+
* pre-hashed payload.
|
|
31
|
+
*/
|
|
32
|
+
export declare const formatTronMessage: (message: string | Uint8Array | {
|
|
33
|
+
raw: string | Uint8Array;
|
|
34
|
+
}) => Uint8Array;
|
|
35
|
+
//# sourceMappingURL=formatTronMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatTronMessage.d.ts","sourceRoot":"","sources":["../../../src/utils/formatTronMessage/formatTronMessage.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,iCAA+B,CAAC;AAWrE;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,GAAG,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,KAAG,UAOhG,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,YAAa,MAAM,GAAG,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,KAAG,UAO/F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/formatTronMessage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TRON transactions are signed over `sha256(raw_data_hex_bytes)`, where
|
|
3
|
+
* `raw_data_hex` is the protobuf-encoded `Transaction.raw` produced by the
|
|
4
|
+
* TRON full node when the unsigned transaction is created.
|
|
5
|
+
*
|
|
6
|
+
* The MPC client never reconstructs the protobuf itself — the caller passes
|
|
7
|
+
* the already-serialized `raw_data_hex` and we hash it deterministically here.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developers.tron.network/docs/transactions
|
|
10
|
+
*/
|
|
11
|
+
export declare const getTronTxId: (rawDataHex: string) => Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Convenience wrapper that returns the txID as a 0x-prefixed hex string
|
|
14
|
+
* (matching the form returned by the TRON full node `/wallet/gettransactioninfobyid`).
|
|
15
|
+
*/
|
|
16
|
+
export declare const getTronTxIdHex: (rawDataHex: string) => string;
|
|
17
|
+
//# sourceMappingURL=getTronTxId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTronTxId.d.ts","sourceRoot":"","sources":["../../../src/utils/getTronTxId/getTronTxId.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,eAAgB,MAAM,KAAG,UAOhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,eAAgB,MAAM,KAAG,MAGnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/getTronTxId/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { TRON_ADDRESS_PREFIX, deriveTronAddress, isValidTronAddress, decodeTronAddress, tronAddressToHex, } from './deriveTronAddress/index.js';
|
|
2
|
+
export { TRON_SIGN_MESSAGE_PREFIX, toTronMessageBytes, formatTronMessage } from './formatTronMessage/index.js';
|
|
3
|
+
export { getTronTxId, getTronTxIdHex } from './getTronTxId/index.js';
|
|
4
|
+
export { serializeECDSASignature } from './serializeECDSASignature/index.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/G,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/serializeECDSASignature/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EcdsaSignature } from '@dynamic-labs-wallet/node';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize an MPC-produced ECDSA signature into the 65-byte
|
|
4
|
+
* `r || s || v` hex form that TRON full nodes expect on
|
|
5
|
+
* `Transaction.signature[0]` and TIP-191 signed messages.
|
|
6
|
+
*
|
|
7
|
+
* TRON canonicalises v to 0 / 1 on the wire (recovery id), while the MPC
|
|
8
|
+
* relay returns v as 27 / 28 (Ethereum legacy convention). We strip the +27
|
|
9
|
+
* offset here so the output is directly usable by TRON tooling without
|
|
10
|
+
* the consumer having to remember the convention.
|
|
11
|
+
*/
|
|
12
|
+
export declare const serializeECDSASignature: (signature: EcdsaSignature) => `0x${string}`;
|
|
13
|
+
//# sourceMappingURL=serializeECDSASignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializeECDSASignature.d.ts","sourceRoot":"","sources":["../../../src/utils/serializeECDSASignature/serializeECDSASignature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,cAAe,cAAc,KAAG,KAAK,MAAM,EAgB9E,CAAC"}
|