pub struct Document {
pub context: Option<Context>,
pub id: DID,
pub also_known_as: Option<AlsoKnownAs>,
pub controller: Option<Controller>,
pub verification_method: Option<BTreeSet<VerificationMethod>>,
pub authentication: Option<VerificationMethods>,
pub assertion_method: Option<VerificationMethods>,
pub key_agreement: Option<VerificationMethods>,
pub capability_invocation: Option<VerificationMethods>,
pub capability_delegation: Option<VerificationMethods>,
pub service: Option<BTreeSet<ServiceEndpoint>>,
}
Expand description
The encapsulation of a decentralized identity document, or DID. This conforms to the did-core spec in totality, according to the rules defined in https://www.w3.org/TR/did-core/#core-properties. Divergence from the spec will be considered a bug, unless otherwise noted.
Please see the individual properties regarding their use. Types in this module will remain undocumented for brevity’s sake, with the exception of methods that live on those types.
One notable thing in this implementation is use of the either crate with wrapping types. This is used to aid in the (de)-serialization of documents properties that can consume multiple switched types. Unfortunately, the spec is not very kind to users of statically-typed languages, so we must take extra precautions to ensure all valid documents can be parsed. To utilize most of these types, there may be an “either wrapper” as well as the either::Either enum itself to encapsulate a type. For example, AlsoKnownAs encapsulates AlsoKnownAsEither as a BTreeSet which then encapsulates either::Either types depending on which style of attribute was used, as DIDs and hypertext url::Urls can be used interchangeably. This approach reduces memory usage and computation time by storing structs instead of raw strings and “figuring it out later”.
JSON-LD attributes (@context
, specifically), are accounted for but not used by this
implementation. This allows you to generate documents and consume ones that follow the JSON-LD
specification but does not attempt to validate the document using the JSON-LD schema. See the
crate’s README for more information regarding this decision.
serde crate implementations are available for all types, to ensure valid serde_json and ciborium I/O, but other formats that serde supports should be technically possible to support without issue.
Fields§
§context: Option<Context>
JSON-LD @context support
id: DID
The DID that this document corresponds to. Will be used as the key when storing in a Registry. This is called the “DID Subject” in the specification.
also_known_as: Option<AlsoKnownAs>
alsoKnownAs determines equivalence for two documents for all purposes. See https://www.w3.org/TR/did-core/#also-known-as for more.
controller: Option<Controller>
§verification_method: Option<BTreeSet<VerificationMethod>>
VerificationMethods are used to verify the identity claiming this document. See https://www.w3.org/TR/did-core/#verification-methods for more. Most following properties that use VerificationMethods may refer to this portion of the document by URL to add additional capabilities to a specific VerificationMethod.
authentication: Option<VerificationMethods>
This set of VerificationMethods corresponds to authentication. https://www.w3.org/TR/did-core/#authentication
assertion_method: Option<VerificationMethods>
This set of VerificationMethods corresponds to assertions. https://www.w3.org/TR/did-core/#assertion
key_agreement: Option<VerificationMethods>
This set of VerificationMethods refers to key agreement. https://www.w3.org/TR/did-core/#key-agreement
capability_invocation: Option<VerificationMethods>
This set of VerificationMethods refers to capability invocation. https://www.w3.org/TR/did-core/#capability-invocation This set of VerificationMethods refers to capability delegation. https://www.w3.org/TR/did-core/#capability-delegation
capability_delegation: Option<VerificationMethods>
§service: Option<BTreeSet<ServiceEndpoint>>
This portion of the document refers to affected services. Services are specially provided by the “DID registry”: https://www.w3.org/TR/did-spec-registries/ and rely on enums to determine how the service is treated.
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Document
impl Ord for Document
Source§impl PartialOrd for Document
impl PartialOrd for Document
impl Eq for Document
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more