Skip to main content

LinkedPresentationBuilder

Struct LinkedPresentationBuilder 

Source
#[non_exhaustive]
pub struct LinkedPresentationBuilder { pub holder: Did, pub id: Option<Uri>, pub credentials: Vec<Jwt>, pub issued_at: DateTime<Utc>, pub expiration: Option<DateTime<Utc>>, }
Available on crate feature linked-vp only.
Expand description

Builds a linked presentation in the JSON Web Token form: a VCDM 1.1 presentation of credential JWTs held by holder, with iss, sub and holder the holder, jti the presentation’s id, iat and nbf the issuance time, exp when an expiration is set, and neither aud nor nonce.

§Examples

use chrono::{TimeZone as _, Utc};
use identity_kit::did::{Did, Uri};
use identity_kit::linked_vp::LinkedPresentationBuilder;

let holder = Did::parse("did:example:123")?;
let claims = LinkedPresentationBuilder::new(holder)
    .with_id(Uri::parse("https://bar.example.com/verifiable-presentation.jwt")?)
    .with_issued_at(Utc.with_ymd_and_hms(2024, 2, 8, 17, 38, 46).unwrap())
    .with_expiration(Utc.with_ymd_and_hms(2029, 2, 8, 17, 38, 46).unwrap())
    .jwt_claims()?;
assert_eq!(claims.iss.as_deref(), Some("did:example:123"));
assert_eq!(claims.sub, claims.iss);
assert_eq!((claims.iat, claims.nbf, claims.exp), (Some(1707413926), Some(1707413926), Some(1865266726)));
assert_eq!(claims.jti.as_deref(), Some("https://bar.example.com/verifiable-presentation.jwt"));
assert!(claims.aud.is_none() && !claims.additional.contains_key("nonce"));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§holder: Did

The holder: the DID whose document links the presentation.

§id: Option<Uri>

The presentation’s id, usually the URL it is published at.

§credentials: Vec<Jwt>

The credential JWTs.

§issued_at: DateTime<Utc>

iat and nbf.

§expiration: Option<DateTime<Utc>>

exp, if the presentation expires.

Implementations§

Source§

impl LinkedPresentationBuilder

Source

pub fn new(holder: Did) -> Self

A presentation by holder of no credentials, issued now, without id or expiration.

Source

pub fn with_id(self, id: impl Into<Uri>) -> Self

This presentation with its id set.

Source

pub fn with_credential(self, credential: Jwt) -> Self

This presentation with credential added.

Source

pub fn with_issued_at(self, issued_at: DateTime<Utc>) -> Self

This presentation issued at issued_at.

Source

pub fn with_expiration(self, expiration: DateTime<Utc>) -> Self

This presentation expiring at expiration, which the specification recommends to limit how long a published presentation stays valid.

Source

pub fn presentation(&self) -> Presentation

The presentation.

Source

pub fn jwt_claims(&self) -> Result<JwtClaims, CredentialError>

The JWT claims: the presentation’s (iss, jti, vp) with sub, iat, nbf and exp.

§Errors

A CredentialError when the presentation does not map to claims; one built here always does.

Source

pub async fn sign( &self, kid: &DidUrl, signer: &dyn Signer, ) -> Result<Jwt, LinkedVpError>

The presentation signed with signer under a header of alg, typ JWT and kid, kid naming a verification method of the holder, which a verifier resolves under authentication.

§Errors

LinkedVpError::Validation with ValidationError::HolderMismatch when kid is not a key of the holder, or with ValidationError::Jws when signing fails.

Trait Implementations§

Source§

impl Clone for LinkedPresentationBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkedPresentationBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LinkedPresentationBuilder

Source§

impl PartialEq for LinkedPresentationBuilder

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LinkedPresentationBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more