Skip to main content

confium_deployment/identity/
attributes.rs

1//! Signer attributes for predicate-based threshold signing.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Attributes bound to a signer, used by predicate evaluation.
8#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct SignerAttributes {
10    /// Geographic region (e.g., "europe", "asia-pacific").
11    pub region: Option<String>,
12    /// Areas of expertise.
13    pub expertise: Vec<String>,
14    /// Nationality (used for conflict-of-interest exclusion).
15    pub nationality: Option<String>,
16    /// Roles held by the signer.
17    pub role: Vec<String>,
18    /// Custom attribute key-value pairs.
19    pub custom: HashMap<String, String>,
20}
21
22impl SignerAttributes {
23    /// Construct a new empty attribute set.
24    pub fn new() -> Self {
25        Self::default()
26    }
27
28    /// Set the region.
29    pub fn with_region(mut self, region: impl Into<String>) -> Self {
30        self.region = Some(region.into());
31        self
32    }
33
34    /// Add an expertise.
35    pub fn with_expertise(mut self, expertise: impl Into<String>) -> Self {
36        self.expertise.push(expertise.into());
37        self
38    }
39
40    /// Add a role.
41    pub fn with_role(mut self, role: impl Into<String>) -> Self {
42        self.role.push(role.into());
43        self
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn build_attributes() {
53        let attrs = SignerAttributes::new()
54            .with_region("europe")
55            .with_expertise("metrology")
56            .with_role("director");
57        assert_eq!(attrs.region.as_deref(), Some("europe"));
58        assert_eq!(attrs.expertise, vec!["metrology"]);
59        assert_eq!(attrs.role, vec!["director"]);
60    }
61}