@ -1,47 +1,44 @@
from typing import TYPE_CHECKING
from trezor . enums import StellarAssetType , StellarSignerType
from trezor . messages import (
StellarAccountMergeOp ,
StellarAllowTrustOp ,
StellarAsset ,
StellarBumpSequenceOp ,
StellarChangeTrustOp ,
StellarCreateAccountOp ,
StellarCreatePassiveSellOfferOp ,
StellarManageBuyOfferOp ,
StellarManageDataOp ,
StellarManageSellOfferOp ,
StellarPathPaymentStrictReceiveOp ,
StellarPathPaymentStrictSendOp ,
StellarPaymentOp ,
StellarSetOptionsOp ,
)
from trezor . ui . layouts import (
confirm_address ,
confirm_amount ,
confirm_blob ,
confirm_metadata ,
confirm_output ,
confirm_properties ,
confirm_text ,
)
from trezor . wire import DataError , ProcessError
from . . import consts , helpers
from . . layout import format_amount , format_asset
from . . layout import format_amount
if TYPE_CHECKING :
from trezor . wire import Context
from trezor . messages import (
StellarAccountMergeOp ,
StellarAllowTrustOp ,
StellarAsset ,
StellarBumpSequenceOp ,
StellarChangeTrustOp ,
StellarCreateAccountOp ,
StellarCreatePassiveSellOfferOp ,
StellarManageDataOp ,
StellarManageSellOfferOp ,
StellarPathPaymentStrictReceiveOp ,
StellarPathPaymentStrictSendOp ,
StellarPaymentOp ,
StellarSetOptionsOp ,
StellarManageBuyOfferOp ,
)
async def confirm_source_account ( ctx : Context , source_account : str ) - > None :
await confirm_address (
ctx ,
" Confirm operation " ,
source_account ,
description = " Source account: " ,
br_type = " op_source_account " ,
" Source account: " ,
" op_source_account " ,
)
@ -49,8 +46,8 @@ async def confirm_allow_trust_op(ctx: Context, op: StellarAllowTrustOp) -> None:
await confirm_properties (
ctx ,
" op_allow_trust " ,
title = " Allow trust " if op . is_authorized else " Revoke trust " ,
props = (
" Allow trust " if op . is_authorized else " Revoke trust " ,
(
( " Asset " , op . asset_code ) ,
( " Trusted Account " , op . trusted_account ) ,
) ,
@ -62,8 +59,8 @@ async def confirm_account_merge_op(ctx: Context, op: StellarAccountMergeOp) -> N
ctx ,
" Account Merge " ,
op . destination_account ,
description = " All XLM will be sent to: " ,
br_type = " op_account_merge " ,
" All XLM will be sent to: " ,
" op_account_merge " ,
)
@ -72,18 +69,18 @@ async def confirm_bump_sequence_op(ctx: Context, op: StellarBumpSequenceOp) -> N
ctx ,
" op_bump " ,
" Bump Sequence " ,
content = " Set sequence to {} ? " ,
param = str ( op . bump_to ) ,
" Set sequence to {} ? " ,
str ( op . bump_to ) ,
)
async def confirm_change_trust_op ( ctx : Context , op : StellarChangeTrustOp ) - > None :
await confirm_amount (
ctx ,
title = " Delete trust " if op . limit == 0 else " Add trust " ,
amount= format_amount( op . limit , op . asset ) ,
description = " Limit: " ,
br_type = " op_change_trust " ,
" Delete trust " if op . limit == 0 else " Add trust " ,
format_amount( op . limit , op . asset ) ,
" Limit: " ,
" op_change_trust " ,
)
await confirm_asset_issuer ( ctx , op . asset )
@ -93,7 +90,7 @@ async def confirm_create_account_op(ctx: Context, op: StellarCreateAccountOp) ->
ctx ,
" op_create_account " ,
" Create Account " ,
props = (
(
( " Account " , op . new_account ) ,
( " Initial Balance " , format_amount ( op . starting_balance ) ) ,
) ,
@ -103,10 +100,7 @@ async def confirm_create_account_op(ctx: Context, op: StellarCreateAccountOp) ->
async def confirm_create_passive_sell_offer_op (
ctx : Context , op : StellarCreatePassiveSellOfferOp
) - > None :
if op . amount == 0 :
text = " Delete Passive Offer "
else :
text = " New Passive Offer "
text = " Delete Passive Offer " if op . amount == 0 else " New Passive Offer "
await _confirm_offer ( ctx , text , op )
@ -128,11 +122,7 @@ async def _confirm_manage_offer_op_common(
if op . offer_id == 0 :
text = " New Offer "
else :
if op . amount == 0 :
text = " Delete "
else :
text = " Update "
text + = f " # { op . offer_id } "
text = f " { ' Delete ' if op . amount == 0 else ' Update ' } # { op . offer_id } "
await _confirm_offer ( ctx , text , op )
@ -143,35 +133,41 @@ async def _confirm_offer(
| StellarManageSellOfferOp
| StellarManageBuyOfferOp ,
) - > None :
from trezor . messages import StellarManageBuyOfferOp
from . . layout import format_asset
buying_asset = op . buying_asset # local_cache_attribute
selling_asset = op . selling_asset # local_cache_attribute
if StellarManageBuyOfferOp . is_type_of ( op ) :
buying = ( " Buying: " , format_amount ( op . amount , op . buying_asset ) )
selling = ( " Selling: " , format_asset ( op . selling_asset ) )
buying = ( " Buying: " , format_amount ( op . amount , buying_asset) )
selling = ( " Selling: " , format_asset ( selling_asset) )
price = (
f " Price per { format_asset ( op . selling_asset ) } : " ,
f " Price per { format_asset ( selling_asset) } : " ,
str ( op . price_n / op . price_d ) ,
)
await confirm_properties (
ctx ,
" op_offer " ,
title = title ,
props = ( buying , selling , price ) ,
title ,
( buying , selling , price ) ,
)
else :
selling = ( " Selling: " , format_amount ( op . amount , op. selling_asset) )
buying = ( " Buying: " , format_asset ( op. buying_asset) )
selling = ( " Selling: " , format_amount ( op . amount , selling_asset) )
buying = ( " Buying: " , format_asset ( buying_asset) )
price = (
f " Price per { format_asset ( op. buying_asset) } : " ,
f " Price per { format_asset ( buying_asset) } : " ,
str ( op . price_n / op . price_d ) ,
)
await confirm_properties (
ctx ,
" op_offer " ,
title = title ,
props = ( selling , buying , price ) ,
title ,
( selling , buying , price ) ,
)
await confirm_asset_issuer ( ctx , op. selling_asset)
await confirm_asset_issuer ( ctx , op. buying_asset)
await confirm_asset_issuer ( ctx , selling_asset)
await confirm_asset_issuer ( ctx , buying_asset)
async def confirm_manage_data_op ( ctx : Context , op : StellarManageDataOp ) - > None :
@ -183,7 +179,7 @@ async def confirm_manage_data_op(ctx: Context, op: StellarManageDataOp) -> None:
ctx ,
" op_data " ,
" Set data " ,
props = ( ( " Key: " , op . key ) , ( " Value (SHA-256): " , digest ) ) ,
( ( " Key: " , op . key ) , ( " Value (SHA-256): " , digest ) ) ,
)
else :
await confirm_metadata (
@ -191,7 +187,7 @@ async def confirm_manage_data_op(ctx: Context, op: StellarManageDataOp) -> None:
" op_data " ,
" Clear data " ,
" Do you want to clear value key {} ? " ,
param= op. key ,
op. key ,
)
@ -200,18 +196,18 @@ async def confirm_path_payment_strict_receive_op(
) - > None :
await confirm_output (
ctx ,
address= op. destination_account ,
amount= format_amount( op . destination_amount , op . destination_asset ) ,
op. destination_account ,
format_amount( op . destination_amount , op . destination_asset ) ,
title = " Path Pay " ,
)
await confirm_asset_issuer ( ctx , op . destination_asset )
# confirm what the sender is using to pay
await confirm_amount (
ctx ,
title = " Debited amount " ,
amount= format_amount( op . send_max , op . send_asset ) ,
description = " Pay at most: " ,
br_type = " op_path_payment_strict_receive " ,
" Debited amount " ,
format_amount( op . send_max , op . send_asset ) ,
" Pay at most: " ,
" op_path_payment_strict_receive " ,
)
await confirm_asset_issuer ( ctx , op . send_asset )
@ -221,18 +217,18 @@ async def confirm_path_payment_strict_send_op(
) - > None :
await confirm_output (
ctx ,
address= op. destination_account ,
amount= format_amount( op . destination_min , op . destination_asset ) ,
op. destination_account ,
format_amount( op . destination_min , op . destination_asset ) ,
title = " Path Pay at least " ,
)
await confirm_asset_issuer ( ctx , op . destination_asset )
# confirm what the sender is using to pay
await confirm_amount (
ctx ,
title = " Debited amount " ,
amount= format_amount( op . send_amount , op . send_asset ) ,
description = " Pay: " ,
br_type = " op_path_payment_strict_send " ,
" Debited amount " ,
format_amount( op . send_amount , op . send_asset ) ,
" Pay: " ,
" op_path_payment_strict_send " ,
)
await confirm_asset_issuer ( ctx , op . send_asset )
@ -240,20 +236,24 @@ async def confirm_path_payment_strict_send_op(
async def confirm_payment_op ( ctx : Context , op : StellarPaymentOp ) - > None :
await confirm_output (
ctx ,
address= op. destination_account ,
amount= format_amount( op . amount , op . asset ) ,
op. destination_account ,
format_amount( op . amount , op . asset ) ,
)
await confirm_asset_issuer ( ctx , op . asset )
async def confirm_set_options_op ( ctx : Context , op : StellarSetOptionsOp ) - > None :
from trezor . enums import StellarSignerType
from trezor . ui . layouts import confirm_blob , confirm_text
from . . import helpers
if op . inflation_destination_account :
await confirm_address (
ctx ,
" Inflation " ,
op . inflation_destination_account ,
description = " Destination: " ,
br_type = " op_inflation " ,
" Destination: " ,
" op_inflation " ,
)
if op . clear_flags :
@ -264,17 +264,27 @@ async def confirm_set_options_op(ctx: Context, op: StellarSetOptionsOp) -> None:
t = _format_flags ( op . set_flags )
await confirm_text ( ctx , " op_set_options " , " Set flags " , data = t )
thresholds = _format_thresholds ( op )
thresholds : list [ tuple [ str , str ] ] = [ ]
append = thresholds . append # local_cache_attribute
if op . master_weight is not None :
append ( ( " Master Weight: " , str ( op . master_weight ) ) )
if op . low_threshold is not None :
append ( ( " Low: " , str ( op . low_threshold ) ) )
if op . medium_threshold is not None :
append ( ( " Medium: " , str ( op . medium_threshold ) ) )
if op . high_threshold is not None :
append ( ( " High: " , str ( op . high_threshold ) ) )
if thresholds :
await confirm_properties (
ctx , " op_thresholds " , " Account Thresholds " , props = thresholds
)
await confirm_properties ( ctx , " op_thresholds " , " Account Thresholds " , thresholds )
if op . home_domain :
await confirm_text ( ctx , " op_home_domain " , " Home Domain " , op . home_domain )
signer_type = op . signer_type # local_cache_attribute
signer_key = op . signer_key # local_cache_attribute
if op . signer_type is not None :
if op . signer_key is None or op . signer_weight is None :
if signer_type is not None :
if signer_key is None or op . signer_weight is None :
raise DataError ( " Stellar: invalid signer option data. " )
if op . signer_weight > 0 :
@ -282,15 +292,15 @@ async def confirm_set_options_op(ctx: Context, op: StellarSetOptionsOp) -> None:
else :
title = " Remove Signer "
data : str | bytes = " "
if op. signer_type == StellarSignerType . ACCOUNT :
if signer_type == StellarSignerType . ACCOUNT :
description = " Account: "
data = helpers . address_from_public_key ( op. signer_key)
elif op. signer_type == StellarSignerType . PRE_AUTH :
data = helpers . address_from_public_key ( signer_key)
elif signer_type == StellarSignerType . PRE_AUTH :
description = " Pre-auth transaction: "
data = op. signer_key
elif op. signer_type == StellarSignerType . HASH :
data = signer_key
elif signer_type == StellarSignerType . HASH :
description = " Hash: "
data = op. signer_key
data = signer_key
else :
raise ProcessError ( " Stellar: invalid signer type " )
@ -303,20 +313,9 @@ async def confirm_set_options_op(ctx: Context, op: StellarSetOptionsOp) -> None:
)
def _format_thresholds ( op : StellarSetOptionsOp ) - > list [ tuple [ str , str ] ] :
props = [ ]
if op . master_weight is not None :
props . append ( ( " Master Weight: " , str ( op . master_weight ) ) )
if op . low_threshold is not None :
props . append ( ( " Low: " , str ( op . low_threshold ) ) )
if op . medium_threshold is not None :
props . append ( ( " Medium: " , str ( op . medium_threshold ) ) )
if op . high_threshold is not None :
props . append ( ( " High: " , str ( op . high_threshold ) ) )
return props
def _format_flags ( flags : int ) - > str :
from . . import consts
if flags > consts . FLAGS_MAX_SIZE :
raise ProcessError ( " Stellar: invalid flags " )
flags_set = [ ]
@ -330,6 +329,8 @@ def _format_flags(flags: int) -> str:
async def confirm_asset_issuer ( ctx : Context , asset : StellarAsset ) - > None :
from trezor . enums import StellarAssetType
if asset . type == StellarAssetType . NATIVE :
return
if asset . issuer is None or asset . code is None :
@ -338,6 +339,6 @@ async def confirm_asset_issuer(ctx: Context, asset: StellarAsset) -> None:
ctx ,
" Confirm Issuer " ,
asset . issuer ,
description = f " { asset . code } issuer: " ,
br_type = " confirm_asset_issuer " ,
f " { asset . code } issuer: " ,
" confirm_asset_issuer " ,
)