tenzro_types/identity.rs
1//! Identity types for the Tenzro Decentralized Identity Protocol (TDIP)
2//!
3//! This module defines foundation types used by the `tenzro-identity` crate
4//! and throughout the Tenzro Network for unified human and machine identity.
5
6use serde::{Deserialize, Serialize};
7
8/// KYC (Know Your Customer) verification tiers for identities
9///
10/// Tiers are ordered by verification strength. `PartialOrd` enables
11/// comparisons like `tier >= KycTier::Enhanced`.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
13pub enum KycTier {
14 /// No verification performed (Tier 0)
15 Unverified = 0,
16 /// Basic email verification (Tier 1)
17 Basic = 1,
18 /// Enhanced verification with ID document (Tier 2)
19 Enhanced = 2,
20 /// Full verification with biometric + institutional verification (Tier 3)
21 Full = 3,
22}
23
24impl KycTier {
25 /// Returns the tier as a human-readable string
26 pub fn as_str(&self) -> &str {
27 match self {
28 KycTier::Unverified => "unverified",
29 KycTier::Basic => "basic",
30 KycTier::Enhanced => "enhanced",
31 KycTier::Full => "full",
32 }
33 }
34
35 /// Returns the numeric tier level
36 pub fn level(&self) -> u8 {
37 *self as u8
38 }
39}
40
41/// Payment protocol identifiers for supported payment rails
42#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
43pub enum PaymentProtocolId {
44 /// Machine Payments Protocol (Stripe/Tempo)
45 Mpp,
46 /// x402 protocol (Coinbase)
47 X402,
48 /// Direct on-chain settlement (Tenzro native)
49 Direct,
50 /// Micropayment channel (off-chain)
51 Channel,
52 /// Custom protocol
53 Custom(String),
54}
55
56impl PaymentProtocolId {
57 /// Returns the protocol name as a string
58 pub fn as_str(&self) -> &str {
59 match self {
60 PaymentProtocolId::Mpp => "mpp",
61 PaymentProtocolId::X402 => "x402",
62 PaymentProtocolId::Direct => "direct",
63 PaymentProtocolId::Channel => "channel",
64 PaymentProtocolId::Custom(name) => name,
65 }
66 }
67}
68
69impl std::fmt::Display for PaymentProtocolId {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 write!(f, "{}", self.as_str())
72 }
73}
74
75/// Type of identity in the Tenzro Decentralized Identity Protocol.
76///
77/// The protocol recognises three identity classes — the enum collapses
78/// the two machine classes into a single tag, distinguished at runtime
79/// by the `controller_did` field on `IdentityData::Machine`:
80///
81/// - **Human** (`did:tenzro:human:{uuid}`)
82/// - **Delegated agent** — machine with a human controller
83/// (`did:tenzro:machine:{controller}:{uuid}`)
84/// - **Autonomous agent** — machine with no controller
85/// (`did:tenzro:machine:{uuid}`)
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
87pub enum IdentityType {
88 /// Human identity
89 Human,
90 /// Machine/Agent identity (delegated or autonomous)
91 Machine,
92 /// Institution identity (`did:tenzro:institution:<lei>:<uuid>`).
93 Institution,
94}
95
96impl IdentityType {
97 /// Returns the type as a string
98 pub fn as_str(&self) -> &str {
99 match self {
100 IdentityType::Human => "human",
101 IdentityType::Machine => "machine",
102 IdentityType::Institution => "institution",
103 }
104 }
105}
106
107impl std::fmt::Display for IdentityType {
108 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109 write!(f, "{}", self.as_str())
110 }
111}