baseid_did/
document.rs

1//! DID Document types per W3C DID Core 1.0.
2
3use serde::{Deserialize, Serialize};
4
5/// A DID Document as defined in W3C DID Core 1.0.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct DidDocument {
9    /// The DID subject (e.g., "did:key:z6Mkf5...").
10    pub id: String,
11
12    /// JSON-LD context.
13    #[serde(rename = "@context")]
14    pub context: Vec<String>,
15
16    /// Verification methods (keys) associated with this DID.
17    #[serde(default, skip_serializing_if = "Vec::is_empty")]
18    pub verification_method: Vec<VerificationMethod>,
19
20    /// Authentication verification relationships.
21    #[serde(default, skip_serializing_if = "Vec::is_empty")]
22    pub authentication: Vec<VerificationRelationship>,
23
24    /// Assertion method verification relationships.
25    #[serde(default, skip_serializing_if = "Vec::is_empty")]
26    pub assertion_method: Vec<VerificationRelationship>,
27
28    /// Key agreement verification relationships.
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub key_agreement: Vec<VerificationRelationship>,
31
32    /// Service endpoints.
33    #[serde(default, skip_serializing_if = "Vec::is_empty")]
34    pub service: Vec<Service>,
35}
36
37/// A verification method (public key) in a DID Document.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct VerificationMethod {
41    pub id: String,
42    pub r#type: String,
43    pub controller: String,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub public_key_jwk: Option<serde_json::Value>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub public_key_multibase: Option<String>,
48}
49
50/// A verification relationship — either a reference (string) or embedded method.
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum VerificationRelationship {
54    Reference(String),
55    Embedded(VerificationMethod),
56}
57
58/// A service endpoint in a DID Document.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct Service {
62    pub id: String,
63    pub r#type: String,
64    pub service_endpoint: ServiceEndpoint,
65}
66
67/// A service endpoint value.
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ServiceEndpoint {
71    Uri(String),
72    Map(serde_json::Value),
73}