mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
src/apps/wallet/sign_tx: refactor address_short function
This commit is contained in:
parent
37ae7c06a4
commit
3d796b971a
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
||||
|
@ -97,6 +97,8 @@ StellarGetPublicKey = 200
|
||||
StellarPublicKey = 201
|
||||
StellarSignTx = 202
|
||||
StellarTxOpRequest = 203
|
||||
StellarGetAddress = 207
|
||||
StellarAddress = 208
|
||||
StellarCreateAccountOp = 210
|
||||
StellarPaymentOp = 211
|
||||
StellarPathPaymentOp = 212
|
||||
|
@ -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
|
||||
|
15
src/trezor/messages/StellarAddress.py
Normal file
15
src/trezor/messages/StellarAddress.py
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
23
src/trezor/messages/StellarGetAddress.py
Normal file
23
src/trezor/messages/StellarGetAddress.py
Normal file
@ -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
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -97,6 +97,8 @@ StellarGetPublicKey = 200
|
||||
StellarPublicKey = 201
|
||||
StellarSignTx = 202
|
||||
StellarTxOpRequest = 203
|
||||
StellarGetAddress = 207
|
||||
StellarAddress = 208
|
||||
StellarCreateAccountOp = 210
|
||||
StellarPaymentOp = 211
|
||||
StellarPathPaymentOp = 212
|
||||
|
Loading…
Reference in New Issue
Block a user