siera_agent/modules/
credential_definition.rs

1use crate::error::Result;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Options provided when registering a credential definition on the ledger
7#[derive(Debug, Deserialize, Serialize, Default)]
8pub struct CredentialDefinitionCreateOptions {
9    /// Schema id that the credential definition will be linked to
10    pub schema_id: String,
11
12    /// Optional tag used for the credential
13    /// If none is supplied `default` will be used
14    pub tag: String,
15
16    /// Whether the credential definition supports revocation
17    pub support_revocation: bool,
18
19    /// The size of the revocation registry, how many credentials
20    /// fit in the revocation registry
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub revocation_registry_size: Option<i32>,
23}
24
25/// Response from the cloudagent when creating a credential definition
26#[derive(Debug, Deserialize, Serialize)]
27pub struct CredentialDefinitionCreateResponse {
28    /// Id of the credential definition
29    #[serde(alias = "id")]
30    pub credential_definition_id: String,
31}
32
33/// Response from the cloudagent when requesting a credential definition
34/// by id
35#[derive(Debug, Serialize, Deserialize)]
36pub struct CredentialDefinitionGetByIdResponse {
37    /// The credential definition requested
38    pub credential_definition: CredentialDefinition,
39}
40
41/// A credential definition structure
42#[derive(Debug, Serialize, Deserialize)]
43pub struct CredentialDefinition {
44    /// Version of the credential definition
45    pub ver: String,
46
47    /// Id of the credential definition
48    pub id: String,
49
50    /// Schema id on which the credential definintion is based
51    #[serde(alias = "schemaId")]
52    pub schema_id: String,
53
54    /// The type of the credential definition
55    #[serde(rename = "type")]
56    pub type_field: String,
57
58    /// Tag used by the credential definition
59    /// default is `default`
60    pub tag: String,
61
62    /// TODO
63    pub value: Value,
64}
65
66/// Response from the cloudagent when requesting all the credential definitions
67#[derive(Debug, Serialize, Deserialize)]
68pub struct CredentialDefinitionGetAllResponse {
69    /// List of credential definitions registered by the cloudagent
70    pub credential_definition_ids: Vec<String>,
71}
72
73/// Generic cloudagent credential definition module
74#[async_trait]
75pub trait CredentialDefinitionModule {
76    /// Register a credential definition on the ledger
77    async fn create(
78        &self,
79        options: CredentialDefinitionCreateOptions,
80    ) -> Result<CredentialDefinitionCreateResponse>;
81
82    /// Get the registered credential definition by id
83    async fn get_by_id(&self, id: String) -> Result<CredentialDefinition>;
84
85    /// Get all the registered credential definitions
86    async fn get_all(&self) -> Result<CredentialDefinitionGetAllResponse>;
87}