Skip to main content

r402_xrpl/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(
3    test,
4    allow(
5        unknown_lints,
6        clippy::unused_async_trait_impl,
7        reason = "in-crate mock impls of AFIT traits have no .await"
8    )
9)]
10
11//! XRPL chain support for the x402 payment protocol.
12//!
13//! This crate implements the x402 `"exact"` scheme for the XRP Ledger: the
14//! buyer signs a `Payment` transaction, and a facilitator submits the signed
15//! blob. The payer pays the network fee; facilitators do not sponsor fees.
16//!
17//! # Features
18//!
19//! - **CAIP-2 Addressing**: `xrpl:0` (mainnet), `xrpl:1` (testnet), `xrpl:2` (devnet)
20//! - **XRP and IOU payments**: native drops or issued-currency decimal values
21//! - **Sequence or ticket sequencing**: `extra.assetTransferMethod`
22//! - **In-process facilitator**: JSON-RPC verify and settle
23//!
24//! # Feature Flags
25//!
26//! - `server` — server-side price tag generation
27//! - `client` — client-side payment signing
28//! - `facilitator` — facilitator-side payment verification and settlement
29//! - `telemetry` — `tracing` instrumentation
30
31#[cfg(all(test, not(any(feature = "client", feature = "facilitator"))))]
32use hex as _;
33#[cfg(all(test, not(any(feature = "client", feature = "facilitator"))))]
34use sha2 as _;
35#[cfg(all(test, not(any(feature = "client", feature = "facilitator"))))]
36use tokio as _;
37#[cfg(feature = "telemetry")]
38use tracing_core as _;
39#[cfg(all(test, not(any(feature = "client", feature = "facilitator"))))]
40use wiremock as _;
41
42/// Default maximum transaction fee accepted by the facilitator, in drops.
43pub const DEFAULT_MAX_FEE_DROPS: u64 = 10_000;
44
45/// Default ledger close interval used to map `maxTimeoutSeconds` to ledgers.
46pub const DEFAULT_LEDGER_CLOSE_SECONDS: u64 = 5;
47
48/// Extra ledgers added beyond the timeout conversion.
49pub const DEFAULT_LEDGER_TOLERANCE: u64 = 2;
50
51/// Partial-payment transaction flag (`tfPartialPayment`).
52pub const TF_PARTIAL_PAYMENT: u32 = 0x0002_0000;
53
54/// Account-root flag disabling the master key pair (`lsfDisableMaster`).
55pub const LSF_DISABLE_MASTER: u32 = 0x0010_0000;
56
57/// Maximum destination tag (`u32::MAX`).
58pub const MAX_DESTINATION_TAG: u32 = u32::MAX;
59
60/// Maximum outstanding tickets an account can hold.
61pub const MAX_ACCOUNT_TICKETS: u32 = 250;
62
63/// Settlement cache TTL floor in milliseconds.
64pub const SETTLEMENT_TTL_MS: u64 = 120_000;
65
66/// Length of a canonical compressed secp256k1 or ed25519 signing public key.
67pub const CANONICAL_SIGNING_PUB_KEY_LEN: usize = 66;
68
69/// SHA-512Half prefix for a signed transaction hash (`TXN\0`).
70pub const TRANSACTION_HASH_PREFIX: [u8; 4] = [0x54, 0x58, 0x4E, 0x00];
71
72/// Native XRP decimal precision (drops).
73pub const XRP_DECIMALS: u8 = 6;
74
75/// Default RLUSD decimal precision.
76pub const RLUSD_DECIMALS: u8 = 15;
77
78/// RLUSD currency as 160-bit hex (ASCII `"RLUSD"` padded).
79pub const RLUSD_CURRENCY: &str = "524C555344000000000000000000000000000000";
80
81/// Official Ripple RLUSD issuer on XRPL mainnet.
82pub const RLUSD_MAINNET_ISSUER: &str = "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De";
83
84/// Official Ripple RLUSD issuer on XRPL testnet.
85pub const RLUSD_TESTNET_ISSUER: &str = "rQhWct2fv4Vc4KRjRgMrxa8xPN9Zx9iLKV";
86
87pub mod chain;
88pub mod exact;
89
90mod networks;
91#[cfg(feature = "facilitator")]
92pub use chain::XrplChainProvider;
93#[cfg(any(feature = "client", feature = "facilitator"))]
94pub use chain::XrplJsonRpc;
95pub use exact::XrplExact;
96#[cfg(feature = "client")]
97pub use exact::client::{XrplExactClient, XrplSigner};
98pub use networks::*;