identity_credential/credential/
mod.rs

1// Copyright 2020-2022 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! The core types used to create Verifiable Credentials.
5
6#![allow(clippy::module_inception)]
7
8mod builder;
9mod credential;
10mod credential_v2;
11mod enveloped_credential;
12mod evidence;
13mod issuer;
14#[cfg(feature = "jpt-bbs-plus")]
15mod jpt;
16#[cfg(feature = "jpt-bbs-plus")]
17mod jwp_credential_options;
18mod jws;
19mod jwt;
20mod jwt_serialization;
21mod linked_domain_service;
22mod linked_verifiable_presentation_service;
23mod policy;
24mod proof;
25mod refresh;
26#[cfg(feature = "revocation-bitmap")]
27mod revocation_bitmap_status;
28mod schema;
29mod status;
30mod subject;
31
32use identity_core::common::Context;
33use identity_core::common::Object;
34use identity_core::common::OneOrMany;
35use identity_core::common::Timestamp;
36
37pub use self::builder::CredentialBuilder;
38pub use self::credential::Credential;
39pub use self::evidence::Evidence;
40pub use self::issuer::Issuer;
41#[cfg(feature = "jpt-bbs-plus")]
42pub use self::jpt::Jpt;
43#[cfg(feature = "jpt-bbs-plus")]
44pub use self::jwp_credential_options::JwpCredentialOptions;
45pub use self::jws::Jws;
46pub use self::jwt::*;
47pub use self::jwt_serialization::JwtCredential;
48pub use self::linked_domain_service::LinkedDomainService;
49pub use self::linked_verifiable_presentation_service::LinkedVerifiablePresentationService;
50pub use self::policy::Policy;
51pub use self::proof::Proof;
52pub use self::refresh::RefreshService;
53#[cfg(feature = "revocation-bitmap")]
54pub use self::revocation_bitmap_status::try_index_to_u32;
55#[cfg(feature = "revocation-bitmap")]
56pub use self::revocation_bitmap_status::RevocationBitmapStatus;
57pub use self::schema::Schema;
58pub use self::status::Status;
59pub use self::subject::Subject;
60pub use credential_v2::Credential as CredentialV2;
61pub use enveloped_credential::*;
62
63#[cfg(feature = "validator")]
64pub(crate) use self::jwt_serialization::CredentialJwtClaims;
65#[cfg(feature = "presentation")]
66pub(crate) use self::jwt_serialization::IssuanceDateClaims;
67
68trait CredentialSealed {}
69
70/// A VerifiableCredential type. This trait is implemented for [Credential]
71/// and for [CredentialV2](credential_v2::Credential).
72#[allow(private_bounds)]
73pub trait CredentialT: CredentialSealed {
74  /// The type of the custom claims.
75  type Properties;
76
77  /// The Credential's context.
78  fn context(&self) -> &OneOrMany<Context>;
79  /// The Credential's types.
80  fn type_(&self) -> &OneOrMany<String>;
81  /// The Credential's subjects.
82  fn subject(&self) -> &OneOrMany<Subject>;
83  /// The Credential's issuer.
84  fn issuer(&self) -> &Issuer;
85  /// The Credential's issuance date.
86  fn valid_from(&self) -> Timestamp;
87  /// The Credential's expiration date, if any.
88  fn valid_until(&self) -> Option<Timestamp>;
89  /// The Credential's validity status, if any.
90  fn status(&self) -> Option<&Status>;
91  /// The Credential's custom properties.
92  fn properties(&self) -> &Self::Properties;
93  /// Whether the Credential's `nonTransferable` property is set.
94  fn non_transferable(&self) -> bool;
95  /// The Credential's base context.
96  fn base_context(&self) -> &'static Context;
97  /// Serializes this credential as a JWT payload encoded string.
98  fn serialize_jwt(&self, custom_claims: Option<Object>) -> Result<String, crate::Error>;
99}