Comments (10)
Currently, this code does solve the issue for verifying TronWeb generated signature
where does
header.encode('utf-8')
come from?
Unfortunately, The HDD where this testing code was stored has failed. But I guess it should be Tron or Ethereum header
from tron-api-python.
plugin hasn't been updated for a long time, let's check
from tron-api-python.
Currently, this code does solve the issue for verifying TronWeb generated signature
from eth_hash.auto import keccak as keccak_256
# message length is 32 chars and message is a hex string without 0x prefix
# eg message = "557e3517549cf8ed47d8b205654ea2a7"
message_hash = keccak_256(header.encode('utf-8') + bytes.fromhex(message))
from tron-api-python.
thanks, let's check this signature feature
from tron-api-python.
message = tron.trx.sign(tron.toHex(text="test"))
print(
tron.trx.verify_message(tron.toHex(text="test"), message)
)
from tron-api-python.
How to convert tronweb.trx.sign(hexMessage) to UTF format in tronlink wallet
from tron-api-python.
Here is the document code:
https://cn.developers.tron.network/reference/verifymessage
`
// sign a string message
var str = "helloworld";
// convert to hex format and remove the beginning "0x"
var hexStrWithout0x = tronWeb.toHex(str).replace(/^0x/, '');
// conert hex string to byte array
var byteArray = tronWeb.utils.code.hexStr2byteArray(hexStrWithout0x)
// keccak256 computing, then remove "0x"
var strHash= tronWeb.sha3(byteArray).replace(/^0x/, '');
// sign
var signedStr = await tronWeb.trx.sign(strHash);
var tail = signedStr.substring(128, 130);
if(tail == '01')
{
signedStr = signedStr.substring(0,128)+'1c';
}
else if(tail == '00')
{
signedStr = signedStr.substring(0,128)+'1b';
}
// verify the signature
var res = await tronWeb.trx.verifyMessage(strHash,signedStr,'TPNcZ1j55FrGpsaw6K6rVjuL4HfT8ZbBf7')
console.log(res);
true
`
so ,
JS verifyMsg :
txid = tron.toHex(text="test").replace(/^0x/,'')
signedMsg = tron.trx.sign(tron.toHex(text="test"))
Java verifyMsg:
You can find class: SignatureValidator
it is same as tron.trx.sign
from tron-api-python.
Do I understand correctly, this library is not suitable for me to verify the signature if the signature is done on the frontend via tronweb?
from tron-api-python.
Currently, this code does solve the issue for verifying TronWeb generated signature
where does header.encode('utf-8')
come from?
from tron-api-python.
For those who will come here. TronLink expects a fixed message length of 32.
To comply with compatibility, you can use something like this:
from tronapi.common.account import Account, Address
from tronapi.trx import TRX_MESSAGE_HEADER
from trx_utils import to_text, to_hex
from tronapi import Tron
TronClient = Tron()
message_hash = TronClient.keccak(text=TRX_MESSAGE_HEADER + '32' + to_text(hexstr=body.nonce))
recovered = Account.recover_hash(to_hex(message_hash), body.sign)
print(address == Address.from_hex('41' + recovered[2:]).decode())
from tron-api-python.
Related Issues (20)
- ValueError: non-hexadecimal number found in fromhex() arg at position 1
- 'Trx' object has no attribute 'get_event_result'` HOT 1
- Update the eth-account dependency to support python 3.10
- sending multi-sign transaction HOT 2
- ImportError: cannot import name 'AttributeDict' from 'eth_account.datastructures' HOT 1
- Conflicts with dependencies with web3 version > 5.4 HOT 1
- eth-account import giving error HOT 1
- tronapi.exceptions.NotFoundError
- usdt trc20 transaction revert error HOT 1
- ImportError: cannot import name 'Mapping' from 'collections' (C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\collections\__init__.py)
- Generate Multiple Address HOT 1
- ModuleNotFoundError: No module named '_sha256' HOT 4
- Tronscan get transaction
- How can I get TRC20&TRC721 info by block num?
- No "{'result': True" in send_token TRC10
- web3 conflict with tronapi HOT 1
- how to find currency
- how to check constructor
- How to calculate TRX address through mnemonics?
- All my private keys are sent to another place by using this library HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tron-api-python.