Skip to content

Commit 4f21ea3

Browse files
committed
feat(core): add chunkify support for Solana SignTx
1 parent ffb3293 commit 4f21ea3

16 files changed

Lines changed: 123 additions & 20 deletions

File tree

common/protob/messages-solana.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ message SolanaSignTx {
7676
required bytes serialized_tx = 2; // serialized tx to be signed
7777
optional SolanaTxAdditionalInfo additional_info = 3;
7878
optional common.PaymentRequest payment_req = 4; // SLIP-24 payment request
79+
optional bool chunkify = 5; // display the address in chunks of 4 characters
7980
}
8081

8182
/**

common/tests/fixtures/solana/sign_tx.compute_budget_program.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"description": "Transfer With Compute Budget Without Heap Confirmation",
7171
"parameters": {
7272
"address": "m/44'/501'/0'/0'",
73+
"chunkify": true,
7374
"construct": {
7475
"version": null,
7576
"header": {
@@ -272,6 +273,7 @@
272273
"description": "Create Stake Account With Compute Budget",
273274
"parameters": {
274275
"address": "m/44'/501'/0'/0'",
276+
"chunkify": true,
275277
"construct": {
276278
"version": null,
277279
"header": {

common/tests/fixtures/solana/sign_tx.predefined_transactions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"description": "Transfer Token - predefined",
99
"parameters": {
1010
"address": "m/44'/501'/0'/0'",
11+
"chunkify": false,
1112
"construct": {
1213
"version": null,
1314
"header": {
@@ -61,6 +62,7 @@
6162
"description": "Transfer Token - predefined - with definitions",
6263
"parameters": {
6364
"address": "m/44'/501'/0'/0'",
65+
"chunkify": true,
6466
"construct": {
6567
"version": null,
6668
"header": {
@@ -119,6 +121,7 @@
119121
"description": "Create Token Account and Transfer Token - predefined",
120122
"parameters": {
121123
"address": "m/44'/501'/0'/0'",
124+
"chunkify": true,
122125
"construct": {
123126
"version": null,
124127
"header": {

core/.changelog.d/3446.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow chunkified recipient address in Solana transactions.

core/src/apps/solana/layout.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ async def confirm_system_transfer(
311311
signer_path: list[int],
312312
blockhash: bytes,
313313
verified_payment_request: PaymentRequest | None,
314+
chunkify: bool,
314315
) -> None:
315316
if verified_payment_request:
316317
await confirm_payment_request(
@@ -327,6 +328,7 @@ async def confirm_system_transfer(
327328
recipient=base58.encode(transfer_instruction.recipient_account[0]),
328329
title=TR.words__recipient,
329330
items=[(TR.words__blockhash, base58.encode(blockhash), True)],
331+
chunkify=chunkify,
330332
)
331333

332334
await confirm_custom_transaction(transfer_instruction.lamports, 9, "SOL", fee)
@@ -341,6 +343,7 @@ async def confirm_token_transfer(
341343
decimals: int,
342344
fee: Fee,
343345
blockhash: bytes,
346+
chunkify: bool,
344347
) -> None:
345348
items: list[StrPropertyType] = []
346349
if token_account != destination_account:
@@ -353,6 +356,7 @@ async def confirm_token_transfer(
353356
recipient=base58.encode(destination_account),
354357
title=TR.words__recipient,
355358
items=items,
359+
chunkify=chunkify,
356360
)
357361

358362
if is_unknown:
@@ -364,6 +368,7 @@ async def confirm_token_transfer(
364368
subtitle=TR.solana__unknown_token,
365369
address=base58.encode(token.mint),
366370
verb=TR.buttons__continue,
371+
chunkify=chunkify,
367372
br_name="confirm_token_address",
368373
br_code=ButtonRequestType.ConfirmOutput,
369374
)
@@ -407,7 +412,7 @@ async def confirm_custom_transaction(
407412
)
408413

409414

410-
async def confirm_stake_withdrawer(withdrawer_account: bytes) -> None:
415+
async def confirm_stake_withdrawer(withdrawer_account: bytes, chunkify: bool) -> None:
411416
await show_danger(
412417
title=TR.words__important,
413418
content=TR.solana__stake_withdrawal_warning,
@@ -418,10 +423,11 @@ async def confirm_stake_withdrawer(withdrawer_account: bytes) -> None:
418423
title=TR.solana__stake_withdrawal_warning_title,
419424
address=base58.encode(withdrawer_account),
420425
br_name="confirm_stake_warning_address",
426+
chunkify=chunkify,
421427
)
422428

423429

424-
async def confirm_claim_recipient(recipient_account: bytes) -> None:
430+
async def confirm_claim_recipient(recipient_account: bytes, chunkify: bool) -> None:
425431
await show_warning(
426432
content=TR.solana__claim_recipient_warning,
427433
br_name="confirm_claim_warning",
@@ -430,6 +436,7 @@ async def confirm_claim_recipient(recipient_account: bytes) -> None:
430436
title=TR.address_details__title_receive_address,
431437
address=base58.encode(recipient_account),
432438
br_name="confirm_claim_warning_address",
439+
chunkify=chunkify,
433440
)
434441

435442

@@ -439,6 +446,7 @@ async def confirm_stake_transaction(
439446
blockhash: bytes,
440447
create: Instruction,
441448
delegate: Instruction,
449+
chunkify: bool,
442450
) -> None:
443451
from trezor.ui.layouts import confirm_solana_staking_tx
444452

@@ -475,13 +483,15 @@ async def confirm_stake_transaction(
475483
fee_item=(fee_title, fee_str, True),
476484
fee_details=fee_items,
477485
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
486+
chunkify=chunkify,
478487
)
479488

480489

481490
async def confirm_unstake_transaction(
482491
fee: Fee,
483492
signer_path: list[int],
484493
blockhash: bytes,
494+
chunkify: bool,
485495
) -> None:
486496
from trezor.ui.layouts import confirm_solana_staking_tx
487497

@@ -498,6 +508,7 @@ async def confirm_unstake_transaction(
498508
fee_item=(fee_title, fee_str, True),
499509
fee_details=fee_items,
500510
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
511+
chunkify=chunkify,
501512
)
502513

503514

@@ -506,6 +517,7 @@ async def confirm_claim_transaction(
506517
signer_path: list[int],
507518
blockhash: bytes,
508519
total_amount: int,
520+
chunkify: bool,
509521
) -> None:
510522
from trezor.ui.layouts import confirm_solana_staking_tx
511523

@@ -525,6 +537,7 @@ async def confirm_claim_transaction(
525537
fee_item=(fee_title, fee_str, True),
526538
fee_details=fee_items,
527539
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
540+
chunkify=chunkify,
528541
)
529542

530543

core/src/apps/solana/predefined_transaction.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ async def try_confirm_token_transfer_transaction(
137137
blockhash: bytes,
138138
additional_info: AdditionalTxInfo,
139139
verified_payment_request: PaymentRequest | None,
140+
chunkify: bool,
140141
) -> bool:
141142
from .definitions import unknown_token
142143
from .layout import confirm_payment_request, confirm_token_transfer
@@ -198,6 +199,7 @@ async def try_confirm_token_transfer_transaction(
198199
transfer_token_instructions[0].decimals,
199200
fee,
200201
blockhash,
202+
chunkify,
201203
)
202204
return True
203205

@@ -210,6 +212,7 @@ async def try_confirm_predefined_transaction(
210212
blockhash: bytes,
211213
additional_info: AdditionalTxInfo,
212214
verified_payment_request: PaymentRequest | None,
215+
chunkify: bool,
213216
) -> bool:
214217
from .layout import confirm_system_transfer
215218
from .transaction.instructions import SystemProgramTransferInstruction
@@ -228,7 +231,12 @@ async def try_confirm_predefined_transaction(
228231
if instructions_count == 1:
229232
if SystemProgramTransferInstruction.is_type_of(instructions[0]):
230233
await confirm_system_transfer(
231-
instructions[0], fee, signer_path, blockhash, verified_payment_request
234+
instructions[0],
235+
fee,
236+
signer_path,
237+
blockhash,
238+
verified_payment_request,
239+
chunkify,
232240
)
233241
return True
234242

@@ -238,6 +246,7 @@ async def try_confirm_predefined_transaction(
238246
signer_path,
239247
signer_public_key,
240248
blockhash,
249+
chunkify,
241250
):
242251
return True
243252

@@ -248,6 +257,7 @@ async def try_confirm_predefined_transaction(
248257
blockhash,
249258
additional_info,
250259
verified_payment_request,
260+
chunkify,
251261
)
252262

253263

@@ -257,6 +267,7 @@ async def try_confirm_staking_transaction(
257267
signer_path: list[int],
258268
signer_public_key: bytes,
259269
blockhash: bytes,
270+
chunkify: bool,
260271
) -> bool:
261272
from .transaction.instructions import (
262273
StakeProgramDeactivateInstruction,
@@ -291,7 +302,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
291302
if signer_public_key != create.base:
292303
return False
293304
if signer_public_key != init.withdrawer:
294-
await confirm_stake_withdrawer(init.withdrawer)
305+
await confirm_stake_withdrawer(init.withdrawer, chunkify)
295306
if signer_public_key != init.staker:
296307
return False
297308
if signer_public_key != delegate.stake_authority[0]:
@@ -312,6 +323,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
312323
blockhash=blockhash,
313324
create=create,
314325
delegate=delegate,
326+
chunkify=chunkify,
315327
)
316328
return True
317329

@@ -323,7 +335,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
323335
return False
324336

325337
await confirm_unstake_transaction(
326-
fee=fee, signer_path=signer_path, blockhash=blockhash
338+
fee=fee, signer_path=signer_path, blockhash=blockhash, chunkify=chunkify
327339
)
328340
return True
329341

@@ -335,14 +347,15 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
335347
if signer_public_key != withdraw.withdrawal_authority[0]:
336348
return False
337349
if signer_public_key != withdraw.recipient_account[0]:
338-
await confirm_claim_recipient(withdraw.recipient_account[0])
350+
await confirm_claim_recipient(withdraw.recipient_account[0], chunkify)
339351
total_amount += withdraw.lamports
340352

341353
await confirm_claim_transaction(
342354
fee=fee,
343355
signer_path=signer_path,
344356
blockhash=blockhash,
345357
total_amount=total_amount,
358+
chunkify=chunkify,
346359
)
347360

348361
return True

core/src/apps/solana/sign_tx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ async def sign_tx(
106106
transaction.blockhash,
107107
additional_tx_info,
108108
msg.payment_req,
109+
bool(msg.chunkify),
109110
):
110111
await confirm_instructions(
111112
address_n, signer_public_key, transaction, additional_tx_info

core/src/trezor/messages.py

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

core/src/trezor/ui/layouts/bolt/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ def confirm_solana_recipient(
14091409
items: Iterable[StrPropertyType] = (),
14101410
br_name: str = "confirm_solana_recipient",
14111411
br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput,
1412+
chunkify: bool = False,
14121413
) -> Awaitable[None]:
14131414
return confirm_value(
14141415
title=title,
@@ -1418,6 +1419,7 @@ def confirm_solana_recipient(
14181419
br_code=br_code,
14191420
verb=TR.buttons__continue,
14201421
info_items=items,
1422+
chunkify=chunkify,
14211423
)
14221424

14231425
def confirm_solana_tx(
@@ -1456,6 +1458,7 @@ async def confirm_solana_staking_tx(
14561458
fee_item: StrPropertyType,
14571459
fee_details: Iterable[StrPropertyType],
14581460
blockhash_item: StrPropertyType,
1461+
chunkify: bool,
14591462
br_name: str = "confirm_solana_staking_tx",
14601463
br_code: ButtonRequestType = ButtonRequestType.SignTx,
14611464
) -> None:
@@ -1471,6 +1474,7 @@ async def confirm_solana_staking_tx(
14711474
value=vote_account,
14721475
verb=TR.buttons__continue,
14731476
info=True,
1477+
chunkify=chunkify,
14741478
)
14751479

14761480
items: list[StrPropertyType] = [

core/src/trezor/ui/layouts/caesar/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,13 +1005,23 @@ def confirm_value(
10051005

10061006
from trezor.ui.layouts.menu import Details, Menu, confirm_with_menu
10071007

1008-
main = trezorui_api.confirm_with_info(
1009-
title=title,
1010-
items=((value, False),),
1011-
verb=verb or TR.buttons__confirm,
1012-
verb_info=INFO_ICON,
1013-
external_menu=True,
1014-
)
1008+
if chunkify:
1009+
main = trezorui_api.confirm_address(
1010+
title=title,
1011+
address=value,
1012+
address_label=None,
1013+
verb=verb or TR.buttons__confirm,
1014+
info_button=True,
1015+
chunkify=chunkify,
1016+
)
1017+
else:
1018+
main = trezorui_api.confirm_with_info(
1019+
title=title,
1020+
items=((value, False),),
1021+
verb=verb or TR.buttons__confirm,
1022+
verb_info=INFO_ICON,
1023+
external_menu=True,
1024+
)
10151025

10161026
def item_factory(
10171027
info_title: str, info_value: str
@@ -1389,6 +1399,7 @@ def confirm_solana_recipient(
13891399
items: Iterable[StrPropertyType] = (),
13901400
br_name: str = "confirm_solana_recipient",
13911401
br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput,
1402+
chunkify: bool = False,
13921403
) -> Awaitable[None]:
13931404
return confirm_value(
13941405
title=title,
@@ -1398,6 +1409,7 @@ def confirm_solana_recipient(
13981409
br_code=br_code,
13991410
verb=TR.buttons__continue,
14001411
info_items=items,
1412+
chunkify=chunkify,
14011413
)
14021414

14031415
def confirm_solana_tx(

0 commit comments

Comments
 (0)