identity_iota_core/did_resolution/
did_resolution_handler.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::rebased::client::IdentityClientReadOnly;
5use crate::Error;
6use crate::IotaDID;
7use crate::IotaDocument;
8use crate::Result;
9
10/// An extension trait that provides helper functions for publication
11/// and resolution of DID documents in identities.
12///
13/// This trait is not intended to be implemented directly, a blanket implementation is
14/// provided for [`IotaIdentityClient`] implementers.
15#[cfg_attr(feature = "send-sync-client-ext", async_trait::async_trait)]
16#[cfg_attr(not(feature = "send-sync-client-ext"), async_trait::async_trait(?Send))]
17pub trait DidResolutionHandler {
18  /// Resolve a [`IotaDocument`]. Returns an empty, deactivated document if the state metadata
19  /// of the identity is empty.
20  ///
21  /// # Errors
22  ///
23  /// - [`DID resolution failed`](Error::DIDResolutionError) if the DID could not be resolved.
24  async fn resolve_did(&self, did: &IotaDID) -> Result<IotaDocument>;
25}
26
27#[cfg_attr(feature = "send-sync-client-ext", async_trait::async_trait)]
28#[cfg_attr(not(feature = "send-sync-client-ext"), async_trait::async_trait(?Send))]
29impl DidResolutionHandler for IdentityClientReadOnly {
30  async fn resolve_did(&self, did: &IotaDID) -> Result<IotaDocument> {
31    self
32      .resolve_did(did)
33      .await
34      .map_err(|err| Error::DIDResolutionError(err.to_string()))
35  }
36}