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
@contextandtypefields.
§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
impl DIDCommPresentation
Sourcepub fn new(thid: Option<String>, attachments: Vec<Attachment>) -> Self
pub fn new(thid: Option<String>, attachments: Vec<Attachment>) -> Self
Creates a new DIDComm Presentation
Sourcepub fn validate(&self) -> Result<()>
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
@contextandtypefields
§Returns
Ok(())if the presentation is validErr(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
impl Clone for DIDCommPresentation
Source§fn clone(&self) -> DIDCommPresentation
fn clone(&self) -> DIDCommPresentation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DIDCommPresentation
impl Debug for DIDCommPresentation
Source§impl<'de> Deserialize<'de> for DIDCommPresentation
impl<'de> Deserialize<'de> for DIDCommPresentation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for DIDCommPresentation
impl Serialize for DIDCommPresentation
Source§impl TapMessageBody for DIDCommPresentation
Implementation of TapMessageBody for DIDCommPresentation
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/presentationas 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.