Skip to content

Commit ec02259

Browse files
authored
Release v0.0.4 (#14)
* API Documentation and small cleanup. * Bump crate version to 0.0.4. Signed-off-by: Sergey Minaev <[email protected]>
1 parent 0b2562d commit ec02259

File tree

7 files changed

+104
-11
lines changed

7 files changed

+104
-11
lines changed

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ We love your input! We want to make contributing to this project as easy and tra
88
- Proposing new features
99
- Becoming a maintainer
1010

11-
## We Develop with Github
11+
## We Develop with GitHub
1212

13-
We use github to host code, to track issues and feature requests, as well as accept pull requests.
13+
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.
1414

15-
## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
15+
## We Use [GitHub Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
1616

17-
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
17+
Pull requests are the best way to propose changes to the codebase (we use [GitHub Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
1818

1919
1. Fork the repo and create your branch from `main`.
2020
2. If you've added code that should be tested, add tests.
@@ -27,7 +27,7 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu
2727

2828
In short, when you submit code changes, your submissions are understood to be under the same [Apache 2.0 License](http://www.apache.org/licenses/) that covers the project. Feel free to contact the maintainers if that's a concern.
2929

30-
## Report bugs using Github's [issues](https://github.com/openwallet-foundation-labs/sd-jwt-rust/issues)
30+
## Report bugs using GitHub's [issues](https://github.com/openwallet-foundation-labs/sd-jwt-rust/issues)
3131

3232
We use GitHub issues to track public bugs. Report a bug by opening a new issue it's that easy!
3333

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sd-jwt-rs"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
edition = "2021"
55
license = "Apache-2.0 OR MIT"
66
description = "Rust reference implementation of the IETF SD-JWT specification (v6)."
@@ -24,3 +24,4 @@ strum = { version = "0.25", default-features = false, features = ["std", "derive
2424

2525
[dev-dependencies]
2626
rstest = "0.18.2"
27+
regex = "1.10"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cargo test
4040
```
4141

4242
### Interoperability testing tool
43-
Coming soon (planned for v0.0.4)
43+
Coming soon (planned for v0.0.5)
4444

4545
## External Dependencies
4646

src/disclosure.rs

+25
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,28 @@ impl SDJWTDisclosure {
2929
}
3030
}
3131
}
32+
33+
#[cfg(test)]
34+
mod tests {
35+
use super::*;
36+
use crate::utils::base64url_decode;
37+
use regex::Regex;
38+
39+
40+
#[test]
41+
fn test_sdjwt_disclosure_when_key_is_none() {
42+
let sdjwt_disclosure = SDJWTDisclosure::new(None, "test");
43+
let decoded_disclosure: String = String::from_utf8(base64url_decode(&sdjwt_disclosure.raw_b64).unwrap()).unwrap();
44+
45+
let re = Regex::new(r#"\[".*", test]"#).unwrap();
46+
assert!(re.is_match(&decoded_disclosure));
47+
}
48+
49+
#[test]
50+
fn test_sdjwt_disclosure_when_key_is_present() {
51+
let sdjwt_disclosure = SDJWTDisclosure::new(Some("key".to_string()), "test");
52+
let decoded = String::from_utf8(base64url_decode(&sdjwt_disclosure.raw_b64).unwrap()).unwrap();
53+
54+
let re = Regex::new(r#"\[".*", "key", test]"#).unwrap();
55+
assert!(re.is_match(&decoded)); }
56+
}

src/holder.rs

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ pub struct SDJWTHolder {
2525
}
2626

2727
impl SDJWTHolder {
28+
/// Build an instance of holder to create one or more presentations based on SD JWT provided by issuer.
29+
///
30+
/// # Arguments
31+
/// * `sd_jwt_with_disclosures` - SD JWT with disclosures in the format specified by `serialization_format`
32+
/// * `serialization_format` - Serialization format of the SD JWT. Supported values are `compact` and `json`
33+
///
34+
/// # Returns
35+
/// * `SDJWTHolder` - Instance of SDJWTHolder
36+
///
37+
/// # Errors
38+
/// * `InvalidInput` - If the serialization format is not supported
39+
/// * `InvalidState` - If the SD JWT data is not valid
40+
/// * `DeserializationError` - If the SD JWT serialization is not valid
2841
pub fn new(sd_jwt_with_disclosures: String, serialization_format: String) -> Result<Self> {
2942
let serialization_format = serialization_format.to_lowercase();
3043
if serialization_format != "compact" && serialization_format != "json" {
@@ -70,6 +83,17 @@ impl SDJWTHolder {
7083
Ok(holder)
7184
}
7285

86+
/// Create a presentation based on the SD JWT provided by issuer.
87+
///
88+
/// # Arguments
89+
/// * `claims_to_disclose` - Claims to disclose in the presentation
90+
/// * `nonce` - Nonce to be used in the key-binding JWT
91+
/// * `aud` - Audience to be used in the key-binding JWT
92+
/// * `holder_key` - Key to sign the key-binding JWT
93+
/// * `sign_alg` - Signing algorithm to be used in the key-binding JWT
94+
///
95+
/// # Returns
96+
/// * `String` - Presentation in the format specified by `serialization_format` in the constructor. It can be either compact or json.
7397
pub fn create_presentation(
7498
&mut self,
7599
claims_to_disclose: Map<String, Value>,

src/issuer.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,20 @@ pub enum SDJWTClaimsStrategy<'a> {
4747
Partial(Vec<&'a str>),
4848
}
4949

50-
// {
51-
// let strategy = Partial(vec!["$.address", "$.address.street_address"])
52-
// }
50+
/// SDJWTClaimsStrategy is used to determine which claims can be selectively disclosed later by the holder.
51+
///
52+
/// The following strategies are supported:
53+
/// * No: No claims can be selectively disclosed.
54+
/// * Flat: Top-level claims can be selectively disclosed, nested objects are fully disclosed.
55+
/// * Full: All claims can be selectively disclosed.
56+
/// * Partial: Claims can be selectively disclosed based on the provided JSONPaths.
57+
///
58+
/// # Examples
59+
/// ```
60+
/// use sd_jwt_rs::issuer::SDJWTClaimsStrategy;
61+
///
62+
/// let strategy = SDJWTClaimsStrategy::Partial(vec!["$.address", "$.address.street_address"]);
63+
/// ```
5364
impl<'a> SDJWTClaimsStrategy<'a> {
5465
fn finalize_input(&mut self) -> Result<()> {
5566
match self {
@@ -108,7 +119,17 @@ impl SDJWTIssuer {
108119
const DECOY_MIN_ELEMENTS: u32 = 2;
109120
const DECOY_MAX_ELEMENTS: u32 = 5;
110121

111-
pub fn new(issuer_key: EncodingKey,sign_alg: Option<String>) -> Self {
122+
/// Creates a new SDJWTIssuer instance.
123+
///
124+
/// The instance can be used mutliple times to issue SD-JWTs.
125+
///
126+
/// # Arguments
127+
/// * `issuer_key` - The key used to sign the SD-JWT.
128+
/// * `sign_alg` - The signing algorithm used to sign the SD-JWT. If not provided, the default algorithm is used.
129+
///
130+
/// # Returns
131+
/// A new SDJWTIssuer instance.
132+
pub fn new(issuer_key: EncodingKey, sign_alg: Option<String>) -> Self {
112133
SDJWTIssuer {
113134
sign_alg: sign_alg.unwrap_or(DEFAULT_SIGNING_ALG.to_owned()),
114135
add_decoy_claims: false,
@@ -131,6 +152,17 @@ impl SDJWTIssuer {
131152
self.serialized_sd_jwt = Default::default();
132153
}
133154

155+
/// Issues a SD-JWT.
156+
///
157+
/// # Arguments
158+
/// * `user_claims` - The claims to be included in the SD-JWT.
159+
/// * `sd_strategy` - The strategy to be used to determine which claims to be selectively disclosed. See SDJWTClaimsStrategy for more details.
160+
/// * `holder_key` - The key used to sign the SD-JWT. If not provided, no key binding is added to the SD-JWT.
161+
/// * `add_decoy_claims` - If true, decoy claims are added to the SD-JWT.
162+
/// * `serialization_format` - The serialization format to be used for the SD-JWT. Only "compact" and "json" formats are supported.
163+
///
164+
/// # Returns
165+
/// The issued SD-JWT as a string in the requested serialization format.
134166
pub fn issue_sd_jwt(
135167
&mut self,
136168
user_claims: Value,

src/verifier.rs

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ pub struct SDJWTVerifier {
2929
}
3030

3131
impl SDJWTVerifier {
32+
/// Create a new SDJWTVerifier instance.
33+
///
34+
/// # Arguments
35+
/// * `sd_jwt_presentation` - The SD-JWT presentation to verify.
36+
/// * `cb_get_issuer_key` - A callback function that takes the issuer and the header of the SD-JWT and returns the public key of the issuer.
37+
/// * `expected_aud` - The expected audience of the SD-JWT.
38+
/// * `expected_nonce` - The expected nonce of the SD-JWT.
39+
/// * `serialization_format` - The serialization format of the SD-JWT.
40+
///
41+
/// # Returns
42+
/// * `SDJWTVerifier` - The SDJWTVerifier instance. The verified claims can be accessed via the `verified_claims` property.
3243
pub fn new(
3344
sd_jwt_presentation: String,
3445
cb_get_issuer_key: Box<KeyResolver>,

0 commit comments

Comments
 (0)