2021-12-08 09:10:58 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2018-06-05 18:21:31 +00:00
|
|
|
from ubinascii import hexlify
|
|
|
|
|
2018-02-27 02:05:15 +00:00
|
|
|
from trezor import ui
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
from trezor.enums import ButtonRequestType, EthereumDataType
|
|
|
|
from trezor.messages import EthereumFieldType, EthereumStructMember
|
|
|
|
from trezor.strings import format_amount, format_plural
|
2021-06-05 00:15:25 +00:00
|
|
|
from trezor.ui.layouts import (
|
2021-12-22 23:36:05 +00:00
|
|
|
confirm_action,
|
2021-06-05 00:15:25 +00:00
|
|
|
confirm_address,
|
|
|
|
confirm_amount,
|
|
|
|
confirm_blob,
|
|
|
|
confirm_output,
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
confirm_text,
|
2022-02-07 14:08:24 +00:00
|
|
|
confirm_total,
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
should_show_more,
|
2021-06-05 00:15:25 +00:00
|
|
|
)
|
2021-03-25 11:32:10 +00:00
|
|
|
from trezor.ui.layouts.tt.altcoin import confirm_total_ethereum
|
2020-08-11 13:55:05 +00:00
|
|
|
|
|
|
|
from . import networks, tokens
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
from .helpers import address_from_bytes, decode_typed_data, get_type_name
|
2017-12-27 11:48:05 +00:00
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
if TYPE_CHECKING:
|
2022-01-07 14:13:54 +00:00
|
|
|
from typing import Awaitable, Iterable
|
2021-12-08 09:10:58 +00:00
|
|
|
|
2021-08-31 09:47:56 +00:00
|
|
|
from trezor.wire import Context
|
|
|
|
|
|
|
|
|
|
|
|
def require_confirm_tx(
|
|
|
|
ctx: Context,
|
|
|
|
to_bytes: bytes,
|
|
|
|
value: int,
|
|
|
|
chain_id: int,
|
|
|
|
token: tokens.TokenInfo | None = None,
|
|
|
|
) -> Awaitable[None]:
|
2019-01-29 14:35:09 +00:00
|
|
|
if to_bytes:
|
|
|
|
to_str = address_from_bytes(to_bytes, networks.by_chain_id(chain_id))
|
2018-02-28 01:09:10 +00:00
|
|
|
else:
|
2018-07-03 14:20:58 +00:00
|
|
|
to_str = "new contract?"
|
2021-08-31 09:47:56 +00:00
|
|
|
return confirm_output(
|
2021-02-25 15:21:06 +00:00
|
|
|
ctx,
|
|
|
|
address=to_str,
|
2021-08-24 10:15:36 +00:00
|
|
|
amount=format_ethereum_amount(value, token, chain_id),
|
2021-02-25 15:21:06 +00:00
|
|
|
font_amount=ui.BOLD,
|
|
|
|
color_to=ui.GREY,
|
|
|
|
br_code=ButtonRequestType.SignTx,
|
|
|
|
)
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2021-08-31 09:47:56 +00:00
|
|
|
def require_confirm_fee(
|
|
|
|
ctx: Context,
|
|
|
|
spending: int,
|
|
|
|
gas_price: int,
|
|
|
|
gas_limit: int,
|
|
|
|
chain_id: int,
|
|
|
|
token: tokens.TokenInfo | None = None,
|
|
|
|
) -> Awaitable[None]:
|
|
|
|
return confirm_total_ethereum(
|
2021-02-25 15:21:06 +00:00
|
|
|
ctx,
|
2021-08-24 10:15:36 +00:00
|
|
|
format_ethereum_amount(spending, token, chain_id),
|
|
|
|
format_ethereum_amount(gas_price, None, chain_id),
|
|
|
|
format_ethereum_amount(gas_price * gas_limit, None, chain_id),
|
2021-02-25 15:21:06 +00:00
|
|
|
)
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2021-06-05 00:15:25 +00:00
|
|
|
async def require_confirm_eip1559_fee(
|
2022-02-07 14:08:24 +00:00
|
|
|
ctx: Context,
|
|
|
|
spending: int,
|
|
|
|
max_priority_fee: int,
|
|
|
|
max_gas_fee: int,
|
|
|
|
gas_limit: int,
|
|
|
|
chain_id: int,
|
|
|
|
token: tokens.TokenInfo | None = None,
|
2021-08-31 09:47:56 +00:00
|
|
|
) -> None:
|
2021-06-05 00:15:25 +00:00
|
|
|
await confirm_amount(
|
|
|
|
ctx,
|
|
|
|
title="Confirm fee",
|
|
|
|
description="Maximum fee per gas",
|
|
|
|
amount=format_ethereum_amount(max_gas_fee, None, chain_id),
|
|
|
|
)
|
|
|
|
await confirm_amount(
|
|
|
|
ctx,
|
|
|
|
title="Confirm fee",
|
|
|
|
description="Priority fee per gas",
|
|
|
|
amount=format_ethereum_amount(max_priority_fee, None, chain_id),
|
|
|
|
)
|
2022-02-07 14:08:24 +00:00
|
|
|
await confirm_total(
|
2021-06-05 00:15:25 +00:00
|
|
|
ctx,
|
2022-02-07 14:08:24 +00:00
|
|
|
total_amount=format_ethereum_amount(spending, token, chain_id),
|
|
|
|
fee_amount=format_ethereum_amount(max_gas_fee * gas_limit, None, chain_id),
|
|
|
|
total_label="Amount sent:\n",
|
|
|
|
fee_label="\nMaximum fee:\n",
|
2021-06-05 00:15:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-31 09:47:56 +00:00
|
|
|
def require_confirm_unknown_token(
|
|
|
|
ctx: Context, address_bytes: bytes
|
|
|
|
) -> Awaitable[None]:
|
2020-06-24 07:24:14 +00:00
|
|
|
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
2021-08-31 09:47:56 +00:00
|
|
|
return confirm_address(
|
2021-02-25 15:21:06 +00:00
|
|
|
ctx,
|
2021-07-16 13:07:50 +00:00
|
|
|
"Unknown token",
|
|
|
|
contract_address_hex,
|
2021-02-25 15:21:06 +00:00
|
|
|
description="Contract:",
|
2021-07-16 13:07:50 +00:00
|
|
|
br_type="unknown_token",
|
2021-02-25 15:21:06 +00:00
|
|
|
icon_color=ui.ORANGE,
|
|
|
|
br_code=ButtonRequestType.SignTx,
|
|
|
|
)
|
2018-02-28 01:09:10 +00:00
|
|
|
|
|
|
|
|
2021-08-31 09:47:56 +00:00
|
|
|
def require_confirm_data(ctx: Context, data: bytes, data_total: int) -> Awaitable[None]:
|
|
|
|
return confirm_blob(
|
2021-02-25 15:21:06 +00:00
|
|
|
ctx,
|
|
|
|
"confirm_data",
|
|
|
|
title="Confirm data",
|
2021-09-27 10:13:51 +00:00
|
|
|
description=f"Size: {data_total} bytes",
|
2021-07-16 13:07:50 +00:00
|
|
|
data=data,
|
2021-02-25 15:21:06 +00:00
|
|
|
br_code=ButtonRequestType.SignTx,
|
2021-10-14 21:52:58 +00:00
|
|
|
ask_pagination=True,
|
2021-02-25 15:21:06 +00:00
|
|
|
)
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2021-12-22 23:36:05 +00:00
|
|
|
async def confirm_typed_data_final(ctx: Context) -> None:
|
|
|
|
await confirm_action(
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
ctx,
|
2021-12-22 23:36:05 +00:00
|
|
|
"confirm_typed_data_final",
|
|
|
|
title="Confirm typed data",
|
|
|
|
action="Really sign EIP-712 typed data?",
|
|
|
|
verb="Hold to confirm",
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
hold=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-12-22 23:36:05 +00:00
|
|
|
def confirm_empty_typed_message(ctx: Context) -> Awaitable[None]:
|
|
|
|
return confirm_text(
|
|
|
|
ctx,
|
|
|
|
"confirm_empty_typed_message",
|
|
|
|
title="Confirm message",
|
|
|
|
data="",
|
|
|
|
description="No message field",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
async def should_show_domain(ctx: Context, name: bytes, version: bytes) -> bool:
|
|
|
|
domain_name = decode_typed_data(name, "string")
|
|
|
|
domain_version = decode_typed_data(version, "string")
|
|
|
|
|
|
|
|
para = (
|
|
|
|
(ui.NORMAL, "Name and version"),
|
|
|
|
(ui.BOLD, domain_name),
|
|
|
|
(ui.BOLD, domain_version),
|
|
|
|
)
|
|
|
|
return await should_show_more(
|
|
|
|
ctx,
|
|
|
|
title="Confirm domain",
|
|
|
|
para=para,
|
|
|
|
button_text="Show full domain",
|
|
|
|
br_type="should_show_domain",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def should_show_struct(
|
|
|
|
ctx: Context,
|
|
|
|
description: str,
|
|
|
|
data_members: list[EthereumStructMember],
|
|
|
|
title: str = "Confirm struct",
|
|
|
|
button_text: str = "Show full struct",
|
|
|
|
) -> bool:
|
|
|
|
para = (
|
|
|
|
(ui.BOLD, description),
|
|
|
|
(
|
|
|
|
ui.NORMAL,
|
|
|
|
format_plural("Contains {count} {plural}", len(data_members), "key"),
|
|
|
|
),
|
|
|
|
(ui.NORMAL, ", ".join(field.name for field in data_members)),
|
|
|
|
)
|
|
|
|
return await should_show_more(
|
|
|
|
ctx,
|
|
|
|
title=title,
|
|
|
|
para=para,
|
|
|
|
button_text=button_text,
|
|
|
|
br_type="should_show_struct",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def should_show_array(
|
|
|
|
ctx: Context,
|
|
|
|
parent_objects: Iterable[str],
|
|
|
|
data_type: str,
|
|
|
|
size: int,
|
|
|
|
) -> bool:
|
|
|
|
para = ((ui.NORMAL, format_plural("Array of {count} {plural}", size, data_type)),)
|
|
|
|
return await should_show_more(
|
|
|
|
ctx,
|
|
|
|
title=limit_str(".".join(parent_objects)),
|
|
|
|
para=para,
|
|
|
|
button_text="Show full array",
|
|
|
|
br_type="should_show_array",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def confirm_typed_value(
|
|
|
|
ctx: Context,
|
|
|
|
name: str,
|
|
|
|
value: bytes,
|
|
|
|
parent_objects: list[str],
|
|
|
|
field: EthereumFieldType,
|
2022-01-07 14:13:54 +00:00
|
|
|
array_index: int | None = None,
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
) -> None:
|
|
|
|
type_name = get_type_name(field)
|
|
|
|
|
|
|
|
if array_index is not None:
|
|
|
|
title = limit_str(".".join(parent_objects + [name]))
|
|
|
|
description = f"[{array_index}] ({type_name})"
|
|
|
|
else:
|
|
|
|
title = limit_str(".".join(parent_objects))
|
|
|
|
description = f"{name} ({type_name})"
|
|
|
|
|
|
|
|
data = decode_typed_data(value, type_name)
|
|
|
|
|
|
|
|
if field.data_type in (EthereumDataType.ADDRESS, EthereumDataType.BYTES):
|
|
|
|
await confirm_blob(
|
|
|
|
ctx,
|
|
|
|
"confirm_typed_value",
|
|
|
|
title=title,
|
|
|
|
data=data,
|
|
|
|
description=description,
|
|
|
|
ask_pagination=True,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
await confirm_text(
|
|
|
|
ctx,
|
|
|
|
"confirm_typed_value",
|
|
|
|
title=title,
|
|
|
|
data=data,
|
|
|
|
description=description,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-31 09:45:21 +00:00
|
|
|
def format_ethereum_amount(
|
|
|
|
value: int, token: tokens.TokenInfo | None, chain_id: int
|
|
|
|
) -> str:
|
|
|
|
if token:
|
|
|
|
suffix = token.symbol
|
|
|
|
decimals = token.decimals
|
2017-12-27 11:48:05 +00:00
|
|
|
else:
|
2021-08-24 10:15:36 +00:00
|
|
|
suffix = networks.shortcut_by_chain_id(chain_id)
|
2018-02-28 01:09:10 +00:00
|
|
|
decimals = 18
|
|
|
|
|
2019-05-16 10:50:23 +00:00
|
|
|
# Don't want to display wei values for tokens with small decimal numbers
|
|
|
|
if decimals > 9 and value < 10 ** (decimals - 9):
|
2018-07-03 14:20:58 +00:00
|
|
|
suffix = "Wei " + suffix
|
2018-02-28 01:09:10 +00:00
|
|
|
decimals = 0
|
2017-12-27 11:48:05 +00:00
|
|
|
|
2021-09-27 10:13:51 +00:00
|
|
|
return f"{format_amount(value, decimals)} {suffix}"
|
feat(core/ethereum): EIP-712
Based on original contribution by Max Kupriianov <xlab@hey.com>
Implemented EIP-712 typed data signatures in Ethereum app.
Add eth_abi into pyproject deps
device test for EIP 712
fixed hex decoding for address
fixup! fixed hex decoding for address
code quality, more pythonic code, removing unused imports
running black and isort on changed files
trezorctl file input for EIP 712 data signing
fixup! code quality, more pythonic code, removing unused imports
fixup! fixup! code quality, more pythonic code, removing unused imports
necessary changes after rebase to master
unit tests for sign_typed_data.py
new protobuf messages, working for nonarray types
simplified and verified solution for our simple data
support for simple arrays, without their confirmation
reverting protobuf value messages to bytes, appropriate changes
showing arrays in Trezor, code quality improvements
data validation on Trezor, minor improvements
using custom types for storing type data instead of dicts, addressing feedback from review
moving helper functions to its own file, tests for decode_data
additional overall tests
support for arrays of structs
adding support for metamask_v4_compat variable
using HashWriter object to collect the final hash continously
minor improvements in code quality
validate_field_type function
streaming values from client without saving them, missing UI
prototype of streamed UI using confirm_properties
accounting for bytes in data, more data types in integration tests
rebase on master, using f-strings
minor fixes and improvements from code review
StructHasher class for the whole hashing process
mypy and style changes
asking users whether to show structs and arrays
protobuf descriptions to fix make defs_check
unifying comments, mypy fix
unit tests for StructHasher class
UI fixtures, skipping device tests for T1
addressing majority of code review comments about code quality and structure
changing file structure - layouts, helpers, sign_typed_data
decode_data renaming and docstring, renaming unit test file
using tuples instead of lists in elifs
layout improvements
excluding core/src/apps/common/confirm.py file from the PR
True/False returning layout with Show more button
code review layout improvements
forgotten br_type argument to should_show_more
2021-04-12 20:38:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def limit_str(s: str, limit: int = 16) -> str:
|
|
|
|
"""Shortens string to show the last <limit> characters."""
|
|
|
|
if len(s) <= limit + 2:
|
|
|
|
return s
|
|
|
|
|
|
|
|
return ".." + s[-limit:]
|