txgate_chain/lib.rs
1//! # txgate-chain
2//!
3//! Multi-chain transaction parsing and construction for the `TxGate` signing service.
4//!
5//! ## Internal Crate Warning
6//!
7//! **This crate is an internal implementation detail of [`txgate`](https://crates.io/crates/txgate).**
8//!
9//! It is published to crates.io only because Cargo requires all dependencies to be
10//! published. The API is **unstable** and may change without notice between any versions,
11//! including patch releases.
12//!
13//! **Do not depend on this crate directly.** Instead:
14//! - For the signing server binary: `cargo install txgate`
15//! - For programmatic access: Open an issue at <https://github.com/luisjpf/txgate>
16//! to discuss a stable public API.
17//!
18//! This crate provides blockchain-specific transaction handling through the
19//! [`Chain`] trait and chain-specific parser implementations.
20//!
21//! ## Core Trait
22//!
23//! The [`Chain`] trait is the foundation for all blockchain parsers:
24//!
25//! ```rust
26//! use txgate_chain::Chain;
27//! use txgate_core::{ParsedTx, TxType, error::ParseError};
28//! use txgate_crypto::CurveType;
29//!
30//! struct MyChainParser;
31//!
32//! impl Chain for MyChainParser {
33//! fn id(&self) -> &'static str {
34//! "my-chain"
35//! }
36//!
37//! fn parse(&self, raw: &[u8]) -> Result<ParsedTx, ParseError> {
38//! // Parse chain-specific transaction format
39//! Ok(ParsedTx {
40//! chain: "my-chain".to_string(),
41//! tx_type: TxType::Transfer,
42//! ..Default::default()
43//! })
44//! }
45//!
46//! fn curve(&self) -> CurveType {
47//! CurveType::Secp256k1
48//! }
49//! }
50//! ```
51//!
52//! ## Modules (planned)
53//!
54//! - `evm` - Ethereum and EVM-compatible chains (Polygon, Arbitrum, etc.)
55//! - `solana` - Solana transaction parsing
56//! - `bitcoin` - Bitcoin transaction handling
57//! - `substrate` - Substrate-based chains (Polkadot, etc.)
58//! - `cosmos` - Cosmos SDK chains
59//!
60//! ## Features
61//!
62//! - Transaction parsing and validation
63//! - Human-readable transaction decoding
64//! - ABI/IDL decoding for smart contract interactions
65//! - Gas estimation helpers
66//! - Chain-specific address validation
67//!
68//! ## Supported Chains (planned)
69//!
70//! - Ethereum Mainnet and testnets
71//! - Polygon, Arbitrum, Optimism, Base
72//! - Solana Mainnet and Devnet
73//! - Bitcoin Mainnet and Testnet
74//!
75//! ## Crate Features
76//!
77//! - `mock` - Enable `MockChain` for use in other crates' tests
78//!
79//! ## Chain Registry
80//!
81//! The [`ChainRegistry`] provides runtime lookup of chain parsers:
82//!
83//! ```rust
84//! use txgate_chain::ChainRegistry;
85//!
86//! let registry = ChainRegistry::new();
87//!
88//! // List all supported chains
89//! for chain_id in registry.supported_chains() {
90//! println!("Supported: {chain_id}");
91//! }
92//!
93//! // Look up a specific chain
94//! if let Some(parser) = registry.get("ethereum") {
95//! println!("Found parser for: {}", parser.id());
96//! }
97//! ```
98
99#![forbid(unsafe_code)]
100#![warn(missing_docs)]
101#![warn(clippy::all)]
102#![warn(clippy::pedantic)]
103
104pub mod bitcoin;
105pub mod chain;
106pub mod erc20;
107pub mod ethereum;
108pub mod registry;
109pub mod rlp;
110pub mod solana;
111pub mod tokens;
112
113// Additional comprehensive tests for 100% coverage
114#[cfg(test)]
115mod additional_tests;
116
117// Re-export the Chain trait at crate root for convenience
118pub use chain::Chain;
119
120// Re-export chain parsers at crate root for convenience
121pub use bitcoin::BitcoinParser;
122pub use ethereum::EthereumParser;
123pub use solana::SolanaParser;
124
125// Re-export ChainRegistry at crate root for convenience
126pub use registry::ChainRegistry;
127
128// Re-export token registry types for convenience
129pub use tokens::{RiskLevel, TokenInfo, TokenRegistry};
130
131// Re-export ERC-20 parsing types for convenience
132pub use erc20::{parse_erc20_call, Erc20Call};
133
134// Re-export MockChain and MockParseError when the mock feature is enabled or in tests
135#[cfg(any(test, feature = "mock"))]
136pub use chain::{MockChain, MockParseError};
137
138// Re-export CurveType from txgate-crypto for convenience
139pub use txgate_crypto::CurveType;
140
141// Placeholder for future modules
142// pub mod evm;
143// pub mod solana;
144// pub mod bitcoin;
145// pub mod substrate;
146// pub mod cosmos;