Skip to content

Commit 6cbe6f0

Browse files
committed
feat(core): add chunkify support for Solana SignTx
1 parent 79cac31 commit 6cbe6f0

19 files changed

Lines changed: 133 additions & 23 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/get_address.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
},
1515
{
1616
"parameters": {
17-
"path": "m/44'/501'/0'"
17+
"path": "m/44'/501'/0'",
18+
"chunkify": true
1819
},
1920
"result": {
2021
"expected_address": "4UR47Kp4FxGJiJZZGSPAzXqRgMmZ27oVfGhHoLmcHakE"
2122
}
2223
},
2324
{
2425
"parameters": {
25-
"path": "m/44'/501'/0'/0'"
26+
"path": "m/44'/501'/0'/0'",
27+
"chunkify": false
2628
},
2729
"result": {
2830
"expected_address": "14CCvQzQzHCVgZM3j9soPnXuJXh1RmCfwLVUcdfbZVBS"

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": {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"description": "Authorize",
5151
"parameters": {
5252
"address": "m/44'/501'/0'/0'",
53+
"chunkify": true,
5354
"construct": {
5455
"version": null,
5556
"header": {
@@ -90,6 +91,7 @@
9091
{
9192
"description": "Delegate",
9293
"parameters": {
94+
"chunkify": false,
9395
"address": "m/44'/501'/0'/0'",
9496
"construct": {
9597
"version": null,

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
@@ -308,6 +308,7 @@ async def confirm_system_transfer(
308308
signer_path: list[int],
309309
blockhash: bytes,
310310
verified_payment_request: PaymentRequest | None,
311+
chunkify: bool,
311312
) -> None:
312313
recipient_account = transfer_instruction.recipient_account
313314
if verified_payment_request:
@@ -330,6 +331,7 @@ async def confirm_system_transfer(
330331
recipient=base58.encode(recipient_account[0]),
331332
title=TR.words__recipient,
332333
items=[(TR.words__blockhash, base58.encode(blockhash), True)],
334+
chunkify=chunkify,
333335
)
334336
else:
335337
await confirm_properties(
@@ -350,6 +352,7 @@ async def confirm_token_transfer(
350352
decimals: int,
351353
fee: Fee,
352354
blockhash: bytes,
355+
chunkify: bool,
353356
) -> None:
354357
items: list[StrPropertyType] = []
355358
if token_account != destination_account:
@@ -362,6 +365,7 @@ async def confirm_token_transfer(
362365
recipient=base58.encode(destination_account),
363366
title=TR.words__recipient,
364367
items=items,
368+
chunkify=chunkify,
365369
)
366370

367371
if is_unknown:
@@ -373,6 +377,7 @@ async def confirm_token_transfer(
373377
subtitle=TR.solana__unknown_token,
374378
address=base58.encode(token.mint),
375379
verb=TR.buttons__continue,
380+
chunkify=chunkify,
376381
br_name="confirm_token_address",
377382
br_code=ButtonRequestType.ConfirmOutput,
378383
)
@@ -416,7 +421,7 @@ async def confirm_custom_transaction(
416421
)
417422

418423

419-
async def confirm_stake_withdrawer(withdrawer_account: bytes) -> None:
424+
async def confirm_stake_withdrawer(withdrawer_account: bytes, chunkify: bool) -> None:
420425
await show_danger(
421426
title=TR.words__important,
422427
content=TR.solana__stake_withdrawal_warning,
@@ -427,10 +432,11 @@ async def confirm_stake_withdrawer(withdrawer_account: bytes) -> None:
427432
title=TR.solana__stake_withdrawal_warning_title,
428433
address=base58.encode(withdrawer_account),
429434
br_name="confirm_stake_warning_address",
435+
chunkify=chunkify,
430436
)
431437

432438

433-
async def confirm_claim_recipient(recipient_account: bytes) -> None:
439+
async def confirm_claim_recipient(recipient_account: bytes, chunkify: bool) -> None:
434440
await show_warning(
435441
content=TR.solana__claim_recipient_warning,
436442
br_name="confirm_claim_warning",
@@ -439,6 +445,7 @@ async def confirm_claim_recipient(recipient_account: bytes) -> None:
439445
title=TR.address_details__title_receive_address,
440446
address=base58.encode(recipient_account),
441447
br_name="confirm_claim_warning_address",
448+
chunkify=chunkify,
442449
)
443450

444451

@@ -448,6 +455,7 @@ async def confirm_stake_transaction(
448455
blockhash: bytes,
449456
create: Instruction,
450457
delegate: Instruction,
458+
chunkify: bool,
451459
) -> None:
452460
from trezor.ui.layouts import confirm_solana_staking_tx
453461

@@ -484,13 +492,15 @@ async def confirm_stake_transaction(
484492
fee_item=(fee_title, fee_str, True),
485493
fee_details=fee_items,
486494
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
495+
chunkify=chunkify,
487496
)
488497

489498

490499
async def confirm_unstake_transaction(
491500
fee: Fee,
492501
signer_path: list[int],
493502
blockhash: bytes,
503+
chunkify: bool,
494504
) -> None:
495505
from trezor.ui.layouts import confirm_solana_staking_tx
496506

@@ -507,6 +517,7 @@ async def confirm_unstake_transaction(
507517
fee_item=(fee_title, fee_str, True),
508518
fee_details=fee_items,
509519
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
520+
chunkify=chunkify,
510521
)
511522

512523

@@ -515,6 +526,7 @@ async def confirm_claim_transaction(
515526
signer_path: list[int],
516527
blockhash: bytes,
517528
total_amount: int,
529+
chunkify: bool,
518530
) -> None:
519531
from trezor.ui.layouts import confirm_solana_staking_tx
520532

@@ -534,6 +546,7 @@ async def confirm_claim_transaction(
534546
fee_item=(fee_title, fee_str, True),
535547
fee_details=fee_items,
536548
blockhash_item=(TR.words__blockhash, base58.encode(blockhash), True),
549+
chunkify=chunkify,
537550
)
538551

539552

core/src/apps/solana/predefined_transaction.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ async def try_confirm_token_transfer_transaction(
138138
blockhash: bytes,
139139
additional_info: AdditionalTxInfo,
140140
verified_payment_request: PaymentRequest | None,
141+
chunkify: bool,
141142
) -> bool:
142143
from .definitions import unknown_token
143144
from .layout import confirm_payment_request, confirm_token_transfer
@@ -199,6 +200,7 @@ async def try_confirm_token_transfer_transaction(
199200
transfer_token_instructions[0].decimals,
200201
fee,
201202
blockhash,
203+
chunkify,
202204
)
203205
return True
204206

@@ -211,6 +213,7 @@ async def try_confirm_predefined_transaction(
211213
blockhash: bytes,
212214
additional_info: AdditionalTxInfo,
213215
verified_payment_request: PaymentRequest | None,
216+
chunkify: bool,
214217
) -> bool:
215218
from .layout import confirm_system_transfer
216219
from .transaction.instructions import SystemProgramTransferInstruction
@@ -229,7 +232,12 @@ async def try_confirm_predefined_transaction(
229232
if instructions_count == 1:
230233
if SystemProgramTransferInstruction.is_type_of(instructions[0]):
231234
await confirm_system_transfer(
232-
instructions[0], fee, signer_path, blockhash, verified_payment_request
235+
instructions[0],
236+
fee,
237+
signer_path,
238+
blockhash,
239+
verified_payment_request,
240+
chunkify,
233241
)
234242
return True
235243

@@ -239,6 +247,7 @@ async def try_confirm_predefined_transaction(
239247
signer_path,
240248
signer_public_key,
241249
blockhash,
250+
chunkify,
242251
):
243252
return True
244253

@@ -249,6 +258,7 @@ async def try_confirm_predefined_transaction(
249258
blockhash,
250259
additional_info,
251260
verified_payment_request,
261+
chunkify,
252262
)
253263

254264

@@ -258,6 +268,7 @@ async def try_confirm_staking_transaction(
258268
signer_path: list[int],
259269
signer_public_key: bytes,
260270
blockhash: bytes,
271+
chunkify: bool,
261272
) -> bool:
262273
from .transaction.instructions import (
263274
StakeProgramDeactivateInstruction,
@@ -292,7 +303,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
292303
if signer_public_key != create.base:
293304
return False
294305
if signer_public_key != init.withdrawer:
295-
await confirm_stake_withdrawer(init.withdrawer)
306+
await confirm_stake_withdrawer(init.withdrawer, chunkify)
296307
if signer_public_key != init.staker:
297308
return False
298309
if signer_public_key != delegate.stake_authority[0]:
@@ -318,6 +329,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
318329
blockhash=blockhash,
319330
create=create,
320331
delegate=delegate,
332+
chunkify=chunkify,
321333
)
322334
return True
323335

@@ -329,7 +341,7 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
329341
return False
330342

331343
await confirm_unstake_transaction(
332-
fee=fee, signer_path=signer_path, blockhash=blockhash
344+
fee=fee, signer_path=signer_path, blockhash=blockhash, chunkify=chunkify
333345
)
334346
return True
335347

@@ -343,14 +355,15 @@ def _match_instructions(*expected_types: Type[Instruction]) -> bool:
343355
if is_address_reference(withdraw.recipient_account):
344356
return False
345357
if signer_public_key != withdraw.recipient_account[0]:
346-
await confirm_claim_recipient(withdraw.recipient_account[0])
358+
await confirm_claim_recipient(withdraw.recipient_account[0], chunkify)
347359
total_amount += withdraw.lamports
348360

349361
await confirm_claim_transaction(
350362
fee=fee,
351363
signer_path=signer_path,
352364
blockhash=blockhash,
353365
total_amount=total_amount,
366+
chunkify=chunkify,
354367
)
355368

356369
return True

core/src/apps/solana/sign_tx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ async def sign_tx(
114114
transaction.blockhash,
115115
additional_tx_info,
116116
msg.payment_req,
117+
bool(msg.chunkify),
117118
):
118119
await confirm_instructions(
119120
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.

0 commit comments

Comments
 (0)