spark_rust/wallet/config/
mod.rs

1//! # Wallet Configuration
2//!
3//! This module manages configuration for the Spark wallet SDK, including:
4//! - Network selection (mainnet, regtest)
5//! - Spark operator connections
6//! - Authentication sessions
7//! - Threshold signing parameters
8//!
9//! The configuration system is composed of a top-level `WalletConfig` struct that contains
10//! protocol-specific configuration through the `SparkConfig` component.
11
12use std::sync::Arc;
13
14// crate
15use crate::error::SparkSdkError;
16use crate::SparkNetwork;
17
18// from self
19pub(crate) mod spark;
20use spark::SparkConfig;
21
22/// Configuration for the Spark wallet SDK
23///
24/// This struct serves as the central configuration for the wallet, containing
25/// all protocol-specific settings needed for the SDK to function. It handles:
26///
27/// - Network selection (mainnet or regtest)
28/// - Connections to Spark operators for threshold signing
29/// - Authentication sessions and tokens
30/// - RPC client configurations
31///
32/// The configuration is created during SDK initialization and shared
33/// throughout the SDK's lifetime.
34#[derive(Clone)]
35pub(crate) struct WalletConfig {
36    /// Configuration for the Spark protocol, including network, operators, and authentication
37    pub(crate) spark_config: Arc<SparkConfig>,
38}
39
40impl WalletConfig {
41    /// Creates a new wallet configuration for the specified Spark network
42    ///
43    /// This initializes all necessary configuration components, including:
44    /// - Setting up the network (mainnet or regtest)
45    /// - Configuring operator connections based on the network
46    /// - Initializing GraphQL clients for API interaction
47    ///
48    /// # Arguments
49    /// * `spark_network` - The Spark network to use (mainnet or regtest)
50    ///
51    /// # Returns
52    /// * `Ok(WalletConfig)` - Successfully created configuration
53    /// * `Err(SparkSdkError)` - If configuration creation fails
54    pub(crate) async fn new(spark_network: SparkNetwork) -> Result<Self, SparkSdkError> {
55        let spark_config = SparkConfig::new(spark_network).await?;
56
57        Ok(Self {
58            spark_config: Arc::new(spark_config),
59        })
60    }
61}