pub struct DidWeb<C> { /* private fields */ }Available on crate feature
did-web and (crate features did-jwk or did-key or did-web) only.Expand description
The did:web method: a DidResolver fetching documents through an HttpClient, and a
DidProducer building the document to publish.
§Examples
use identity_kit::did::Did;
use identity_kit::methods::web::{DidWeb, HttpClient, HttpError, HttpResponse};
use identity_kit::resolver::Resolver;
use url::Url;
/// Serves one document from memory.
struct Static(String);
#[async_trait::async_trait]
impl HttpClient for Static {
async fn get(&self, url: &Url) -> Result<HttpResponse, HttpError> {
Ok(if url.as_str() == "https://example.com/.well-known/did.json" {
HttpResponse::new(200, self.0.as_bytes())
} else {
HttpResponse::new(404, Vec::new())
})
}
}
let document = r#"{"id": "did:web:example.com"}"#.to_owned();
let resolver = Resolver::builder().with(DidWeb::new(Static(document))).build();
let did = Did::parse("did:web:example.com")?;
assert_eq!(resolver.resolve_document(&did).await?.id, did);Implementations§
Trait Implementations§
Source§impl<C: HttpClient> DidProducer for DidWeb<C>
impl<C: HttpClient> DidProducer for DidWeb<C>
Source§type Params = Url
type Params = Url
The HTTPS URL the document will be served under, as did_from_url reads it.
Source§fn capabilities(&self) -> MethodCapabilities
fn capabilities(&self) -> MethodCapabilities
Hosted on the web, any number of keys, updated by republishing; fragments come from the keys.
Source§fn produce<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Jwk],
url: Url,
) -> Pin<Box<dyn Future<Output = Result<DidDocument, ProduceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn produce<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Jwk],
url: Url,
) -> Pin<Box<dyn Future<Output = Result<DidDocument, ProduceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The document to publish at url for keys.
Each key becomes a JsonWebKey2020 verification method whose fragment is the key’s
kid, or key-<index> when it has none. A key with use enc, or an X25519 key, is
referenced from keyAgreement; every other key from authentication,
assertionMethod, capabilityInvocation and capabilityDelegation. The document’s
@context is CONTEXT.
§Errors
ProduceError::NoKeyswithout a key.ProduceError::InvalidParamswhenurlhas nodid:web(seedid_from_url).ProduceError::UnsupportedKeyfor akidthat is not a valid fragment.ProduceError::Documentfor two keys with the samekid.
Source§impl<C: HttpClient> DidResolver for DidWeb<C>
impl<C: HttpClient> DidResolver for DidWeb<C>
Source§fn resolve<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 Did,
options: &'life2 ResolutionOptions,
) -> Pin<Box<dyn Future<Output = Result<ResolutionResult, ResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn resolve<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 Did,
options: &'life2 ResolutionOptions,
) -> Pin<Box<dyn Future<Output = Result<ResolutionResult, ResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Fetches the document of did from document_url and checks that its id is did.
§Errors
ResolutionError::InvalidDidwhendidhas no document URL.ResolutionError::NotFoundon a404or410response.ResolutionError::InternalErrorwhen the client fails or returns any other non-success status.ResolutionError::InvalidDidDocumentwhen the body is not a DID document, or is the document of another DID.ResolutionError::RepresentationNotSupportedfor anacceptthat is not JSON.
Auto Trait Implementations§
impl<C> Freeze for DidWeb<C>where
C: Freeze,
impl<C> RefUnwindSafe for DidWeb<C>where
C: RefUnwindSafe,
impl<C> Send for DidWeb<C>where
C: Send,
impl<C> Sync for DidWeb<C>where
C: Sync,
impl<C> Unpin for DidWeb<C>where
C: Unpin,
impl<C> UnsafeUnpin for DidWeb<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for DidWeb<C>where
C: UnwindSafe,
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
Mutably borrows from an owned value. Read more