Skip to content
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

Fix the presentation submission in the oid4vp-rs e2e test. #8

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
10611a8
wip: use ssi 0.8.1, debugging e2e test using did resolver
Ryanmtate Aug 8, 2024
7ea4c50
wip: use VerificationMethodDIDResolver for DIDClient constructor
Ryanmtate Aug 8, 2024
7b3ced0
remove unused imports
Ryanmtate Aug 8, 2024
4a77347
wip: debugging did resolver jwk not found in e2e flow
Ryanmtate Aug 9, 2024
48e152e
feat/improve-presentation-exchange-support-in-oid4vp-rs
Ryanmtate Aug 9, 2024
26e62f1
add getter methods for presentation definition member fields
Ryanmtate Aug 9, 2024
8c47808
fix broken links in documentation
Ryanmtate Aug 9, 2024
de5db7d
update presentation submission implementation
Ryanmtate Aug 10, 2024
24845c7
fix test cases. todo: update test cases to use newly created interfac…
Ryanmtate Aug 10, 2024
5036a69
update json schema validator to use anyhow result type
Ryanmtate Aug 10, 2024
ac8e904
merge presentation exchange updates
Ryanmtate Aug 11, 2024
6fe4d46
wip: use latest implementation changes, update tests
Ryanmtate Aug 12, 2024
6d29442
fix verification method did resolver tests
Ryanmtate Aug 12, 2024
e885a4c
wip: remove unused imports
Ryanmtate Aug 12, 2024
3996946
add ClaimFormat type
Ryanmtate Aug 12, 2024
4e841cc
add regex support for string pattern matching
Ryanmtate Aug 12, 2024
edcc8a2
revert uuid presentation definition id type to string
Ryanmtate Aug 12, 2024
23e589a
fix: ensure negation of regex pattern match for error
Ryanmtate Aug 12, 2024
1527933
add 'other' variante to claim format type
Ryanmtate Aug 12, 2024
8ed8828
remove commented out code
Ryanmtate Aug 12, 2024
97b3462
merge presentation exchange updates
Ryanmtate Aug 12, 2024
dcdde5c
use ssi sub-crates instead of main ssi dependency
Ryanmtate Aug 12, 2024
1a2af67
add jwt_vc_json and jwt_vp_json claim formats
Ryanmtate Aug 12, 2024
61043a9
wip: construct verifiable presentation for e2e test
Ryanmtate Aug 13, 2024
24497dd
wip: perform validation on presentation submission
Ryanmtate Aug 13, 2024
3423d13
ensure range exclusive values are checked; fix inclusive range values
Ryanmtate Aug 13, 2024
7bd0660
ensure enum values are parsed in alpha descending order
Ryanmtate Aug 13, 2024
ce60c03
wip: verify authorized response presentation submission
Ryanmtate Aug 14, 2024
cd22624
ensure json schema validator adheres to the specification
Ryanmtate Aug 14, 2024
26dda42
ensure json schema validator adheres to the specification
Ryanmtate Aug 14, 2024
d188434
add unit tests for schema validator
Ryanmtate Aug 14, 2024
89db3b2
use serde default value for constraints field if not found during des…
Ryanmtate Aug 14, 2024
0ec29b3
merge schema validator changes
Ryanmtate Aug 14, 2024
d478103
remove unused imports
Ryanmtate Aug 14, 2024
5e65c4e
Merge branch 'main' into fix/fix-the-presentation-submission-in-the-o…
Ryanmtate Aug 14, 2024
e276d6a
remove unsed imports in test files
Ryanmtate Aug 14, 2024
3d93a0e
update vp token
Ryanmtate Aug 14, 2024
0843f66
rebase with main
Ryanmtate Aug 14, 2024
b7d8083
resolve merge conflict; remove schema validator and replace with json…
Ryanmtate Aug 16, 2024
096d383
remove unused dependencies
Ryanmtate Aug 16, 2024
f82fa26
add rand crate and provide random nonce method using Rng trait
Ryanmtate Aug 20, 2024
b07b715
remove todos and update comments, use JWKResolver instead of Verifica…
Ryanmtate Aug 20, 2024
fcb4ed9
fix clippy warnings
Ryanmtate Aug 20, 2024
1398cad
verify jwt in validate_authorization_response presentation definition…
Ryanmtate Aug 20, 2024
be2bbed
Update tests/e2e.rs
Ryanmtate Aug 20, 2024
32a49b7
update descriptor map nested path in e2e example
Ryanmtate Aug 20, 2024
d050355
remove dependency patches
Ryanmtate Aug 20, 2024
4a0217b
add paths to example for input descriptor constraints field
Ryanmtate Aug 20, 2024
9997486
use top level json path for jwt_vp_json
Ryanmtate Aug 20, 2024
2a93750
Update src/verifier/client.rs
Ryanmtate Aug 20, 2024
f490b8b
rebase
Ryanmtate Aug 20, 2024
347259d
revert validation function async signature to use boxed pin future
Ryanmtate Aug 20, 2024
05d550e
add helper methods
Ryanmtate Aug 22, 2024
129d22c
debug: jwt claim signing does not include public key
Ryanmtate Aug 22, 2024
a3bf215
make request signer methods return a result
Ryanmtate Aug 22, 2024
7733f65
refactor presentation exchange file into smaller modules
Ryanmtate Aug 23, 2024
54c0f79
fix clippy warnings
Ryanmtate Aug 23, 2024
efd5773
Merge branch 'main' into fix/fix-the-presentation-submission-in-the-o…
Ryanmtate Aug 23, 2024
a7aed11
fix outcome error cause
Ryanmtate Aug 23, 2024
2e453ca
add credential format and add requested fields helper method to input…
Ryanmtate Aug 26, 2024
a3bfdcb
Update src/core/presentation_definition.rs
Ryanmtate Aug 27, 2024
7a337ae
Update src/core/presentation_definition.rs
Ryanmtate Aug 27, 2024
76e3a3a
wip: add notes on required fields parsing
Ryanmtate Aug 27, 2024
51e11e8
update vp token base64 encoding and check for multiple vp payloads
Ryanmtate Aug 28, 2024
65e1b11
move validation to auth response impl instead of presentation definit…
Ryanmtate Aug 28, 2024
d0c7439
remove feature gated non-optional deps
Ryanmtate Aug 28, 2024
033fd5e
remove cfg features
Ryanmtate Aug 28, 2024
d98d2a4
wip: handle groups in presentation definition, input descriptor tests
Ryanmtate Aug 28, 2024
915b922
remove cfg feature tags
Ryanmtate Aug 28, 2024
3d7b1f5
remove extraneous metadata helper methods; use UntypedObject for dere…
Ryanmtate Aug 28, 2024
e9b33df
add submission requirement check for presentation validation
Ryanmtate Aug 29, 2024
64f87eb
add validate method to vp token; ensure submission requirement all ru…
Ryanmtate Aug 29, 2024
d3dce7f
add vp token validate unencoded method. fix minor todos.
Ryanmtate Aug 29, 2024
458ff5f
Update Cargo.toml
Ryanmtate Sep 12, 2024
165b1c7
fix other claim format serde
Ryanmtate Sep 12, 2024
0e0f985
use Vec::is_empty versus Option::is_none for various serialization fi…
Ryanmtate Sep 13, 2024
b8e9141
revert to use of ClaimFormatMap to pass presentation defintion test s…
Ryanmtate Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/core/authorization_request/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{fmt, ops::Deref};

use crate::core::{
object::{ParsingErrorContext, TypedParameter, UntypedObject},
presentation_definition::PresentationDefinition as PresentationDefinitionParsed,
util::{base_request, AsyncHttpClient},
};
use anyhow::{bail, Context, Error, Ok};
Expand Down Expand Up @@ -467,25 +468,23 @@ impl From<State> for Json {
#[derive(Debug, Clone)]
pub struct PresentationDefinition {
raw: Json,
parsed: crate::presentation_exchange::PresentationDefinition,
parsed: PresentationDefinitionParsed,
}

impl PresentationDefinition {
pub fn into_parsed(self) -> crate::presentation_exchange::PresentationDefinition {
pub fn into_parsed(self) -> PresentationDefinitionParsed {
self.parsed
}

pub fn parsed(&self) -> &crate::presentation_exchange::PresentationDefinition {
pub fn parsed(&self) -> &PresentationDefinitionParsed {
&self.parsed
}
}

impl TryFrom<crate::presentation_exchange::PresentationDefinition> for PresentationDefinition {
impl TryFrom<PresentationDefinitionParsed> for PresentationDefinition {
type Error = Error;

fn try_from(
parsed: crate::presentation_exchange::PresentationDefinition,
) -> Result<Self, Self::Error> {
fn try_from(parsed: PresentationDefinitionParsed) -> Result<Self, Self::Error> {
let raw = serde_json::to_value(parsed.clone())?;
Ok(Self { raw, parsed })
}
Expand Down
249 changes: 249 additions & 0 deletions src/core/credential_format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

/// A credential format that can be transmitted using OID4VP.
pub trait CredentialFormat {
/// The ID of the credential format.
Expand All @@ -15,3 +19,248 @@ pub struct JwtVc;
impl CredentialFormat for JwtVc {
const ID: &'static str = "jwt_vc";
}

Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
/// A Json object of claim formats.
pub type ClaimFormatMap = HashMap<ClaimFormatDesignation, ClaimFormatPayload>;
Comment on lines +5 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed in addition to ClaimFormat? Isn't ClaimFormatMap equivalent to Vec<ClaimFormat>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presentation exchange presentation definition test suite test case format_example shows format property as a map. I tried with the Vec<ClaimFormat> but encountered errors in the test case.

{
  "presentation_definition": {
    "id": "32f54163-7166-48f1-93d8-ff217bdb0653",
    "input_descriptors": [],
    "format": {
      "jwt": {
        "alg": ["EdDSA", "ES256K", "ES384"]
      },
      "jwt_vc": {
        "alg": ["ES256K", "ES384"]
      },
      "jwt_vp": {
        "alg": ["EdDSA", "ES256K"]
      },
      "ldp_vc": {
        "proof_type": [
          "JsonWebSignature2020",
          "Ed25519Signature2018",
          "EcdsaSecp256k1Signature2019",
          "RsaSignature2018"
        ]
      },
      "ldp_vp": {
        "proof_type": ["Ed25519Signature2018"]
      },
      "ldp": {
        "proof_type": ["RsaSignature2018"]
      }
    }
  }
}


/// The Presentation Definition MAY include a format property. The value MUST be an object with one or
/// more properties matching the registered [ClaimFormatDesignation] (e.g., jwt, jwt_vc, jwt_vp, etc.).
/// The properties inform the Holder of the Claim format configurations the Verifier can process.
/// The value for each claim format property MUST be an object composed as follows:
///
/// The object MUST include a format-specific property (i.e., alg, proof_type) that expresses which
/// algorithms the Verifier supports for the format. Its value MUST be an array of one or more
/// format-specific algorithmic identifier references, as noted in the [ClaimFormatDesignation].
///
/// See [https://identity.foundation/presentation-exchange/spec/v2.0.0/#presentation-definition](https://identity.foundation/presentation-exchange/spec/v2.0.0/#presentation-definition)
/// for an example schema.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum ClaimFormat {
#[serde(rename = "jwt")]
Jwt {
// The algorithm used to sign the JWT.
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
alg: Vec<String>,
},
#[serde(rename = "jwt_vc")]
JwtVc {
// The algorithm used to sign the JWT verifiable credential.
alg: Vec<String>,
},
#[serde(rename = "jwt_vp")]
JwtVp {
// The algorithm used to sign the JWT verifiable presentation.
alg: Vec<String>,
},
#[serde(rename = "jwt_vc_json")]
JwtVcJson {
// Used in the OID4VP specification for wallet methods supported.
alg_values_supported: Vec<String>,
},
#[serde(rename = "jwt_vp_json")]
JwtVpJson {
// Used in the OID4VP specification for wallet methods supported.
alg_values_supported: Vec<String>,
},
#[serde(rename = "ldp")]
Ldp {
// The proof type used to sign the linked data proof.
// e.g., "JsonWebSignature2020", "Ed25519Signature2018", "EcdsaSecp256k1Signature2019", "RsaSignature2018"
proof_type: Vec<String>,
},
#[serde(rename = "ldp_vc")]
LdpVc {
// The proof type used to sign the linked data proof verifiable credential.
proof_type: Vec<String>,
},
#[serde(rename = "ldp_vp")]
LdpVp {
// The proof type used to sign the linked data proof verifiable presentation.
proof_type: Vec<String>,
},
#[serde(rename = "ac_vc")]
AcVc {
// The proof type used to sign the anoncreds verifiable credential.
proof_type: Vec<String>,
},
#[serde(rename = "ac_vp")]
AcVp {
// The proof type used to sign the anoncreds verifiable presentation.
proof_type: Vec<String>,
},
#[serde(rename = "mso_mdoc")]
MsoMDoc(serde_json::Value),
Other(serde_json::Value),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this Other case needs #[serde(untagged)] otherwise it will only capture:

{
  ...
  "Other": { ... }
  ...
}

Could you add a little unit test for deserializing and the designation fn for this case?

}

impl ClaimFormat {
/// Returns the designated format of the claim.
///
/// e.g., jwt, jwt_vc, jwt_vp, ldp, ldp_vc, ldp_vp, ac_vc, ac_vp, mso_mdoc
pub fn designation(&self) -> ClaimFormatDesignation {
match self {
ClaimFormat::Jwt { .. } => ClaimFormatDesignation::Jwt,
ClaimFormat::JwtVc { .. } => ClaimFormatDesignation::JwtVc,
ClaimFormat::JwtVcJson { .. } => ClaimFormatDesignation::JwtVcJson,
ClaimFormat::JwtVp { .. } => ClaimFormatDesignation::JwtVp,
ClaimFormat::JwtVpJson { .. } => ClaimFormatDesignation::JwtVpJson,
ClaimFormat::Ldp { .. } => ClaimFormatDesignation::Ldp,
ClaimFormat::LdpVc { .. } => ClaimFormatDesignation::LdpVc,
ClaimFormat::LdpVp { .. } => ClaimFormatDesignation::LdpVp,
ClaimFormat::AcVc { .. } => ClaimFormatDesignation::AcVc,
ClaimFormat::AcVp { .. } => ClaimFormatDesignation::AcVp,
ClaimFormat::MsoMDoc(_) => ClaimFormatDesignation::MsoMDoc,
ClaimFormat::Other(value) => {
// parse the format from the value
let format = value
.get("format")
.and_then(|format| format.as_str())
// If a `format` property is not present, default to "unknown"
.unwrap_or("unknown");

ClaimFormatDesignation::Other(format.to_string())
}
}
}
}

/// Claim format payload
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ClaimFormatPayload {
#[serde(rename = "alg")]
Alg(Vec<String>),
/// This variant is primarily used for `jwt_vc_json` and `jwt_vp_json`
/// claim presentation algorithm types supported by a wallet.
#[serde(rename = "alg_values_supported")]
AlgValuesSupported(Vec<String>),
#[serde(rename = "proof_type")]
ProofType(Vec<String>),
#[serde(untagged)]
Json(serde_json::Value),
}

impl ClaimFormatPayload {
/// Adds an algorithm value to the list of supported algorithms.
///
/// This method is a no-op if self is not of type `AlgValuesSupported` or `Alg`.
pub fn add_alg(&mut self, alg: String) {
if let Self::Alg(algs) | Self::AlgValuesSupported(algs) = self {
algs.push(alg);
}
}

/// Adds a proof type to the list of supported proof types.
///
/// This method is a no-op if self is not of type `ProofType`.
pub fn add_proof_type(&mut self, proof_type: String) {
if let Self::ProofType(proof_types) = self {
proof_types.push(proof_type);
}
}
}

/// The claim format designation type is used in the input description object to specify the format of the claim.
///
/// Registry of claim format type: https://identity.foundation/claim-format-registry/#registry
///
/// Documentation based on the [DIF Presentation Exchange Specification v2.0](https://identity.foundation/presentation-exchange/spec/v2.0.0/#claim-format-designations)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ClaimFormatDesignation {
/// The format is a JSON Web Token (JWT) as defined by [RFC7519](https://identity.foundation/claim-format-registry/#ref:RFC7519)
/// that will be submitted in the form of a JWT encoded string. Expression of
/// supported algorithms in relation to this format MUST be conveyed using an `alg`
/// property paired with values that are identifiers from the JSON Web Algorithms
/// registry [RFC7518](https://identity.foundation/claim-format-registry/#ref:RFC7518).
#[serde(rename = "jwt")]
Jwt,
/// These formats are JSON Web Tokens (JWTs) [RFC7519](https://identity.foundation/claim-format-registry/#ref:RFC7519)
/// that will be submitted in the form of a JWT-encoded string, with a payload extractable from it defined according to the
/// JSON Web Token (JWT) [section] of the W3C [VC-DATA-MODEL](https://identity.foundation/claim-format-registry/#term:vc-data-model)
/// specification. Expression of supported algorithms in relation to these formats MUST be conveyed using an JWT alg
/// property paired with values that are identifiers from the JSON Web Algorithms registry in
/// [RFC7518](https://identity.foundation/claim-format-registry/#ref:RFC7518) Section 3.
#[serde(rename = "jwt_vc")]
JwtVc,
/// See [JwtVc](JwtVc) for more information.
#[serde(rename = "jwt_vp")]
JwtVp,
#[serde(rename = "jwt_vc_json")]
JwtVcJson,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this format?

#[serde(rename = "jwt_vp_json")]
JwtVpJson,
/// The format is a Linked-Data Proof that will be submitted as an object.
/// Expression of supported algorithms in relation to these formats MUST be
/// conveyed using a proof_type property with values that are identifiers from
/// the Linked Data Cryptographic Suite Registry [LDP-Registry](https://identity.foundation/claim-format-registry/#term:ldp-registry).
#[serde(rename = "ldp")]
Ldp,
/// Verifiable Credentials or Verifiable Presentations signed with Linked Data Proof formats.
/// These are descriptions of formats normatively defined in the W3C Verifiable Credentials
/// specification [VC-DATA-MODEL](https://identity.foundation/claim-format-registry/#term:vc-data-model),
/// and will be submitted in the form of a JSON object. Expression of supported algorithms in relation to
/// these formats MUST be conveyed using a proof_type property paired with values that are identifiers from the
/// Linked Data Cryptographic Suite Registry (LDP-Registry).
#[serde(rename = "ldp_vc")]
LdpVc,
/// See [LdpVc](LdpVc) for more information.
#[serde(rename = "ldp_vp")]
LdpVp,
/// This format is for Verifiable Credentials using AnonCreds.
/// AnonCreds is a VC format that adds important
/// privacy-protecting ZKP (zero-knowledge proof) capabilities
/// to the core VC assurances.
#[serde(rename = "ac_vc")]
AcVc,
/// This format is for Verifiable Presentations using AnonCreds.
/// AnonCreds is a VC format that adds important privacy-protecting ZKP
/// (zero-knowledge proof) capabilities to the core VC assurances.
#[serde(rename = "ac_vp")]
AcVp,
/// The format is defined by ISO/IEC 18013-5:2021 [ISO.18013-5](https://identity.foundation/claim-format-registry/#term:iso.18013-5)
/// which defines a mobile driving license (mDL) Credential in the mobile document (mdoc) format.
/// Although ISO/IEC 18013-5:2021 ISO.18013-5 is specific to mobile driving licenses (mDLs),
/// the Credential format can be utilized with any type of Credential (or mdoc document types).
#[serde(rename = "mso_mdoc")]
MsoMDoc,
/// Other claim format designations not covered by the above.
///
/// The value of this variant is the name of the claim format designation.
Other(String),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above I think this needs a #[serde(untagged)]. Please add a test.

}

impl From<&str> for ClaimFormatDesignation {
fn from(s: &str) -> Self {
match s {
"jwt" => Self::Jwt,
"jwt_vc" => Self::JwtVc,
"jwt_vp" => Self::JwtVp,
"jwt_vc_json" => Self::JwtVcJson,
"jwt_vp_json" => Self::JwtVpJson,
"ldp" => Self::Ldp,
"ldp_vc" => Self::LdpVc,
"ldp_vp" => Self::LdpVp,
"ac_vc" => Self::AcVc,
"ac_vp" => Self::AcVp,
"mso_mdoc" => Self::MsoMDoc,
s => Self::Other(s.to_string()),
}
}
}

impl From<ClaimFormatDesignation> for String {
fn from(format: ClaimFormatDesignation) -> Self {
match format {
ClaimFormatDesignation::AcVc => "ac_vc".to_string(),
ClaimFormatDesignation::AcVp => "ac_vp".to_string(),
ClaimFormatDesignation::Jwt => "jwt".to_string(),
ClaimFormatDesignation::JwtVc => "jwt_vc".to_string(),
ClaimFormatDesignation::JwtVp => "jwt_vp".to_string(),
ClaimFormatDesignation::JwtVcJson => "jwt_vc_json".to_string(),
ClaimFormatDesignation::JwtVpJson => "jwt_vp_json".to_string(),
ClaimFormatDesignation::Ldp => "ldp".to_string(),
ClaimFormatDesignation::LdpVc => "ldp_vc".to_string(),
ClaimFormatDesignation::LdpVp => "ldp_vp".to_string(),
ClaimFormatDesignation::MsoMDoc => "mso_mdoc".to_string(),
ClaimFormatDesignation::Other(s) => s,
}
}
}
Loading
Loading