pub struct DidJwk;did-jwk and (crate features did-jwk or did-key or did-web) only.Expand description
The did:jwk method: a DidResolver that expands the DID and a DidProducer that
encodes one public key.
§Examples
use identity_kit::did::{Did, VerificationRelationship};
use identity_kit::jose::Jwk;
use identity_kit::methods::DidJwk;
let jwk: Jwk = serde_json::from_str(
r#"{"kty":"OKP","crv":"Ed25519","x":"11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo"}"#,
)?;
let did = DidJwk::did(&jwk)?;
assert!(did.as_str().starts_with("did:jwk:eyJ"));
let document = DidJwk::document(&did)?;
let key = did.join("#0")?;
let method = document.resolve_verification_method(&key, Some(VerificationRelationship::Authentication))?;
assert_eq!(method.public_key_jwk(), Some(&jwk));Implementations§
Source§impl DidJwk
impl DidJwk
Sourcepub const MAX_DID_LEN: usize
pub const MAX_DID_LEN: usize
The longest did:jwk whose document this method can represent: the verification
method id did#0 must fit DEFAULT_MAX_LEN bytes.
Sourcepub fn did(jwk: &Jwk) -> Result<Did, DidError>
pub fn did(jwk: &Jwk) -> Result<Did, DidError>
The did:jwk of the public part of jwk: base64url of its JSON Canonicalization
Scheme form (RFC 8785), so members are sorted, and extension members too, recursively.
Private parameters never reach the DID.
Any other serialization of the same key is another valid DID, which
document resolves but this function never produces; see the
module documentation.
§Errors
DidError::TooLongwhen the encoded key exceedsMAX_DID_LENbytes, as a JWK carrying anx5cchain or large extension members may; base64url is otherwise valid DID syntax.DidError::UnsupportedNumberwhen an extension member holds a number with no finite double value, which onlyserde_json’sarbitrary_precisionfeature keeps.
§Examples
use identity_kit::jose::Jwk;
use identity_kit::methods::DidJwk;
// The key of the did:jwk specification's P-256 example, members in any order: its DID
// is the specification's, which is in JCS order.
let jwk: Jwk = serde_json::from_str(
r#"{
"kty": "EC",
"crv": "P-256",
"x": "acbIQiuMs3i8_uszEjJ2tpTtRM4EU3yz91PH6CdH2V0",
"y": "_KcyLj9vWMptnmKtm46GqDz8wf74I5LKgrl2GzH3nSE"
}"#,
)?;
assert_eq!(
DidJwk::did(&jwk)?.as_str(),
"did:jwk:eyJjcnYiOiJQLTI1NiIsImt0eSI6IkVDIiwieCI6ImFjYklRaXVNczNpOF91c3pFakoydHBUdFJNNEVVM3l6OTFQSDZDZEgyVjAiLCJ5IjoiX0tjeUxqOXZXTXB0bm1LdG00NkdxRHo4d2Y3NEk1TEtncmwyR3pIM25TRSJ9"
);§Panics
Never: a Jwk always serializes to JSON.
Sourcepub fn document(did: &Did) -> Result<DidDocument, ResolutionError>
pub fn document(did: &Did) -> Result<DidDocument, ResolutionError>
The DID document did expands to (the method’s Read operation).
§Errors
A ResolutionError whose kind is:
MethodNotSupportedwhendidis not adid:jwk.InvalidDidwhen the method-specific id is not base64url of a JSON Web Key, the key carries private parameters, or the DID is longer thanMAX_DID_LEN. The detail says which, and the base64url or JSON error is the source.
Trait Implementations§
impl Copy for DidJwk
Source§impl DidProducer for DidJwk
impl DidProducer for DidJwk
Source§fn capabilities(&self) -> MethodCapabilities
fn capabilities(&self) -> MethodCapabilities
Embedded, one key, never updated, verification method #0.
Source§fn produce<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [Jwk],
__arg2: (),
) -> 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],
__arg2: (),
) -> Pin<Box<dyn Future<Output = Result<DidDocument, ProduceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The document DidJwk::did of the one key in keys resolves to, which holds the key in
its canonical form.
Source§impl DidResolver for DidJwk
impl DidResolver for DidJwk
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,
Expands did with DidJwk::document; options may only ask for a JSON
representation.
impl Eq for DidJwk
impl StructuralPartialEq for DidJwk
Auto Trait Implementations§
impl Freeze for DidJwk
impl RefUnwindSafe for DidJwk
impl Send for DidJwk
impl Sync for DidJwk
impl Unpin for DidJwk
impl UnsafeUnpin for DidJwk
impl UnwindSafe for DidJwk
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.