eip712 0.3.0__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {eip712-0.3.0/eip712.egg-info → eip712-0.3.2}/PKG-INFO +1 -1
- {eip712-0.3.0 → eip712-0.3.2}/eip712/messages.py +42 -5
- {eip712-0.3.0 → eip712-0.3.2}/eip712/version.py +3 -3
- {eip712-0.3.0 → eip712-0.3.2/eip712.egg-info}/PKG-INFO +1 -1
- {eip712-0.3.0 → eip712-0.3.2}/.github/ISSUE_TEMPLATE/bug.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/ISSUE_TEMPLATE/feature.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/ISSUE_TEMPLATE/work-item.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/release-drafter.yml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/codeql.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/commitlint.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/docs.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/draft.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/prtitle.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/publish.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.github/workflows/test.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.gitignore +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/.pre-commit-config.yaml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/CONTRIBUTING.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/LICENSE +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/README.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/_static/custom.css +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/_static/custom.js +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/_templates/layout.html +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/conf.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/favicon.ico +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/index.rst +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/logo.gif +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/methoddocs/common.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/methoddocs/messages.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/docs/userguides/quickstart.md +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712/__init__.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712/common.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712/py.typed +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712/utils.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712.egg-info/SOURCES.txt +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712.egg-info/dependency_links.txt +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712.egg-info/requires.txt +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/eip712.egg-info/top_level.txt +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/pyproject.toml +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/setup.cfg +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/__init__.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/conftest.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/test_common.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/test_fuzzing.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/test_messages.py +0 -0
- {eip712-0.3.0 → eip712-0.3.2}/tests/test_utils.py +0 -0
|
@@ -4,7 +4,11 @@ Message classes for typed structured data hashing and signing in Ethereum.
|
|
|
4
4
|
|
|
5
5
|
from typing import Any, ClassVar, get_args
|
|
6
6
|
|
|
7
|
-
from eth_account.messages import
|
|
7
|
+
from eth_account.messages import (
|
|
8
|
+
SignableMessage,
|
|
9
|
+
encode_typed_data,
|
|
10
|
+
hash_domain,
|
|
11
|
+
)
|
|
8
12
|
from eth_pydantic_types import HexBytes, abi
|
|
9
13
|
from eth_utils.crypto import keccak
|
|
10
14
|
from pydantic import BaseModel, ConfigDict, PrivateAttr, model_validator
|
|
@@ -37,12 +41,17 @@ class EIP712Domain(BaseModel):
|
|
|
37
41
|
return {
|
|
38
42
|
"EIP712Domain": [
|
|
39
43
|
{"name": field, "type": inner_type.__name__}
|
|
40
|
-
for field, field_info in
|
|
44
|
+
for field, field_info in EIP712Domain.model_fields.items()
|
|
41
45
|
if getattr(self, field) is not None
|
|
42
46
|
and (inner_type := get_args(field_info.annotation)[0])
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
@property
|
|
51
|
+
def separator(self) -> HexBytes:
|
|
52
|
+
domain = _prepare_data_for_hashing(self.model_dump(exclude_none=True))
|
|
53
|
+
return HexBytes(hash_domain(domain))
|
|
54
|
+
|
|
46
55
|
|
|
47
56
|
class EIP712Message(BaseModel):
|
|
48
57
|
"""
|
|
@@ -69,7 +78,7 @@ class EIP712Message(BaseModel):
|
|
|
69
78
|
"""
|
|
70
79
|
|
|
71
80
|
eip712_domain: ClassVar[EIP712Domain | None] = None
|
|
72
|
-
"""The default EIP712 to use for this model. Can be
|
|
81
|
+
"""The default EIP712 to use for this model. Can be overridden on model init"""
|
|
73
82
|
|
|
74
83
|
_eip712_domain_: EIP712Domain = PrivateAttr()
|
|
75
84
|
|
|
@@ -130,13 +139,21 @@ def extract_eip712_struct_message(msg: EIP712Message) -> dict:
|
|
|
130
139
|
"""The EIP-712 structured message to be used for serialization and hashing."""
|
|
131
140
|
|
|
132
141
|
return {
|
|
133
|
-
"domain": msg
|
|
134
|
-
"types":
|
|
142
|
+
"domain": extract_eip712_domain(msg),
|
|
143
|
+
"types": extract_eip712_types(msg),
|
|
135
144
|
"primaryType": msg.__class__.__name__,
|
|
136
145
|
"message": msg.model_dump(),
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
|
|
149
|
+
def extract_eip712_domain(msg: EIP712Message) -> dict:
|
|
150
|
+
return msg._eip712_domain_.model_dump(exclude_none=True)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def extract_eip712_types(msg: EIP712Message) -> dict:
|
|
154
|
+
return {**msg._eip712_domain_.eip712_type, **build_eip712_type(msg.__class__)}
|
|
155
|
+
|
|
156
|
+
|
|
140
157
|
def calculate_hash(msg: SignableMessage) -> HexBytes:
|
|
141
158
|
return HexBytes(keccak(b"".join([bytes.fromhex("19"), *msg])))
|
|
142
159
|
|
|
@@ -152,3 +169,23 @@ def hash_message(msg: EIP712Message) -> HexBytes:
|
|
|
152
169
|
HexBytes: 32 byte hash of the message, hashed according to EIP712
|
|
153
170
|
"""
|
|
154
171
|
return calculate_hash(msg.signable_message)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _prepare_data_for_hashing(data: dict) -> dict:
|
|
175
|
+
result: dict = {}
|
|
176
|
+
|
|
177
|
+
for key, value in data.items():
|
|
178
|
+
item: Any = value
|
|
179
|
+
if isinstance(value, BaseModel):
|
|
180
|
+
item = value.model_dump(exclude_none=True)
|
|
181
|
+
elif isinstance(value, dict):
|
|
182
|
+
item = _prepare_data_for_hashing(item)
|
|
183
|
+
elif isinstance(value, list):
|
|
184
|
+
elms = []
|
|
185
|
+
for elm in item:
|
|
186
|
+
if isinstance(elm, dict):
|
|
187
|
+
elm = _prepare_data_for_hashing(elm)
|
|
188
|
+
elms.append(elm)
|
|
189
|
+
item = elms
|
|
190
|
+
result[key] = item
|
|
191
|
+
return result
|
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.3.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 3,
|
|
31
|
+
__version__ = version = '0.3.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 3, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g5104707b8'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|