Keys and Addresses¶
There are two types of address format, “base58check” and “hex str”. The base58check variant is more user-friendly.
TronPy accepts both type of address. The Base58check type is preferred.
Key API reference¶
-
tronpy.keys.
to_base58check_address
(raw_addr: Union[str, bytes]) → str¶ Convert hex address or base58check address to base58check address(and verify it).
-
class
tronpy.keys.
PrivateKey
(private_key_bytes: bytes)¶ The private key.
-
classmethod
fromhex
(hex_str)¶ Construct a key from a hex str.
Returns: The key object.
-
hex
()¶ Key as a hex str.
Returns: A hex str.
-
classmethod
from_passphrase
(passphrase: bytes) → tronpy.keys.PrivateKey¶ Get a private key from sha256 of a passphrase.
-
classmethod
random
() → tronpy.keys.PrivateKey¶ Generate a random private key.
-
sign_msg
(message: bytes) → tronpy.keys.Signature¶ Sign a raw message.
-
sign_msg_hash
(message_hash: bytes) → tronpy.keys.Signature¶ Sign a message hash(sha256).
-
classmethod
-
class
tronpy.keys.
PublicKey
(public_key_bytes: bytes)¶ The public key.
-
classmethod
fromhex
(hex_str)¶ Construct a key from a hex str.
Returns: The key object.
-
hex
()¶ Key as a hex str.
Returns: A hex str.
-
classmethod
recover_from_msg
(message: bytes, signature: tronpy.keys.Signature)¶ Recover public key(address) from raw message and signature.
-
classmethod
recover_from_msg_hash
(message_hash: bytes, signature: tronpy.keys.Signature)¶ Recover public key(address) from message hash and signature.
-
to_base58check_address
() → str¶ Get the base58check address of the public key.
-
verify_msg
(message: bytes, signature: tronpy.keys.Signature) → bool¶ Verify message and signature.
-
verify_msg_hash
(message_hash: bytes, signature: tronpy.keys.Signature) → bool¶ Verify message hash and signature.
-
classmethod
-
class
tronpy.keys.
Signature
(signature_bytes: bytes)¶ The signature object.
-
classmethod
fromhex
(hex_str: str) → tronpy.keys.Signature¶ Construct a Signature from hex str.
-
hex
() → str¶ Return signature as a hex str.
Returns: A hex str.
-
recover_public_key_from_msg
(message: bytes) → tronpy.keys.PublicKey¶ Recover public key(address) from message and signature.
-
recover_public_key_from_msg_hash
(message_hash: bytes) → tronpy.keys.PublicKey¶ Recover public key(address) from message hash and signature.
-
verify_msg
(message: bytes, public_key: tronpy.keys.PublicKey) → bool¶ Verify message and signature.
-
verify_msg_hash
(message_hash: bytes, public_key: tronpy.keys.PublicKey) → bool¶ Verify message hash and signature.
-
classmethod