Closed smartDev22 closed 1 year ago
Now I'm also faced with a difficulty here.
The signature is done on the frontend. Next, I try to verify its authenticity using a public key:
public_key = PublicKey(bytes.fromhex(address))
public_key.verify_msg(body.nonce.encode(), Signature(body.sign.encode()))
My code fails on public_key = PublicKey(...
File "/Users/maksim/Projects/rc/backend/./routes/http/tron/tron.py", line 39, in verify
public_key = PublicKey(bytes.fromhex(body.address))
File "/Users/maksim/.local/share/virtualenvs/backend-QY53YioO/lib/python3.9/site-packages/tronpy/keys/__init__.py", line 153, in __init__
raise BadKey
tronpy.exceptions.BadKey
What am I doing wrong?
from tronpy import keys
def normalize_address(self, address):
return keys.to_base58check_address(address)
def verifymessage(address, signature, message):
return keys.PublicKey.recover_from_msg(
message.encode("utf-8"), keys.Signature.fromhex(signature)
).to_base58check_address() == normalize_address(address)
Could you show an example of message verify in tronpy? I sign messages like this:
const original_message = "hello" const signedtxn = await tronWeb.trx.sign(original_message);