identity_kit/methods/web/mod.rs
1//! `did:web`: a DID document served over HTTPS by a web origin.
2//!
3//! The [did:web method] maps a DID to the URL of its document: `did:web:example.com` is served
4//! at `https://example.com/.well-known/did.json`, and `did:web:example.com%3A8443:user:alice`
5//! at `https://example.com:8443/user/alice/did.json` (a port is percent-encoded as `%3A`, path
6//! segments are separated by `:`). [`document_url`] implements that mapping and
7//! [`did_from_url`] its inverse. The document is fetched through an [`HttpClient`] the caller
8//! injects; [`ReqwestClient`] (feature `reqwest`) is a hardened default that speaks HTTPS only,
9//! follows no redirect, refuses non-public addresses and caps the response size.
10//!
11//! The method is updated by republishing the document and deactivated by removing it; neither
12//! has an API, so [`DidWeb`] as a [`DidProducer`] builds the document to publish and nothing
13//! more.
14//!
15//! [did:web method]: https://w3c-ccg.github.io/did-method-web/
16
17use core::fmt;
18use core::fmt::Write as _;
19use std::error::Error;
20use std::sync::Arc;
21
22use url::{Host, Url};
23
24use crate::did::{
25 Context, Did, DidDocument, MethodType, ResolutionError, ResolutionErrorKind, ResolutionOptions,
26 ResolutionResult, VerificationMaterial, VerificationMethod, VerificationRelationship,
27};
28use crate::jose::Jwk;
29use crate::resolver::{DidProducer, DidResolver, Hosting, MethodCapabilities, ProduceError};
30
31use super::check_accept;
32
33#[cfg(feature = "reqwest")]
34mod client;
35
36#[cfg(feature = "reqwest")]
37#[cfg_attr(docsrs, doc(cfg(feature = "reqwest")))]
38pub use client::ReqwestClient;
39#[cfg(feature = "local-network")]
40#[cfg_attr(docsrs, doc(cfg(feature = "local-network")))]
41pub use client::{LocalNetwork, ReqwestClientBuilder};
42
43/// The method name, `web`.
44pub const METHOD: &str = "web";
45
46/// The `@context` of a document [`DidWeb`] produces.
47pub const CONTEXT: [&str; 2] = [
48 Context::DID_V1,
49 "https://w3id.org/security/suites/jws-2020/v1",
50];
51
52// ---------------------------------------------------------------------------------------------
53// HTTP
54// ---------------------------------------------------------------------------------------------
55
56/// What [`DidWeb`] needs from HTTP: a `GET` of a URL.
57///
58/// Implement it over the HTTP client of the application so `did:web` resolution shares its
59/// connection pool, proxy and TLS settings. The implementation decides the security policy:
60/// [`ReqwestClient`] is the one this crate ships.
61///
62/// Every URL a client is given comes from untrusted input (a DID, a credential's status list
63/// reference), so an implementation must refuse what [`ReqwestClient`] refuses, or weigh the
64/// consequence: plain `http`, redirects, hosts that resolve to loopback, private, link-local or
65/// other non-public addresses, unbounded bodies and unbounded waits.
66///
67/// A client follows no redirect itself: it returns the 3xx response, with its `Location` in
68/// [`HttpResponse::location`]. A caller that follows redirects, such as the status list check
69/// of the `sd-jwt` feature, fetches each target with a new call, so that every hop goes
70/// through the client's rules.
71#[async_trait::async_trait]
72pub trait HttpClient: Send + Sync {
73 /// Fetches `url`, returning the status and the body of the response.
74 ///
75 /// # Errors
76 ///
77 /// Any failure to get a response: a refused URL, a network or TLS error, a timeout, a body
78 /// over the client's limit. An HTTP error status is a response, not an error.
79 async fn get(&self, url: &Url) -> Result<HttpResponse, HttpError>;
80
81 /// Fetches `url` asking for a body of `media_type`, sent as the `Accept` header.
82 ///
83 /// The default calls [`get`](Self::get) and sends no `Accept` header; [`ReqwestClient`]
84 /// sends it. Implement it when a server negotiates the content type.
85 ///
86 /// # Errors
87 ///
88 /// As [`get`](Self::get).
89 async fn get_accepting(&self, url: &Url, media_type: &str) -> Result<HttpResponse, HttpError> {
90 let _ = media_type;
91 self.get(url).await
92 }
93}
94
95// Implements `HttpClient` for `&T`, `Box<T>` and `Arc<T>` by forwarding every method to `T`.
96// A method added to the trait is added here too: one with a default body would still compile
97// if left out, and calls through these wrappers would then run the default, not `T`'s
98// override. `clippy::missing_trait_methods` turns that omission into an error.
99macro_rules! forward_http_client {
100 ($($t:ty),* $(,)?) => {$(
101 #[async_trait::async_trait]
102 #[deny(clippy::missing_trait_methods)]
103 impl<T: HttpClient + ?Sized> HttpClient for $t {
104 async fn get(&self, url: &Url) -> Result<HttpResponse, HttpError> {
105 (**self).get(url).await
106 }
107
108 async fn get_accepting(
109 &self,
110 url: &Url,
111 media_type: &str,
112 ) -> Result<HttpResponse, HttpError> {
113 (**self).get_accepting(url, media_type).await
114 }
115 }
116 )*};
117}
118
119forward_http_client!(&T, Box<T>, Arc<T>);
120
121/// An HTTP response: the status code, the body and, for a redirect, its target.
122#[derive(Debug, Clone, PartialEq, Eq)]
123#[non_exhaustive]
124pub struct HttpResponse {
125 /// The status code, `200` for a served document.
126 pub status: u16,
127 /// The body, which a `did:web` resolver parses as JSON.
128 pub body: Vec<u8>,
129 /// The `Location` header of a 3xx response, as sent: possibly relative to the requested
130 /// URL. `None` for any other response.
131 pub location: Option<String>,
132}
133
134impl HttpResponse {
135 /// A response with `status` and `body`, and no `location`.
136 pub fn new(status: u16, body: impl Into<Vec<u8>>) -> Self {
137 Self {
138 status,
139 body: body.into(),
140 location: None,
141 }
142 }
143
144 /// This response with the `Location` header `location`.
145 #[must_use]
146 pub fn with_location(mut self, location: impl Into<String>) -> Self {
147 self.location = Some(location.into());
148 self
149 }
150}
151
152/// Why an [`HttpClient`] could not get a response.
153#[derive(Debug)]
154pub struct HttpError(Box<dyn Error + Send + Sync + 'static>);
155
156impl HttpError {
157 /// Wraps `error`.
158 pub fn new<E: Error + Send + Sync + 'static>(error: E) -> Self {
159 Self(Box::new(error))
160 }
161
162 /// An error carrying `message`.
163 pub fn msg<M: fmt::Display>(message: M) -> Self {
164 Self(message.to_string().into())
165 }
166
167 /// The wrapped error.
168 pub fn inner(&self) -> &(dyn Error + Send + Sync + 'static) {
169 self.0.as_ref()
170 }
171}
172
173impl fmt::Display for HttpError {
174 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175 fmt::Display::fmt(&self.0, f)
176 }
177}
178
179impl Error for HttpError {
180 fn source(&self) -> Option<&(dyn Error + 'static)> {
181 self.0.source()
182 }
183}
184
185impl From<Box<dyn Error + Send + Sync + 'static>> for HttpError {
186 fn from(error: Box<dyn Error + Send + Sync + 'static>) -> Self {
187 Self(error)
188 }
189}
190
191// ---------------------------------------------------------------------------------------------
192// DID <-> URL
193// ---------------------------------------------------------------------------------------------
194
195/// Why a URL has no `did:web`, or a `did:web` no document URL.
196#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
197#[non_exhaustive]
198pub enum WebError {
199 /// The URL is not an HTTPS location a `did:web` can name.
200 #[error("`{url}` cannot be a did:web: {reason}")]
201 InvalidUrl {
202 /// The URL.
203 url: Url,
204 /// What is wrong with it.
205 reason: &'static str,
206 },
207 /// The DID is not a well-formed `did:web`.
208 #[error("`{did}` is not a valid did:web: {reason}")]
209 InvalidDid {
210 /// The DID.
211 did: Did,
212 /// What is wrong with it.
213 reason: &'static str,
214 },
215}
216
217/// The directory of the document of a DID without path segments.
218const WELL_KNOWN: &str = ".well-known";
219
220/// The file name of the document.
221const DOCUMENT_FILE: &str = "did.json";
222
223/// The `did:web` whose document lives under `url`: `https://example.com` gives
224/// `did:web:example.com`, `https://example.com:8443/user/alice` gives
225/// `did:web:example.com%3A8443:user:alice`.
226///
227/// The URL must be `https`, name a domain (not an IP address) and carry no credentials, query
228/// or fragment. A trailing slash is ignored, as is the document file name that
229/// [`document_url`] appends (`/.well-known/did.json` or `/did.json`), so a document URL maps
230/// back to its DID; other path segments become `:`-separated id segments, percent-encoded where
231/// the DID syntax requires it.
232///
233/// # Errors
234///
235/// [`WebError::InvalidUrl`] when the URL breaks one of those rules.
236///
237/// # Examples
238///
239/// ```
240/// use identity_kit::methods::web::did_from_url;
241/// use url::Url;
242///
243/// let did = did_from_url(&Url::parse("https://example.com:3000/user/alice/")?)?;
244/// assert_eq!(did.as_str(), "did:web:example.com%3A3000:user:alice");
245/// let did = did_from_url(&Url::parse("https://example.com/.well-known/did.json")?)?;
246/// assert_eq!(did.as_str(), "did:web:example.com");
247/// assert!(did_from_url(&Url::parse("https://192.0.2.1/")?).is_err());
248/// # Ok::<(), Box<dyn std::error::Error>>(())
249/// ```
250pub fn did_from_url(url: &Url) -> Result<Did, WebError> {
251 let invalid = |reason| WebError::InvalidUrl {
252 url: url.clone(),
253 reason,
254 };
255 if url.scheme() != "https" {
256 return Err(invalid("the scheme must be `https`"));
257 }
258 let domain = match url.host() {
259 Some(Host::Domain(domain)) => domain,
260 Some(_) => return Err(invalid("the host must be a domain name, not an IP address")),
261 None => return Err(invalid("the URL has no host")),
262 };
263 if !domain
264 .bytes()
265 .all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'.')
266 {
267 return Err(invalid("the host has characters a DID cannot carry"));
268 }
269 if !url.username().is_empty() || url.password().is_some() {
270 return Err(invalid("the URL must not carry credentials"));
271 }
272 if url.query().is_some() || url.fragment().is_some() {
273 return Err(invalid("the URL must not have a query or a fragment"));
274 }
275 let mut id = domain.to_owned();
276 if let Some(port) = url.port() {
277 let _ = write!(id, "%3A{port}");
278 }
279 let mut segments: Vec<&str> = url
280 .path_segments()
281 .map(Iterator::collect)
282 .unwrap_or_default();
283 if segments.last() == Some(&"") {
284 segments.pop();
285 }
286 if segments.last() == Some(&DOCUMENT_FILE) {
287 segments.pop();
288 if segments.as_slice() == [WELL_KNOWN] {
289 segments.clear();
290 }
291 }
292 for segment in segments {
293 if segment.is_empty() {
294 return Err(invalid("the path has an empty segment"));
295 }
296 id.push(':');
297 id.push_str(&encode_segment(segment));
298 }
299 Did::parse(&format!("did:web:{id}")).map_err(|_| invalid("the URL does not map to a DID"))
300}
301
302/// The `did:web` of the origin of `url`: as [`did_from_url`], but the URL must have no path.
303///
304/// # Errors
305///
306/// [`WebError::InvalidUrl`] when the URL has a path, or breaks a rule of [`did_from_url`].
307pub fn did_from_origin(url: &Url) -> Result<Did, WebError> {
308 if !matches!(url.path(), "" | "/") {
309 return Err(WebError::InvalidUrl {
310 url: url.clone(),
311 reason: "an origin has no path",
312 });
313 }
314 did_from_url(url)
315}
316
317/// `segment` with every byte outside the DID `idchar` set percent-encoded.
318fn encode_segment(segment: &str) -> String {
319 let bytes = segment.as_bytes();
320 let mut out = String::with_capacity(segment.len());
321 let mut i = 0;
322 while i < bytes.len() {
323 let b = bytes[i];
324 if b.is_ascii_alphanumeric() || matches!(b, b'.' | b'-' | b'_') {
325 out.push(char::from(b));
326 } else if b == b'%'
327 && bytes.get(i + 1).is_some_and(u8::is_ascii_hexdigit)
328 && bytes.get(i + 2).is_some_and(u8::is_ascii_hexdigit)
329 {
330 out.push_str(&segment[i..i + 3]);
331 i += 3;
332 continue;
333 } else {
334 let _ = write!(out, "%{b:02X}");
335 }
336 i += 1;
337 }
338 out
339}
340
341/// The URL of the document of `did` (the Read operation's URL construction):
342/// `https://host[:port]/.well-known/did.json` for a bare domain, else
343/// `https://host[:port]/<segments>/did.json`.
344///
345/// # Errors
346///
347/// [`WebError::InvalidDid`] when `did` is not a `did:web`, names an IP address, has a
348/// malformed port, or has an empty, `.` or `..` path segment, percent-encoded or not.
349///
350/// # Examples
351///
352/// ```
353/// use identity_kit::did::Did;
354/// use identity_kit::methods::web::document_url;
355///
356/// let url = document_url(&Did::parse("did:web:example.com")?)?;
357/// assert_eq!(url.as_str(), "https://example.com/.well-known/did.json");
358///
359/// let url = document_url(&Did::parse("did:web:example.com%3A3000:user:alice")?)?;
360/// assert_eq!(url.as_str(), "https://example.com:3000/user/alice/did.json");
361/// # Ok::<(), Box<dyn std::error::Error>>(())
362/// ```
363pub fn document_url(did: &Did) -> Result<Url, WebError> {
364 let invalid = |reason| WebError::InvalidDid {
365 did: did.clone(),
366 reason,
367 };
368 if did.method() != METHOD {
369 return Err(invalid("the method is not `web`"));
370 }
371 let mut segments = did.method_specific_id().split(':');
372 let authority = percent_decode(segments.next().unwrap_or_default());
373 let (host, port) = match authority.rsplit_once(':') {
374 Some((host, port)) => (host, Some(port)),
375 None => (authority.as_str(), None),
376 };
377 if host.is_empty()
378 || !host
379 .bytes()
380 .all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'.')
381 {
382 return Err(invalid("the host is not a domain name"));
383 }
384 if let Some(port) = port
385 && (port.is_empty() || port.len() > 5 || !port.bytes().all(|b| b.is_ascii_digit()))
386 {
387 return Err(invalid("the port is not a number"));
388 }
389 let mut path = String::new();
390 let mut has_segments = false;
391 for segment in segments {
392 if is_dot_segment(segment) {
393 return Err(invalid("a path segment is empty, `.` or `..`"));
394 }
395 has_segments = true;
396 path.push('/');
397 path.push_str(segment);
398 }
399 if !has_segments {
400 path.push('/');
401 path.push_str(WELL_KNOWN);
402 }
403 let port = port.map(|port| format!(":{port}")).unwrap_or_default();
404 let url = Url::parse(&format!("https://{host}{port}{path}/{DOCUMENT_FILE}"))
405 .map_err(|_| invalid("the DID does not map to a URL"))?;
406 match url.host() {
407 Some(Host::Domain(_)) => Ok(url),
408 _ => Err(invalid("the host is an IP address")),
409 }
410}
411
412/// Whether `segment` is empty, or is `.` or `..` as the URL parser reads it: a segment of `.` and
413/// `%2E` in any combination and case is a dot segment, which the parser collapses into the path
414/// before it, so `did:web:example.com:a:%2E%2E:b` would name `https://example.com/b/did.json`.
415fn is_dot_segment(segment: &str) -> bool {
416 let mut dots = 0;
417 let mut i = 0;
418 let bytes = segment.as_bytes();
419 while i < bytes.len() {
420 if bytes[i] == b'.' {
421 i += 1;
422 } else if bytes[i..]
423 .get(..3)
424 .is_some_and(|b| b.eq_ignore_ascii_case(b"%2e"))
425 {
426 i += 3;
427 } else {
428 return false;
429 }
430 dots += 1;
431 }
432 dots <= 2
433}
434
435/// Decodes the percent-encoded octets of a DID segment, which the DID syntax has checked to be
436/// complete; non-UTF-8 octets become replacement characters and fail the host check.
437#[expect(clippy::cast_possible_truncation, reason = "a hex digit is below 16")]
438fn percent_decode(s: &str) -> String {
439 let bytes = s.as_bytes();
440 let mut out = Vec::with_capacity(bytes.len());
441 let mut i = 0;
442 while i < bytes.len() {
443 match (bytes[i], bytes.get(i + 1), bytes.get(i + 2)) {
444 (b'%', Some(hi), Some(lo)) if hi.is_ascii_hexdigit() && lo.is_ascii_hexdigit() => {
445 let hex = |b: u8| (b as char).to_digit(16).unwrap_or(0) as u8;
446 out.push(hex(*hi) << 4 | hex(*lo));
447 i += 3;
448 }
449 (b, _, _) => {
450 out.push(b);
451 i += 1;
452 }
453 }
454 }
455 String::from_utf8_lossy(&out).into_owned()
456}
457
458// ---------------------------------------------------------------------------------------------
459// The method
460// ---------------------------------------------------------------------------------------------
461
462/// The `did:web` method: a [`DidResolver`] fetching documents through an [`HttpClient`], and a
463/// [`DidProducer`] building the document to publish.
464///
465/// # Examples
466///
467/// ```
468/// use identity_kit::did::Did;
469/// use identity_kit::methods::web::{DidWeb, HttpClient, HttpError, HttpResponse};
470/// use identity_kit::resolver::Resolver;
471/// use url::Url;
472///
473/// /// Serves one document from memory.
474/// struct Static(String);
475///
476/// #[async_trait::async_trait]
477/// impl HttpClient for Static {
478/// async fn get(&self, url: &Url) -> Result<HttpResponse, HttpError> {
479/// Ok(if url.as_str() == "https://example.com/.well-known/did.json" {
480/// HttpResponse::new(200, self.0.as_bytes())
481/// } else {
482/// HttpResponse::new(404, Vec::new())
483/// })
484/// }
485/// }
486///
487/// # tokio::runtime::Builder::new_current_thread().build()?.block_on(async {
488/// let document = r#"{"id": "did:web:example.com"}"#.to_owned();
489/// let resolver = Resolver::builder().with(DidWeb::new(Static(document))).build();
490/// let did = Did::parse("did:web:example.com")?;
491/// assert_eq!(resolver.resolve_document(&did).await?.id, did);
492/// # Ok::<(), Box<dyn std::error::Error>>(())
493/// # })?;
494/// # Ok::<(), Box<dyn std::error::Error>>(())
495/// ```
496#[derive(Debug, Clone)]
497pub struct DidWeb<C> {
498 client: C,
499}
500
501impl<C: HttpClient> DidWeb<C> {
502 /// The method fetching documents with `client`.
503 pub const fn new(client: C) -> Self {
504 Self { client }
505 }
506
507 /// The HTTP client.
508 pub const fn client(&self) -> &C {
509 &self.client
510 }
511}
512
513#[async_trait::async_trait]
514impl<C: HttpClient> DidResolver for DidWeb<C> {
515 fn method(&self) -> &'static str {
516 METHOD
517 }
518
519 /// Fetches the document of `did` from [`document_url`] and checks that its `id` is `did`.
520 ///
521 /// # Errors
522 ///
523 /// A [`ResolutionError`] whose kind is:
524 ///
525 /// - [`InvalidDid`](ResolutionErrorKind::InvalidDid) when `did` has no document URL, caused
526 /// by the [`WebError`].
527 /// - [`NotFound`](ResolutionErrorKind::NotFound) on a `404` or `410` response.
528 /// - [`InternalError`](ResolutionErrorKind::InternalError) when the client fails, caused by
529 /// its [`HttpError`], or when it returns any other non-success status, which the detail
530 /// names.
531 /// - [`InvalidDidDocument`](ResolutionErrorKind::InvalidDidDocument) when the body is not a
532 /// DID document, caused by the [`serde_json::Error`], or is the document of another DID,
533 /// which the detail names.
534 /// - [`RepresentationNotSupported`](ResolutionErrorKind::RepresentationNotSupported) for an
535 /// `accept` that is not JSON.
536 async fn resolve(
537 &self,
538 did: &Did,
539 options: &ResolutionOptions,
540 ) -> Result<ResolutionResult, ResolutionError> {
541 check_accept(options)?;
542 let url = document_url(did).map_err(|error| {
543 ResolutionError::new(ResolutionErrorKind::InvalidDid).with_source(error)
544 })?;
545 let response = self.client.get(&url).await.map_err(|error| {
546 ResolutionError::new(ResolutionErrorKind::InternalError)
547 .with_detail(format!("fetching `{url}` failed"))
548 .with_source(error)
549 })?;
550 let kind = match response.status {
551 200..=299 => None,
552 404 | 410 => Some(ResolutionErrorKind::NotFound),
553 _ => Some(ResolutionErrorKind::InternalError),
554 };
555 if let Some(kind) = kind {
556 return Err(ResolutionError::new(kind).with_detail(format!(
557 "`{url}` responded with HTTP status {}",
558 response.status
559 )));
560 }
561 let document: DidDocument = serde_json::from_slice(&response.body).map_err(|error| {
562 ResolutionError::new(ResolutionErrorKind::InvalidDidDocument)
563 .with_detail(format!("the body of `{url}` is not a DID document"))
564 .with_source(error)
565 })?;
566 if document.id != *did {
567 return Err(
568 ResolutionError::new(ResolutionErrorKind::InvalidDidDocument).with_detail(format!(
569 "`{url}` holds the document of `{}`, not `{did}`",
570 document.id
571 )),
572 );
573 }
574 Ok(ResolutionResult::new(document))
575 }
576}
577
578#[async_trait::async_trait]
579impl<C: HttpClient> DidProducer for DidWeb<C> {
580 /// The HTTPS URL the document will be served under, as [`did_from_url`] reads it.
581 type Params = Url;
582
583 fn method(&self) -> &'static str {
584 METHOD
585 }
586
587 /// Hosted on the web, any number of keys, updated by republishing; fragments come from the
588 /// keys.
589 fn capabilities(&self) -> MethodCapabilities {
590 MethodCapabilities::new(Hosting::Web).with_updatable(true)
591 }
592
593 /// The document to publish at `url` for `keys`.
594 ///
595 /// Each key becomes a `JsonWebKey2020` verification method whose fragment is the key's
596 /// `kid`, or `key-<index>` when it has none. A key with `use` `enc`, or an X25519 key, is
597 /// referenced from `keyAgreement`; every other key from `authentication`,
598 /// `assertionMethod`, `capabilityInvocation` and `capabilityDelegation`. The document's
599 /// `@context` is [`CONTEXT`].
600 ///
601 /// # Errors
602 ///
603 /// - [`ProduceError::NoKeys`] without a key.
604 /// - [`ProduceError::InvalidParams`] when `url` has no `did:web` (see [`did_from_url`]).
605 /// - [`ProduceError::UnsupportedKey`] for a `kid` that is not a valid fragment.
606 /// - [`ProduceError::Document`] for two keys with the same `kid`.
607 async fn produce(&self, keys: &[Jwk], url: Url) -> Result<DidDocument, ProduceError> {
608 if keys.is_empty() {
609 return Err(ProduceError::NoKeys);
610 }
611 let did = did_from_url(&url).map_err(|error| ProduceError::InvalidParams {
612 reason: "the URL is not a `did:web` location".to_owned(),
613 source: Some(Box::new(error)),
614 })?;
615 let mut builder = DidDocument::builder(did.clone()).context(Context::uris(CONTEXT));
616 for (index, key) in keys.iter().enumerate() {
617 let id = match key.kid() {
618 Some(kid) => {
619 did.join(&format!("#{kid}"))
620 .map_err(|error| ProduceError::UnsupportedKey {
621 index,
622 reason: format!("`kid` {kid:?} is not a valid DID URL fragment"),
623 source: Some(Box::new(error)),
624 })?
625 }
626 None => did.to_url().with_fragment(&format!("key-{index}")),
627 };
628 let relationships: &[VerificationRelationship] =
629 if key.key_use() == Some("enc") || key.crv() == Some("X25519") {
630 &[VerificationRelationship::KeyAgreement]
631 } else {
632 &[
633 VerificationRelationship::Authentication,
634 VerificationRelationship::AssertionMethod,
635 VerificationRelationship::CapabilityInvocation,
636 VerificationRelationship::CapabilityDelegation,
637 ]
638 };
639 let method = VerificationMethod::new(
640 id,
641 MethodType::JSON_WEB_KEY_2020,
642 did.clone(),
643 VerificationMaterial::jwk(key),
644 );
645 builder = builder.verification_method(method, relationships.iter().copied());
646 }
647 Ok(builder.build()?)
648 }
649}