Skip to main content

volt_client_grpc/
constants.rs

1//! Constants used throughout the Volt client library.
2
3/// The name of the header used for authentication tokens
4pub const AUTH_TOKEN_NAME: &str = "volt-token";
5
6/// Default DID host name for resolving DIDs
7pub const DEFAULT_DID_HOST_NAME: &str = "coreid.com";
8
9/// Prefix for encrypted private keys
10pub const PRIVATE_ENCRYPTED_KEY_PREFIX: &str = "-----BEGIN ENCRYPTED PRIVATE KEY-----";
11
12/// DID prefix for Volt DIDs
13pub const VOLT_DID_PREFIX: &str = "did:volt:";
14
15/// Default DID registry URLs
16pub const DEFAULT_REGISTRY_LIST: &[&str] =
17    &["coreid.com", "https://tdxvolt.com", "https://tdxid.com"];
18
19/// DID service types
20pub mod did_service_type {
21    /// Volt configuration discovery service type
22    pub const VOLT_CONFIG: &str = "volt-discovery";
23}
24
25/// Service type identifiers that map to protobuf definitions
26pub mod service_type {
27    /// File API service
28    pub const FILE_API: &str = "tdx.volt_api.volt.v1.FileAPI";
29    /// SQLite server API service
30    pub const SQLITE_SERVER_API: &str = "tdx.volt_api.data.v1.SqliteServerAPI";
31    /// SQLite database API service
32    pub const SQLITE_DATABASE_API: &str = "tdx.volt_api.data.v1.SqliteDatabaseAPI";
33    /// SSI API service
34    pub const SSI_API: &str = "tdx.volt_api.volt.v1.SsiAPI";
35    /// Relay API service
36    pub const RELAY_API: &str = "tdx.volt_api.relay.v1.RelayAPI";
37    /// Sync API service
38    pub const SYNC_API: &str = "tdx.volt_api.volt.v1.SyncAPI";
39    /// Terminal API service
40    pub const TERMINAL_API: &str = "tdx.volt_api.volt.v1.TerminalAPI";
41    /// Volt API service
42    pub const VOLT_API: &str = "tdx.volt_api.volt.v1.VoltAPI";
43    /// Wire API service
44    pub const WIRE_API: &str = "tdx.volt_api.volt.v1.WireAPI";
45}
46
47/// Method types for gRPC calls
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum MethodType {
50    /// Unary RPC - single request, single response
51    Unary,
52    /// Client streaming RPC - stream of requests, single response
53    ClientStream,
54    /// Server streaming RPC - single request, stream of responses
55    ServerStream,
56    /// Bidirectional streaming RPC - stream of requests and responses
57    Bidi,
58}
59
60impl MethodType {
61    pub fn as_str(&self) -> &'static str {
62        match self {
63            MethodType::Unary => "METHOD_TYPE_UNARY",
64            MethodType::ClientStream => "METHOD_TYPE_CLIENT_STREAM",
65            MethodType::ServerStream => "METHOD_TYPE_SERVER_STREAM",
66            MethodType::Bidi => "METHOD_TYPE_BIDI",
67        }
68    }
69}
70
71impl std::fmt::Display for MethodType {
72    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73        write!(f, "{}", self.as_str())
74    }
75}
76
77/// Policy decision types returned by the Volt
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
79pub enum PolicyDecision {
80    /// Unknown decision
81    Unknown,
82    /// Access is permitted
83    Permit,
84    /// Access is denied
85    Deny,
86    /// Access requires prompt/confirmation
87    Prompt,
88    /// Access request is pending
89    Pending,
90}
91
92impl PolicyDecision {
93    pub fn from_str(s: &str) -> Self {
94        match s {
95            "POLICY_DECISION_PERMIT" => PolicyDecision::Permit,
96            "POLICY_DECISION_DENY" => PolicyDecision::Deny,
97            "POLICY_DECISION_PROMPT" => PolicyDecision::Prompt,
98            "POLICY_DECISION_PENDING" => PolicyDecision::Pending,
99            _ => PolicyDecision::Unknown,
100        }
101    }
102
103    pub fn as_str(&self) -> &'static str {
104        match self {
105            PolicyDecision::Unknown => "POLICY_DECISION_UNKNOWN",
106            PolicyDecision::Permit => "POLICY_DECISION_PERMIT",
107            PolicyDecision::Deny => "POLICY_DECISION_DENY",
108            PolicyDecision::Prompt => "POLICY_DECISION_PROMPT",
109            PolicyDecision::Pending => "POLICY_DECISION_PENDING",
110        }
111    }
112
113    pub fn is_permit(&self) -> bool {
114        matches!(self, PolicyDecision::Permit)
115    }
116}
117
118/// Access types for resource access requests
119#[derive(Debug, Clone, Copy, PartialEq, Eq)]
120#[derive(Default)]
121pub enum VoltAccessType {
122    /// Read access
123    #[default]
124    Read,
125    /// Write access
126    Write,
127    /// Admin access
128    Admin,
129}
130
131impl VoltAccessType {
132    pub fn as_str(&self) -> &'static str {
133        match self {
134            VoltAccessType::Read => "VOLT_ACCESS_READ",
135            VoltAccessType::Write => "VOLT_ACCESS_WRITE",
136            VoltAccessType::Admin => "VOLT_ACCESS_ADMIN",
137        }
138    }
139}
140