trustchain_core/
issuer.rs

1//! DID issuer API.
2use crate::key_manager::KeyManagerError;
3use crate::resolver::TrustchainResolver;
4use crate::subject::Subject;
5use async_trait::async_trait;
6use ssi::jsonld::ContextLoader;
7use ssi::vc::{Credential, LinkedDataProofOptions};
8use thiserror::Error;
9
10/// An error relating to a Trustchain Issuer.
11#[derive(Error, Debug)]
12pub enum IssuerError {
13    /// Wrapped error for ssi-vc error.
14    #[error("A wrapped variant for an SSI VC error: {0}")]
15    VC(ssi::vc::Error),
16    /// Wrapped error for ssi-ldp error.
17    #[error("A wrapped variant for an SSI LDP error: {0}")]
18    LDP(ssi::ldp::Error),
19    /// Wrapped error for key manager error.
20    #[error("A wrapped variant for a key manager error: {0}")]
21    KeyManager(KeyManagerError),
22}
23
24impl From<ssi::vc::Error> for IssuerError {
25    fn from(err: ssi::vc::Error) -> Self {
26        IssuerError::VC(err)
27    }
28}
29
30impl From<ssi::ldp::Error> for IssuerError {
31    fn from(err: ssi::ldp::Error) -> Self {
32        IssuerError::LDP(err)
33    }
34}
35
36impl From<KeyManagerError> for IssuerError {
37    fn from(err: KeyManagerError) -> Self {
38        IssuerError::KeyManager(err)
39    }
40}
41
42/// A credential issuer signs a credential to generate a verifiable credential.
43#[async_trait]
44pub trait Issuer: Subject {
45    /// Signs a credential. An issuer attests to a credential by signing the credential with one of their private signing keys.
46    async fn sign(
47        &self,
48        credential: &Credential,
49        linked_data_proof_options: Option<LinkedDataProofOptions>,
50        key_id: Option<&str>,
51        resolver: &dyn TrustchainResolver,
52        context_loader: &mut ContextLoader,
53    ) -> Result<Credential, IssuerError>;
54}