Skip to content

Commit a6b78c3

Browse files
committed
feat(common,core,python,tests): add tron TransferContract support.
[no changelog]
1 parent 6bab1c5 commit a6b78c3

File tree

33 files changed

+1857
-27
lines changed

33 files changed

+1857
-27
lines changed

common/protob/messages-tron.proto

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,57 @@ option java_outer_classname = "TrezorMessageTron";
1212
* @next Failure
1313
*/
1414
message TronGetAddress {
15-
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
16-
optional bool show_display = 2; // Optionally show on display before sending the result
17-
optional bool chunkify = 3; // display the address in chunks of 4 characters
15+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
16+
optional bool show_display = 2; // Optionally show on display before sending the result
17+
optional bool chunkify = 3; // display the address in chunks of 4 characters
1818
}
1919

2020
/**
2121
* Response: Contains Tron address derived from device private seed
2222
* @end
2323
*/
2424
message TronAddress {
25-
required string address = 1; // Tron address in Base32 encoding
26-
optional bytes mac = 2; // Address authentication code
25+
required string address = 1; // Tron address in Base32 encoding
26+
optional bytes mac = 2; // Address authentication code
27+
}
28+
29+
/**
30+
* Request: ask device to sign Stellar transaction
31+
* @start
32+
* @next StellarTxOpRequest
33+
*/
34+
message TronSignTx {
35+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
36+
required bytes ref_block_bytes = 2; // The height of the transaction reference block, using the 6th to 8th (exclusive) bytes of the reference block height, a total of 2 bytes
37+
required bytes ref_block_hash = 3; // The hash of the transaction reference block
38+
required sint64 expiration = 4; // Transaction expiration time, beyond which the transaction will no longer be packed
39+
optional bytes data = 5; // Transaction memo. (256 bytes maximum, this is a Trezor limitation, not a Tron protocol limitation)
40+
required sint64 timestamp = 6; // Transaction timestamp, set as the transaction creation time
41+
optional sint64 fee_limit = 7; // The maximum energy cost allowed for the execution of smart contract transactions. Only deploying and triggering smart contract transactions need to be set, others not
42+
}
43+
44+
/**
45+
* Response: device is ready for client to send the next operation
46+
* @next TronTransferContract
47+
*/
48+
message TronContractRequest {
49+
}
50+
51+
/**
52+
* Request: ask device to confirm this operation type
53+
* @next TronSignature
54+
*/
55+
message TronTransferContract {
56+
// https://developers.tron.network/docs/tron-contracttype#2-transfercontract
57+
required string owner_address = 1; // Sender's address
58+
required string to_address = 2; // Recipient's address
59+
required sint64 amount = 3; // Transfer amount (in SUN)
60+
}
61+
62+
/**
63+
* Response: signature for transaction
64+
* @end
65+
*/
66+
message TronSignature {
67+
required bytes signature = 1; // Signature of the transaction
2768
}

common/protob/messages.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ enum MessageType {
336336
// Tron
337337
MessageType_TronGetAddress = 3001 [(wire_in) = true];
338338
MessageType_TronAddress = 3002 [(wire_out) = true];
339+
MessageType_TronSignTx = 3003 [(wire_in) = true];
340+
MessageType_TronSignature = 3004 [(wire_out) = true];
341+
MessageType_TronContractRequest = 3005 [(wire_out) = true];
342+
// https://github.com/tronprotocol/protocol/blob/37bb922a9967bbbef1e84de1c9e5cda56a2d7998/core/Tron.proto#L338-L380
343+
MessageType_TronTransferContract = 3101 [(wire_in) = true];
339344

340345
// Benchmark
341346
MessageType_BenchmarkListNames = 9100 [(bitcoin_only) = true];
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
{
2+
"comment": "raw field is used only for debugging.",
3+
"setup": {
4+
"mnemonic": "all all all all all all all all all all all all",
5+
"passphrase": ""
6+
},
7+
"tests": [
8+
{
9+
"name": "TransferContract",
10+
"parameters": {
11+
"address_n": "m/44'/195'/0'/0/0",
12+
"tx": {
13+
"ref_block_bytes": "e942",
14+
"ref_block_hash": "6394747da9fee421",
15+
"expiration": 1752562632000,
16+
"timestamp": 1752562572000
17+
},
18+
"contract": {
19+
"_message_type": "TronTransferContract",
20+
"owner_address": "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT",
21+
"to_address": "TFz2CJn9CJb8C4i1Gke3jmZX2fRMJxniH2",
22+
"amount": 18123456
23+
},
24+
"raw": {
25+
"visible": false,
26+
"txID": "91813c4e057a4c881d9dc4981f041c33cffb17c41e860a53eb68e7995f5de821",
27+
"raw_data_hex": "0a02e94222086394747da9fee42140c08afee680335a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541f2cd810c48c401d392ead3c6e1e1cb9f57750a5812154141f82674a30ae1328745d08afe2d1a0a2419528318c095d20870e0b5fae68033",
28+
"raw_data": {
29+
"contract": [
30+
{
31+
"parameter": {
32+
"value": {
33+
"to_address": "4141f82674a30ae1328745d08afe2d1a0a24195283",
34+
"owner_address": "41f2cd810c48c401d392ead3c6e1e1cb9f57750a58",
35+
"amount": 18123456
36+
},
37+
"type_url": "type.googleapis.com/protocol.TransferContract"
38+
},
39+
"type": "TransferContract"
40+
}
41+
],
42+
"ref_block_bytes": "e942",
43+
"ref_block_hash": "6394747da9fee421",
44+
"expiration": 1752562632000,
45+
"timestamp": 1752562572000
46+
}
47+
}
48+
},
49+
"result": {
50+
"signature": "a7f8602b02413e9dded0170daa5b4ada9a2679198af276be456f4faea1bc326f5070789bec5e6471de3f726f4fe0c9daced8df183e4a62804db26d5650c59a521C"
51+
}
52+
},
53+
{
54+
"name": "TransferContract_owner_address_not_equals_trezor_account",
55+
"parameters": {
56+
"address_n": "m/44'/195'/0'/0/1",
57+
"tx": {
58+
"ref_block_bytes": "e942",
59+
"ref_block_hash": "6394747da9fee421",
60+
"expiration": 1752562632000,
61+
"timestamp": 1752562572000
62+
},
63+
"contract": {
64+
"_message_type": "TronTransferContract",
65+
"owner_address": "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT",
66+
"to_address": "TFz2CJn9CJb8C4i1Gke3jmZX2fRMJxniH2",
67+
"amount": 18123456
68+
},
69+
"raw": {
70+
"visible": false,
71+
"txID": "91813c4e057a4c881d9dc4981f041c33cffb17c41e860a53eb68e7995f5de821",
72+
"raw_data_hex": "0a02e94222086394747da9fee42140c08afee680335a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541f2cd810c48c401d392ead3c6e1e1cb9f57750a5812154141f82674a30ae1328745d08afe2d1a0a2419528318c095d20870e0b5fae68033",
73+
"raw_data": {
74+
"contract": [
75+
{
76+
"parameter": {
77+
"value": {
78+
"to_address": "4141f82674a30ae1328745d08afe2d1a0a24195283",
79+
"owner_address": "41f2cd810c48c401d392ead3c6e1e1cb9f57750a58",
80+
"amount": 18123456
81+
},
82+
"type_url": "type.googleapis.com/protocol.TransferContract"
83+
},
84+
"type": "TransferContract"
85+
}
86+
],
87+
"ref_block_bytes": "e942",
88+
"ref_block_hash": "6394747da9fee421",
89+
"expiration": 1752562632000,
90+
"timestamp": 1752562572000
91+
}
92+
}
93+
},
94+
"result": {
95+
"signature": "14d5eae24e33eb6af03998ea845f98e105e8a2d3206b12163b11702ed3479f41719f757c50e2d85ab6b41ff28ce9752a6bbb74158b8a1aaffb44a837466d93ba1B"
96+
}
97+
},
98+
{
99+
"name": "TransferContract_amount_int64_max",
100+
"parameters": {
101+
"address_n": "m/44'/195'/0'/0/0",
102+
"tx": {
103+
"ref_block_bytes": "0fc4",
104+
"ref_block_hash": "9643b084bc8b5cde",
105+
"expiration": 1752568944000,
106+
"timestamp": 1752571244333
107+
},
108+
"contract": {
109+
"_message_type": "TronTransferContract",
110+
"owner_address": "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT",
111+
"to_address": "TFz2CJn9CJb8C4i1Gke3jmZX2fRMJxniH2",
112+
"amount": 9223372036854775807
113+
},
114+
"comment": "tornweb JavaScript SDK does not support big integers"
115+
},
116+
"result": {
117+
"signature": "36db819a6c50b8c770ff1067a2753692fa8c8bfa7efde8ddfc2f891f7053d9955f6ffd0ee7d6217b448ac3515d97f6877159b721f2a78da78d1fcc10c1019dd51b"
118+
}
119+
},
120+
{
121+
"name": "Memo_hello_world",
122+
"parameters": {
123+
"address_n": "m/44'/195'/0'/0/0",
124+
"tx": {
125+
"ref_block_bytes": "ea2a",
126+
"ref_block_hash": "d43320ee5a8b677f",
127+
"expiration": 1752563334000,
128+
"timestamp": 1752563274000,
129+
"data": "68656c6c6f20776f726c6421"
130+
},
131+
"contract": {
132+
"_message_type": "TronTransferContract",
133+
"owner_address": "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT",
134+
"to_address": "TFz2CJn9CJb8C4i1Gke3jmZX2fRMJxniH2",
135+
"amount": 18123456
136+
},
137+
"raw": {
138+
"txID": "2b166e72fe1cfb71345d5061d15e10ac2cc5ee3bb85b5ad34a14c9bf112b8372",
139+
"raw_data": {
140+
"data": "68656c6c6f20776f726c6421",
141+
"contract": [
142+
{
143+
"parameter": {
144+
"value": {
145+
"amount": 18123456,
146+
"owner_address": "41f2cd810c48c401d392ead3c6e1e1cb9f57750a58",
147+
"to_address": "4141f82674a30ae1328745d08afe2d1a0a24195283"
148+
},
149+
"type_url": "type.googleapis.com/protocol.TransferContract"
150+
},
151+
"type": "TransferContract"
152+
}
153+
],
154+
"ref_block_bytes": "ea2a",
155+
"ref_block_hash": "d43320ee5a8b677f",
156+
"expiration": 1752563334000,
157+
"timestamp": 1752563274000
158+
},
159+
"raw_data_hex": "0a02ea2a2208d43320ee5a8b677f40f0f6a8e78033520c68656c6c6f20776f726c64215a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541f2cd810c48c401d392ead3c6e1e1cb9f57750a5812154141f82674a30ae1328745d08afe2d1a0a2419528318c095d2087090a2a5e78033",
160+
"visible": false
161+
}
162+
},
163+
"result": {
164+
"signature": "7b43c3e8977db4f5475656eec2e643bf1549d923f29c28c009c85b51556a78602aa0f3f2780cb19655dfa8d4eb2102a3c6b3440ce5b7448a814c860cdc925dd21C"
165+
}
166+
},
167+
{
168+
"name": "Memo_long_hex_string",
169+
"parameters": {
170+
"address_n": "m/44'/195'/0'/0/0",
171+
"tx": {
172+
"ref_block_bytes": "ea54",
173+
"ref_block_hash": "e5ae03970dae489a",
174+
"expiration": 1752563466000,
175+
"timestamp": 1752563406000,
176+
"data": "e7fb3e7e39d4c650449e8d80c2731c4cc7fe0c7888a189a6eb1ead3621729a3ae8578299b2a1a35edf5ce3d9ae732cc4f202a34304900156ab37a78917609ae58dae01cb4de5ed98ff79a56e7f0e41f6042d3a734ae3b438209294a8a1899ddd4dee47c1cc86a0b2bf7d57d8457dfeed5fc2a24cd553c08a831f10a02ce5fb776d287e71e6a1a899ae966a0928f01ce6d3c4b0ee5151872c6dd80fefbfb79cff1949bfb5aba76b624e4c58eadf6c8ad97680e34d50807dc628dce44b39f3f405d5da406eb109cabdfc8c782be22f39c2e8814946e69977781fd66c691416b2785f41b508db37e819257751ee97794a57d7a8db5fb4b2cfce6031b76874922010"
177+
},
178+
"contract": {
179+
"_message_type": "TronTransferContract",
180+
"owner_address": "TY72iA3SBtrds3QLYsS7LwYfkzXwAXCRWT",
181+
"to_address": "TFz2CJn9CJb8C4i1Gke3jmZX2fRMJxniH2",
182+
"amount": 18123456
183+
},
184+
"raw": {
185+
"txID": "005fe60597b52c7d9e021795f084ca7da323f4fc08a406292443ce7a4d480dc5",
186+
"raw_data": {
187+
"data": "e7fb3e7e39d4c650449e8d80c2731c4cc7fe0c7888a189a6eb1ead3621729a3ae8578299b2a1a35edf5ce3d9ae732cc4f202a34304900156ab37a78917609ae58dae01cb4de5ed98ff79a56e7f0e41f6042d3a734ae3b438209294a8a1899ddd4dee47c1cc86a0b2bf7d57d8457dfeed5fc2a24cd553c08a831f10a02ce5fb776d287e71e6a1a899ae966a0928f01ce6d3c4b0ee5151872c6dd80fefbfb79cff1949bfb5aba76b624e4c58eadf6c8ad97680e34d50807dc628dce44b39f3f405d5da406eb109cabdfc8c782be22f39c2e8814946e69977781fd66c691416b2785f41b508db37e819257751ee97794a57d7a8db5fb4b2cfce6031b76874922010",
188+
"contract": [
189+
{
190+
"parameter": {
191+
"value": {
192+
"amount": 18123456,
193+
"owner_address": "41f2cd810c48c401d392ead3c6e1e1cb9f57750a58",
194+
"to_address": "4141f82674a30ae1328745d08afe2d1a0a24195283"
195+
},
196+
"type_url": "type.googleapis.com/protocol.TransferContract"
197+
},
198+
"type": "TransferContract"
199+
}
200+
],
201+
"ref_block_bytes": "ea54",
202+
"ref_block_hash": "e5ae03970dae489a",
203+
"expiration": 1752563466000,
204+
"timestamp": 1752563406000
205+
},
206+
"raw_data_hex": "0a02ea542208e5ae03970dae489a4090feb0e78033528002e7fb3e7e39d4c650449e8d80c2731c4cc7fe0c7888a189a6eb1ead3621729a3ae8578299b2a1a35edf5ce3d9ae732cc4f202a34304900156ab37a78917609ae58dae01cb4de5ed98ff79a56e7f0e41f6042d3a734ae3b438209294a8a1899ddd4dee47c1cc86a0b2bf7d57d8457dfeed5fc2a24cd553c08a831f10a02ce5fb776d287e71e6a1a899ae966a0928f01ce6d3c4b0ee5151872c6dd80fefbfb79cff1949bfb5aba76b624e4c58eadf6c8ad97680e34d50807dc628dce44b39f3f405d5da406eb109cabdfc8c782be22f39c2e8814946e69977781fd66c691416b2785f41b508db37e819257751ee97794a57d7a8db5fb4b2cfce6031b768749220105a68080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541f2cd810c48c401d392ead3c6e1e1cb9f57750a5812154141f82674a30ae1328745d08afe2d1a0a2419528318c095d20870b0a9ade78033",
207+
"visible": false
208+
}
209+
},
210+
"result": {
211+
"signature": "22cc2bf4942334a0ac8d5536f372cb514b0768b32abfa2fa9bdc16067e92ad8313f23848beb7d938134fe829ef2d46409e950b4dea7312977ff1e478b2e5b90a1B"
212+
}
213+
}
214+
]
215+
}

core/embed/rust/librust_qstr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ static void _librust_qstrs(void) {
865865
MP_QSTR_words__instructions;
866866
MP_QSTR_words__keep_it_safe;
867867
MP_QSTR_words__know_what_your_doing;
868+
MP_QSTR_words__memo;
868869
MP_QSTR_words__my_trezor;
869870
MP_QSTR_words__no;
870871
MP_QSTR_words__not_recommended;

core/embed/rust/src/translations/generated/translated_string.rs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/embed/upymod/qstrdefsport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,13 @@ Q(apps.tezos.helpers)
584584
Q(apps.tezos.layout)
585585
Q(apps.tezos.sign_tx)
586586
Q(apps.tron)
587+
Q(apps.tron.consts)
587588
Q(apps.tron.get_address)
588589
Q(apps.tron.helpers)
590+
Q(apps.tron.layout)
591+
Q(apps.tron.serialize)
592+
Q(apps.tron.sign_tx)
593+
Q(apps.tron.writers)
589594
Q(apps.webauthn)
590595
Q(apps.webauthn.add_resident_credential)
591596
Q(apps.webauthn.common)

core/mocks/trezortranslate_keys.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ class TR:
990990
words__instructions: str = "Instructions"
991991
words__keep_it_safe: str = "Keep it safe!"
992992
words__know_what_your_doing: str = "Continue only if you know what you are doing!"
993+
words__memo: str = "Memo"
993994
words__my_trezor: str = "My Trezor"
994995
words__no: str = "No"
995996
words__not_recommended: str = "Not recommended!"

0 commit comments

Comments
 (0)