-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SD-JWT VC implementation #1413
Open
UMR1352
wants to merge
31
commits into
main
Choose a base branch
from
feat/sd-jwt-vc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
SD-JWT VC implementation #1413
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b7853fb
Resolver trait and CompoundResolver macro
UMR1352 0114b35
invert Resolver type parameters
UMR1352 88a538e
associated type Target instead of type parameter T
UMR1352 bfd5d59
fix type issue in #[resolver(..)] annotation, support for multiple re…
UMR1352 5671118
resolver integration
UMR1352 d7c2cd9
Merge branch 'main' into identity2/resolver
UMR1352 7c815c5
feature gate resolver-v2
UMR1352 b28fa9a
structures & basic operations
UMR1352 2f7fadf
SdJwtVc behaves as a superset of SdJwt
UMR1352 0d3127f
issuer's metadata fetching & validation
UMR1352 55319c5
type metadata & credential verification
UMR1352 704b395
change resolver's constraints
UMR1352 130af00
integrity metadata
UMR1352 d278060
display metadata
UMR1352 0a1ed27
claim metadata
UMR1352 8d00263
fetch issuer's JWK (to ease verification)
UMR1352 2111e3b
validate claim disclosability
UMR1352 06e31f2
add missing license header
UMR1352 e5e8537
resolver change, validation
UMR1352 9bf907f
SdJwtVcBuilder & tests
UMR1352 67a0abc
validation test
UMR1352 a510185
KB-JWT validation
UMR1352 654b188
review comment
UMR1352 72333bb
undo resolver-v2
UMR1352 468809e
Merge branch 'main' into feat/sd-jwt-vc
UMR1352 3f992c4
fix CI errors
UMR1352 66f7b79
make clippy happy
UMR1352 03f1483
add missing license headers
UMR1352 51e1b28
add 'SdJwtVcBuilder::from_credential' to easily convert into a SD-JWT VC
UMR1352 035b50f
cargo clippy
UMR1352 f2c0704
fix wasm compilation errors, clippy
UMR1352 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Copyright 2020-2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::convert::Infallible; | ||
use std::fmt::Display; | ||
use std::str::FromStr; | ||
|
||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use super::Url; | ||
|
||
/// A type that represents either an arbitrary string or a URL. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum StringOrUrl { | ||
/// A well-formed URL. | ||
Url(Url), | ||
/// An arbitrary UTF-8 string. | ||
String(String), | ||
} | ||
|
||
impl StringOrUrl { | ||
/// Parses a [`StringOrUrl`] from a string. | ||
pub fn parse(s: &str) -> Result<Self, Infallible> { | ||
s.parse() | ||
} | ||
/// Returns a [`Url`] reference if `self` is [`StringOrUrl::Url`]. | ||
pub fn as_url(&self) -> Option<&Url> { | ||
match self { | ||
Self::Url(url) => Some(url), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Returns a [`str`] reference if `self` is [`StringOrUrl::String`]. | ||
pub fn as_string(&self) -> Option<&str> { | ||
match self { | ||
Self::String(s) => Some(s), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Returns whether `self` is a [`StringOrUrl::Url`]. | ||
pub fn is_url(&self) -> bool { | ||
matches!(self, Self::Url(_)) | ||
} | ||
|
||
/// Returns whether `self` is a [`StringOrUrl::String`]. | ||
pub fn is_string(&self) -> bool { | ||
matches!(self, Self::String(_)) | ||
} | ||
} | ||
|
||
impl Default for StringOrUrl { | ||
fn default() -> Self { | ||
StringOrUrl::String(String::default()) | ||
} | ||
} | ||
|
||
impl Display for StringOrUrl { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Url(url) => write!(f, "{url}"), | ||
Self::String(s) => write!(f, "{s}"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for StringOrUrl { | ||
// Cannot fail. | ||
type Err = Infallible; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok( | ||
s.parse::<Url>() | ||
.map(Self::Url) | ||
.unwrap_or_else(|_| Self::String(s.to_string())), | ||
) | ||
} | ||
} | ||
|
||
impl AsRef<str> for StringOrUrl { | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
Self::String(s) => s, | ||
Self::Url(url) => url.as_str(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Url> for StringOrUrl { | ||
fn from(value: Url) -> Self { | ||
Self::Url(value) | ||
} | ||
} | ||
|
||
impl From<String> for StringOrUrl { | ||
fn from(value: String) -> Self { | ||
Self::String(value) | ||
} | ||
} | ||
|
||
impl From<StringOrUrl> for String { | ||
fn from(value: StringOrUrl) -> Self { | ||
match value { | ||
StringOrUrl::String(s) => s, | ||
StringOrUrl::Url(url) => url.into_string(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct TestData { | ||
string_or_url: StringOrUrl, | ||
} | ||
|
||
impl Default for TestData { | ||
fn default() -> Self { | ||
Self { | ||
string_or_url: StringOrUrl::Url(TEST_URL.parse().unwrap()), | ||
} | ||
} | ||
} | ||
|
||
const TEST_URL: &str = "file:///tmp/file.txt"; | ||
|
||
#[test] | ||
fn deserialization_works() { | ||
let test_data: TestData = serde_json::from_value(serde_json::json!({ "string_or_url": TEST_URL })).unwrap(); | ||
let target_url: Url = TEST_URL.parse().unwrap(); | ||
assert_eq!(test_data.string_or_url.as_url(), Some(&target_url)); | ||
} | ||
|
||
#[test] | ||
fn serialization_works() { | ||
assert_eq!( | ||
serde_json::to_value(TestData::default()).unwrap(), | ||
serde_json::json!({ "string_or_url": TEST_URL }) | ||
) | ||
} | ||
|
||
#[test] | ||
fn parsing_works() { | ||
assert!(TEST_URL.parse::<StringOrUrl>().unwrap().is_url()); | ||
assert!("I'm a random string :)".parse::<StringOrUrl>().unwrap().is_string()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency split can be removed after iotaledger/sd-jwt-payload#14 has been merged, right? ^^