open_payments/lib.rs
1//! # Open Payments Rust Client
2//!
3//! A Rust client library for the Open Payments specification, providing types and HTTP signatures utilities for building Open Payments applications.
4//!
5//! ## Features
6//!
7//! - **Types**: Complete type definitions for all Open Payments resources and operations
8//! - **HTTP Client**: Async HTTP client with authentication and signature support
9//! - **HTTP Signatures**: Utilities for creating and validating HTTP message signatures
10//! - **Snippets**: Ready-to-use code examples for common operations (optional feature)
11//!
12//! ## Quick Start
13//!
14//! ```rust,no_run
15//! use open_payments::client::{AuthenticatedClient, ClientConfig, AuthenticatedResources, UnauthenticatedResources};
16//! use open_payments::types::{IncomingPayment, OutgoingPayment};
17//!
18//! #[tokio::main]
19//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
20//! // In a real application, you would use actual file paths
21//! let config = ClientConfig {
22//! private_key_path: "path/to/private-key.pem".into(),
23//! key_id: "my-key-id".to_string(),
24//! jwks_path: Some("path/to/jwks.json".into()),
25//! };
26//!
27//! // This would fail in a real scenario if the files don't exist
28//! // but demonstrates the API usage
29//! let client = AuthenticatedClient::new(config)?;
30//!
31//! // Use the client to interact with Open Payments resources
32//! let wallet_address_url = "https://rafiki.money/alice";
33//! let wallet_address = client.wallet_address().get(wallet_address_url).await?;
34//!
35//! Ok(())
36//! }
37//! ```
38//!
39//! ## Modules
40//!
41//! - [`client`] - HTTP client for making unauthenticated and authenticated requests to Open Payments servers
42//! - [`types`] - Type definitions for all Open Payments resources and operations
43//! - [`http_signature`] - Utilities for HTTP message signature creation and validation
44//! - \[`snippets`\] - Code examples for common operations (requires `snippets` feature)
45//!
46//! ## Cargo Features
47//!
48//! - `snippets` - Enables snippet binaries with example code for common operations
49//!
50//! ## Examples
51//!
52//! ### Creating an Incoming Payment
53//!
54//! ```rust,no_run
55//! use open_payments::client::{AuthenticatedClient, AuthenticatedResources};
56//! use open_payments::types::{Amount, resource::CreateIncomingPaymentRequest};
57//! use chrono::{Duration, Utc};
58//!
59//! #[tokio::main]
60//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
61//! // In a real application, you would use actual file paths
62//! let config = open_payments::client::ClientConfig {
63//! private_key_path: "path/to/private-key.pem".into(),
64//! key_id: "my-key-id".to_string(),
65//! jwks_path: Some("path/to/jwks.json".into()),
66//! };
67//!
68//! // This would fail in a real scenario if the files don't exist
69//! // but demonstrates the API usage
70//! let client = AuthenticatedClient::new(config)?;
71//!
72//! let request = CreateIncomingPaymentRequest {
73//! wallet_address: "https://rafiki.money/alice".to_string(),
74//! incoming_amount: Some(Amount {
75//! value: "1000".to_string(),
76//! asset_code: "EUR".to_string(),
77//! asset_scale: 2,
78//! }),
79//! expires_at: Some(Utc::now() + Duration::hours(1)),
80//! metadata: None,
81//! };
82//!
83//! let resource_server_url = "https://ilp.rafiki.money";
84//! let access_token = "your-access-token";
85//!
86//! let payment = client
87//! .incoming_payments()
88//! .create(&resource_server_url, &request, Some(&access_token))
89//! .await?;
90//!
91//! Ok(())
92//! }
93//! ```
94//!
95//! ### HTTP Signature Creation
96//!
97//! ```rust
98//! use open_payments::http_signature::{create_signature_headers, SignOptions};
99//! use http::{Request, Method, Uri};
100//! use ed25519_dalek::SigningKey;
101//!
102//! fn main() -> Result<(), Box<dyn std::error::Error>> {
103//! let mut request = Request::new(Some("test body".to_string()));
104//! *request.method_mut() = Method::POST;
105//! *request.uri_mut() = Uri::from_static("https://ilp.rafiki.money/incoming-payments");
106//!
107//! let signing_key = SigningKey::generate(&mut rand::rngs::OsRng);
108//! let options = SignOptions::new(&request, &signing_key, "test-key".to_string());
109//! let headers = create_signature_headers(options)?;
110//!
111//! println!("Signature: {}", headers.signature);
112//! println!("Signature-Input: {}", headers.signature_input);
113//! Ok(())
114//! }
115//! ```
116//!
117//! ## License
118//!
119//! This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
120
121pub mod client;
122pub mod http_signature;
123#[cfg(feature = "snippets")]
124pub mod snippets;
125pub mod types;
126
127// Re-export everything public from client at the crate root
128pub use client::*;