2020-07-23 13:54:49 +00:00
|
|
|
from trezor import ui
|
2021-07-23 09:42:38 +00:00
|
|
|
from trezor.enums import (
|
|
|
|
ButtonRequestType,
|
|
|
|
CardanoAddressType,
|
|
|
|
CardanoCertificateType,
|
|
|
|
CardanoNativeScriptHashDisplayFormat,
|
|
|
|
CardanoNativeScriptType,
|
2021-07-23 12:54:32 +00:00
|
|
|
CardanoTxSigningMode,
|
2021-07-23 09:42:38 +00:00
|
|
|
)
|
2021-07-23 10:14:29 +00:00
|
|
|
from trezor.messages import CardanoAddressParametersType
|
2020-07-23 13:54:49 +00:00
|
|
|
from trezor.strings import format_amount
|
2021-03-10 09:52:26 +00:00
|
|
|
from trezor.ui.layouts import (
|
2021-07-23 09:42:38 +00:00
|
|
|
confirm_blob,
|
2021-03-10 09:52:26 +00:00
|
|
|
confirm_metadata,
|
|
|
|
confirm_output,
|
|
|
|
confirm_path_warning,
|
|
|
|
confirm_properties,
|
2021-07-23 12:54:32 +00:00
|
|
|
confirm_text,
|
2021-07-23 10:14:29 +00:00
|
|
|
show_address,
|
2021-03-10 09:52:26 +00:00
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-03-23 12:29:25 +00:00
|
|
|
from apps.common.paths import address_n_to_str
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2020-09-29 18:23:25 +00:00
|
|
|
from . import seed
|
2021-07-23 10:14:29 +00:00
|
|
|
from .address import derive_human_readable_address
|
2020-07-23 13:54:49 +00:00
|
|
|
from .helpers import protocol_magics
|
2021-02-08 21:00:00 +00:00
|
|
|
from .helpers.utils import (
|
|
|
|
format_account_number,
|
2021-03-02 18:08:14 +00:00
|
|
|
format_asset_fingerprint,
|
2021-07-23 09:42:38 +00:00
|
|
|
format_key_hash,
|
2021-02-08 21:00:00 +00:00
|
|
|
format_optional_int,
|
2021-07-23 09:42:38 +00:00
|
|
|
format_script_hash,
|
2021-02-08 21:00:00 +00:00
|
|
|
format_stake_pool_id,
|
|
|
|
to_account_path,
|
|
|
|
)
|
2021-07-23 12:54:32 +00:00
|
|
|
from .seed import is_minting_path, is_multisig_path
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
if False:
|
|
|
|
from trezor import wire
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.messages import (
|
2021-07-23 09:42:38 +00:00
|
|
|
CardanoNativeScript,
|
2021-06-30 12:13:43 +00:00
|
|
|
CardanoTxCertificate,
|
|
|
|
CardanoTxWithdrawal,
|
2021-03-23 12:35:27 +00:00
|
|
|
CardanoPoolParametersType,
|
2021-06-30 12:13:43 +00:00
|
|
|
CardanoPoolOwner,
|
2021-03-23 12:35:27 +00:00
|
|
|
CardanoPoolMetadataType,
|
2021-06-30 12:13:43 +00:00
|
|
|
CardanoToken,
|
2020-07-27 10:48:31 +00:00
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-06-23 08:02:09 +00:00
|
|
|
from trezor.ui.layouts import PropertyType
|
2021-07-23 10:14:29 +00:00
|
|
|
from .helpers.credential import Credential
|
2021-06-23 08:02:09 +00:00
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
ADDRESS_TYPE_NAMES = {
|
|
|
|
CardanoAddressType.BYRON: "Legacy",
|
|
|
|
CardanoAddressType.BASE: "Base",
|
2021-07-23 10:14:29 +00:00
|
|
|
CardanoAddressType.BASE_SCRIPT_KEY: "Base",
|
|
|
|
CardanoAddressType.BASE_KEY_SCRIPT: "Base",
|
|
|
|
CardanoAddressType.BASE_SCRIPT_SCRIPT: "Base",
|
2020-07-23 13:54:49 +00:00
|
|
|
CardanoAddressType.POINTER: "Pointer",
|
2021-07-23 10:14:29 +00:00
|
|
|
CardanoAddressType.POINTER_SCRIPT: "Pointer",
|
2020-07-23 13:54:49 +00:00
|
|
|
CardanoAddressType.ENTERPRISE: "Enterprise",
|
2021-07-23 10:14:29 +00:00
|
|
|
CardanoAddressType.ENTERPRISE_SCRIPT: "Enterprise",
|
2020-07-23 13:54:49 +00:00
|
|
|
CardanoAddressType.REWARD: "Reward",
|
2021-07-23 10:14:29 +00:00
|
|
|
CardanoAddressType.REWARD_SCRIPT: "Reward",
|
2020-07-23 13:54:49 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 09:42:38 +00:00
|
|
|
SCRIPT_TYPE_NAMES = {
|
|
|
|
CardanoNativeScriptType.PUB_KEY: "Key",
|
|
|
|
CardanoNativeScriptType.ALL: "All",
|
|
|
|
CardanoNativeScriptType.ANY: "Any",
|
|
|
|
CardanoNativeScriptType.N_OF_K: "N of K",
|
|
|
|
CardanoNativeScriptType.INVALID_BEFORE: "Invalid before",
|
|
|
|
CardanoNativeScriptType.INVALID_HEREAFTER: "Invalid hereafter",
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:48:31 +00:00
|
|
|
CERTIFICATE_TYPE_NAMES = {
|
|
|
|
CardanoCertificateType.STAKE_REGISTRATION: "Stake key registration",
|
|
|
|
CardanoCertificateType.STAKE_DEREGISTRATION: "Stake key deregistration",
|
|
|
|
CardanoCertificateType.STAKE_DELEGATION: "Stake delegation",
|
2020-09-29 18:23:25 +00:00
|
|
|
CardanoCertificateType.STAKE_POOL_REGISTRATION: "Stakepool registration",
|
2020-07-27 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
def format_coin_amount(amount: int) -> str:
|
2021-09-27 10:13:51 +00:00
|
|
|
return f"{format_amount(amount, 6)} ADA"
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
def is_printable_ascii_bytestring(bytestr: bytes) -> bool:
|
|
|
|
return all((32 < b < 127) for b in bytestr)
|
|
|
|
|
|
|
|
|
2021-07-23 09:42:38 +00:00
|
|
|
async def show_native_script(
|
|
|
|
ctx: wire.Context,
|
|
|
|
script: CardanoNativeScript,
|
2021-10-13 13:45:53 +00:00
|
|
|
indices: list[int] | None = None,
|
2021-07-23 09:42:38 +00:00
|
|
|
) -> None:
|
2021-10-13 13:45:53 +00:00
|
|
|
script_heading = "Script"
|
|
|
|
if indices is None:
|
|
|
|
indices = []
|
|
|
|
if indices:
|
|
|
|
script_heading += " " + ".".join(str(i) for i in indices)
|
2021-07-23 09:42:38 +00:00
|
|
|
|
|
|
|
script_type_name_suffix = ""
|
|
|
|
if script.type == CardanoNativeScriptType.PUB_KEY:
|
|
|
|
if script.key_path:
|
|
|
|
script_type_name_suffix = "path"
|
|
|
|
elif script.key_hash:
|
|
|
|
script_type_name_suffix = "hash"
|
|
|
|
|
|
|
|
props: list[PropertyType] = [
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"{script_heading} - {SCRIPT_TYPE_NAMES[script.type]} {script_type_name_suffix}:",
|
2021-07-23 09:42:38 +00:00
|
|
|
None,
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
if script.type == CardanoNativeScriptType.PUB_KEY:
|
|
|
|
assert script.key_hash is not None or script.key_path # validate_script
|
|
|
|
if script.key_hash:
|
|
|
|
props.append((None, format_key_hash(script.key_hash, True)))
|
|
|
|
elif script.key_path:
|
|
|
|
props.append((address_n_to_str(script.key_path), None))
|
|
|
|
elif script.type == CardanoNativeScriptType.N_OF_K:
|
|
|
|
assert script.required_signatures_count is not None # validate_script
|
|
|
|
props.append(
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"Requires {script.required_signatures_count} out of {len(script.scripts)} signatures.",
|
2021-07-23 09:42:38 +00:00
|
|
|
None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
elif script.type == CardanoNativeScriptType.INVALID_BEFORE:
|
|
|
|
assert script.invalid_before is not None # validate_script
|
|
|
|
props.append((str(script.invalid_before), None))
|
|
|
|
elif script.type == CardanoNativeScriptType.INVALID_HEREAFTER:
|
|
|
|
assert script.invalid_hereafter is not None # validate_script
|
|
|
|
props.append((str(script.invalid_hereafter), None))
|
|
|
|
|
|
|
|
if script.type in (
|
|
|
|
CardanoNativeScriptType.ALL,
|
|
|
|
CardanoNativeScriptType.ANY,
|
|
|
|
CardanoNativeScriptType.N_OF_K,
|
|
|
|
):
|
|
|
|
assert script.scripts # validate_script
|
2021-09-27 10:13:51 +00:00
|
|
|
props.append((f"Contains {len(script.scripts)} nested scripts.", None))
|
2021-07-23 09:42:38 +00:00
|
|
|
|
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"verify_script",
|
|
|
|
title="Verify script",
|
|
|
|
props=props,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
|
|
|
|
|
|
|
for i, sub_script in enumerate(script.scripts):
|
2021-10-13 13:45:53 +00:00
|
|
|
await show_native_script(ctx, sub_script, indices + [i + 1])
|
2021-07-23 09:42:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def show_script_hash(
|
|
|
|
ctx: wire.Context,
|
|
|
|
script_hash: bytes,
|
|
|
|
display_format: CardanoNativeScriptHashDisplayFormat,
|
|
|
|
) -> None:
|
|
|
|
assert display_format in (
|
|
|
|
CardanoNativeScriptHashDisplayFormat.BECH32,
|
|
|
|
CardanoNativeScriptHashDisplayFormat.POLICY_ID,
|
|
|
|
)
|
|
|
|
|
|
|
|
if display_format == CardanoNativeScriptHashDisplayFormat.BECH32:
|
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"verify_script",
|
|
|
|
title="Verify script",
|
|
|
|
props=[("Script hash:", format_script_hash(script_hash))],
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
|
|
|
elif display_format == CardanoNativeScriptHashDisplayFormat.POLICY_ID:
|
|
|
|
await confirm_blob(
|
|
|
|
ctx,
|
|
|
|
"verify_script",
|
|
|
|
title="Verify script",
|
|
|
|
data=script_hash,
|
|
|
|
description="Policy ID:",
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
async def show_transaction_signing_mode(
|
|
|
|
ctx: wire.Context, signing_mode: CardanoTxSigningMode
|
|
|
|
) -> None:
|
|
|
|
if signing_mode == CardanoTxSigningMode.MULTISIG_TRANSACTION:
|
|
|
|
await confirm_metadata(
|
|
|
|
ctx,
|
|
|
|
"confirm_signing_mode",
|
|
|
|
title="Confirm transaction",
|
|
|
|
content="Confirming a multisig transaction.",
|
|
|
|
larger_vspace=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
async def confirm_sending(
|
|
|
|
ctx: wire.Context,
|
|
|
|
ada_amount: int,
|
|
|
|
to: str,
|
2021-07-23 10:14:29 +00:00
|
|
|
is_change_output: bool,
|
2021-01-25 16:12:32 +00:00
|
|
|
) -> None:
|
2021-07-23 10:14:29 +00:00
|
|
|
subtitle = "Change amount:" if is_change_output else "Confirm sending:"
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_output(
|
|
|
|
ctx,
|
2021-04-01 13:17:58 +00:00
|
|
|
to,
|
2021-03-10 09:52:26 +00:00
|
|
|
format_coin_amount(ada_amount),
|
|
|
|
title="Confirm transaction",
|
2021-07-23 10:14:29 +00:00
|
|
|
subtitle=subtitle,
|
2021-03-10 09:52:26 +00:00
|
|
|
font_amount=ui.BOLD,
|
|
|
|
width_paginated=17,
|
|
|
|
to_str="\nto\n",
|
|
|
|
to_paginated=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
2021-04-01 13:17:58 +00:00
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
async def confirm_sending_token(
|
|
|
|
ctx: wire.Context, policy_id: bytes, token: CardanoToken
|
2021-01-25 16:12:32 +00:00
|
|
|
) -> None:
|
2021-07-23 12:54:32 +00:00
|
|
|
assert token.amount is not None # _validate_token
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_token",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
|
|
|
(
|
|
|
|
"Asset fingerprint:",
|
|
|
|
format_asset_fingerprint(
|
|
|
|
policy_id=policy_id,
|
|
|
|
asset_name_bytes=token.asset_name_bytes,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
("Amount sent:", format_amount(token.amount, 0)),
|
|
|
|
],
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2021-01-25 16:12:32 +00:00
|
|
|
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
async def show_credentials(
|
|
|
|
ctx: wire.Context,
|
|
|
|
payment_credential: Credential,
|
|
|
|
stake_credential: Credential,
|
|
|
|
is_change_output: bool = False,
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
2021-07-23 10:14:29 +00:00
|
|
|
await _show_credential(ctx, payment_credential, is_change_output)
|
|
|
|
await _show_credential(ctx, stake_credential, is_change_output)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
async def _show_credential(
|
2020-09-25 11:59:16 +00:00
|
|
|
ctx: wire.Context,
|
2021-07-23 10:14:29 +00:00
|
|
|
credential: Credential,
|
|
|
|
is_change_output: bool = False,
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
2021-07-23 10:14:29 +00:00
|
|
|
if is_change_output:
|
|
|
|
title = "Confirm transaction"
|
|
|
|
else:
|
2021-09-27 10:13:51 +00:00
|
|
|
title = f"{ADDRESS_TYPE_NAMES[credential.address_type]} address"
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
props: list[PropertyType] = []
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
# Credential can be empty in case of enterprise address stake credential
|
|
|
|
# and reward address payment credential. In that case we don't want to
|
|
|
|
# show some of the "props".
|
|
|
|
if credential.is_set():
|
|
|
|
if is_change_output:
|
|
|
|
address_usage = "Change address"
|
|
|
|
else:
|
|
|
|
address_usage = "Address"
|
|
|
|
|
|
|
|
credential_title = credential.get_title()
|
|
|
|
props.append(
|
2021-03-10 09:52:26 +00:00
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"{address_usage} {credential.type_name} credential is a {credential_title}:",
|
2021-03-10 09:52:26 +00:00
|
|
|
None,
|
2021-07-23 10:14:29 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
props.extend(credential.format())
|
|
|
|
|
|
|
|
if credential.is_unusual_path:
|
|
|
|
props.append((None, "Path is unusual."))
|
|
|
|
if credential.is_mismatch:
|
|
|
|
props.append((None, "Credential doesn't match payment credential."))
|
|
|
|
if credential.is_reward:
|
|
|
|
props.append(("Address is a reward address.", None))
|
|
|
|
if credential.is_no_staking:
|
|
|
|
props.append(
|
2021-03-10 09:52:26 +00:00
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"{ADDRESS_TYPE_NAMES[credential.address_type]} address - no staking rewards.",
|
2021-07-23 10:14:29 +00:00
|
|
|
None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if credential.should_warn():
|
|
|
|
icon = ui.ICON_WRONG
|
|
|
|
icon_color = ui.RED
|
|
|
|
else:
|
|
|
|
icon = ui.ICON_SEND
|
|
|
|
icon_color = ui.GREEN
|
|
|
|
|
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_credential",
|
|
|
|
title=title,
|
|
|
|
props=props,
|
|
|
|
icon=icon,
|
|
|
|
icon_color=icon_color,
|
2021-03-10 09:52:26 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
async def show_warning_path(ctx: wire.Context, path: list[int], title: str) -> None:
|
|
|
|
await confirm_path_warning(ctx, address_n_to_str(path), path_type=title)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
|
|
|
|
async def show_warning_tx_output_contains_tokens(ctx: wire.Context) -> None:
|
|
|
|
await confirm_metadata(
|
2021-03-10 09:52:26 +00:00
|
|
|
ctx,
|
2021-07-23 10:14:29 +00:00
|
|
|
"confirm_tokens",
|
2021-03-10 09:52:26 +00:00
|
|
|
title="Confirm transaction",
|
2021-07-23 10:14:29 +00:00
|
|
|
content="The following\ntransaction output\ncontains tokens.",
|
|
|
|
larger_vspace=True,
|
2021-03-10 09:52:26 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
async def confirm_witness_request(
|
|
|
|
ctx: wire.Context,
|
|
|
|
witness_path: list[int],
|
|
|
|
) -> None:
|
|
|
|
if is_multisig_path(witness_path):
|
|
|
|
path_title = "multi-sig path"
|
|
|
|
elif is_minting_path(witness_path):
|
|
|
|
path_title = "token minting path"
|
|
|
|
else:
|
|
|
|
path_title = "path"
|
|
|
|
|
|
|
|
await confirm_text(
|
|
|
|
ctx,
|
|
|
|
"confirm_total",
|
|
|
|
title="Confirm transaction",
|
|
|
|
data=address_n_to_str(witness_path),
|
2021-09-27 10:13:51 +00:00
|
|
|
description=f"Sign transaction with {path_title}:",
|
2021-07-23 12:54:32 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-07-29 06:22:36 +00:00
|
|
|
async def confirm_transaction(
|
2021-01-08 10:31:03 +00:00
|
|
|
ctx: wire.Context,
|
2020-12-03 21:53:30 +00:00
|
|
|
fee: int,
|
|
|
|
protocol_magic: int,
|
2021-03-18 09:48:50 +00:00
|
|
|
ttl: int | None,
|
|
|
|
validity_interval_start: int | None,
|
2020-12-03 21:53:30 +00:00
|
|
|
is_network_id_verifiable: bool,
|
2020-07-29 06:22:36 +00:00
|
|
|
) -> None:
|
2021-06-23 08:02:09 +00:00
|
|
|
props: list[PropertyType] = [
|
2021-03-10 09:52:26 +00:00
|
|
|
("Transaction fee:", format_coin_amount(fee)),
|
|
|
|
]
|
2020-11-02 18:27:34 +00:00
|
|
|
|
2020-12-03 21:53:30 +00:00
|
|
|
if is_network_id_verifiable:
|
2021-09-27 10:13:51 +00:00
|
|
|
props.append((f"Network: {protocol_magics.to_ui_string(protocol_magic)}", None))
|
2021-03-10 09:52:26 +00:00
|
|
|
|
2021-09-27 10:13:51 +00:00
|
|
|
props.append((f"Valid since: {format_optional_int(validity_interval_start)}", None))
|
|
|
|
props.append((f"TTL: {format_optional_int(ttl)}", None))
|
2020-11-02 18:27:34 +00:00
|
|
|
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_total",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=props,
|
|
|
|
hold=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2020-07-27 10:48:31 +00:00
|
|
|
async def confirm_certificate(
|
2021-06-30 12:13:43 +00:00
|
|
|
ctx: wire.Context, certificate: CardanoTxCertificate
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
|
|
|
# stake pool registration requires custom confirmation logic not covered
|
|
|
|
# in this call
|
|
|
|
assert certificate.type != CardanoCertificateType.STAKE_POOL_REGISTRATION
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
props: list[PropertyType] = [
|
2021-03-10 09:52:26 +00:00
|
|
|
("Confirm:", CERTIFICATE_TYPE_NAMES[certificate.type]),
|
|
|
|
]
|
2021-07-23 12:54:32 +00:00
|
|
|
|
|
|
|
if certificate.path:
|
|
|
|
props.append(
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"for account {format_account_number(certificate.path)}:",
|
2021-07-23 12:54:32 +00:00
|
|
|
address_n_to_str(to_account_path(certificate.path)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
assert certificate.script_hash is not None # validate_certificate
|
|
|
|
props.append(("for script:", format_script_hash(certificate.script_hash)))
|
|
|
|
|
2020-07-27 10:48:31 +00:00
|
|
|
if certificate.type == CardanoCertificateType.STAKE_DELEGATION:
|
2021-01-08 10:31:03 +00:00
|
|
|
assert certificate.pool is not None # validate_certificate
|
2021-03-10 09:52:26 +00:00
|
|
|
props.append(("to pool:", format_stake_pool_id(certificate.pool)))
|
2020-07-27 10:48:31 +00:00
|
|
|
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_certificate",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=props,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-27 10:48:31 +00:00
|
|
|
|
|
|
|
|
2020-09-29 18:23:25 +00:00
|
|
|
async def confirm_stake_pool_parameters(
|
2021-06-30 12:13:43 +00:00
|
|
|
ctx: wire.Context, pool_parameters: CardanoPoolParametersType
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
|
|
|
margin_percentage = (
|
|
|
|
100.0 * pool_parameters.margin_numerator / pool_parameters.margin_denominator
|
|
|
|
)
|
2021-09-27 10:13:51 +00:00
|
|
|
percentage_formatted = str(float(margin_percentage)).rstrip("0").rstrip(".")
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_pool_registration",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
|
|
|
(
|
|
|
|
"Stake pool registration\nPool ID:",
|
|
|
|
format_stake_pool_id(pool_parameters.pool_id),
|
|
|
|
),
|
|
|
|
("Pool reward account:", pool_parameters.reward_account),
|
|
|
|
(
|
2021-10-13 13:45:53 +00:00
|
|
|
f"Pledge: {format_coin_amount(pool_parameters.pledge)}\n"
|
|
|
|
+ f"Cost: {format_coin_amount(pool_parameters.cost)}\n"
|
|
|
|
+ f"Margin: {percentage_formatted}%",
|
2021-03-10 09:52:26 +00:00
|
|
|
None,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
async def confirm_stake_pool_owner(
|
2020-09-29 18:23:25 +00:00
|
|
|
ctx: wire.Context,
|
2021-01-08 10:31:03 +00:00
|
|
|
keychain: seed.Keychain,
|
2021-06-30 12:13:43 +00:00
|
|
|
owner: CardanoPoolOwner,
|
2021-07-23 10:14:29 +00:00
|
|
|
protocol_magic: int,
|
2020-09-29 18:23:25 +00:00
|
|
|
network_id: int,
|
|
|
|
) -> None:
|
2021-03-10 09:52:26 +00:00
|
|
|
props: list[tuple[str, str | None]] = []
|
2021-06-30 12:13:43 +00:00
|
|
|
if owner.staking_key_path:
|
|
|
|
props.append(("Pool owner:", address_n_to_str(owner.staking_key_path)))
|
|
|
|
props.append(
|
|
|
|
(
|
2021-07-23 10:14:29 +00:00
|
|
|
derive_human_readable_address(
|
|
|
|
keychain,
|
|
|
|
CardanoAddressParametersType(
|
|
|
|
address_type=CardanoAddressType.REWARD,
|
|
|
|
address_n=owner.staking_key_path,
|
|
|
|
),
|
|
|
|
protocol_magic,
|
|
|
|
network_id,
|
2021-06-30 12:13:43 +00:00
|
|
|
),
|
|
|
|
None,
|
2020-09-29 18:23:25 +00:00
|
|
|
)
|
2021-06-30 12:13:43 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
assert owner.staking_key_hash is not None # validate_pool_owners
|
|
|
|
props.append(
|
|
|
|
(
|
|
|
|
"Pool owner:",
|
2021-07-23 10:14:29 +00:00
|
|
|
derive_human_readable_address(
|
|
|
|
keychain,
|
|
|
|
CardanoAddressParametersType(
|
|
|
|
address_type=CardanoAddressType.REWARD,
|
|
|
|
staking_key_hash=owner.staking_key_hash,
|
|
|
|
),
|
|
|
|
protocol_magic,
|
|
|
|
network_id,
|
2021-06-30 12:13:43 +00:00
|
|
|
),
|
2020-09-29 18:23:25 +00:00
|
|
|
)
|
2021-06-30 12:13:43 +00:00
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_pool_owners",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=props,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def confirm_stake_pool_metadata(
|
|
|
|
ctx: wire.Context,
|
2021-03-18 09:48:50 +00:00
|
|
|
metadata: CardanoPoolMetadataType | None,
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
|
|
|
if metadata is None:
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_pool_metadata",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[("Pool has no metadata (anonymous pool)", None)],
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
return
|
|
|
|
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_pool_metadata",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
|
|
|
("Pool metadata url:", metadata.url),
|
2021-06-22 13:14:15 +00:00
|
|
|
("Pool metadata hash:", metadata.hash),
|
2021-03-10 09:52:26 +00:00
|
|
|
],
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
async def confirm_stake_pool_registration_final(
|
2021-01-08 10:31:03 +00:00
|
|
|
ctx: wire.Context,
|
|
|
|
protocol_magic: int,
|
2021-03-18 09:48:50 +00:00
|
|
|
ttl: int | None,
|
|
|
|
validity_interval_start: int | None,
|
2021-01-25 16:12:32 +00:00
|
|
|
) -> None:
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
2021-06-30 12:13:43 +00:00
|
|
|
"confirm_pool_final",
|
2021-03-10 09:52:26 +00:00
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
2021-06-30 12:13:43 +00:00
|
|
|
("Confirm signing the stake pool registration as an owner.", None),
|
2021-03-10 09:52:26 +00:00
|
|
|
("Network:", protocol_magics.to_ui_string(protocol_magic)),
|
2021-06-30 12:13:43 +00:00
|
|
|
("Valid since:", format_optional_int(validity_interval_start)),
|
|
|
|
("TTL:", format_optional_int(ttl)),
|
2021-03-10 09:52:26 +00:00
|
|
|
],
|
|
|
|
hold=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
|
|
|
|
|
2020-07-27 10:48:31 +00:00
|
|
|
async def confirm_withdrawal(
|
2021-06-30 12:13:43 +00:00
|
|
|
ctx: wire.Context, withdrawal: CardanoTxWithdrawal
|
2020-09-29 18:23:25 +00:00
|
|
|
) -> None:
|
2021-07-23 12:54:32 +00:00
|
|
|
props: list[PropertyType] = [
|
|
|
|
("Confirm withdrawal", None),
|
|
|
|
]
|
|
|
|
|
|
|
|
if withdrawal.path:
|
|
|
|
props.append(
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"for account {format_account_number(withdrawal.path)}:",
|
2021-07-23 12:54:32 +00:00
|
|
|
address_n_to_str(to_account_path(withdrawal.path)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
assert withdrawal.script_hash is not None # validate_withdrawal
|
|
|
|
props.append(("for script:", format_script_hash(withdrawal.script_hash)))
|
|
|
|
|
|
|
|
props.append(("Amount:", format_coin_amount(withdrawal.amount)))
|
|
|
|
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_withdrawal",
|
|
|
|
title="Confirm transaction",
|
2021-07-23 12:54:32 +00:00
|
|
|
props=props,
|
2021-03-10 09:52:26 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-27 10:48:31 +00:00
|
|
|
|
|
|
|
|
2021-03-26 07:46:14 +00:00
|
|
|
async def confirm_catalyst_registration(
|
|
|
|
ctx: wire.Context,
|
|
|
|
public_key: str,
|
|
|
|
staking_path: list[int],
|
|
|
|
reward_address: str,
|
|
|
|
nonce: int,
|
|
|
|
) -> None:
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
|
|
|
"confirm_catalyst_registration",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
|
|
|
("Catalyst voting key registration", None),
|
|
|
|
("Voting public key:", public_key),
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
f"Staking key for account {format_account_number(staking_path)}:",
|
2021-03-10 09:52:26 +00:00
|
|
|
address_n_to_str(staking_path),
|
|
|
|
),
|
|
|
|
("Rewards go to:", reward_address),
|
|
|
|
("Nonce:", str(nonce)),
|
|
|
|
],
|
|
|
|
br_code=ButtonRequestType.Other,
|
2021-03-26 07:46:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def show_auxiliary_data_hash(
|
|
|
|
ctx: wire.Context, auxiliary_data_hash: bytes
|
|
|
|
) -> None:
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
2020-07-23 13:54:49 +00:00
|
|
|
ctx,
|
2021-03-10 09:52:26 +00:00
|
|
|
"confirm_auxiliary_data",
|
|
|
|
title="Confirm transaction",
|
2021-06-22 13:14:15 +00:00
|
|
|
props=[("Auxiliary data hash:", auxiliary_data_hash)],
|
2021-03-10 09:52:26 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
2020-07-23 13:54:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
async def show_warning_tx_contains_mint(ctx: wire.Context) -> None:
|
|
|
|
await confirm_metadata(
|
|
|
|
ctx,
|
|
|
|
"confirm_tokens",
|
|
|
|
title="Confirm transaction",
|
|
|
|
content="The transaction contains\nminting or burning of\ntokens.",
|
|
|
|
larger_vspace=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2021-03-10 09:52:26 +00:00
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
|
|
|
|
async def confirm_token_minting(
|
|
|
|
ctx: wire.Context, policy_id: bytes, token: CardanoToken
|
|
|
|
) -> None:
|
|
|
|
assert token.mint_amount is not None # _validate_token
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_properties(
|
|
|
|
ctx,
|
2021-07-23 12:54:32 +00:00
|
|
|
"confirm_mint",
|
|
|
|
title="Confirm transaction",
|
|
|
|
props=[
|
|
|
|
(
|
|
|
|
"Asset fingerprint:",
|
|
|
|
format_asset_fingerprint(
|
|
|
|
policy_id=policy_id,
|
|
|
|
asset_name_bytes=token.asset_name_bytes,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
2021-09-27 10:13:51 +00:00
|
|
|
"Amount minted:" if token.mint_amount >= 0 else "Amount burned:",
|
2021-07-23 12:54:32 +00:00
|
|
|
format_amount(token.mint_amount, 0),
|
|
|
|
),
|
|
|
|
],
|
2021-03-10 09:52:26 +00:00
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
2020-12-03 21:53:30 +00:00
|
|
|
async def show_warning_tx_network_unverifiable(ctx: wire.Context) -> None:
|
2021-03-10 09:52:26 +00:00
|
|
|
await confirm_metadata(
|
|
|
|
ctx,
|
|
|
|
"warning_no_outputs",
|
|
|
|
title="Warning",
|
|
|
|
content="Transaction has no outputs, network cannot be verified.",
|
|
|
|
larger_vspace=True,
|
|
|
|
br_code=ButtonRequestType.Other,
|
|
|
|
)
|
2020-12-03 21:53:30 +00:00
|
|
|
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
async def show_cardano_address(
|
|
|
|
ctx: wire.Context,
|
|
|
|
address_parameters: CardanoAddressParametersType,
|
|
|
|
address: str,
|
|
|
|
protocol_magic: int,
|
2020-07-23 13:54:49 +00:00
|
|
|
) -> None:
|
2021-07-23 10:14:29 +00:00
|
|
|
network_name = None
|
|
|
|
if not protocol_magics.is_mainnet(protocol_magic):
|
|
|
|
network_name = protocol_magics.to_ui_string(protocol_magic)
|
|
|
|
|
2021-09-27 10:13:51 +00:00
|
|
|
title = f"{ADDRESS_TYPE_NAMES[address_parameters.address_type]} address"
|
2021-07-23 10:14:29 +00:00
|
|
|
address_extra = None
|
|
|
|
title_qr = title
|
|
|
|
if address_parameters.address_type in (
|
|
|
|
CardanoAddressType.BYRON,
|
|
|
|
CardanoAddressType.BASE,
|
|
|
|
CardanoAddressType.BASE_KEY_SCRIPT,
|
|
|
|
CardanoAddressType.POINTER,
|
|
|
|
CardanoAddressType.ENTERPRISE,
|
|
|
|
CardanoAddressType.REWARD,
|
|
|
|
):
|
|
|
|
if address_parameters.address_n:
|
|
|
|
address_extra = address_n_to_str(address_parameters.address_n)
|
|
|
|
title_qr = address_n_to_str(address_parameters.address_n)
|
|
|
|
elif address_parameters.address_n_staking:
|
|
|
|
address_extra = address_n_to_str(address_parameters.address_n_staking)
|
|
|
|
title_qr = address_n_to_str(address_parameters.address_n_staking)
|
|
|
|
|
|
|
|
await show_address(
|
2021-03-10 09:52:26 +00:00
|
|
|
ctx,
|
2021-07-23 10:14:29 +00:00
|
|
|
address=address,
|
|
|
|
title=title,
|
|
|
|
network=network_name,
|
|
|
|
address_extra=address_extra,
|
|
|
|
title_qr=title_qr,
|
2021-03-10 09:52:26 +00:00
|
|
|
)
|