r402_tron/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Tron chain support for the x402 payment protocol.
4//!
5//! This crate provides implementations of the x402 payment protocol for Tron
6//! chains with the "exact" payment scheme based on EIP-3009
7//! `transferWithAuthorization` and SUN.io Permit2 via `x402ExactPermit2Proxy`.
8//!
9//! # Features
10//!
11//! - **CAIP-2 Addressing**: Uses CAIP-2 chain IDs (e.g., `tron:0x2b6653dc`) for chain identification
12//! - **`Base58Check` Addresses**: Tron-native `T`-prefixed addresses with 0x41 prefix
13//! - **TIP-712 Signing**: Byte-compatible with EIP-712, using secp256k1 ECDSA
14//! - **EIP-3009 Payments**: Gasless token transfers using `transferWithAuthorization`
15//! - **Permit2 Payments**: SUN.io Permit2 fallback for tokens without EIP-3009 (e.g. USDT)
16//! - **`TronGrid` API**: HTTP REST API for chain interaction (no JSON-RPC)
17//!
18//! # Architecture
19//!
20//! The crate is organized into two modules:
21//!
22//! - [`chain`] - Core Tron chain types, providers, and contract bindings
23//! - [`exact`] - Tron "exact" payment scheme
24//!
25//! # Feature Flags
26//!
27//! - `server` - Server-side price tag generation
28//! - `client` - Client-side payment signing
29//! - `facilitator` - Facilitator-side payment verification and settlement
30//! - `telemetry` - `OpenTelemetry` tracing support
31
32// Silence the linter when default features disable every consumer.
33#[cfg(not(any(feature = "client", feature = "server", feature = "facilitator")))]
34use compact_str as _;
35#[cfg(not(any(feature = "client", feature = "server", feature = "facilitator")))]
36use serde_json as _;
37#[cfg(feature = "telemetry")]
38use tracing_core as _;
39
40/// Default clock-skew tolerance (seconds) applied to TIP-712 time-window checks.
41///
42/// Tron produces blocks approximately every 3 seconds; we use 6 seconds
43/// (2 blocks) to provide a reasonable grace window for clock drift between
44/// the facilitator and the Tron network.
45pub const TRON_DEFAULT_CLOCK_SKEW_TOLERANCE_SECS: u64 = 6;
46
47pub mod chain;
48pub mod exact;
49
50mod networks;
51pub use exact::TronExact;
52#[cfg(feature = "client")]
53pub use exact::client::{Eip3009SigningParams, Permit2SigningParams, SignerLike, TronExactClient};
54pub use networks::*;