zoe_app_primitives/identity.rs
1use serde::{Deserialize, Serialize};
2use zoe_wire_protocol::VerifyingKey;
3
4use crate::Metadata;
5
6/// Unified identity type - either a raw VerifyingKey or a VerifyingKey + alias
7///
8/// This is the fundamental identity concept in the system.
9#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Eq, Ord, Serialize, Deserialize)]
10pub enum IdentityRef {
11 /// Raw verifying key identity (always valid, no declaration needed)
12 Key(VerifyingKey),
13 /// Alias identity controlled by a specific key
14 Alias {
15 /// The controlling verifying key
16 key: VerifyingKey,
17 /// The alias name
18 alias: String,
19 },
20}
21
22impl IdentityRef {
23 /// Get the controlling verifying key for this identity
24 pub fn controlling_key(&self) -> VerifyingKey {
25 match self {
26 IdentityRef::Key(key) => key.clone(),
27 IdentityRef::Alias { key, .. } => key.clone(),
28 }
29 }
30
31 /// Check if this identity is controlled by the given key
32 pub fn is_controlled_by(&self, key: &VerifyingKey) -> bool {
33 self.controlling_key() == *key
34 }
35
36 /// Check if this identity is controlled by the given ML-DSA key
37 /// This is a compatibility method for the ML-DSA transition
38 pub fn is_controlled_by_ml_dsa(&self, _key: &VerifyingKey) -> bool {
39 // For now, ML-DSA keys cannot control Ed25519-based identities
40 // This will need to be updated when we fully transition to ML-DSA
41 false
42 }
43
44 /// Get a display string for this identity (used when no display name is set)
45 pub fn fallback_display(&self) -> String {
46 match self {
47 IdentityRef::Key(key) => format!("Key:{key:?}"),
48 IdentityRef::Alias { alias, .. } => alias.clone(),
49 }
50 }
51}
52
53/// Type of alias being declared
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
55pub enum IdentityType {
56 /// This identity is the same as the key itself
57 Main,
58 /// This is about an alias identfied by the alias is
59 Alias {
60 /// Which external system this alias represents
61 alias_id: String,
62 },
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
66pub struct IdentityInfo {
67 /// The display name for this identity
68 pub display_name: String,
69 /// The metadata for this identity
70 pub metadata: Vec<Metadata>,
71}