You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The encode_data method which is the underlying method for EIP712 encoding uses encode_field to encode its fields into the underlying python type. In the case of bool it just uses the python bool method to convert values to booleans, this however leads to very counterintuitive results, with strings like "False", "false", or "0" all getting parsed to True
Code that produced the error
frometh_account._utils.encode_typed_data.encoding_and_hashingimportencode_dataif__name__=='__main__':
comp=encode_data(
'Wow',
{
'Wow': [
{'name': 'nice', 'type': 'bool'}
]
},
{
'nice': '0'# can substitute for 'False' for same result
}
)
# outputs: aa6fc6f6e625657d3af464fe79175e37e32237d2b4af802593e53cf78ab9a2090000000000000000000000000000000000000000000000000000000000000001print(f'comp.hex(): {comp.hex()}')
Full error output
No response
Fill this section in if you know how this could or should be fixed
Change the bool parsing approach to recognize string formatted values like "false" / "False"
Be more explicit about parsing, either expecting the already encoded type or rejecting unrecognized versions with an actual error
What happened?
The
encode_data
method which is the underlying method for EIP712 encoding usesencode_field
to encode its fields into the underlying python type. In the case ofbool
it just uses the pythonbool
method to convert values to booleans, this however leads to very counterintuitive results, with strings like"False"
,"false"
, or"0"
all getting parsed toTrue
Code that produced the error
Full error output
No response
Fill this section in if you know how this could or should be fixed
"false"
/"False"
eth-account Version
0.13.4
Python Version
3.12.4
Operating System
osx
Output from
pip freeze
The text was updated successfully, but these errors were encountered: