SdJwtBuilder

Struct SdJwtBuilder 

Source
pub struct SdJwtBuilder<H> { /* private fields */ }
Expand description

Builder structure to create an issuable SD-JWT.

Implementations§

Source§

impl SdJwtBuilder<Sha256Hasher>

Source

pub fn new<T: Serialize>(object: T) -> Result<Self>

Creates a new SdJwtBuilder with sha-256 hash function.

§Error

Returns Error::DataTypeMismatch if object is not a valid JSON object.

Source§

impl<H: Hasher> SdJwtBuilder<H>

Source

pub fn new_with_hasher<T: Serialize>(object: T, hasher: H) -> Result<Self>

Creates a new SdJwtBuilder with custom hash function to create digests.

Source

pub fn new_with_hasher_and_salt_size<T: Serialize>( object: T, hasher: H, salt_size: usize, ) -> Result<Self>

Creates a new SdJwtBuilder with custom hash function to create digests, and custom salt size.

Source

pub fn make_concealable(self, path: &str) -> Result<Self>

Substitutes a value with the digest of its disclosure.

§Notes
  • path indicates the pointer to the value that will be concealed using the syntax of JSON pointer.
§Example
use sd_jwt_payload::SdJwtBuilder;
use sd_jwt_payload::json;

let obj = json!({
 "id": "did:value",
 "claim1": {
    "abc": true
 },
 "claim2": ["val_1", "val_2"]
});
let builder = SdJwtBuilder::new(obj)
 .unwrap()
 .make_concealable("/id").unwrap() //conceals "id": "did:value"
 .make_concealable("/claim1/abc").unwrap() //"abc": true
 .make_concealable("/claim2/0").unwrap(); //conceals "val_1"
§Error
Source

pub fn header(self, header: JsonObject) -> Self

Sets the JWT header.

§Notes
  • if SdJwtBuilder::header is not called, the default header is used: json { "typ": "sd-jwt", "alg": "<algorithm used in SdJwtBuilder::finish>" }
  • alg is always replaced with the value passed to SdJwtBuilder::finish.
Source

pub fn insert_claim<'a, K, V>(self, key: K, value: V) -> Result<Self>
where K: Into<Cow<'a, str>>, V: Serialize,

Adds a new claim to the underlying object.

Source

pub fn add_decoys(self, path: &str, number_of_decoys: usize) -> Result<Self>

Adds a decoy digest to the specified path.

path indicates the pointer to the value that will be concealed using the syntax of JSON pointer.

Use path = “” to add decoys to the top level.

Source

pub fn require_key_binding(self, key_bind: RequiredKeyBinding) -> Self

Require a proof of possession of a given key from the holder.

This operation adds a JWT confirmation (cnf) claim as specified in RFC8300.

Source

pub async fn finish<S>(self, signer: &S, alg: &str) -> Result<SdJwt>
where S: JwsSigner,

Creates an SD-JWT with the provided data.

Trait Implementations§

Source§

impl<H: Debug> Debug for SdJwtBuilder<H>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H> Freeze for SdJwtBuilder<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for SdJwtBuilder<H>
where H: RefUnwindSafe,

§

impl<H> Send for SdJwtBuilder<H>
where H: Send,

§

impl<H> Sync for SdJwtBuilder<H>
where H: Sync,

§

impl<H> Unpin for SdJwtBuilder<H>
where H: Unpin,

§

impl<H> UnwindSafe for SdJwtBuilder<H>
where H: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V