Skip to main content

didwebvh_rs/log_entry/
spec_1_0_pre.rs

1//! WebVH Specification pre 1.0 implementation
2//! This exists as there was a period of time where some LogEntries
3//! for version 1.0 may contain nulls instead of empty arrays
4
5use chrono::{DateTime, FixedOffset};
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8
9use crate::{
10    DIDWebVHError,
11    log_entry::{LogEntry, LogEntryCreate, format_version_time, impl_log_entry_common},
12    parameters::{Parameters, spec_1_0_pre::Parameters1_0Pre},
13};
14
15/// Each version of the DID gets a new log entry
16/// [Log Entries](https://identity.foundation/didwebvh/v1.0/#the-did-log-file)
17#[derive(Clone, Debug, Deserialize, Serialize)]
18#[serde(rename_all = "camelCase")]
19pub struct LogEntry1_0Pre {
20    /// format integer-prev_hash
21    pub version_id: String,
22
23    /// ISO 8601 date format
24    #[serde(serialize_with = "format_version_time")]
25    pub version_time: DateTime<FixedOffset>,
26
27    /// Parameters for this LogEntry
28    pub parameters: Parameters1_0Pre,
29
30    /// DID document
31    pub state: Value,
32
33    /// Data Integrity Proof
34    #[serde(skip_serializing_if = "Vec::is_empty", default)]
35    pub proof: Vec<affinidi_data_integrity::DataIntegrityProof>,
36}
37
38impl_log_entry_common!(LogEntry1_0Pre);
39
40impl LogEntryCreate for LogEntry1_0Pre {
41    fn create(
42        _: String,
43        _: DateTime<FixedOffset>,
44        _: Parameters,
45        _: Value,
46    ) -> Result<LogEntry, DIDWebVHError> {
47        Err(DIDWebVHError::LogEntryError(
48            "LogEntry1_0Pre cannot be created directly. Use LogEntry1_0Pre::new() instead."
49                .to_string(),
50        ))
51    }
52}