Remove the use of eip712_structs for processing eip712 message - use eth_account.message.encode_structured_data instead.

This removes reliance on eip712_structs and therefore pysha3.
pull/3221/head
derekpierre 2023-09-01 13:31:06 -04:00
parent d9bfd1e86a
commit 7b15f9cd41
2 changed files with 13 additions and 17 deletions

View File

@ -27,7 +27,6 @@ aiohttp = "==3.8.2"
flask = "*"
requests = "*"
# Third-Party Ethereum
eip712-structs = "*"
eth-tester = "*" # providers.py still uses this
py-evm = "*"
web3 = ">=6.0.0"

View File

@ -1,9 +1,9 @@
from typing import Any
from eip712_structs import Bytes, EIP712Struct, String, Uint
import eth_account.messages
from eth_account.account import Account
from eth_account.messages import HexBytes, SignableMessage
from eth_account.messages import HexBytes
from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address
@ -17,15 +17,6 @@ USER_ADDRESS_CONTEXT = ":userAddress"
_CONTEXT_PREFIX = ":"
_EIP712_VERSION_BYTE = b"\x01"
class UserAddress(EIP712Struct):
address = String()
blockNumber = Uint()
blockHash = Bytes(32)
signatureText = String()
def _recover_user_address(**context) -> ChecksumAddress:
# Expected format:
@ -44,11 +35,17 @@ def _recover_user_address(**context) -> ChecksumAddress:
signature = user_address_info["signature"]
user_address = to_checksum_address(user_address_info["address"])
eip712_message = user_address_info["typedData"]
message, domain = UserAddress.from_message(eip712_message)
signable_message = SignableMessage(
HexBytes(_EIP712_VERSION_BYTE),
header=domain.hash_struct(),
body=message.hash_struct(),
# convert hex data for byte fields - bytes are expected by underlying library
# 1. salt
salt = eip712_message["domain"]["salt"]
eip712_message["domain"]["salt"] = HexBytes(salt)
# 2. blockHash
blockHash = eip712_message["message"]["blockHash"]
eip712_message["message"]["blockHash"] = HexBytes(blockHash)
signable_message = eth_account.messages.encode_structured_data(
primitive=eip712_message
)
except Exception as e:
# data could not be processed