-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.rs
More file actions
81 lines (76 loc) · 2.73 KB
/
config.rs
File metadata and controls
81 lines (76 loc) · 2.73 KB
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
76
77
78
79
80
81
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
///
/// Configuration for an authenticated Open Payments client.
///
/// This struct contains all the necessary configuration for creating an authenticated
/// client that can sign HTTP requests. It includes paths to cryptographic keys and
/// identifiers used in the signing process.
///
/// ## Example
///
/// ```rust
/// use open_payments::client::ClientConfig;
/// use std::path::PathBuf;
///
/// let config = ClientConfig {
/// key_id: "my-key-2024".to_string(),
/// private_key_path: PathBuf::from("keys/private.pem"),
/// jwks_path: Some(PathBuf::from("keys/jwks.json")),
/// wallet_address_url: "https://rafiki.money/alice".into(),
/// };
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientConfig {
pub key_id: String,
/// Path to the private key file used for signing HTTP requests.
///
/// The private key should be in PEM format (either in plain text or base64 encoded) and compatible with Ed25519 signing.
/// If the file doesn't exist, a new key will be generated automatically.
pub private_key_path: PathBuf,
/// Optional path where the JSON Web Key Set (JWKS) should be saved.
///
/// If provided, the client will automatically generate a JWKS containing the
/// public key corresponding to the private key and save it to this location.
///
/// ## Usage
///
/// - Set to `Some(path)` to enable automatic JWKS generation
/// - Set to `None` to disable JWKS generation
/// - The JWKS file will be created automatically when the client is initialized
///
/// Example: `Some(PathBuf::from("keys/jwks.json"))`
pub jwks_path: Option<PathBuf>,
/// URL of the wallet address to use for the client.
///
/// This is the URL of the wallet address that will be used to send and receive payments.
pub wallet_address_url: String,
}
impl Default for ClientConfig {
/// Creates a default configuration with reasonable defaults.
///
/// The default configuration uses:
/// - Empty key ID
/// - `private.key` as the private key path
/// - `jwks.json` as the JWKS path
///
/// **Note**: You should typically override the `key_id` with a meaningful value
/// and consider using more secure paths for production environments.
///
/// ## Example
///
/// ```rust
/// use open_payments::client::ClientConfig;
///
/// let mut config = ClientConfig::default();
/// config.key_id = "my-key".to_string();
/// ```
fn default() -> Self {
Self {
key_id: "".into(),
private_key_path: PathBuf::from("private.key"),
jwks_path: None,
wallet_address_url: "".into(),
}
}
}