Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade eth-account [APE-1614] #42

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.12.0
hooks:
- id: black
name: black
Expand Down
24 changes: 21 additions & 3 deletions eip712/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from typing import Any, Dict, Optional

from dataclassy import dataclass, fields
from dataclassy import asdict, dataclass, fields
from eth_abi import is_encodable_type
from eth_account.messages import SignableMessage, hash_domain, hash_eip712_message
from eth_utils import keccak
Expand Down Expand Up @@ -143,12 +143,30 @@ def signable_message(self) -> SignableMessage:
The current message as a :class:`SignableMessage` named tuple instance.
**NOTE**: The 0x19 prefix is NOT included.
"""
domain = _prepare_data_for_hashing(self._domain_["domain"])
types = _prepare_data_for_hashing(self._types_)
message = _prepare_data_for_hashing(self._body_["message"])
return SignableMessage(
HexBytes(1),
HexBytes(hash_domain(self._domain_)),
HexBytes(hash_eip712_message(self._body_)),
HexBytes(hash_domain(domain)),
HexBytes(hash_eip712_message(types, message)),
)


def calculate_hash(msg: SignableMessage) -> HexBytes:
return HexBytes(keccak(b"".join([bytes.fromhex("19"), *msg])))


def _prepare_data_for_hashing(data: Dict) -> Dict:
result: Dict = {}

for key, value in data.items():
item: Any = value
if isinstance(value, EIP712Type):
item = asdict(value)
elif isinstance(value, dict):
item = _prepare_data_for_hashing(item)

result[key] = item

return result
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"hypothesis>=6.70.0,<7", # Strategy-based fuzzer
],
"lint": [
"black>=23.7.0,<24", # auto-formatter and linter
"mypy>=1.5.1,<2", # Static type analyzer
"black>=23.12.0,<24", # auto-formatter and linter
"mypy>=1.7.1,<2", # Static type analyzer
"types-setuptools", # Needed for mypy type shed
"flake8>=6.0.0,<7", # Style linter
"flake8>=6.1.0,<7", # Style linter
"isort>=5.12.0,<6", # Import sorting linter
"mdformat>=0.7.16,<0.8", # Auto-formatter for markdown
"mdformat>=0.7.17,<0.8", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5,<0.4", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1,<0.5", # Needed for headers in GH issue templates
],
Expand Down Expand Up @@ -65,11 +65,11 @@
include_package_data=True,
install_requires=[
"dataclassy>=0.8.2,<1",
"eth-abi>=4.1.0,<5",
"eth-account>=0.8.0,<0.9",
"eth-abi>=4.2.1,<5",
"eth-account>=0.10.0,<0.11",
"eth-hash[pycryptodome]", # NOTE: Pinned by eth-abi
"eth-typing>=3.3.0,<4",
"eth-utils>=2.1.0,<3",
"eth-typing>=3.5.2,<4",
"eth-utils>=2.3.1,<3",
"hexbytes>=0.3.0,<1",
],
python_requires=">=3.8,<4",
Expand Down