use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::TapMessage;
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(message_type = "https://tap.rsvp/schema/1.0#RequestPresentation")]
pub struct RequestPresentation {
#[tap(thread_id)]
pub transaction_id: String,
pub presentation_definition: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub challenge: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub for_originator: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub for_beneficiary: Option<bool>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
#[tap(message_type = "https://didcomm.org/present-proof/3.0/presentation")]
pub struct Presentation {
pub challenge: String,
pub credentials: Vec<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
#[tap(optional_transaction_id)]
pub transaction_id: Option<String>,
pub id: String,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub metadata: HashMap<String, serde_json::Value>,
}
impl Presentation {
pub fn new(
challenge: String,
credentials: Vec<serde_json::Value>,
transaction_id: Option<String>,
) -> Self {
Self {
challenge,
credentials,
transaction_id,
id: uuid::Uuid::new_v4().to_string(),
metadata: HashMap::new(),
}
}
pub fn with_metadata(mut self, key: &str, value: serde_json::Value) -> Self {
self.metadata.insert(key.to_string(), value);
self
}
}