r402_casper/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! Casper chain support for the x402 payment protocol.
4//!
5//! This crate implements the x402 "exact" payment scheme for the
6//! [Casper Network](https://casper.network), settling in wCSPR — a CEP-18
7//! token — through the contract's `transfer_with_authorization` entry point.
8//!
9//! # Features
10//!
11//! - **CAIP-2 Addressing**: `casper:casper` (mainnet) and
12//! `casper:casper-test` (testnet)
13//! - **CEP-18 Payments**: token transfers authorised by an EIP-712
14//! `TransferWithAuthorization` signature, relayed and gas-paid by the
15//! facilitator
16//! - **Exact Mote Arithmetic**: CSPR has 9 decimals; every conversion is
17//! integer-only and sub-mote precision is a typed error, never a silent
18//! truncation (see [`Motes`])
19//! - **Key Validation**: tagged Casper addressable keys (`00` account hash,
20//! `01` hash) and public keys (`01` ed25519, `02` secp256k1)
21//! - **Facilitator Client**: `/verify`, `/settle`, and `/supported` against
22//! the hosted Casper facilitator, overridable via config or environment
23//!
24//! # Architecture
25//!
26//! The crate mirrors the layout of the sibling chain crates:
27//!
28//! - [`chain`] — Casper chain types (references, addresses, deployments)
29//! - [`exact`] — the Casper "exact" payment scheme
30//! - [`motes`] — exact 9-decimal base-unit arithmetic
31//! - [`hex`] — minimal hex codec for Casper wire values
32//!
33//! # Feature Flags
34//!
35//! - `server` — server-side price tag generation
36//! - `client` — client-side authorisation assembly
37//! - `facilitator` — facilitator client for verify/settle/supported
38//! - `telemetry` — tracing instrumentation
39//!
40//! # Example
41//!
42//! ```
43//! use r402_casper::chain::Address;
44//! use r402_casper::{CasperExact, WCSPR};
45//!
46//! # #[cfg(feature = "server")]
47//! # fn main() {
48//! let pay_to: Address = "00fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321"
49//! .parse()
50//! .unwrap();
51//! // 1.5 wCSPR, expressed exactly in motes.
52//! let tag = CasperExact::price_tag(pay_to, WCSPR::casper_test().amount(1_500_000_000));
53//! assert_eq!(tag.requirements.network.to_string(), "casper:casper-test");
54//! # }
55//! # #[cfg(not(feature = "server"))]
56//! # fn main() {}
57//! ```
58
59// The `telemetry` feature wires tracing through `r402-core`'s instrumentation;
60// this crate declares the dependency so downstream feature unification works.
61// Optional `client` deps are consumed from feature-gated modules
62// (`exact::client`, `exact::eip712`). Name them at the crate root so
63// `unused_crate_dependencies` still sees them under feature unification.
64#[cfg(feature = "client")]
65use rand as _;
66#[cfg(feature = "client")]
67use sha3 as _;
68#[cfg(feature = "telemetry")]
69use tracing as _;
70
71/// Public JSON-RPC endpoint documentation for the Casper facilitator stack.
72///
73/// The hosted facilitator, node endpoints, and their request/response shapes
74/// are documented at this address.
75pub const CASPER_DOCS_URL: &str = "https://docs.cspr.cloud";
76
77pub mod chain;
78pub mod exact;
79pub mod hex;
80pub mod motes;
81
82mod networks;
83
84pub use exact::CasperExact;
85#[cfg(feature = "http-client")]
86#[cfg_attr(docsrs, doc(cfg(feature = "http-client")))]
87pub use exact::facilitator::ReqwestTransport;
88#[cfg(feature = "facilitator")]
89#[cfg_attr(docsrs, doc(cfg(feature = "facilitator")))]
90pub use exact::facilitator::{CasperExactFacilitator, CasperFacilitatorConfig};
91#[cfg(feature = "client")]
92#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
93pub use exact::{CasperExactClient, CasperSigner, Eip712Domain};
94pub use motes::{CSPR_DECIMALS, MOTES_PER_CSPR, Motes, MotesParseError};
95pub use networks::*;