pub struct IotaDocument {
    pub metadata: IotaDocumentMetadata,
    /* private fields */
}
Expand description

A DID Document adhering to the IOTA DID method specification.

This extends CoreDocument.

Fields§

§metadata: IotaDocumentMetadata

The metadata of an IOTA DID document.

Implementations§

source§

impl IotaDocument

source

pub fn new(network: &NetworkName) -> IotaDocument

Constructs an empty DID Document with a IotaDID::placeholder identifier for the given network.

source

pub fn new_with_id(id: IotaDID) -> IotaDocument

Constructs an empty DID Document with the given identifier.

source

pub fn id(&self) -> &IotaDID

Returns the DID document identifier.

source

pub fn controller(&self) -> impl Iterator<Item = &IotaDID>

Returns an iterator yielding the DID controllers.

source

pub fn set_controller<T>(&mut self, controller: T)
where T: IntoIterator<Item = IotaDID>,

Sets the value of the document controller.

Note:

  • Duplicates in controller will be ignored.
  • Use an empty collection to clear all controllers.
source

pub fn also_known_as(&self) -> &OrderedSet<Url>

Returns a reference to the alsoKnownAs set.

source

pub fn also_known_as_mut(&mut self) -> &mut OrderedSet<Url>

Returns a mutable reference to the alsoKnownAs set.

source

pub fn core_document(&self) -> &CoreDocument

Returns a reference to the underlying CoreDocument.

source

pub fn properties(&self) -> &BTreeMap<String, Value>

Returns a reference to the custom DID Document properties.

source

pub fn properties_mut_unchecked(&mut self) -> &mut BTreeMap<String, Value>

Returns a mutable reference to the custom DID Document properties.

§Warning

The properties returned are not checked against the standard fields in a CoreDocument. Incautious use can have undesired consequences such as key collision when attempting to serialize the document or distinct resources (such as services and methods) being identified by the same DID URL.

source

pub fn service(&self) -> &OrderedSet<Service>

Return a set of all Services in the document.

source

pub fn insert_service(&mut self, service: Service) -> Result<(), Error>

Add a new Service to the document.

§Errors

An error is returned if there already exists a service or (verification) method with the same identifier in the document.

source

pub fn remove_service(&mut self, did_url: &DIDUrl) -> Option<Service>

Remove and return the Service identified by the given DIDUrl from the document.

None is returned if the service does not exist in the document.

source

pub fn methods(&self, scope: Option<MethodScope>) -> Vec<&VerificationMethod>

Returns a Vec of verification method references whose verification relationship matches scope.

If scope is None, all embedded methods are returned.

source

pub fn insert_method( &mut self, method: VerificationMethod, scope: MethodScope ) -> Result<(), Error>

Adds a new VerificationMethod to the document in the given MethodScope.

§Errors

Returns an error if a method with the same fragment already exists.

source

pub fn remove_method(&mut self, did_url: &DIDUrl) -> Option<VerificationMethod>

Removes and returns the VerificationMethod identified by did_url from the document.

§Note

All references to the method found in the document will be removed. This includes cases where the reference is to a method contained in another DID document.

source

pub fn remove_method_and_scope( &mut self, did_url: &DIDUrl ) -> Option<(VerificationMethod, MethodScope)>

Removes and returns the VerificationMethod from the document. The MethodScope under which the method was found is appended to the second position of the returned tuple.

§Note

All references to the method found in the document will be removed. This includes cases where the reference is to a method contained in another DID document.

source

pub fn attach_method_relationship<'query, Q>( &mut self, method_query: Q, relationship: MethodRelationship ) -> Result<bool, Error>
where Q: Into<DIDUrlQuery<'query>>,

Attaches the relationship to the method resolved by method_query.

§Errors

Returns an error if the method does not exist or if it is embedded. To convert an embedded method into a generic verification method, remove it first and insert it with MethodScope::VerificationMethod.

source

pub fn detach_method_relationship<'query, Q>( &mut self, method_query: Q, relationship: MethodRelationship ) -> Result<bool, Error>
where Q: Into<DIDUrlQuery<'query>>,

Detaches the relationship from the method identified by did_url. Returns true if the relationship was found and removed, false otherwise.

§Errors

Returns an error if the method does not exist or is embedded. To remove an embedded method, use Self::remove_method.

§Note

If the method is referenced in the given scope, but the document does not contain the referenced verification method, then the reference will persist in the document (i.e. it is not removed).

source

pub fn resolve_method_mut<'query, Q>( &mut self, method_query: Q, scope: Option<MethodScope> ) -> Option<&mut VerificationMethod>
where Q: Into<DIDUrlQuery<'query>>,

Returns the first VerificationMethod with an id property matching the provided method_query and the verification relationship specified by scope if present.

§Warning

Incorrect use of this method can lead to distinct document resources being identified by the same DID URL.

source

pub fn resolve_service<'query, 'me, Q>( &'me self, service_query: Q ) -> Option<&'me Service>
where Q: Into<DIDUrlQuery<'query>>,

Returns the first Service with an id property matching the provided service_query, if present.

source

pub fn resolve_method<'query, 'me, Q>( &'me self, method_query: Q, scope: Option<MethodScope> ) -> Option<&'me VerificationMethod>
where Q: Into<DIDUrlQuery<'query>>,

Returns the first VerificationMethod with an id property matching the provided method_query and the verification relationship specified by scope if present.

source

pub fn verify_jws<'jws, T>( &self, jws: &'jws Jws, detached_payload: Option<&'jws [u8]>, signature_verifier: &T, options: &JwsVerificationOptions ) -> Result<DecodedJws<'jws>, Error>
where T: JwsVerifier,

Decodes and verifies the provided JWS according to the passed JwsVerificationOptions and JwsVerifier.

Regardless of which options are passed the following conditions must be met in order for a verification attempt to take place.

  • The JWS must be encoded according to the JWS compact serialization.
  • The kid value in the protected header must be an identifier of a verification method in this DID document.
source

pub fn pack(self) -> Result<Vec<u8>, Error>

Serializes the document for inclusion in an Alias Output’s state metadata with the default StateMetadataEncoding.

source

pub fn pack_with_encoding( self, encoding: StateMetadataEncoding ) -> Result<Vec<u8>, Error>

Serializes the document for inclusion in an Alias Output’s state metadata.

source§

impl IotaDocument

source

pub fn unpack_from_output( did: &IotaDID, alias_output: &AliasOutput, allow_empty: bool ) -> Result<IotaDocument, Error>

Deserializes the document from an Alias Output.

If allow_empty is true, this will return an empty DID document marked as deactivated if state_metadata is empty.

NOTE: did is required since it is omitted from the serialized DID Document and cannot be inferred from the state metadata. It also indicates the network, which is not encoded in the AliasId alone.

source

pub fn unpack_from_block( network: &NetworkName, block: &Block ) -> Result<Vec<IotaDocument>, Error>

Returns all DID documents of the Alias Outputs contained in the block’s transaction payload outputs, if any.

Errors if any Alias Output does not contain a valid or empty DID Document.

source§

impl IotaDocument

source

pub fn revoke_credentials<'query, 'me, Q>( &mut self, service_query: Q, indices: &[u32] ) -> Result<(), Error>
where Q: Into<DIDUrlQuery<'query>>,

If the document has a RevocationBitmap service identified by service_query, revoke all specified indices.

source

pub fn unrevoke_credentials<'query, 'me, Q>( &'me mut self, service_query: Q, indices: &[u32] ) -> Result<(), Error>
where Q: Into<DIDUrlQuery<'query>>,

If the document has a RevocationBitmap service with an id by service_query, unrevoke all specified indices.

Trait Implementations§

source§

impl AsRef<CoreDocument> for IotaDocument

source§

fn as_ref(&self) -> &CoreDocument

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for IotaDocument

source§

fn clone(&self) -> IotaDocument

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for IotaDocument

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for IotaDocument

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<IotaDocument, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for IotaDocument

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<IotaDocument> for CoreDocument

source§

fn from(document: IotaDocument) -> CoreDocument

Converts to this type from the input type.
source§

impl From<IotaDocument> for StateMetadataDocument

source§

fn from(document: IotaDocument) -> StateMetadataDocument

Transforms a IotaDocument into its state metadata representation by replacing all occurrences of its did with a placeholder.

source§

impl JwkDocumentExt for IotaDocument

source§

fn generate_method<'life0, 'life1, 'life2, 'async_trait, K, I>( &'life0 mut self, storage: &'life1 Storage<K, I>, key_type: KeyType, alg: JwsAlgorithm, fragment: Option<&'life2 str>, scope: MethodScope ) -> Pin<Box<dyn Future<Output = Result<String, JwkStorageDocumentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, K: JwkStorage + 'async_trait, I: KeyIdStorage + 'async_trait, IotaDocument: 'async_trait,

Generate new key material in the given storage and insert a new verification method with the corresponding public key material into the DID document. Read more
source§

fn purge_method<'life0, 'life1, 'life2, 'async_trait, K, I>( &'life0 mut self, storage: &'life1 Storage<K, I>, id: &'life2 DIDUrl ) -> Pin<Box<dyn Future<Output = Result<(), JwkStorageDocumentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, K: JwkStorage + 'async_trait, I: KeyIdStorage + 'async_trait, IotaDocument: 'async_trait,

Remove the method identified by the given id from the document and delete the corresponding key material in the given storage. Read more
source§

fn create_jws<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait, K, I>( &'life0 self, storage: &'life1 Storage<K, I>, fragment: &'life2 str, payload: &'life3 [u8], options: &'life4 JwsSignatureOptions ) -> Pin<Box<dyn Future<Output = Result<Jws, JwkStorageDocumentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, K: JwkStorage + 'async_trait, I: KeyIdStorage + 'async_trait, IotaDocument: 'async_trait,

Sign the arbitrary payload according to options with the storage backed private key corresponding to the public key material in the verification method identified by the given `fragment. Read more
source§

fn create_credential_jwt<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait, K, I, T>( &'life0 self, credential: &'life1 Credential<T>, storage: &'life2 Storage<K, I>, fragment: &'life3 str, options: &'life4 JwsSignatureOptions, custom_claims: Option<BTreeMap<String, Value>> ) -> Pin<Box<dyn Future<Output = Result<Jwt, JwkStorageDocumentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, K: JwkStorage + 'async_trait, I: KeyIdStorage + 'async_trait, T: ToOwned<Owned = T> + Serialize + DeserializeOwned + Sync + 'async_trait, IotaDocument: 'async_trait,

Produces a JWT where the payload is produced from the given credential in accordance with VC Data Model v1.1. Read more
source§

fn create_presentation_jwt<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait, K, I, CRED, T>( &'life0 self, presentation: &'life1 Presentation<CRED, T>, storage: &'life2 Storage<K, I>, fragment: &'life3 str, options: &'life4 JwsSignatureOptions, jwt_options: &'life5 JwtPresentationOptions ) -> Pin<Box<dyn Future<Output = Result<Jwt, JwkStorageDocumentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait, K: JwkStorage + 'async_trait, I: KeyIdStorage + 'async_trait, T: ToOwned<Owned = T> + Serialize + DeserializeOwned + Sync + 'async_trait, CRED: ToOwned<Owned = CRED> + Serialize + DeserializeOwned + Clone + Sync + 'async_trait, IotaDocument: 'async_trait,

Produces a JWT where the payload is produced from the given presentation in accordance with VC Data Model v1.1. Read more
source§

impl PartialEq for IotaDocument

source§

fn eq(&self, other: &IotaDocument) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for IotaDocument

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<(CoreDocument, IotaDocumentMetadata)> for IotaDocument

source§

fn try_from( value: (CoreDocument, IotaDocumentMetadata) ) -> Result<IotaDocument, <IotaDocument as TryFrom<(CoreDocument, IotaDocumentMetadata)>>::Error>

Converts the tuple into an IotaDocument if the given CoreDocument has an identifier satisfying the requirements of the IOTA UTXO method and the same holds for all of the CoreDocument's controllers.

§Important

This does not check the relationship between the CoreDocument and the IotaDocumentMetadata.

§

type Error = Error

The type returned in the event of a conversion error.
source§

impl TryFrom<ProvisionalIotaDocument> for IotaDocument

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( provisional: ProvisionalIotaDocument ) -> Result<IotaDocument, <IotaDocument as TryFrom<ProvisionalIotaDocument>>::Error>

Performs the conversion.
source§

impl Eq for IotaDocument

source§

impl StructuralPartialEq for IotaDocument

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> ConvertTo<T> for T
where T: Send,

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> FmtJson for T
where T: ToJson,

source§

fn fmt_json(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Format this as a JSON string or pretty-JSON string based on whether the # format flag was used.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromJson for T
where T: for<'de> Deserialize<'de>,

source§

fn from_json(json: &(impl AsRef<str> + ?Sized)) -> Result<Self, Error>

Deserialize Self from a string of JSON text.
source§

fn from_json_slice(json: &(impl AsRef<[u8]> + ?Sized)) -> Result<Self, Error>

Deserialize Self from bytes of JSON text.
source§

fn from_json_value(json: Value) -> Result<Self, Error>

Deserialize Self from a serde_json::Value.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToJson for T
where T: Serialize,

source§

fn to_json(&self) -> Result<String, Error>

Serialize self as a string of JSON.
source§

fn to_json_vec(&self) -> Result<Vec<u8>, Error>

Serialize self as a JSON byte vector.
source§

fn to_json_value(&self) -> Result<Value, Error>

Serialize self as a serde_json::Value.
source§

fn to_json_pretty(&self) -> Result<String, Error>

Serialize self as a pretty-printed string of JSON.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,