trustchain_core/
controller.rs

1//! DID controller API.
2use crate::attestor::Attestor;
3use crate::key_manager::KeyManagerError;
4use crate::utils::get_did_suffix;
5use ssi::jwk::JWK;
6use thiserror::Error;
7
8/// An error relating to Trustchain controllers.
9#[derive(Error, Debug, PartialEq, Eq, PartialOrd, Ord)]
10pub enum ControllerError {
11    /// Subject does not exist.
12    #[error("DID: {0} as Trustchain subject does not exist.")]
13    NoTrustchainSubject(String),
14    /// No recovery key.
15    #[error("DID: {0} recovery key does not exist.")]
16    NoRecoveryKey(String),
17    /// No update key.
18    #[error("DID: {0} update key does not exist.")]
19    NoUpdateKey(String),
20}
21
22/// A DID controller.
23pub trait Controller {
24    /// Returns the DID controlled by this controller.
25    fn controlled_did(&self) -> &str;
26    /// Returns the suffix of the DID controlled by this controller.
27    fn controlled_did_suffix(&self) -> &str {
28        get_did_suffix(self.controlled_did())
29    }
30    /// Converts this controller into an attestor.
31    fn to_attestor(&self) -> Box<dyn Attestor>;
32    /// Retrieves the update key.
33    fn update_key(&self) -> Result<JWK, KeyManagerError>;
34    /// Retrieves the next update key.
35    fn next_update_key(&self) -> Result<Option<JWK>, KeyManagerError>;
36    /// Retrieves the recovery key.
37    fn recovery_key(&self) -> Result<JWK, KeyManagerError>;
38    /// Generates a new update key.
39    fn generate_next_update_key(&self) -> Result<(), KeyManagerError>;
40}