rust_eigenda_client/
config.rs

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