ssi_dids_core/document/
service.rs

1use std::collections::BTreeMap;
2
3use iref::UriBuf;
4use serde::{Deserialize, Serialize};
5use ssi_core::one_or_many::OneOrMany;
6
7/// DID Service.
8///
9/// Services express ways of communicating with the DID subject or associated
10/// entities.
11///
12// See: <https://w3c.github.io/did-core/#service-properties>
13#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
14#[serde(rename_all = "camelCase")]
15pub struct Service {
16    /// id property (URI) of a service map.
17    pub id: UriBuf,
18
19    #[serde(rename = "type")]
20    pub type_: OneOrMany<String>,
21
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub service_endpoint: Option<OneOrMany<Endpoint>>,
24
25    #[serde(flatten)]
26    pub property_set: BTreeMap<String, serde_json::Value>,
27}
28
29/// Service endpoint.
30///
31/// Value for a [serviceEndpoint](https://www.w3.org/TR/did-core/#dfn-serviceendpoint) property of
32/// a [service](https://www.w3.org/TR/did-core/#services) map in a DID document.
33///
34/// "The value of the serviceEndpoint property MUST be a string \[URI], a map, or a set composed of one or
35/// more strings \[URIs] and/or maps."
36#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
37#[serde(rename_all = "camelCase")]
38#[serde(untagged)]
39pub enum Endpoint {
40    Uri(UriBuf), // TODO must be an URI
41    Map(serde_json::Value),
42}