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:
parent
4146ab7f9e
commit
cf14e06aa0
1
core/.changelog.d/1586.added.1
Normal file
1
core/.changelog.d/1586.added.1
Normal file
@ -0,0 +1 @@
|
||||
Show address confirmation in SignMessage.
|
@ -7,7 +7,7 @@ from trezor.ui.layouts import confirm_signverify
|
||||
from apps.common.paths import validate_path
|
||||
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
|
||||
|
||||
if False:
|
||||
@ -26,12 +26,19 @@ async def sign_message(
|
||||
script_type = msg.script_type or InputScriptType.SPENDADDRESS
|
||||
|
||||
await validate_path(ctx, keychain, address_n)
|
||||
await confirm_signverify(ctx, coin.coin_shortcut, decode_message(message))
|
||||
|
||||
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()
|
||||
|
||||
address = get_address(script_type, coin, node)
|
||||
digest = message_digest(coin, message)
|
||||
signature = secp256k1.sign(seckey, digest)
|
||||
|
||||
|
@ -67,6 +67,7 @@ async def verify_message(ctx: wire.Context, msg: VerifyMessage) -> Success:
|
||||
coin.coin_shortcut,
|
||||
decode_message(message),
|
||||
address=address_short(coin, address),
|
||||
verify=True,
|
||||
)
|
||||
|
||||
return Success(message="Message verified")
|
||||
|
@ -31,9 +31,13 @@ async def sign_message(
|
||||
ctx: Context, msg: EthereumSignMessage, keychain: Keychain
|
||||
) -> EthereumMessageSignature:
|
||||
await paths.validate_path(ctx, keychain, msg.address_n)
|
||||
await confirm_signverify(ctx, "ETH", decode_message(msg.message))
|
||||
|
||||
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(
|
||||
node.private_key(),
|
||||
message_digest(msg.message),
|
||||
@ -42,6 +46,6 @@ async def sign_message(
|
||||
)
|
||||
|
||||
return EthereumMessageSignature(
|
||||
address=address_from_bytes(node.ethereum_pubkeyhash()),
|
||||
address=address,
|
||||
signature=signature[1:] + bytearray([signature[0]]),
|
||||
)
|
||||
|
@ -33,6 +33,8 @@ async def verify_message(ctx: Context, msg: EthereumVerifyMessage) -> Success:
|
||||
|
||||
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")
|
||||
|
@ -983,24 +983,24 @@ async def confirm_sign_identity(
|
||||
|
||||
|
||||
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:
|
||||
if address:
|
||||
if verify:
|
||||
header = f"Verify {coin} message"
|
||||
font = ui.MONO
|
||||
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:
|
||||
header = f"Sign {coin} message"
|
||||
font = ui.NORMAL
|
||||
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(
|
||||
interact(
|
||||
ctx,
|
||||
|
Loading…
Reference in New Issue
Block a user