Signers
A signer holds (or has access to) a private key and produces signatures over
transaction hashes. tronz defines a small TronSigner trait so different
backends — in-memory keys, HSMs, remote signers — can be used interchangeably.
use tronz::{TronSigner, LocalSigner};The TronSigner trait
The following is an abbreviated view of the 0.5 trait (implementation details and feature-gated methods are omitted):
pub trait TronSigner {
/// The address derived from this signer's key.
fn address(&self) -> Address;
/// Sign a 32-byte hash, returning a recoverable signature.
async fn sign_hash(
&self,
hash: &B256,
) -> Result<RecoverableSignature, SignerError>;
/// Sign plaintext using TRON's message prefix and hashing scheme.
async fn sign_message(
&self,
message: &[u8],
) -> Result<RecoverableSignature, SignerError>;
}Signing is async even for in-memory keys, so the same trait covers signers
that hit the network or dedicated hardware. tronz signs the transaction id — the
sha256 of the protobuf-encoded raw transaction — and attaches a 65-byte
recoverable signature. With the signer-tip712 feature (included by full),
the trait also exposes TIP-712 typed-data signing methods; see
TIP-712 typed data.
Implementations
| Type | Description |
|---|---|
LocalSigner | secp256k1 private key held in memory |
TronWallet | Cloneable wallet that can route signing across multiple keys |
A provider built without a wallet can read and build transactions, but its type
does not implement the signing capability required by .send().
Attaching a signer to a provider
You rarely call a signer directly. Instead, hand it to the
ProviderBuilder, which wires it into the filler
chain so transactions are signed automatically before broadcast:
use tronz::{LocalSigner, ProviderBuilder, TRONGRID_NILE};
let signer = LocalSigner::from_hex("PRIVATE_KEY_HEX")?;
let provider = ProviderBuilder::new()
.with_signer(signer)
.connect_grpc(TRONGRID_NILE)
.await?;