pub struct DidWeb<C> { /* private fields */ }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
A ResolutionError whose kind is:
InvalidDidwhendidhas no document URL, caused by theWebError.NotFoundon a404or410response.InternalErrorwhen the client fails, caused by itsHttpError, or when it returns any other non-success status, which the detail names.InvalidDidDocumentwhen the body is not a DID document, caused by theserde_json::Error, or is the document of another DID, which the detail names.RepresentationNotSupportedfor anacceptthat is not JSON.