You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+129-79
Original file line number
Diff line number
Diff line change
@@ -36,15 +36,20 @@
36
36
37
37
# SD-JWT Reference implementation
38
38
39
-
Rust implementation of the [Selective Disclosure for JWTs (SD-JWT) **version 07**](https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-07.html)
39
+
Rust implementation of the [Selective Disclosure for JWTs (SD-JWT) **version 12**](https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-12.html)
40
40
41
41
## Overview
42
42
43
43
This library supports
44
-
***Encoding**:
45
-
- creating disclosers and replacing values in objects and arrays with the digest of their disclosure.
46
-
- Adding decoys to objects and arrays.
47
-
***Decoding**
44
+
***Issuing SD-JWTs**:
45
+
- Create a selectively disclosable JWT by choosing which properties can be concealed from a verifier.
46
+
Concealable claims are replaced with their disclosure's digest.
47
+
- Adding decoys to both JSON objects and arrays.
48
+
- Requiring an holder's key-bind.
49
+
***Managing SD-JWTs**
50
+
- Conceal with ease any concealable property.
51
+
- Insert a key-bind.
52
+
***Verifying SD-JWTs**
48
53
- Recursively replace digests in objects and arrays with their corresponding disclosure value.
49
54
50
55
`Sha-256` hash function is shipped by default, encoding/decoding with other hash functions is possible.
@@ -54,7 +59,7 @@ Include the library in your `cargo.toml`.
54
59
55
60
```bash
56
61
[dependencies]
57
-
sd-jwt-payload = { version = "0.2.1" }
62
+
sd-jwt-payload = { version = "0.3.0" }
58
63
```
59
64
60
65
## Examples
@@ -64,153 +69,198 @@ See [sd_jwt.rs](./examples/sd_jwt.rs) for a runnable example.
This creates a stateful encoder with `Sha-256`hashfunctionby default to create disclosure digests.
110
+
This creates a stateful builder with `Sha-256`hashfunctionby default to create disclosure digests.
99
111
100
-
*Note: `SdObjectEncoder` is generic over `Hasher` which allows custom encoding with other hash functions.*
112
+
*Note: `SdJwtBuilder` is generic over `Hasher` which allows custom encoding with other hash functions.*
101
113
102
-
The encoder can encode any of the object's values or array elements, using the `conceal` method. Suppose the value of `street_address` should be selectively disclosed as well as the value of `address` and the first `phone` value.
114
+
The builder can encode any of the object's values or array elements, using the `make_concealable` method. Suppose the value of `street_address` in 'address'should be selectively disclosed as well as the entire value of `address` and the first `phone` value.
103
115
104
116
105
117
```rust
106
-
let disclosure1 = encoder.conceal("/address/street_address"], None)?;
107
-
let disclosure2 = encoder.conceal("/address", None)?;
108
-
let disclosure3 = encoder.conceal("/phone/0", None)?;
*Note: the `conceal` method takes a [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) to determine the element to conceal inside the JSON object.*
126
+
*Note: the `make_concealable` method takes a [JSON Pointer](https://datatracker.ietf.org/doc/html/rfc6901) to determine the element to conceal inside the JSON object.*
117
127
118
128
119
-
The encoder also supports adding decoys. For instance, the amount of phone numbers and the amount of claims need to be hidden.
129
+
The builder also supports adding decoys. For instance, the amount of phone numbers and the amount of claims need to be hidden.
120
130
121
131
```rust
122
-
encoder.add_decoys("/phone", 3).unwrap(); //Adds 3 decoys to the array `phone`.
123
-
encoder.add_decoys("", 6).unwrap(); // Adds 6 decoys to the top level object.
132
+
builder
133
+
.add_decoys("/nationalities", 1)? // Adds 1 decoys to the array `nationalities`.
134
+
.add_decoys("", 2)? // Adds 2 decoys to the top level object.
124
135
```
125
136
126
-
Add the hash function claim.
137
+
Through the builder an issuer can require a specific key-binding that will be verified upon validation:
138
+
127
139
```rust
128
-
encoder.add_sd_alg_property(); // This adds "_sd_alg": "sha-256"
*Note: no JWT claims like `exp` or `iat` are added. If necessary, these need to be added and validated manually.*
166
178
167
-
### Creating SD-JWT
168
-
169
-
Since creating JWTs is outside the scope of this library, see [sd_jwt.rs example](./examples/sd_jwt.rs) where `josekit` is used to create `jwt` with the object above as the claim set.
170
-
171
-
Create SD-JWT
179
+
To create the actual SD-JWT the `finish` method must be called on the builder:
172
180
173
181
```rust
174
-
let sd_jwt: SdJwt = SdJwt::new(jwt, disclosures.clone(), None);
0 commit comments