Skip to main content

DidJwk

Struct DidJwk 

Source
pub struct DidJwk;
Available on crate feature 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

Source

pub const METHOD: &'static str = "jwk"

The method name, jwk.

Source

pub const FRAGMENT: &'static str = "0"

The fragment of the one verification method, 0.

Source

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.

Source

pub const CONTEXT: [&'static str; 2]

The @context of every did:jwk document.

Source

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::TooLong when the encoded key exceeds MAX_DID_LEN bytes, as a JWK carrying an x5c chain or large extension members may; base64url is otherwise valid DID syntax.
  • DidError::UnsupportedNumber when an extension member holds a number with no finite double value, which only serde_json’s arbitrary_precision feature 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.

Source

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:

  • MethodNotSupported when did is not a did:jwk.
  • InvalidDid when the method-specific id is not base64url of a JSON Web Key, the key carries private parameters, or the DID is longer than MAX_DID_LEN. The detail says which, and the base64url or JSON error is the source.

Trait Implementations§

Source§

impl Clone for DidJwk

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DidJwk

Source§

impl Debug for DidJwk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DidJwk

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DidProducer for DidJwk

Source§

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,

The document DidJwk::did of the one key in keys resolves to, which holds the key in its canonical form.

Source§

type Params = ()

Method-specific parameters.
Source§

fn method(&self) -> &'static str

The method name: web for did:web.
Source§

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,

Expands did with DidJwk::document; options may only ask for a JSON representation.

Source§

fn method(&self) -> &'static str

The method name this resolver handles: web for did:web.
Source§

impl Eq for DidJwk

Source§

impl PartialEq for DidJwk

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DidJwk

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more