1pub use crate::cis2_types::MetadataUrl;
2use crate::{
3 contracts_common::{self, self as concordium_std},
4 web3id::*,
5};
6
7#[derive(
10 contracts_common::Serialize, PartialEq, Eq, Clone, Debug, serde::Serialize, serde::Deserialize,
11)]
12#[serde(transparent)]
13pub struct CredentialType {
14 #[concordium(size_length = 1)]
15 pub credential_type: String,
16}
17
18#[derive(
23 contracts_common::Serialize, PartialEq, Eq, Clone, Debug, serde::Serialize, serde::Deserialize,
24)]
25#[serde(transparent)]
26pub struct SchemaRef {
27 pub schema_ref: MetadataUrl,
28}
29
30#[derive(
31 serde::Serialize, serde::Deserialize, contracts_common::Serialize, PartialEq, Eq, Clone, Debug,
32)]
33#[serde(rename_all = "camelCase")]
34pub struct CredentialInfo {
35 pub holder_id: CredentialHolderId,
37 pub holder_revocable: bool,
39 pub valid_from: contracts_common::Timestamp,
41 pub valid_until: Option<contracts_common::Timestamp>,
44 pub metadata_url: MetadataUrl,
46}
47
48#[derive(serde::Serialize, serde::Deserialize, contracts_common::Serialize, Clone, Debug)]
50#[serde(rename_all = "camelCase")]
51pub struct CredentialEntry {
52 pub credential_info: CredentialInfo,
53 pub schema_ref: SchemaRef,
56 pub revocation_nonce: u64,
60}
61
62#[derive(
63 serde::Serialize,
64 serde::Deserialize,
65 contracts_common::Serialize,
66 PartialOrd,
67 Ord,
68 Hash,
69 PartialEq,
70 Eq,
71 Clone,
72 Copy,
73 Debug,
74 derive_more::Display,
75)]
76#[serde(rename_all = "camelCase")]
77pub enum CredentialStatus {
79 #[display(fmt = "Active")]
81 Active,
82 #[display(fmt = "Revoked")]
84 Revoked,
85 #[display(fmt = "Expired")]
87 Expired,
88 #[display(fmt = "NotActivated")]
90 NotActivated,
91}
92
93#[doc(hidden)]
94pub enum RevocationKeyRole {}
95
96pub type RevocationKey = Ed25519PublicKey<RevocationKeyRole>;
97
98#[derive(contracts_common::Serialize, Debug)]
99pub struct RevocationKeyWithNonce {
102 pub key: RevocationKey,
103 pub nonce: u64,
104}
105
106#[derive(contracts_common::Serialize, Debug, Clone)]
108pub struct RegistryMetadata {
109 pub issuer_metadata: MetadataUrl,
111 pub credential_type: CredentialType,
113 pub credential_schema: SchemaRef,
115}
116
117#[doc(hidden)]
118pub enum IssuerKeyRole {}
119
120pub type IssuerKey = Ed25519PublicKey<IssuerKeyRole>;
122
123#[derive(contracts_common::Serialize, Debug, Clone)]
125pub struct CredentialEventData {
126 pub holder_id: CredentialHolderId,
128 pub schema_ref: SchemaRef,
130 pub credential_type: CredentialType,
132 pub metadata_url: MetadataUrl,
134}
135
136#[derive(contracts_common::Serialize, Debug, Clone)]
139pub enum Revoker {
140 Issuer,
141 Holder,
142 Other(RevocationKey),
146}
147
148#[derive(contracts_common::Serialize, Debug, Clone)]
150pub struct RevokeCredentialEvent {
151 pub holder_id: CredentialHolderId,
153 pub revoker: Revoker,
155 pub reason: Option<Reason>,
159}
160
161#[derive(Debug, contracts_common::Serialize, Clone)]
162pub struct IssuerMetadataEvent {
165 pub metadata_url: MetadataUrl,
167}
168
169#[derive(contracts_common::Serialize, Debug, Clone)]
171pub struct CredentialSchemaRefEvent {
172 pub r#type: CredentialType,
173 pub schema_ref: SchemaRef,
174}
175
176#[derive(Debug, Clone, contracts_common::Serialize)]
177pub struct CredentialMetadataEvent {
178 pub credential_id: CredentialHolderId,
179 pub metadata_url: MetadataUrl,
180}
181
182#[derive(contracts_common::Serialize, Debug, Clone)]
183pub enum RevocationKeyAction {
184 Register,
185 Remove,
186}
187
188#[derive(contracts_common::Serialize, Debug, Clone)]
192pub struct RevocationKeyEvent {
193 pub key: RevocationKey,
195 pub action: RevocationKeyAction,
197}
198
199#[derive(Debug, Clone)]
201pub enum CredentialEvent {
202 Register(CredentialEventData),
205 Revoke(RevokeCredentialEvent),
207 IssuerMetadata(MetadataUrl),
209 CredentialMetadata(CredentialMetadataEvent),
211 Schema(CredentialSchemaRefEvent),
213 RevocationKey(RevocationKeyEvent),
215 Unknown,
217}
218
219impl contracts_common::Deserial for CredentialEvent {
220 fn deserial<R: contracts_common::Read>(source: &mut R) -> contracts_common::ParseResult<Self> {
221 use contracts_common::Get;
222 match source.get()? {
223 249u8 => Ok(Self::Register(source.get()?)),
224 248u8 => Ok(Self::Revoke(source.get()?)),
225 247u8 => Ok(Self::IssuerMetadata(source.get()?)),
226 246u8 => Ok(Self::CredentialMetadata(source.get()?)),
227 245u8 => Ok(Self::Schema(source.get()?)),
228 244u8 => Ok(Self::RevocationKey(source.get()?)),
229 _ => Ok(Self::Unknown),
230 }
231 }
232}
233
234impl<'a> TryFrom<&'a crate::smart_contracts::ContractEvent> for CredentialEvent {
237 type Error = crate::contracts_common::ParseError;
238
239 fn try_from(value: &'a crate::smart_contracts::ContractEvent) -> Result<Self, Self::Error> {
240 use crate::contracts_common::Get;
241 let data = value.as_ref();
242 let mut cursor = crate::contracts_common::Cursor::new(data);
243 let event = cursor.get()?;
244 if cursor.offset == data.len() || matches!(event, CredentialEvent::Unknown) {
246 Ok(event)
247 } else {
248 Err(crate::contracts_common::ParseError {})
249 }
250 }
251}
252
253#[derive(contracts_common::Serialize, Clone, Debug)]
257pub struct Reason {
258 #[concordium(size_length = 1)]
259 reason: String,
260}