1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! # 402fly Core
//!
//! Core library for the 402fly payment protocol with Solana blockchain integration.
//!
//! This library provides the fundamental types, error handling, and payment processing
//! capabilities for implementing the 402fly protocol - an open standard enabling AI agents
//! to autonomously pay for API access using Solana blockchain micropayments.
//!
//! ## Features
//!
//! - **Payment Models**: `PaymentRequest` and `PaymentAuthorization` for structured payment flow
//! - **Error Handling**: Comprehensive error types for all 402fly operations
//! - **Solana Integration**: `SolanaPaymentProcessor` for blockchain transactions
//! - **Serialization**: Base64-encoded JSON for HTTP headers
//!
//! ## Example
//!
//! ```rust,no_run
//! use fly402_core::{PaymentRequest, SolanaPaymentProcessor};
//! use solana_sdk::signature::Keypair;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse payment request from API response
//! let payment_request = PaymentRequest::from_json(r#"{
//! "max_amount_required": "0.10",
//! "asset_type": "SPL",
//! "asset_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
//! "payment_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
//! "network": "solana-devnet",
//! "expires_at": "2025-10-31T12:00:00Z",
//! "nonce": "abc123",
//! "payment_id": "pay_123",
//! "resource": "/api/premium-data"
//! }"#)?;
//!
//! // Create payment processor
//! let processor = SolanaPaymentProcessor::new(
//! "https://api.devnet.solana.com",
//! None
//! );
//!
//! // Create and send payment
//! let keypair = Keypair::new(); // Use your actual keypair
//! let authorization = processor.create_payment(&payment_request, &keypair).await?;
//!
//! // Use authorization in retry request
//! let header_value = authorization.to_header_value()?;
//! println!("X-Payment-Authorization: {}", header_value);
//!
//! Ok(())
//! }
//! ```
// Re-export commonly used types
pub use ;
pub use ;
pub use SolanaPaymentProcessor;
/// Library version
pub const VERSION: &str = env!;