From 7b15f9cd41c644759a50e75ef2066d268ae38b44 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Fri, 1 Sep 2023 13:31:06 -0400 Subject: [PATCH] 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. --- Pipfile | 1 - nucypher/policy/conditions/context.py | 29 ++++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Pipfile b/Pipfile index 181691b54..78394dfb4 100644 --- a/Pipfile +++ b/Pipfile @@ -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" diff --git a/nucypher/policy/conditions/context.py b/nucypher/policy/conditions/context.py index dd3df432c..d8bc0f1f3 100644 --- a/nucypher/policy/conditions/context.py +++ b/nucypher/policy/conditions/context.py @@ -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