use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use super::subject::PassportCredentialSubject;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PassportCredential {
#[serde(rename = "@context")]
pub context: Vec<Value>,
#[serde(rename = "type")]
pub credential_type: Vec<String>,
pub id: String,
pub issuer: String,
pub valid_from: DateTime<Utc>,
pub credential_subject: PassportCredentialSubject,
}
impl PassportCredential {
pub const VC_BASE_CONTEXT: &'static str = "https://www.w3.org/ns/credentials/v2";
fn dpp_terms() -> Value {
json!({
"dpp": "https://schema.odal-node.io/dpp#",
"DppPassportCredential": "dpp:DppPassportCredential",
"payloadHash": "dpp:payloadHash",
})
}
#[must_use]
pub fn new(issuer: String, credential_subject: PassportCredentialSubject) -> Self {
Self {
context: vec![json!(Self::VC_BASE_CONTEXT), Self::dpp_terms()],
credential_type: vec![
"VerifiableCredential".into(),
"DppPassportCredential".into(),
],
id: format!("urn:uuid:{}", uuid::Uuid::now_v7()),
issuer,
valid_from: Utc::now(),
credential_subject,
}
}
}