From 3bfe3d9ef9c8d1de713bc43140ecde4a60f13e32 Mon Sep 17 00:00:00 2001 From: antazoey Date: Wed, 13 Dec 2023 14:23:54 -0600 Subject: [PATCH] feat: upgrade eth-account [APE-1614] (#42) --- .pre-commit-config.yaml | 2 +- eip712/messages.py | 24 +++++++++++++++++++++--- setup.py | 16 ++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 818a71f..e15dfcf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/eip712/messages.py b/eip712/messages.py index 17fdcd1..a207e5c 100644 --- a/eip712/messages.py +++ b/eip712/messages.py @@ -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 @@ -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 diff --git a/setup.py b/setup.py index e9024d6..0a9c22c 100644 --- a/setup.py +++ b/setup.py @@ -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 ], @@ -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",