@dynamic-labs-wallet/tron 0.0.0 → 1.0.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/index.cjs +1155 -0
- package/index.d.ts +1 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +1123 -0
- package/package.json +35 -1
- package/src/client/client.d.ts +149 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/constants.d.ts +40 -0
- package/src/client/constants.d.ts.map +1 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.d.ts.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.d.ts.map +1 -0
- package/src/types.d.ts +39 -0
- package/src/types.d.ts.map +1 -0
- package/src/utils/deriveTronAddress/deriveTronAddress.d.ts +30 -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 +37 -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,35 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs-wallet/tron",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@dynamic-labs-wallet/browser": "1.0.1",
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "^0.0.984",
|
|
9
|
+
"@noble/hashes": "1.7.1",
|
|
10
|
+
"bs58": "^6.0.0"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"nx": {
|
|
16
|
+
"sourceRoot": "packages/tron/src",
|
|
17
|
+
"projectType": "library",
|
|
18
|
+
"name": "tron",
|
|
19
|
+
"targets": {
|
|
20
|
+
"build": {}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./index.cjs",
|
|
24
|
+
"module": "./index.esm.js",
|
|
25
|
+
"types": "./index.esm.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./index.esm.d.ts",
|
|
30
|
+
"import": "./index.esm.js",
|
|
31
|
+
"require": "./index.cjs",
|
|
32
|
+
"default": "./index.esm.js"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { DynamicWalletClient, type DynamicWalletClientInternalOptions, type DynamicWalletClientProps, type EcdsaKeygenResult, type EcdsaPublicKey, type Ed25519KeygenResult, type RequestWithElevatedAccessToken, type ThresholdSignatureScheme, type TraceContext } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
import type { TronSignMessageContext, TronTransaction } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Wallet client for TRON (SLIP-44 coin type 195, secp256k1 / ECDSA).
|
|
6
|
+
*
|
|
7
|
+
* V1 surface (matches the locked Wave C-1 handoff):
|
|
8
|
+
* - create / signMessageV2 / signTransaction / importPrivateKey / exportPrivateKey
|
|
9
|
+
* - No legacy V1 message signing (`signMessage` returns a TIP-191 result;
|
|
10
|
+
* consumers should call `signMessageV2`).
|
|
11
|
+
* - Networks (Mainnet / Shasta / Nile) share the same address format and
|
|
12
|
+
* keyshare namespace; the network is selected at the broadcast layer
|
|
13
|
+
* via the raw_data the caller assembles against the full node of their
|
|
14
|
+
* choice. See `TRON_NETWORKS` in `./constants`.
|
|
15
|
+
*
|
|
16
|
+
* Address derivation: keccak256 of the uncompressed secp256k1 public key
|
|
17
|
+
* (minus the 0x04 prefix), last 20 bytes, prefixed with 0x41, encoded as
|
|
18
|
+
* Base58Check (`T...`).
|
|
19
|
+
*
|
|
20
|
+
* Transaction signing: SHA-256 of `raw_data_hex` is the digest, sent through
|
|
21
|
+
* the forward-MPC path as a pre-hashed (`isFormatted: true`) payload.
|
|
22
|
+
*
|
|
23
|
+
* Message signing (TIP-191): keccak256 of `\x19TRON Signed Message:\n<len><msg>`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class DynamicTronWalletClient extends DynamicWalletClient {
|
|
26
|
+
readonly chainName = "TRON";
|
|
27
|
+
constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Create a new TRON wallet account using MPC key generation.
|
|
30
|
+
*/
|
|
31
|
+
createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, traceContext, }: {
|
|
32
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
33
|
+
password?: string;
|
|
34
|
+
onError?: (error: Error) => void;
|
|
35
|
+
signedSessionId: string;
|
|
36
|
+
traceContext?: TraceContext;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
accountAddress: string;
|
|
39
|
+
publicKeyHex: string;
|
|
40
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* TIP-191 personal-sign for TRON. This is the `signMessageV2` surface
|
|
44
|
+
* referenced in the rollout — there is no V1 legacy message-sign path.
|
|
45
|
+
*
|
|
46
|
+
* The TIP-191 prefix + keccak256 hashing happens client-side; the resulting
|
|
47
|
+
* 32-byte digest is sent to the forward-MPC relay as `isFormatted: true`
|
|
48
|
+
* (matches the EVM/TEMPO forward-MPC contract).
|
|
49
|
+
*/
|
|
50
|
+
signMessage({ message, accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext, }: {
|
|
51
|
+
message: string;
|
|
52
|
+
accountAddress: string;
|
|
53
|
+
password?: string;
|
|
54
|
+
signedSessionId: string;
|
|
55
|
+
mfaToken?: string;
|
|
56
|
+
elevatedAccessToken?: string;
|
|
57
|
+
context?: SignMessageContext;
|
|
58
|
+
onError?: (error: Error) => void;
|
|
59
|
+
traceContext?: TraceContext;
|
|
60
|
+
}): Promise<`0x${string}`>;
|
|
61
|
+
/**
|
|
62
|
+
* Sign a TRON transaction.
|
|
63
|
+
*
|
|
64
|
+
* The caller supplies the unsigned `raw_data_hex` produced by a TRON full
|
|
65
|
+
* node (e.g. `/wallet/createtransaction` or `/wallet/triggersmartcontract`),
|
|
66
|
+
* either as a parsed `TronTransaction` object or as the JSON string that
|
|
67
|
+
* came back from the full node. The MPC signer hashes those bytes with
|
|
68
|
+
* SHA-256 (the TRON `txID`) and signs the digest.
|
|
69
|
+
*
|
|
70
|
+
* Returns the entire signed transaction (with the new signature appended to
|
|
71
|
+
* `transaction.signature[]`) as a JSON string, ready to be passed to the
|
|
72
|
+
* full-node `/wallet/broadcasttransaction` endpoint. Returning a string
|
|
73
|
+
* (rather than the object) matches the SDK's iframe `signTransaction`
|
|
74
|
+
* contract, which only carries strings over message transport.
|
|
75
|
+
*/
|
|
76
|
+
signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext, }: {
|
|
77
|
+
senderAddress: string;
|
|
78
|
+
transaction: TronTransaction | string;
|
|
79
|
+
password?: string;
|
|
80
|
+
signedSessionId: string;
|
|
81
|
+
mfaToken?: string;
|
|
82
|
+
elevatedAccessToken?: string;
|
|
83
|
+
context?: TronSignMessageContext;
|
|
84
|
+
onError?: (error: Error) => void;
|
|
85
|
+
traceContext?: TraceContext;
|
|
86
|
+
}): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Derive account address from ECDSA public key.
|
|
89
|
+
*
|
|
90
|
+
* TRON addresses are the keccak256 hash of the uncompressed pubkey (minus
|
|
91
|
+
* the 0x04 prefix), last 20 bytes, prefixed with 0x41, then Base58Check
|
|
92
|
+
* encoded.
|
|
93
|
+
*/
|
|
94
|
+
deriveAccountAddress({ rawPublicKey }: {
|
|
95
|
+
rawPublicKey: EcdsaPublicKey;
|
|
96
|
+
}): {
|
|
97
|
+
accountAddress: string;
|
|
98
|
+
publicKeyHex: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Export private key from MPC key shares.
|
|
102
|
+
*
|
|
103
|
+
* TRON uses the raw hex (no encoded prefix) for its private key format,
|
|
104
|
+
* matching what tronweb / TronLink expose. We return it as 0x-prefixed
|
|
105
|
+
* so it round-trips cleanly through `importPrivateKey`.
|
|
106
|
+
*/
|
|
107
|
+
exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext, }: RequestWithElevatedAccessToken<{
|
|
108
|
+
accountAddress: string;
|
|
109
|
+
password?: string;
|
|
110
|
+
signedSessionId: string;
|
|
111
|
+
mfaToken?: string;
|
|
112
|
+
traceContext?: TraceContext;
|
|
113
|
+
}>): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Offline export of private key from key shares.
|
|
116
|
+
*/
|
|
117
|
+
offlineExportPrivateKey({ keyShares, derivationPath, }: {
|
|
118
|
+
keyShares: (EcdsaKeygenResult | Ed25519KeygenResult)[];
|
|
119
|
+
derivationPath?: string;
|
|
120
|
+
}): Promise<{
|
|
121
|
+
derivedPrivateKey: string | undefined;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Import an existing TRON private key into MPC.
|
|
125
|
+
*/
|
|
126
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, signedSessionId, publicAddressCheck, legacyWalletId, }: {
|
|
127
|
+
privateKey: string;
|
|
128
|
+
chainName: string;
|
|
129
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
130
|
+
password?: string;
|
|
131
|
+
onError?: (error: Error) => void;
|
|
132
|
+
signedSessionId: string;
|
|
133
|
+
publicAddressCheck?: string;
|
|
134
|
+
legacyWalletId?: string;
|
|
135
|
+
}): Promise<{
|
|
136
|
+
accountAddress: string;
|
|
137
|
+
publicKeyHex: string;
|
|
138
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Get all TRON wallets known to this client.
|
|
142
|
+
*/
|
|
143
|
+
getTronWallets(): Promise<any>;
|
|
144
|
+
/**
|
|
145
|
+
* Check if the raw public key is a valid ECDSA public key instance.
|
|
146
|
+
*/
|
|
147
|
+
private checkRawPublicKeyInstance;
|
|
148
|
+
}
|
|
149
|
+
//# 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,EAGnB,KAAK,kCAAkC,EACvC,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEnB,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AASrE,OAAO,KAAK,EAAE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pB;;OAEG;IACG,uBAAuB,CAAC,EAC5B,SAAS,EACT,cAAc,GACf,EAAE;QACD,SAAS,EAAE,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,EAAE,CAAC;QACvD,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC;QAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAUtD;;OAEG;IACG,gBAAgB,CAAC,EACrB,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,cAAc,GACf,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC;QACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;KAChE,CAAC;IAwEF;;OAEG;IACG,cAAc;IAMpB;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAUlC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* Chain IDs match TRON's reserved chainId space and are exposed mainly so
|
|
20
|
+
* consumers can build provider configs without re-declaring the constants.
|
|
21
|
+
*/
|
|
22
|
+
export declare const TRON_NETWORKS: {
|
|
23
|
+
readonly MAINNET: {
|
|
24
|
+
readonly name: "Mainnet";
|
|
25
|
+
readonly rpcUrl: "https://api.trongrid.io";
|
|
26
|
+
readonly chainId: "0x2b6653dc";
|
|
27
|
+
};
|
|
28
|
+
readonly SHASTA: {
|
|
29
|
+
readonly name: "Shasta";
|
|
30
|
+
readonly rpcUrl: "https://api.shasta.trongrid.io";
|
|
31
|
+
readonly chainId: "0x94a9059e";
|
|
32
|
+
};
|
|
33
|
+
readonly NILE: {
|
|
34
|
+
readonly name: "Nile";
|
|
35
|
+
readonly rpcUrl: "https://nile.trongrid.io";
|
|
36
|
+
readonly chainId: "0xcd8690dc";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type TronNetwork = keyof typeof TRON_NETWORKS;
|
|
40
|
+
//# 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;;;;;;;;;;;GAWG;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,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DynamicTronWalletClient } from './client/index.js';
|
|
2
|
+
export { TRON_ADDRESS_PREFIX, deriveTronAddress, isValidTronAddress, decodeTronAddress, tronAddressToHex, TRON_SIGN_MESSAGE_PREFIX, toTronMessageBytes, formatTronMessage, getTronTxId, getTronTxIdHex, serializeECDSASignature, } from './utils/index.js';
|
|
3
|
+
export type { TronTransaction, TronTransactionContext, TronSignMessageContext } from './types.js';
|
|
4
|
+
export * as sdkApiCore from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
//# 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,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,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAClG,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC"}
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
/**
|
|
3
|
+
* Unsigned TRON transaction shape, matching the JSON returned by full-node
|
|
4
|
+
* endpoints like `/wallet/createtransaction` or `/wallet/triggersmartcontract`.
|
|
5
|
+
*
|
|
6
|
+
* The wallet client only needs `raw_data_hex` to sign — the rest of the
|
|
7
|
+
* fields are forwarded back to the caller (and on to a TRON full node) so
|
|
8
|
+
* the signed transaction can be broadcast unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export interface TronTransaction {
|
|
11
|
+
/** Pre-computed by the TRON full node; SHA256 of `raw_data_hex` */
|
|
12
|
+
txID?: string;
|
|
13
|
+
/** JSON view of the protobuf raw_data — passthrough for the consumer */
|
|
14
|
+
raw_data?: any;
|
|
15
|
+
/** Hex-encoded protobuf-serialized raw_data (this is what we sign) */
|
|
16
|
+
raw_data_hex: string;
|
|
17
|
+
/** Signatures already attached to the transaction (multi-sig flows) */
|
|
18
|
+
signature?: string[];
|
|
19
|
+
/** Visible flag for TRON address auto-conversion */
|
|
20
|
+
visible?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Context fields forwarded to policy validation for TRON transactions.
|
|
24
|
+
* Kept small in V1 — wallet-service is enum-only for TRON today, so this is
|
|
25
|
+
* mostly informational for client-side logging until validators land.
|
|
26
|
+
*/
|
|
27
|
+
export interface TronTransactionContext {
|
|
28
|
+
/** Hex-encoded raw_data bytes that were hashed */
|
|
29
|
+
rawDataHex: string;
|
|
30
|
+
/** txID (SHA256 of raw_data) as a 0x-prefixed hex string */
|
|
31
|
+
txid: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sign-message context with TRON-specific transaction details attached.
|
|
35
|
+
*/
|
|
36
|
+
export interface TronSignMessageContext extends SignMessageContext {
|
|
37
|
+
tronTransaction?: TronTransactionContext;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../packages/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IAExE,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;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,eAAe,CAAC,EAAE,sBAAsB,CAAC;CAC1C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export declare const deriveTronAddress: ({ publicKeyHex }: {
|
|
10
|
+
publicKeyHex: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Validate a TRON Base58Check address.
|
|
14
|
+
*
|
|
15
|
+
* Performs the full decode + checksum + prefix check, so it rejects EVM
|
|
16
|
+
* `0x...` addresses, malformed Base58, and addresses whose checksum was
|
|
17
|
+
* tampered with.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isValidTronAddress: (address: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Decode a TRON Base58Check address to its 21-byte payload (prefix + 20-byte
|
|
22
|
+
* hash). Throws if the checksum doesn't validate.
|
|
23
|
+
*/
|
|
24
|
+
export declare const decodeTronAddress: (address: string) => Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* Convert a TRON Base58Check address to its 0x41-prefixed hex form (used in
|
|
27
|
+
* raw transactions).
|
|
28
|
+
*/
|
|
29
|
+
export declare const tronAddressToHex: (address: string) => string;
|
|
30
|
+
//# 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;AA8BxC,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,37 @@
|
|
|
1
|
+
import type { ILogger } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
/**
|
|
3
|
+
* TIP-191 personal-sign prefix used by TRON for signed messages.
|
|
4
|
+
*
|
|
5
|
+
* The hash that gets signed is:
|
|
6
|
+
* keccak256("\x19TRON Signed Message:\n" || len(message) || message)
|
|
7
|
+
*
|
|
8
|
+
* where `message` is the raw bytes the user agreed to sign.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/tronprotocol/tips/blob/master/tip-191.md
|
|
11
|
+
*/
|
|
12
|
+
export declare const TRON_SIGN_MESSAGE_PREFIX = "\u0019TRON Signed Message:\n";
|
|
13
|
+
/**
|
|
14
|
+
* Convert a user-supplied message into the bytes that TIP-191 expects to be
|
|
15
|
+
* hashed. Mirrors the shape of `formatTempoMessage` so the wallet client can
|
|
16
|
+
* treat both chains uniformly.
|
|
17
|
+
*
|
|
18
|
+
* - `string` starting with `0x` → treated as hex bytes
|
|
19
|
+
* - `string` otherwise → treated as utf-8 bytes
|
|
20
|
+
* - `Uint8Array` → passed through
|
|
21
|
+
* - `{ raw: ... }` → mirrors viem's `{ raw }` escape hatch for already-hashed payloads
|
|
22
|
+
*/
|
|
23
|
+
export declare const toTronMessageBytes: (message: string | Uint8Array | {
|
|
24
|
+
raw: string | Uint8Array;
|
|
25
|
+
}) => Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Apply the TIP-191 prefix and return the keccak256 hash that should be
|
|
28
|
+
* signed by the MPC ECDSA flow.
|
|
29
|
+
*
|
|
30
|
+
* Returns a `Uint8Array` (32 bytes). The wallet client converts this into a
|
|
31
|
+
* `MessageHash` (`isFormatted: true`) before handing it to `sign(...)` so
|
|
32
|
+
* the forward-MPC path sees a pre-hashed payload.
|
|
33
|
+
*/
|
|
34
|
+
export declare const formatTronMessage: (message: string | Uint8Array | {
|
|
35
|
+
raw: string | Uint8Array;
|
|
36
|
+
}, logger: ILogger) => Uint8Array;
|
|
37
|
+
//# sourceMappingURL=formatTronMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatTronMessage.d.ts","sourceRoot":"","sources":["../../../src/utils/formatTronMessage/formatTronMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAG5D;;;;;;;;;GASG;AACH,eAAO,MAAM,wBAAwB,iCAA+B,CAAC;AAWrE;;;;;;;;;GASG;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,YACnB,MAAM,GAAG,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UACnD,OAAO,KACd,UAYF,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, ILogger } from '@dynamic-labs-wallet/browser';
|
|
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, logger: ILogger) => `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,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAE5E;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,cAAe,cAAc,UAAU,OAAO,KAAG,KAAK,MAAM,EAwB/F,CAAC"}
|