verity_ic/crypto/
config.rs

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
use crate::crypto::ecdsa;
use candid::CandidType;
use serde::Deserialize;

/// Represents the environment in which the canister operates.
#[derive(CandidType, Deserialize, Debug, Clone, PartialEq, Default)]
pub enum Environment {
	/// Development environment, used for local testing and development.
	#[default]
	Development,
	/// Staging environment, used for pre-production testing.
	Staging,
	/// Production environment, used for live deployments.
	Production,
}

/// Configuration settings for the canister.
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct Config {
	/// The current environment setting.
	pub env: Environment,
	/// ECDSA key identifiers used for cryptographic operations.
	pub key: ecdsa::EcdsaKeyIds,
	/// The number of cycles allocated for signing operations.
	pub sign_cycles: u64,
}

impl Default for Config {
	/// Provides a default configuration, using the Development environment.
	fn default() -> Self {
		Self::from(Environment::Development)
	}
}

impl From<Environment> for Config {
	/// Creates a configuration based on the specified environment.
	fn from(env: Environment) -> Self {
		if env == Environment::Staging {
			Self {
				env: Environment::Staging,
				key: ecdsa::EcdsaKeyIds::TestKey1,
				sign_cycles: 10_000_000_000,
			}
		} else if env == Environment::Production {
			Self {
				env: Environment::Production,
				key: ecdsa::EcdsaKeyIds::ProductionKey1,
				sign_cycles: 26_153_846_153,
			}
		} else {
			Self {
				env: Environment::Development,
				key: ecdsa::EcdsaKeyIds::TestKeyLocalDevelopment,
				sign_cycles: 25_000_000_000,
			}
		}
	}
}