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//!
11//! ## Quick Start
12//!
13//! ```rust,no_run
14//! use open_payments::client::{AuthenticatedClient, ClientConfig, AuthenticatedResources, UnauthenticatedResources};
15//! use open_payments::types::{IncomingPayment, OutgoingPayment};
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
19//! // In a real application, you would use actual file paths
20//! let config = ClientConfig {
21//! private_key_path: "path/to/private-key.pem".into(),
22//! key_id: "my-key-id".to_string(),
23//! jwks_path: Some("path/to/jwks.json".into()),
24//! wallet_address_url: "https://rafiki.money/alice".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//!
45//! ## Examples
46//!
47//! ### Creating an Incoming Payment
48//!
49//! ```rust,no_run
50//! use open_payments::client::{AuthenticatedClient, AuthenticatedResources};
51//! use open_payments::types::{Amount, resource::CreateIncomingPaymentRequest};
52//! use chrono::{Duration, Utc};
53//!
54//! #[tokio::main]
55//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
56//! // In a real application, you would use actual file paths
57//! let config = open_payments::client::ClientConfig {
58//! private_key_path: "path/to/private-key.pem".into(),
59//! key_id: "my-key-id".to_string(),
60//! jwks_path: Some("path/to/jwks.json".into()),
61//! wallet_address_url: "https://rafiki.money/alice".into(),
62//! };
63//!
64//! // This would fail in a real scenario if the files don't exist
65//! // but demonstrates the API usage
66//! let client = AuthenticatedClient::new(config)?;
67//!
68//! let request = CreateIncomingPaymentRequest {
69//! wallet_address: "https://rafiki.money/alice".to_string(),
70//! incoming_amount: Some(Amount {
71//! value: "1000".to_string(),
72//! asset_code: "EUR".to_string(),
73//! asset_scale: 2,
74//! }),
75//! expires_at: Some(Utc::now() + Duration::hours(1)),
76//! metadata: None,
77//! };
78//!
79//! let resource_server_url = "https://ilp.rafiki.money";
80//! let access_token = "your-access-token";
81//!
82//! let payment = client
83//! .incoming_payments()
84//! .create(&resource_server_url, &request, Some(&access_token))
85//! .await?;
86//!
87//! Ok(())
88//! }
89//! ```
90//!
91//! ### HTTP Signature Creation
92//!
93//! ```rust
94//! use open_payments::http_signature::{create_signature_headers, SignOptions};
95//! use http::{Request, Method, Uri};
96//! use ed25519_dalek::SigningKey;
97//!
98//! fn main() -> Result<(), Box<dyn std::error::Error>> {
99//! let mut request = Request::new(Some("test body".to_string()));
100//! *request.method_mut() = Method::POST;
101//! *request.uri_mut() = Uri::from_static("https://ilp.rafiki.money/incoming-payments");
102//!
103//! let signing_key = SigningKey::generate(&mut rand::rngs::OsRng);
104//! let options = SignOptions::new(&request, &signing_key, "test-key".to_string());
105//! let headers = create_signature_headers(options)?;
106//!
107//! println!("Signature: {}", headers.signature);
108//! println!("Signature-Input: {}", headers.signature_input);
109//! Ok(())
110//! }
111//! ```
112//!
113//! ## License
114//!
115//! This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
116
117pub mod client;
118pub mod http_signature;
119pub mod types;
120
121// Re-export everything public from client at the crate root
122pub use client::*;