tap_msg/message/
presentation.rs1use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9use crate::TapMessage;
10
11#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
13#[tap(message_type = "https://tap.rsvp/schema/1.0#RequestPresentation")]
14pub struct RequestPresentation {
15 #[tap(thread_id)]
17 pub transaction_id: String,
18
19 pub presentation_definition: String,
21
22 #[serde(skip_serializing_if = "Option::is_none")]
24 pub description: Option<String>,
25
26 pub challenge: String,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub for_originator: Option<bool>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub for_beneficiary: Option<bool>,
36
37 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
39 pub metadata: HashMap<String, serde_json::Value>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
44#[tap(message_type = "https://didcomm.org/present-proof/3.0/presentation")]
45pub struct Presentation {
46 pub challenge: String,
48
49 pub credentials: Vec<serde_json::Value>,
51
52 #[serde(skip_serializing_if = "Option::is_none")]
54 #[tap(optional_transaction_id)]
55 pub transaction_id: Option<String>,
56
57 pub id: String,
59
60 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
62 pub metadata: HashMap<String, serde_json::Value>,
63}
64
65impl Presentation {
66 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 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}