Struct DIDCommPresentation

Source
pub struct DIDCommPresentation {
    pub thid: Option<String>,
    pub comment: Option<String>,
    pub goal_code: Option<String>,
    pub attachments: Vec<Attachment>,
    pub metadata: HashMap<String, Value>,
}
Expand description

DIDComm Presentation format (using present-proof protocol)

This struct implements the standard DIDComm present-proof protocol format as defined in DIDComm Messaging Present Proof Protocol 3.0.

It is used for exchanging verifiable presentations between parties in a DIDComm conversation. The presentation may contain identity credentials, proof of control, or other verifiable claims.

§Compatibility Notes

  • This implementation is fully compatible with the standard DIDComm present-proof protocol.
  • The message type used is https://didcomm.org/present-proof/3.0/presentation.
  • Thread ID (thid) is required for proper message correlation.
  • At least one attachment containing a verifiable presentation is required.
  • Attachment data must include either base64 or JSON format data.
  • Verifiable presentations in JSON format must include @context and type fields.

§Example

use std::collections::HashMap;
use tap_msg::message::{Attachment, AttachmentData, DIDCommPresentation};
use serde_json::json;

// Create a presentation with a verifiable credential
let presentation = DIDCommPresentation {
    thid: Some("123e4567-e89b-12d3-a456-426614174000".to_string()),
    comment: Some("Proof of identity".to_string()),
    goal_code: Some("kyc.individual".to_string()),
    attachments: vec![
        Attachment {
            id: "credential-1".to_string(),
            media_type: "application/json".to_string(),
            data: Some(AttachmentData {
                base64: None,
                json: Some(json!({
                    "@context": ["https://www.w3.org/2018/credentials/v1"],
                    "type": ["VerifiablePresentation"],
                    "verifiableCredential": [{
                        "@context": ["https://www.w3.org/2018/credentials/v1"],
                        "type": ["VerifiableCredential"],
                        "issuer": "did:web:issuer.example",
                        "issuanceDate": "2022-01-01T19:23:24Z",
                        "credentialSubject": {
                            "id": "did:example:ebfeb1f712ebc6f1c276e12ec21"
                        }
                    }]
                })),
            }),
        }
    ],
    metadata: HashMap::new(),
};

Fields§

§thid: Option<String>

Reference to a previous message in the thread

§comment: Option<String>

Optional comment

§goal_code: Option<String>

Goal code

§attachments: Vec<Attachment>

Attachments containing the verifiable presentations

§metadata: HashMap<String, Value>

Additional metadata

Implementations§

Source§

impl DIDCommPresentation

Source

pub fn new(thid: Option<String>, attachments: Vec<Attachment>) -> Self

Creates a new DIDComm Presentation

Source

pub fn validate(&self) -> Result<()>

Validate the DIDComm Presentation

This method validates a DIDComm presentation according to the standard protocol requirements. For a presentation to be valid, it must satisfy the following criteria:

  • Must have a thread ID (thid) for message correlation
  • Must include at least one attachment
  • Each attachment must have a non-empty ID and media type
  • Each attachment must include data in either base64 or JSON format
  • Verifiable presentations in JSON format must include @context and type fields
§Returns
  • Ok(()) if the presentation is valid
  • Err(Error::Validation) with a descriptive message if validation fails
§Examples
use tap_msg::message::DIDCommPresentation;
use tap_msg::Result;

fn check_presentation(presentation: &DIDCommPresentation) -> Result<()> {
    // Validate the presentation
    presentation.validate()?;
     
    // If we get here, the presentation is valid
    Ok(())
}

Trait Implementations§

Source§

impl Clone for DIDCommPresentation

Source§

fn clone(&self) -> DIDCommPresentation

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DIDCommPresentation

Source§

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

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

impl<'de> Deserialize<'de> for DIDCommPresentation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for DIDCommPresentation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TapMessageBody for DIDCommPresentation

Implementation of TapMessageBody for DIDCommPresentation

This implementation ensures that DIDCommPresentation can be converted to and from didcomm::Message objects, allowing seamless integration with the DIDComm messaging protocol.

§Details

  • Message Type: Uses https://didcomm.org/present-proof/3.0/presentation as specified by the standard protocol
  • Conversion to DIDComm: Converts attachments to didcomm::Attachment format with appropriate data representation
  • Conversion from DIDComm: Extracts presentation data from DIDComm message, handling both Base64 and JSON formats

This implementation follows the DIDComm Messaging Specification and the Present Proof Protocol 3.0.

Source§

fn message_type() -> &'static str

Get the message type string for this body type.
Source§

fn validate(&self) -> Result<()>

Validate the message body.
Source§

fn from_didcomm(message: &Message) -> Result<Self>

Extract this body type from a DIDComm message.
Source§

fn to_didcomm(&self, from_did: Option<&str>) -> Result<Message>

Convert this body to a DIDComm message.
Source§

fn to_didcomm_with_route<'a, I>( &self, from: Option<&str>, to: I, ) -> Result<Message>
where I: IntoIterator<Item = &'a str>,

Convert this body to a DIDComm message with a sender and multiple recipients. Read more

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,