diff --git a/src/apps/wallet/get_address.py b/src/apps/wallet/get_address.py index 04854246be..6a9c0ca257 100644 --- a/src/apps/wallet/get_address.py +++ b/src/apps/wallet/get_address.py @@ -11,7 +11,7 @@ async def get_address(ctx, msg): node = await seed.derive_node(ctx, msg.address_n) address = addresses.get_address(msg.script_type, coin, node, msg.multisig) - address_short = address[len(coin.cashaddr_prefix) + 1:] if coin.cashaddr_prefix is not None else address + address_short = addresses.address_short(coin, address) if msg.show_display: while True: diff --git a/src/apps/wallet/sign_tx/addresses.py b/src/apps/wallet/sign_tx/addresses.py index aebd7c50cd..f5929a1bcc 100644 --- a/src/apps/wallet/sign_tx/addresses.py +++ b/src/apps/wallet/sign_tx/addresses.py @@ -174,3 +174,10 @@ def ecdsa_hash_pubkey(pubkey: bytes) -> bytes: h = sha256(pubkey).digest() h = ripemd160(h).digest() return h + + +def address_short(coin: CoinInfo, address: str) -> str: + if coin.cashaddr_prefix is not None and address.startswith(coin.cashaddr_prefix + ':'): + return address[len(coin.cashaddr_prefix) + 1:] + else: + return address diff --git a/src/apps/wallet/sign_tx/layout.py b/src/apps/wallet/sign_tx/layout.py index 852698786d..d8824a2334 100644 --- a/src/apps/wallet/sign_tx/layout.py +++ b/src/apps/wallet/sign_tx/layout.py @@ -6,6 +6,7 @@ from trezor.messages import ButtonRequestType from trezor.messages import OutputScriptType from apps.common.confirm import confirm from apps.common.confirm import hold_to_confirm +from apps.wallet.sign_tx import addresses def format_coin_amount(amount, coin): @@ -29,7 +30,7 @@ async def confirm_output(ctx, output, coin): ui.MONO, *split_op_return(data), icon_color=ui.GREEN) else: address = output.address - address_short = address[len(coin.cashaddr_prefix) + 1:] if coin.cashaddr_prefix is not None and address.startswith(coin.cashaddr_prefix + ':') else address + address_short = addresses.address_short(coin, address) content = Text('Confirm sending', ui.ICON_SEND, ui.NORMAL, format_coin_amount(output.amount, coin) + ' to', ui.MONO, *split_address(address_short), icon_color=ui.GREEN) diff --git a/src/apps/wallet/verify_message.py b/src/apps/wallet/verify_message.py index 38f81f7e43..cd5ea10cf6 100644 --- a/src/apps/wallet/verify_message.py +++ b/src/apps/wallet/verify_message.py @@ -7,7 +7,7 @@ from apps.common import coins from apps.common.confirm import require_confirm from apps.common.display_address import split_address from apps.common.signverify import message_digest, split_message -from apps.wallet.sign_tx.addresses import address_pkh, address_p2wpkh_in_p2sh, address_p2wpkh, address_to_cashaddr +from apps.wallet.sign_tx.addresses import address_pkh, address_p2wpkh_in_p2sh, address_p2wpkh, address_to_cashaddr, address_short async def verify_message(ctx, msg): @@ -51,9 +51,7 @@ async def verify_message(ctx, msg): if addr != address: raise wire.ProcessError('Invalid signature') - address_short = address[len(coin.cashaddr_prefix) + 1:] if coin.cashaddr_prefix is not None else address - - await require_confirm_verify_message(ctx, address_short, message) + await require_confirm_verify_message(ctx, address_short(coin, address), message) return Success(message='Message verified') diff --git a/src/trezor/messages/MessageType.py b/src/trezor/messages/MessageType.py index bed0c35415..e927e9a4f7 100644 --- a/src/trezor/messages/MessageType.py +++ b/src/trezor/messages/MessageType.py @@ -97,6 +97,8 @@ StellarGetPublicKey = 200 StellarPublicKey = 201 StellarSignTx = 202 StellarTxOpRequest = 203 +StellarGetAddress = 207 +StellarAddress = 208 StellarCreateAccountOp = 210 StellarPaymentOp = 211 StellarPathPaymentOp = 212 diff --git a/src/trezor/messages/StellarAccountMergeOp.py b/src/trezor/messages/StellarAccountMergeOp.py index 474a96e878..30e15e4280 100644 --- a/src/trezor/messages/StellarAccountMergeOp.py +++ b/src/trezor/messages/StellarAccountMergeOp.py @@ -5,14 +5,14 @@ import protobuf as p class StellarAccountMergeOp(p.MessageType): MESSAGE_WIRE_TYPE = 218 FIELDS = { - 1: ('source_account', p.BytesType, 0), - 2: ('destination_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), + 2: ('destination_account', p.UnicodeType, 0), } def __init__( self, - source_account: bytes = None, - destination_account: bytes = None + source_account: str = None, + destination_account: str = None ) -> None: self.source_account = source_account self.destination_account = destination_account diff --git a/src/trezor/messages/StellarAddress.py b/src/trezor/messages/StellarAddress.py new file mode 100644 index 0000000000..a52721241d --- /dev/null +++ b/src/trezor/messages/StellarAddress.py @@ -0,0 +1,15 @@ +# Automatically generated by pb2py +import protobuf as p + + +class StellarAddress(p.MessageType): + MESSAGE_WIRE_TYPE = 208 + FIELDS = { + 1: ('address', p.UnicodeType, 0), + } + + def __init__( + self, + address: str = None + ) -> None: + self.address = address diff --git a/src/trezor/messages/StellarAllowTrustOp.py b/src/trezor/messages/StellarAllowTrustOp.py index a7fe5c7c11..4f6efc0020 100644 --- a/src/trezor/messages/StellarAllowTrustOp.py +++ b/src/trezor/messages/StellarAllowTrustOp.py @@ -5,8 +5,8 @@ import protobuf as p class StellarAllowTrustOp(p.MessageType): MESSAGE_WIRE_TYPE = 217 FIELDS = { - 1: ('source_account', p.BytesType, 0), - 2: ('trusted_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), + 2: ('trusted_account', p.UnicodeType, 0), 3: ('asset_type', p.UVarintType, 0), 4: ('asset_code', p.UnicodeType, 0), 5: ('is_authorized', p.UVarintType, 0), @@ -14,8 +14,8 @@ class StellarAllowTrustOp(p.MessageType): def __init__( self, - source_account: bytes = None, - trusted_account: bytes = None, + source_account: str = None, + trusted_account: str = None, asset_type: int = None, asset_code: str = None, is_authorized: int = None diff --git a/src/trezor/messages/StellarAssetType.py b/src/trezor/messages/StellarAssetType.py index f32da707db..877f76c3ad 100644 --- a/src/trezor/messages/StellarAssetType.py +++ b/src/trezor/messages/StellarAssetType.py @@ -6,14 +6,14 @@ class StellarAssetType(p.MessageType): FIELDS = { 1: ('type', p.UVarintType, 0), 2: ('code', p.UnicodeType, 0), - 3: ('issuer', p.BytesType, 0), + 3: ('issuer', p.UnicodeType, 0), } def __init__( self, type: int = None, code: str = None, - issuer: bytes = None + issuer: str = None ) -> None: self.type = type self.code = code diff --git a/src/trezor/messages/StellarBumpSequenceOp.py b/src/trezor/messages/StellarBumpSequenceOp.py index c805abc2de..f04d4bca85 100644 --- a/src/trezor/messages/StellarBumpSequenceOp.py +++ b/src/trezor/messages/StellarBumpSequenceOp.py @@ -5,13 +5,13 @@ import protobuf as p class StellarBumpSequenceOp(p.MessageType): MESSAGE_WIRE_TYPE = 221 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('bump_to', p.UVarintType, 0), } def __init__( self, - source_account: bytes = None, + source_account: str = None, bump_to: int = None ) -> None: self.source_account = source_account diff --git a/src/trezor/messages/StellarChangeTrustOp.py b/src/trezor/messages/StellarChangeTrustOp.py index 3b94f4fe6a..0f221680b5 100644 --- a/src/trezor/messages/StellarChangeTrustOp.py +++ b/src/trezor/messages/StellarChangeTrustOp.py @@ -6,14 +6,14 @@ from .StellarAssetType import StellarAssetType class StellarChangeTrustOp(p.MessageType): MESSAGE_WIRE_TYPE = 216 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('asset', StellarAssetType, 0), 3: ('limit', p.UVarintType, 0), } def __init__( self, - source_account: bytes = None, + source_account: str = None, asset: StellarAssetType = None, limit: int = None ) -> None: diff --git a/src/trezor/messages/StellarCreateAccountOp.py b/src/trezor/messages/StellarCreateAccountOp.py index 72e7f92584..39aff15336 100644 --- a/src/trezor/messages/StellarCreateAccountOp.py +++ b/src/trezor/messages/StellarCreateAccountOp.py @@ -5,15 +5,15 @@ import protobuf as p class StellarCreateAccountOp(p.MessageType): MESSAGE_WIRE_TYPE = 210 FIELDS = { - 1: ('source_account', p.BytesType, 0), - 2: ('new_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), + 2: ('new_account', p.UnicodeType, 0), 3: ('starting_balance', p.SVarintType, 0), } def __init__( self, - source_account: bytes = None, - new_account: bytes = None, + source_account: str = None, + new_account: str = None, starting_balance: int = None ) -> None: self.source_account = source_account diff --git a/src/trezor/messages/StellarCreatePassiveOfferOp.py b/src/trezor/messages/StellarCreatePassiveOfferOp.py index 28acd9e907..e4b329633b 100644 --- a/src/trezor/messages/StellarCreatePassiveOfferOp.py +++ b/src/trezor/messages/StellarCreatePassiveOfferOp.py @@ -6,7 +6,7 @@ from .StellarAssetType import StellarAssetType class StellarCreatePassiveOfferOp(p.MessageType): MESSAGE_WIRE_TYPE = 214 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('selling_asset', StellarAssetType, 0), 3: ('buying_asset', StellarAssetType, 0), 4: ('amount', p.SVarintType, 0), @@ -16,7 +16,7 @@ class StellarCreatePassiveOfferOp(p.MessageType): def __init__( self, - source_account: bytes = None, + source_account: str = None, selling_asset: StellarAssetType = None, buying_asset: StellarAssetType = None, amount: int = None, diff --git a/src/trezor/messages/StellarGetAddress.py b/src/trezor/messages/StellarGetAddress.py new file mode 100644 index 0000000000..0c35b16991 --- /dev/null +++ b/src/trezor/messages/StellarGetAddress.py @@ -0,0 +1,23 @@ +# Automatically generated by pb2py +import protobuf as p +if __debug__: + try: + from typing import List + except ImportError: + List = None + + +class StellarGetAddress(p.MessageType): + MESSAGE_WIRE_TYPE = 207 + FIELDS = { + 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), + 2: ('show_display', p.BoolType, 0), + } + + def __init__( + self, + address_n: List[int] = None, + show_display: bool = None + ) -> None: + self.address_n = address_n if address_n is not None else [] + self.show_display = show_display diff --git a/src/trezor/messages/StellarGetPublicKey.py b/src/trezor/messages/StellarGetPublicKey.py index 46a7842888..803beb3c49 100644 --- a/src/trezor/messages/StellarGetPublicKey.py +++ b/src/trezor/messages/StellarGetPublicKey.py @@ -11,10 +11,13 @@ class StellarGetPublicKey(p.MessageType): MESSAGE_WIRE_TYPE = 200 FIELDS = { 1: ('address_n', p.UVarintType, p.FLAG_REPEATED), + 2: ('show_display', p.BoolType, 0), } def __init__( self, - address_n: List[int] = None + address_n: List[int] = None, + show_display: bool = None ) -> None: self.address_n = address_n if address_n is not None else [] + self.show_display = show_display diff --git a/src/trezor/messages/StellarManageDataOp.py b/src/trezor/messages/StellarManageDataOp.py index c20c5aab81..b5b75ae9c0 100644 --- a/src/trezor/messages/StellarManageDataOp.py +++ b/src/trezor/messages/StellarManageDataOp.py @@ -5,14 +5,14 @@ import protobuf as p class StellarManageDataOp(p.MessageType): MESSAGE_WIRE_TYPE = 220 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('key', p.UnicodeType, 0), 3: ('value', p.BytesType, 0), } def __init__( self, - source_account: bytes = None, + source_account: str = None, key: str = None, value: bytes = None ) -> None: diff --git a/src/trezor/messages/StellarManageOfferOp.py b/src/trezor/messages/StellarManageOfferOp.py index c99617866e..6415b3ebcc 100644 --- a/src/trezor/messages/StellarManageOfferOp.py +++ b/src/trezor/messages/StellarManageOfferOp.py @@ -6,7 +6,7 @@ from .StellarAssetType import StellarAssetType class StellarManageOfferOp(p.MessageType): MESSAGE_WIRE_TYPE = 213 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('selling_asset', StellarAssetType, 0), 3: ('buying_asset', StellarAssetType, 0), 4: ('amount', p.SVarintType, 0), @@ -17,7 +17,7 @@ class StellarManageOfferOp(p.MessageType): def __init__( self, - source_account: bytes = None, + source_account: str = None, selling_asset: StellarAssetType = None, buying_asset: StellarAssetType = None, amount: int = None, diff --git a/src/trezor/messages/StellarPathPaymentOp.py b/src/trezor/messages/StellarPathPaymentOp.py index 228dede1a0..1ad0f9655b 100644 --- a/src/trezor/messages/StellarPathPaymentOp.py +++ b/src/trezor/messages/StellarPathPaymentOp.py @@ -11,10 +11,10 @@ from .StellarAssetType import StellarAssetType class StellarPathPaymentOp(p.MessageType): MESSAGE_WIRE_TYPE = 212 FIELDS = { - 1: ('source_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), 2: ('send_asset', StellarAssetType, 0), 3: ('send_max', p.SVarintType, 0), - 4: ('destination_account', p.BytesType, 0), + 4: ('destination_account', p.UnicodeType, 0), 5: ('destination_asset', StellarAssetType, 0), 6: ('destination_amount', p.SVarintType, 0), 7: ('paths', StellarAssetType, p.FLAG_REPEATED), @@ -22,10 +22,10 @@ class StellarPathPaymentOp(p.MessageType): def __init__( self, - source_account: bytes = None, + source_account: str = None, send_asset: StellarAssetType = None, send_max: int = None, - destination_account: bytes = None, + destination_account: str = None, destination_asset: StellarAssetType = None, destination_amount: int = None, paths: List[StellarAssetType] = None diff --git a/src/trezor/messages/StellarPaymentOp.py b/src/trezor/messages/StellarPaymentOp.py index 3a66f8479f..138ef17973 100644 --- a/src/trezor/messages/StellarPaymentOp.py +++ b/src/trezor/messages/StellarPaymentOp.py @@ -6,16 +6,16 @@ from .StellarAssetType import StellarAssetType class StellarPaymentOp(p.MessageType): MESSAGE_WIRE_TYPE = 211 FIELDS = { - 1: ('source_account', p.BytesType, 0), - 2: ('destination_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), + 2: ('destination_account', p.UnicodeType, 0), 3: ('asset', StellarAssetType, 0), 4: ('amount', p.SVarintType, 0), } def __init__( self, - source_account: bytes = None, - destination_account: bytes = None, + source_account: str = None, + destination_account: str = None, asset: StellarAssetType = None, amount: int = None ) -> None: diff --git a/src/trezor/messages/StellarSetOptionsOp.py b/src/trezor/messages/StellarSetOptionsOp.py index 19362c623a..18b9632b34 100644 --- a/src/trezor/messages/StellarSetOptionsOp.py +++ b/src/trezor/messages/StellarSetOptionsOp.py @@ -5,8 +5,8 @@ import protobuf as p class StellarSetOptionsOp(p.MessageType): MESSAGE_WIRE_TYPE = 215 FIELDS = { - 1: ('source_account', p.BytesType, 0), - 2: ('inflation_destination_account', p.BytesType, 0), + 1: ('source_account', p.UnicodeType, 0), + 2: ('inflation_destination_account', p.UnicodeType, 0), 3: ('clear_flags', p.UVarintType, 0), 4: ('set_flags', p.UVarintType, 0), 5: ('master_weight', p.UVarintType, 0), @@ -21,8 +21,8 @@ class StellarSetOptionsOp(p.MessageType): def __init__( self, - source_account: bytes = None, - inflation_destination_account: bytes = None, + source_account: str = None, + inflation_destination_account: str = None, clear_flags: int = None, set_flags: int = None, master_weight: int = None, diff --git a/src/trezor/messages/StellarSignTx.py b/src/trezor/messages/StellarSignTx.py index d75971294c..af4961d82c 100644 --- a/src/trezor/messages/StellarSignTx.py +++ b/src/trezor/messages/StellarSignTx.py @@ -13,7 +13,7 @@ class StellarSignTx(p.MessageType): 1: ('protocol_version', p.UVarintType, 0), 2: ('address_n', p.UVarintType, p.FLAG_REPEATED), 3: ('network_passphrase', p.UnicodeType, 0), - 4: ('source_account', p.BytesType, 0), + 4: ('source_account', p.UnicodeType, 0), 5: ('fee', p.UVarintType, 0), 6: ('sequence_number', p.UVarintType, 0), 8: ('timebounds_start', p.UVarintType, 0), @@ -30,7 +30,7 @@ class StellarSignTx(p.MessageType): protocol_version: int = None, address_n: List[int] = None, network_passphrase: str = None, - source_account: bytes = None, + source_account: str = None, fee: int = None, sequence_number: int = None, timebounds_start: int = None, diff --git a/src/trezor/messages/wire_types.py b/src/trezor/messages/wire_types.py index bed0c35415..e927e9a4f7 100644 --- a/src/trezor/messages/wire_types.py +++ b/src/trezor/messages/wire_types.py @@ -97,6 +97,8 @@ StellarGetPublicKey = 200 StellarPublicKey = 201 StellarSignTx = 202 StellarTxOpRequest = 203 +StellarGetAddress = 207 +StellarAddress = 208 StellarCreateAccountOp = 210 StellarPaymentOp = 211 StellarPathPaymentOp = 212