Skip to content

Commit cc1fbd7

Browse files
committed
refactor(core): optimize the signing process of Stellar transactions.
1 parent f7e1444 commit cc1fbd7

File tree

14 files changed

+269
-99
lines changed

14 files changed

+269
-99
lines changed

core/embed/rust/librust_qstr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,15 @@ static void _librust_qstrs(void) {
12271227
MP_QSTR_stellar__confirm_operation;
12281228
MP_QSTR_stellar__confirm_stellar;
12291229
MP_QSTR_stellar__confirm_timebounds;
1230+
MP_QSTR_stellar__confirm_transaction_source;
12301231
MP_QSTR_stellar__create_account;
12311232
MP_QSTR_stellar__debited_amount;
12321233
MP_QSTR_stellar__delete;
12331234
MP_QSTR_stellar__delete_passive_offer;
12341235
MP_QSTR_stellar__delete_trust;
12351236
MP_QSTR_stellar__destination;
12361237
MP_QSTR_stellar__exchanges_require_memo;
1238+
MP_QSTR_stellar__extra_transaction_info;
12371239
MP_QSTR_stellar__final_confirm;
12381240
MP_QSTR_stellar__hash;
12391241
MP_QSTR_stellar__high;
@@ -1247,6 +1249,7 @@ static void _librust_qstrs(void) {
12471249
MP_QSTR_stellar__low;
12481250
MP_QSTR_stellar__master_weight;
12491251
MP_QSTR_stellar__medium;
1252+
MP_QSTR_stellar__network;
12501253
MP_QSTR_stellar__new_offer;
12511254
MP_QSTR_stellar__new_passive_offer;
12521255
MP_QSTR_stellar__no_memo_set;
@@ -1267,13 +1270,16 @@ static void _librust_qstrs(void) {
12671270
MP_QSTR_stellar__set_sequence_to_template;
12681271
MP_QSTR_stellar__sign_tx_count_template;
12691272
MP_QSTR_stellar__sign_tx_fee_template;
1273+
MP_QSTR_stellar__signing_with;
12701274
MP_QSTR_stellar__source_account;
12711275
MP_QSTR_stellar__testnet_network;
1276+
MP_QSTR_stellar__transaction_source_diff_warning;
12721277
MP_QSTR_stellar__trusted_account;
12731278
MP_QSTR_stellar__update;
12741279
MP_QSTR_stellar__valid_from;
12751280
MP_QSTR_stellar__valid_to;
12761281
MP_QSTR_stellar__value_sha256;
1282+
MP_QSTR_stellar__verify_issuer;
12771283
MP_QSTR_stellar__wanna_clean_value_key_template;
12781284
MP_QSTR_stellar__your_account;
12791285
MP_QSTR_tezos__baker_address;

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

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

core/mocks/trezortranslate_keys.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,15 @@ class TR:
837837
stellar__confirm_operation: str = "Confirm operation"
838838
stellar__confirm_stellar: str = "Confirm Stellar"
839839
stellar__confirm_timebounds: str = "Confirm timebounds"
840+
stellar__confirm_transaction_source: str = "Confirm transaction source"
840841
stellar__create_account: str = "Create Account"
841842
stellar__debited_amount: str = "Debited amount"
842843
stellar__delete: str = "Delete"
843844
stellar__delete_passive_offer: str = "Delete Passive Offer"
844845
stellar__delete_trust: str = "Delete trust"
845846
stellar__destination: str = "Destination"
846847
stellar__exchanges_require_memo: str = "Important: Many exchanges require a memo when depositing"
848+
stellar__extra_transaction_info: str = "Transaction info"
847849
stellar__final_confirm: str = "Final confirm"
848850
stellar__hash: str = "Hash"
849851
stellar__high: str = "High:"
@@ -857,6 +859,7 @@ class TR:
857859
stellar__low: str = "Low:"
858860
stellar__master_weight: str = "Master Weight:"
859861
stellar__medium: str = "Medium:"
862+
stellar__network: str = "Network"
860863
stellar__new_offer: str = "New Offer"
861864
stellar__new_passive_offer: str = "New Passive Offer"
862865
stellar__no_memo_set: str = "No memo set!"
@@ -877,13 +880,16 @@ class TR:
877880
stellar__set_sequence_to_template: str = "Set sequence to {0}?"
878881
stellar__sign_tx_count_template: str = "Sign this transaction made up of {0}"
879882
stellar__sign_tx_fee_template: str = "and pay {0}\nfor fee?"
883+
stellar__signing_with: str = "Signing with"
880884
stellar__source_account: str = "Source account"
881885
stellar__testnet_network: str = "testnet network"
886+
stellar__transaction_source_diff_warning: str = "Transaction source differs from Trezor account"
882887
stellar__trusted_account: str = "Trusted Account"
883888
stellar__update: str = "Update"
884889
stellar__valid_from: str = "Valid from (UTC)"
885890
stellar__valid_to: str = "Valid to (UTC)"
886891
stellar__value_sha256: str = "Value (SHA-256):"
892+
stellar__verify_issuer: str = "Verify issuer"
887893
stellar__wanna_clean_value_key_template: str = "Do you want to clear value key {0}?"
888894
stellar__your_account: str = " your account"
889895
storage_msg__processing: str = "Processing"

core/src/apps/stellar/layout.py

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,13 @@
1111
from trezor.messages import StellarAsset
1212

1313

14-
async def require_confirm_init(
15-
address: str,
16-
network_passphrase: str,
17-
accounts_match: bool,
18-
) -> None:
19-
description = (
20-
TR.stellar__initialize_signing_with + TR.stellar__your_account
21-
if accounts_match
22-
else ""
23-
)
14+
async def require_confirm_tx_source(tx_source: str):
2415
await layouts.confirm_address(
25-
TR.stellar__confirm_stellar,
26-
address,
27-
description=description,
28-
br_name="confirm_init",
29-
)
30-
31-
# get_network_warning
32-
if network_passphrase == consts.NETWORK_PASSPHRASE_PUBLIC:
33-
network = None
34-
elif network_passphrase == consts.NETWORK_PASSPHRASE_TESTNET:
35-
network = TR.stellar__testnet_network
36-
else:
37-
network = TR.stellar__private_network
38-
39-
if network:
40-
await layouts.confirm_metadata(
41-
"confirm_init_network",
42-
TR.stellar__confirm_network,
43-
TR.stellar__on_network_template,
44-
network,
45-
ButtonRequestType.ConfirmOutput,
46-
)
47-
48-
49-
async def require_confirm_timebounds(start: int, end: int) -> None:
50-
await layouts.confirm_properties(
51-
"confirm_timebounds",
52-
TR.stellar__confirm_timebounds,
53-
(
54-
(
55-
TR.stellar__valid_from,
56-
(
57-
strings.format_timestamp(start)
58-
if start > 0
59-
else TR.stellar__no_restriction
60-
),
61-
),
62-
(
63-
TR.stellar__valid_to,
64-
(
65-
strings.format_timestamp(end)
66-
if end > 0
67-
else TR.stellar__no_restriction
68-
),
69-
),
70-
),
16+
TR.stellar__confirm_transaction_source,
17+
tx_source,
18+
description=TR.stellar__transaction_source_diff_warning,
19+
br_name="confirm_tx_source",
20+
br_code=ButtonRequestType.ConfirmOutput,
7121
)
7222

7323

@@ -89,32 +39,53 @@ async def require_confirm_memo(memo_type: StellarMemoType, memo_text: str) -> No
8939
TR.stellar__no_memo_set,
9040
TR.stellar__exchanges_require_memo,
9141
br_code=ButtonRequestType.ConfirmOutput,
92-
prompt_screen=True,
9342
)
9443

95-
await layouts.confirm_blob(
44+
await layouts.confirm_text(
9645
"confirm_memo",
9746
TR.stellar__confirm_memo,
9847
memo_text,
9948
description,
49+
ButtonRequestType.ConfirmOutput,
10050
)
10151

10252

103-
async def require_confirm_final(fee: int, num_operations: int) -> None:
104-
op_str = strings.format_plural(
105-
"{count} {plural}", num_operations, TR.plurals__transaction_of_x_operations
106-
)
107-
text = (
108-
TR.stellar__sign_tx_count_template.format(op_str)
109-
+ " "
110-
+ TR.stellar__sign_tx_fee_template
111-
)
112-
await layouts.confirm_metadata(
113-
"confirm_final",
114-
TR.stellar__final_confirm,
115-
text,
116-
format_amount(fee),
117-
hold=True,
53+
async def require_confirm_final(
54+
fee: int,
55+
timebonuds: tuple[int, int],
56+
network_passphrase: str,
57+
account_index: int,
58+
account_id: str,
59+
) -> None:
60+
extra_items = []
61+
62+
# Add network info if it is not public
63+
if network_passphrase == consts.NETWORK_PASSPHRASE_PUBLIC:
64+
pass
65+
elif network_passphrase == consts.NETWORK_PASSPHRASE_TESTNET:
66+
extra_items.append(("Network", TR.stellar__testnet_network))
67+
else:
68+
extra_items.append(("Network", TR.stellar__private_network))
69+
70+
# Add timebounds info if they are restricted
71+
timebonuds_start, timebonuds_end = timebonuds
72+
if timebonuds_start > 0:
73+
extra_items.append(
74+
(
75+
TR.stellar__valid_from,
76+
strings.format_timestamp(timebonuds_start),
77+
)
78+
)
79+
if timebonuds_end > 0:
80+
extra_items.append(
81+
(
82+
TR.stellar__valid_to,
83+
strings.format_timestamp(timebonuds_end),
84+
)
85+
)
86+
87+
await layouts.confirm_stellar_tx(
88+
format_amount(fee), account_index, account_id, extra_items
11889
)
11990

12091

core/src/apps/stellar/operations/layout.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
confirm_metadata,
99
confirm_output,
1010
confirm_properties,
11+
should_show_more,
1112
)
1213
from trezor.wire import DataError, ProcessError
13-
14+
from trezor.enums import ButtonRequestType
1415
from ..layout import format_amount
1516

1617
if TYPE_CHECKING:
@@ -82,13 +83,21 @@ async def confirm_change_trust_op(op: StellarChangeTrustOp) -> None:
8283

8384

8485
async def confirm_create_account_op(op: StellarCreateAccountOp) -> None:
85-
await confirm_properties(
86-
"op_create_account",
87-
TR.stellar__create_account,
88-
(
89-
(TR.words__account, op.new_account),
90-
(TR.stellar__initial_balance, format_amount(op.starting_balance)),
91-
),
86+
# The `title` in the `confirm_output` function works on `bolt`,
87+
# while the `description` works on `delizia` and `eckhart`.
88+
await confirm_address(
89+
TR.words__recipient,
90+
op.new_account,
91+
description=TR.stellar__create_account,
92+
br_name="op_create_account_new_account",
93+
br_code=ButtonRequestType.ConfirmOutput,
94+
)
95+
await confirm_amount(
96+
TR.words__amount,
97+
format_amount(op.starting_balance),
98+
TR.stellar__initial_balance,
99+
br_name="op_create_account_starting_balance",
100+
br_code=ButtonRequestType.ConfirmOutput,
92101
)
93102

94103

@@ -223,11 +232,34 @@ async def confirm_path_payment_strict_send_op(
223232

224233

225234
async def confirm_payment_op(op: StellarPaymentOp) -> None:
226-
await confirm_output(
235+
from trezor.enums import StellarAssetType
236+
237+
await confirm_address(
238+
TR.words__recipient,
227239
op.destination_account,
228-
format_amount(op.amount, op.asset),
240+
br_name="op_payment_destination_account",
241+
br_code=ButtonRequestType.ConfirmOutput,
229242
)
230-
await confirm_asset_issuer(op.asset)
243+
244+
amount = format_amount(op.amount, op.asset)
245+
if op.asset.type == StellarAssetType.NATIVE:
246+
await confirm_amount(
247+
TR.words__amount,
248+
amount,
249+
br_name="op_payment_amount",
250+
br_code=ButtonRequestType.ConfirmOutput,
251+
)
252+
else:
253+
# Users can only send assets they've already trusted,
254+
# so we don't display the issuer by default.
255+
if await should_show_more(
256+
TR.words__amount,
257+
((amount, False),),
258+
TR.stellar__verify_issuer,
259+
br_name="op_payment_amount",
260+
br_code=ButtonRequestType.ConfirmOutput,
261+
):
262+
await confirm_asset_issuer(op.asset)
231263

232264

233265
async def confirm_set_options_op(op: StellarSetOptionsOp) -> None:

0 commit comments

Comments
 (0)