Skip to main content

didwebvh_rs/log_entry/
spec_1_0.rs

1//! WebVH Specification 1.0 implementation
2
3use chrono::{DateTime, FixedOffset};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7use crate::{
8    DIDWebVHError,
9    log_entry::{LogEntry, LogEntryCreate, format_version_time, impl_log_entry_common},
10    parameters::{Parameters, spec_1_0::Parameters1_0},
11};
12
13/// Each version of the DID gets a new log entry
14/// [Log Entries](https://identity.foundation/didwebvh/v1.0/#the-did-log-file)
15#[derive(Clone, Debug, Deserialize, Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct LogEntry1_0 {
18    /// format integer-prev_hash
19    pub version_id: String,
20
21    /// ISO 8601 date format
22    #[serde(serialize_with = "format_version_time")]
23    pub version_time: DateTime<FixedOffset>,
24
25    /// Parameters for this LogEntry
26    pub parameters: Parameters1_0,
27
28    /// DID document
29    pub state: Value,
30
31    /// Data Integrity Proof
32    #[serde(skip_serializing_if = "Vec::is_empty", default)]
33    pub proof: Vec<affinidi_data_integrity::DataIntegrityProof>,
34}
35
36impl_log_entry_common!(LogEntry1_0);
37
38impl LogEntryCreate for LogEntry1_0 {
39    fn create(
40        version_id: String,
41        version_time: DateTime<FixedOffset>,
42        parameters: Parameters,
43        state: Value,
44    ) -> Result<LogEntry, DIDWebVHError> {
45        Ok(LogEntry::Spec1_0(LogEntry1_0 {
46            version_id,
47            version_time,
48            parameters: parameters.into(),
49            state,
50            proof: vec![],
51        }))
52    }
53}