rust_eigen_client/
config.rs

1use ethereum_types::H160;
2use secrecy::{ExposeSecret, Secret};
3use std::str::FromStr;
4use url::Url;
5
6use crate::errors::{ConfigError, EigenClientError};
7
8#[derive(Debug, Clone)]
9/// A URL stored securely using the `Secret` type from the secrecy crate
10pub struct SecretUrl {
11    // We keep the URL as a String because Secret<T> enforces T: DefaultIsZeroes
12    // which is not the case for the type Url
13    inner: Secret<String>,
14}
15
16impl SecretUrl {
17    /// Create a new `SecretUrl` from a `Url`
18    pub fn new(url: Url) -> Self {
19        Self {
20            inner: Secret::new(url.to_string()),
21        }
22    }
23}
24
25impl From<SecretUrl> for Url {
26    fn from(secret_url: SecretUrl) -> Self {
27        Url::parse(secret_url.inner.expose_secret()).unwrap() // Safe to unwrap, as the `new` fn ensures the URL is valid
28    }
29}
30
31impl PartialEq for SecretUrl {
32    fn eq(&self, other: &Self) -> bool {
33        self.inner.expose_secret().eq(other.inner.expose_secret())
34    }
35}
36
37#[derive(Clone, Debug, PartialEq)]
38pub enum SrsPointsSource {
39    /// Path to the SRS points file, it should have both g1 and power of g2 points
40    Path(String),
41    /// Urls to g1 and power of g2 points
42    Url((String, String)),
43}
44
45/// Configuration for the EigenDA remote disperser client.
46#[derive(Clone, Debug, PartialEq)]
47pub struct EigenConfig {
48    /// URL of the Disperser RPC server
49    pub disperser_rpc: String,
50    /// URL of the Ethereum RPC server
51    pub eth_rpc_url: Option<SecretUrl>,
52    /// Block height needed to reach in order to consider the blob finalized
53    /// a value less or equal to 0 means that the disperser will not wait for finalization
54    pub settlement_layer_confirmation_depth: u32,
55    /// Address of the service manager contract
56    pub eigenda_svc_manager_address: H160,
57    /// Wait for the blob to be finalized before returning the response
58    pub wait_for_finalization: bool,
59    /// Authenticated dispersal
60    pub authenticated: bool,
61    /// Points source
62    pub srs_points_source: SrsPointsSource,
63}
64
65/// Contains the private key
66#[derive(Clone, Debug, PartialEq)]
67pub struct EigenSecrets {
68    pub private_key: PrivateKey,
69}
70
71/// Secretly enclosed Private Key
72#[derive(Debug, Clone)]
73pub struct PrivateKey(pub Secret<String>);
74
75impl PartialEq for PrivateKey {
76    fn eq(&self, other: &Self) -> bool {
77        self.0.expose_secret().eq(other.0.expose_secret())
78    }
79}
80
81impl FromStr for PrivateKey {
82    type Err = EigenClientError;
83
84    fn from_str(s: &str) -> Result<Self, Self::Err> {
85        Ok(PrivateKey(s.parse().map_err(|_| ConfigError::PrivateKey)?))
86    }
87}