tap_msg/message/
presentation.rs

1//! Presentation and RequestPresentation message types for the Transaction Authorization Protocol.
2//!
3//! This module defines the Presentation and RequestPresentation message types, which
4//! are used for requesting and submitting verifiable credentials in the TAP protocol.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9use crate::TapMessage;
10
11/// Request Presentation message body (TAIP-10).
12#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
13#[tap(message_type = "https://tap.rsvp/schema/1.0#RequestPresentation")]
14pub struct RequestPresentation {
15    /// Transfer ID that this request is related to.
16    #[tap(thread_id)]
17    pub transaction_id: String,
18
19    /// Presentation definition identifier or URI.
20    pub presentation_definition: String,
21
22    /// Description of the request.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub description: Option<String>,
25
26    /// Challenge to be included in the response.
27    pub challenge: String,
28
29    /// Whether the request is for the originator's information.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub for_originator: Option<bool>,
32
33    /// Whether the request is for the beneficiary's information.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub for_beneficiary: Option<bool>,
36
37    /// Additional metadata.
38    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
39    pub metadata: HashMap<String, serde_json::Value>,
40}
41
42/// Presentation message body (TAIP-8, TAIP-10).
43#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
44#[tap(message_type = "https://didcomm.org/present-proof/3.0/presentation")]
45pub struct Presentation {
46    /// Challenge from the request.
47    pub challenge: String,
48
49    /// Credential data.
50    pub credentials: Vec<serde_json::Value>,
51
52    /// Transfer ID that this presentation is related to (optional).
53    #[serde(skip_serializing_if = "Option::is_none")]
54    #[tap(optional_transaction_id)]
55    pub transaction_id: Option<String>,
56
57    /// Identifier for this presentation (used for message_id)
58    pub id: String,
59
60    /// Additional metadata.
61    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
62    pub metadata: HashMap<String, serde_json::Value>,
63}
64
65impl Presentation {
66    /// Create a new Presentation
67    pub fn new(
68        challenge: String,
69        credentials: Vec<serde_json::Value>,
70        transaction_id: Option<String>,
71    ) -> Self {
72        Self {
73            challenge,
74            credentials,
75            transaction_id,
76            id: uuid::Uuid::new_v4().to_string(),
77            metadata: HashMap::new(),
78        }
79    }
80
81    /// Add metadata to the presentation
82    pub fn with_metadata(mut self, key: &str, value: serde_json::Value) -> Self {
83        self.metadata.insert(key.to_string(), value);
84        self
85    }
86}