pub struct SdJwtBuilder<H> { /* private fields */ }
Expand description
Builder structure to create an issuable SD-JWT.
Implementations§
Source§impl SdJwtBuilder<Sha256Hasher>
impl SdJwtBuilder<Sha256Hasher>
Sourcepub fn new<T: Serialize>(object: T) -> Result<Self>
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>
impl<H: Hasher> SdJwtBuilder<H>
Sourcepub fn new_with_hasher<T: Serialize>(object: T, hasher: H) -> Result<Self>
pub fn new_with_hasher<T: Serialize>(object: T, hasher: H) -> Result<Self>
Creates a new SdJwtBuilder
with custom hash function to create digests.
Sourcepub fn new_with_hasher_and_salt_size<T: Serialize>(
object: T,
hasher: H,
salt_size: usize,
) -> Result<Self>
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.
Sourcepub fn make_concealable(self, path: &str) -> Result<Self>
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
Error::InvalidPath
if pointer is invalid.Error::DataTypeMismatch
if existing SD format is invalid.
Sourcepub fn header(self, header: JsonObject) -> Self
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 toSdJwtBuilder::finish
.
Sourcepub fn insert_claim<'a, K, V>(self, key: K, value: V) -> Result<Self>
pub fn insert_claim<'a, K, V>(self, key: K, value: V) -> Result<Self>
Adds a new claim to the underlying object.
Sourcepub fn add_decoys(self, path: &str, number_of_decoys: usize) -> Result<Self>
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.
Sourcepub fn require_key_binding(self, key_bind: RequiredKeyBinding) -> Self
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.
Trait Implementations§
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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