verity_ic/crypto/
config.rs

1use crate::crypto::ecdsa;
2use candid::CandidType;
3use serde::Deserialize;
4
5/// Represents the environment in which the canister operates.
6#[derive(CandidType, Deserialize, Debug, Clone, PartialEq, Default)]
7pub enum Environment {
8    /// Development environment, used for local testing and development.
9    #[default]
10    Development,
11    /// Staging environment, used for pre-production testing.
12    Staging,
13    /// Production environment, used for live deployments.
14    Production,
15}
16
17/// Configuration settings for the canister.
18#[derive(CandidType, Deserialize, Debug, Clone)]
19pub struct Config {
20    /// The current environment setting.
21    pub env: Environment,
22    /// ECDSA key identifiers used for cryptographic operations.
23    pub key: ecdsa::EcdsaKeyIds,
24    /// The number of cycles allocated for signing operations.
25    pub sign_cycles: u64,
26}
27
28impl Default for Config {
29    /// Provides a default configuration, using the Development environment.
30    fn default() -> Self {
31        Self::from(Environment::Development)
32    }
33}
34
35impl From<Environment> for Config {
36    /// Creates a configuration based on the specified environment.
37    fn from(env: Environment) -> Self {
38        if env == Environment::Staging {
39            Self {
40                env: Environment::Staging,
41                key: ecdsa::EcdsaKeyIds::TestKey1,
42                sign_cycles: 10_000_000_000,
43            }
44        } else if env == Environment::Production {
45            Self {
46                env: Environment::Production,
47                key: ecdsa::EcdsaKeyIds::ProductionKey1,
48                sign_cycles: 26_153_846_153,
49            }
50        } else {
51            Self {
52                env: Environment::Development,
53                key: ecdsa::EcdsaKeyIds::TestKeyLocalDevelopment,
54                sign_cycles: 25_000_000_000,
55            }
56        }
57    }
58}