1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-17 19:00:58 +00:00

feat(core): Show address confirmation in SignMessage.

This commit is contained in:
Andrew Kozlik 2021-11-05 18:03:17 +01:00 committed by Andrew Kozlik
parent 4146ab7f9e
commit cf14e06aa0
6 changed files with 30 additions and 15 deletions

View File

@ -0,0 +1 @@
Show address confirmation in SignMessage.

View File

@ -7,7 +7,7 @@ from trezor.ui.layouts import confirm_signverify
from apps.common.paths import validate_path from apps.common.paths import validate_path
from apps.common.signverify import decode_message, message_digest from apps.common.signverify import decode_message, message_digest
from .addresses import get_address from .addresses import address_short, get_address
from .keychain import with_keychain from .keychain import with_keychain
if False: if False:
@ -26,12 +26,19 @@ async def sign_message(
script_type = msg.script_type or InputScriptType.SPENDADDRESS script_type = msg.script_type or InputScriptType.SPENDADDRESS
await validate_path(ctx, keychain, address_n) await validate_path(ctx, keychain, address_n)
await confirm_signverify(ctx, coin.coin_shortcut, decode_message(message))
node = keychain.derive(address_n) node = keychain.derive(address_n)
address = get_address(script_type, coin, node)
await confirm_signverify(
ctx,
coin.coin_shortcut,
decode_message(message),
address_short(coin, address),
verify=False,
)
seckey = node.private_key() seckey = node.private_key()
address = get_address(script_type, coin, node)
digest = message_digest(coin, message) digest = message_digest(coin, message)
signature = secp256k1.sign(seckey, digest) signature = secp256k1.sign(seckey, digest)

View File

@ -67,6 +67,7 @@ async def verify_message(ctx: wire.Context, msg: VerifyMessage) -> Success:
coin.coin_shortcut, coin.coin_shortcut,
decode_message(message), decode_message(message),
address=address_short(coin, address), address=address_short(coin, address),
verify=True,
) )
return Success(message="Message verified") return Success(message="Message verified")

View File

@ -31,9 +31,13 @@ async def sign_message(
ctx: Context, msg: EthereumSignMessage, keychain: Keychain ctx: Context, msg: EthereumSignMessage, keychain: Keychain
) -> EthereumMessageSignature: ) -> EthereumMessageSignature:
await paths.validate_path(ctx, keychain, msg.address_n) await paths.validate_path(ctx, keychain, msg.address_n)
await confirm_signverify(ctx, "ETH", decode_message(msg.message))
node = keychain.derive(msg.address_n) node = keychain.derive(msg.address_n)
address = address_from_bytes(node.ethereum_pubkeyhash())
await confirm_signverify(
ctx, "ETH", decode_message(msg.message), address, verify=False
)
signature = secp256k1.sign( signature = secp256k1.sign(
node.private_key(), node.private_key(),
message_digest(msg.message), message_digest(msg.message),
@ -42,6 +46,6 @@ async def sign_message(
) )
return EthereumMessageSignature( return EthereumMessageSignature(
address=address_from_bytes(node.ethereum_pubkeyhash()), address=address,
signature=signature[1:] + bytearray([signature[0]]), signature=signature[1:] + bytearray([signature[0]]),
) )

View File

@ -33,6 +33,8 @@ async def verify_message(ctx: Context, msg: EthereumVerifyMessage) -> Success:
address = address_from_bytes(address_bytes) address = address_from_bytes(address_bytes)
await confirm_signverify(ctx, "ETH", decode_message(msg.message), address=address) await confirm_signverify(
ctx, "ETH", decode_message(msg.message), address=address, verify=True
)
return Success(message="Message verified") return Success(message="Message verified")

View File

@ -983,24 +983,24 @@ async def confirm_sign_identity(
async def confirm_signverify( async def confirm_signverify(
ctx: wire.GenericContext, coin: str, message: str, address: str | None = None ctx: wire.GenericContext, coin: str, message: str, address: str, verify: bool
) -> None: ) -> None:
if address: if verify:
header = f"Verify {coin} message" header = f"Verify {coin} message"
font = ui.MONO font = ui.MONO
br_type = "verify_message" br_type = "verify_message"
text = Text(header, new_lines=False)
text.bold("Confirm address:\n")
text.mono(*chunks_intersperse(address, MONO_ADDR_PER_LINE))
await raise_if_cancelled(
interact(ctx, Confirm(text), br_type, ButtonRequestType.Other)
)
else: else:
header = f"Sign {coin} message" header = f"Sign {coin} message"
font = ui.NORMAL font = ui.NORMAL
br_type = "sign_message" br_type = "sign_message"
text = Text(header, new_lines=False)
text.bold("Confirm address:\n")
text.mono(*chunks_intersperse(address, MONO_ADDR_PER_LINE))
await raise_if_cancelled(
interact(ctx, Confirm(text), br_type, ButtonRequestType.Other)
)
await raise_if_cancelled( await raise_if_cancelled(
interact( interact(
ctx, ctx,