Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in tronapi.trx.Trx.verify_message/sign. #49

Closed
oldnote opened this issue Aug 16, 2019 · 3 comments
Closed

Bug in tronapi.trx.Trx.verify_message/sign. #49

oldnote opened this issue Aug 16, 2019 · 3 comments

Comments

@oldnote
Copy link

oldnote commented Aug 16, 2019

Code example
TRON_SETTINGS = {
    'full_node': 'https://api.shasta.trongrid.io',
    'solidity_node': 'https://api.shasta.trongrid.io',
    'event_server': 'https://api.shasta.trongrid.io',
}

tron = tronapi.Tron(**TRON_SETTINGS)

account = tron.create_account  # XXX: create_account is property.
tron.private_key = account.private_key
tron.default_address = account.address.base58

message = tron.toHex(text='hello')
signed = tron.trx.sign(message)

tron.trx.verify_message(message, signed)

Result is always ValueError: Signature does not match.

I've inspected tronapi.trx.Trx.sign and tronapi.trx.Trx.verify_message and found that they have different code for header definition:

tronapi.trx.Trx.sign
            # Determine which header to attach to the message
            # before encrypting or decrypting
            header = TRX_MESSAGE_HEADER if use_tron else ETH_MESSAGE_HEADER
            header += str(len(transaction))

            message_hash = self.tron.keccak(text=header+transaction)
tronapi.trx.Trx.verify_message
        # Determine which header to attach to the message
        # before encrypting or decrypting
        header = TRX_MESSAGE_HEADER if use_tron else ETH_MESSAGE_HEADER

        message_hash = self.tron.keccak(text=header+message)

Adding header += str(len(message)) string into tronapi.trx.Trx.verify_message fixes the problem.

@serderovsh
Copy link
Contributor

f001328

@oldnote oldnote closed this as completed Aug 16, 2019
@oldnote
Copy link
Author

oldnote commented Aug 16, 2019

@serderovsh add new tag please, i can't install version with changes.

@birdonwheels5
Copy link

birdonwheels5 commented Oct 18, 2020

@Anon731 Can you please provide a complete working code sample with the added header? I'm trying to use your suggestion but not having much luck.

Edit: I ended up using the NodeJS API to correctly match the signature generated with the clientside tronweb API. The python API really shouldn't be doing this differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants