#[non_exhaustive]pub struct Presentation {
pub context: Context,
pub id: Option<Uri>,
pub types: OneOrMany<String>,
pub verifiable_credential: Vec<Jwt>,
pub holder: Option<Party>,
pub properties: IndexMap<String, Value>,
}vc only.Expand description
A verifiable presentation of the Verifiable Credentials Data Model 1.1 whose credentials are JWTs, as data.
Deserialization checks that the first @context is the base context and type includes
VerifiablePresentation. A presentation is secured by signing its JWT form, see
to_jwt_claims; the holder signs it, so the holder is the iss.
§Examples
use identity_kit::did::{Did, Uri};
use identity_kit::vc::{Jwt, Presentation};
let credential: Jwt = "eyJhbGciOiJFZERTQSJ9.RXhhbXBsZSBvZiBFZDI1NTE5IHNpZ25pbmc.\
hgyY0il_MGCjP0JzlnLWG1PPOt7-09PGcvMg3AIbQR6dWbhijcNR4ki4iylGjg5BhVsPt9g7sVvpAr_MuM0KAg"
.parse()?;
let presentation = Presentation::new()
.with_id(Uri::parse("urn:uuid:3978344f-8596-4c3a-a978-8fcaba3903c5")?)
.with_holder(Did::parse("did:example:ebfeb1f712ebc6f1c276e12ec21")?)
.with_credential(credential);
let claims = presentation.to_jwt_claims()?.with_aud("did:example:4a57546973436f6f6c4a4a57573");
assert_eq!(claims.iss.as_deref(), Some("did:example:ebfeb1f712ebc6f1c276e12ec21"));
assert_eq!(claims.jti.as_deref(), Some("urn:uuid:3978344f-8596-4c3a-a978-8fcaba3903c5"));
assert_eq!(claims.additional["vp"]["verifiableCredential"].as_array().map(Vec::len), Some(1));
assert_eq!(Presentation::from_jwt_claims(&claims)?, presentation);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.context: Context@context, starting with Presentation::CONTEXT.
id: Option<Uri>The identifier of the presentation.
types: OneOrMany<String>type, including Presentation::TYPE.
verifiable_credential: Vec<Jwt>The presented credentials, as JWTs.
holder: Option<Party>The holder presenting the credentials.
properties: IndexMap<String, Value>Every other property, in insertion order.
Implementations§
Source§impl Presentation
impl Presentation
pub fn serialize<__S>(
__self: &Presentation,
__serializer: __S,
) -> Result<__S::Ok, __S::Error>where
__S: Serializer,
Source§impl<'de> Presentation
impl<'de> Presentation
pub fn deserialize<__D>(__deserializer: __D) -> Result<Presentation, __D::Error>where
__D: Deserializer<'de>,
Source§impl Presentation
impl Presentation
Sourcepub const CONTEXT: &'static str = CONTEXT_V1
pub const CONTEXT: &'static str = CONTEXT_V1
The base context, https://www.w3.org/2018/credentials/v1.
Sourcepub const TYPE: &'static str = "VerifiablePresentation"
pub const TYPE: &'static str = "VerifiablePresentation"
The type every presentation has, VerifiablePresentation.
Sourcepub fn with_context(self, context: impl Into<String>) -> Self
pub fn with_context(self, context: impl Into<String>) -> Self
This presentation with context appended to its @context.
Sourcepub fn with_type(self, presentation_type: impl Into<String>) -> Self
pub fn with_type(self, presentation_type: impl Into<String>) -> Self
This presentation with presentation_type appended to its type.
Sourcepub fn with_holder(self, holder: impl Into<Party>) -> Self
pub fn with_holder(self, holder: impl Into<Party>) -> Self
This presentation with its holder set.
Sourcepub fn with_credential(self, credential: Jwt) -> Self
pub fn with_credential(self, credential: Jwt) -> Self
This presentation with credential added.
Sourcepub fn with_property(
self,
name: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_property( self, name: impl Into<String>, value: impl Into<Value>, ) -> Self
This presentation with the property name set to value.
Sourcepub fn has_type(&self, presentation_type: &str) -> bool
pub fn has_type(&self, presentation_type: &str) -> bool
Whether presentation_type is among the types.
Sourcepub fn check(&self) -> Result<(), CredentialError>
pub fn check(&self) -> Result<(), CredentialError>
Checks that the first @context is the base context and type includes
VerifiablePresentation.
§Errors
The first CredentialError found.
Sourcepub fn to_jwt_claims(&self) -> Result<JwtClaims, CredentialError>
pub fn to_jwt_claims(&self) -> Result<JwtClaims, CredentialError>
Sourcepub fn from_jwt_claims(jwt_claims: &JwtClaims) -> Result<Self, CredentialError>
pub fn from_jwt_claims(jwt_claims: &JwtClaims) -> Result<Self, CredentialError>
The presentation of a JWT claims set (VCDM 1.1 §6.3.1 “JWT Decoding”): the vp claim
with iss and jti mapped back to holder and id.
§Errors
As Credential::from_jwt_claims, for vp.
Trait Implementations§
Source§impl Clone for Presentation
impl Clone for Presentation
Source§impl Debug for Presentation
impl Debug for Presentation
Source§impl Default for Presentation
impl Default for Presentation
Source§impl<'de> Deserialize<'de> for Presentation
impl<'de> Deserialize<'de> for Presentation
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Reads the presentation and checks it with Presentation::check.
impl Eq for Presentation
Source§impl PartialEq for Presentation
impl PartialEq for Presentation
Source§impl PartialSchema for Presentation
Available on crate feature utoipa only.
impl PartialSchema for Presentation
utoipa only.Source§impl Serialize for Presentation
impl Serialize for Presentation
impl StructuralPartialEq for Presentation
Auto Trait Implementations§
impl Freeze for Presentation
impl RefUnwindSafe for Presentation
impl Send for Presentation
impl Sync for Presentation
impl Unpin for Presentation
impl UnsafeUnpin for Presentation
impl UnwindSafe for Presentation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.