import hashlib
from eth_utils import keccak
import base58
import ecdsa
from tronpy.keys import PrivateKey
def test1():
private_key_hex = "your_private_key_hex_string"
private_key_bytes = bytes.fromhex(private_key_hex)
sk = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
vk = sk.get_verifying_key()
public_key_bytes = vk.to_string()
public_key_point = vk.pubkey.point
public_key_hash = keccak(public_key_bytes)
tron_prefix = b'\x41'
prefixed_hash160 = tron_prefix + public_key_hash[-20:]
first_sha256 = hashlib.sha256(prefixed_hash160).digest()
second_sha256 = hashlib.sha256(first_sha256).digest()
checksum = second_sha256[:4]
full_payload = prefixed_hash160 + checksum
trc_address_hex = prefixed_hash160.hex()
trc_address = base58.b58encode(full_payload).decode()
print("私钥 (十六进制):", sk.to_string().hex())
print("公钥 (十六进制):", vk.to_string().hex())
print("公钥对应的椭圆曲线上的点:")
print(" x 坐标 (十六进制):", hex(public_key_point.x()))
print(" y 坐标 (十六进制):", hex(public_key_point.y()))
print("Keccak-256哈希:", public_key_hash.hex())
print("校验和:", checksum.hex())
print("完整地址数据:", full_payload.hex())
print("TRC 地址数据:", trc_address_hex)
print("TRC 地址:", trc_address)
print('\n')
def test2():
private_key_hex = "your_private_key_hex_string"
private_key = PrivateKey(bytes.fromhex(private_key_hex))
public_key = private_key.public_key
address = public_key.to_base58check_address()
print("指定的私钥 (十六进制):", private_key_hex)
print("公钥 (十六进制):", public_key.hex())
print("TRC地址:", address)
print('\n')
test1()
test2()