ethereum / eth-keys

A common API for Ethereum key operations.
MIT License
159 stars 64 forks source link

PublicKey.recover_from_msg error #84

Closed ven0xm closed 2 years ago

ven0xm commented 2 years ago

Running 'eth_keys.KeyAPI.PublicKey.recover_from_msg' when supplying a signature manually from outside causes 'has no attribute 'to_bytes' issue

`

msg = 'jq788rddfw6498oiutewqwoplnbvctews86543k' message = bytes(msg, 'utf-8') signature = '02b73260666b93455e1f90218ffb65ce6a801def771b8ffd1cf6e8f566a617194ab667193debb6d97dc827a921010a0cee9c911f2a40c6b736113e8ea11871391b' eth_keys.KeyAPI.PublicKey.recover_from_msg(message, signature) Traceback (most recent call last): File "", line 1, in File "/eth_keys/datatypes.py", line 205, in recover_from_msg return cls.recover_from_msg_hash(message_hash, signature, backend) File "/eth_keys/datatypes.py", line 215, in recover_from_msg_hash return backend.ecdsa_recover(message_hash, signature) File "/eth_keys/backends/coincurve.py", line 94, in ecdsa_recover signature_bytes = signature.to_bytes() AttributeError: 'str' object has no attribute 'to_bytes' `

How can it be fixed?

carver commented 2 years ago

Sorry, there's not much in the way of guides, because frankly eth-keys is meant as a sort of "internal" tool. You may be looking for one of our more user-facing tools, something like the eth-account tool which gets bundled with web3. See the docs for verifying a message.