use base64::{engine::general_purpose::STANDARD, Engine};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Proof {
#[serde(rename = "type")]
pub type_: String,
pub created: DateTime<Utc>,
pub verification_method: String,
pub proof_purpose: ProofPurpose,
#[serde(skip_serializing_if = "Option::is_none")]
pub proof_value: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub jws: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub domain: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub challenge: Option<String>,
#[serde(flatten)]
pub properties: HashMap<String, Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ProofPurpose {
AssertionMethod,
Authentication,
KeyAgreement,
CapabilityInvocation,
CapabilityDelegation,
}
impl Proof {
pub fn new_ed25519_signature(
verification_method: String,
signature: Vec<u8>,
) -> Self {
Self {
type_: "Ed25519Signature2020".to_string(),
created: Utc::now(),
verification_method,
proof_purpose: ProofPurpose::AssertionMethod,
proof_value: Some(STANDARD.encode(signature)),
jws: None,
domain: None,
challenge: None,
properties: HashMap::new(),
}
}
}