Skip to content

Commit

Permalink
Update credential offer definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
theosirian committed Aug 22, 2024
1 parent 0a037fa commit ffe657c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 74 deletions.
89 changes: 81 additions & 8 deletions src/core/profiles/w3c/jwtld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,87 @@ use crate::profiles::{
CredentialRequestProfile, CredentialResponseProfile,
};

use super::{CredentialDefinitionLD, CredentialOfferDefinitionLD};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Metadata {}
pub struct Metadata {
credential_definition: CredentialDefinitionLD,
}

impl Metadata {
pub fn new(credential_definition: CredentialDefinitionLD) -> Self {
Self {
credential_definition,
}
}

field_getters_setters![
pub self [self] ["JWT VC LD metadata value"] {
set_credential_definition -> credential_definition[CredentialDefinitionLD],
}
];
}

impl CredentialMetadataProfile for Metadata {
type Request = Request;

fn to_request(&self) -> Self::Request {
Request::new()
Request::new(self.credential_definition.clone())
}
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Offer {}
pub struct Offer {
credential_definition: CredentialOfferDefinitionLD,
}

impl Offer {
pub fn new(credential_definition: CredentialOfferDefinitionLD) -> Self {
Self {
credential_definition,
}
}

field_getters_setters![
pub self [self] ["JWT VC LD offer value"] {
set_credential_definition -> credential_definition[CredentialOfferDefinitionLD],
}
];
}
impl CredentialOfferProfile for Offer {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AuthorizationDetails {
credential_definition: CredentialDefinitionLD,

#[serde(
default,
skip_serializing,
deserialize_with = "crate::deny_field::deny_field",
rename = "credential_configuration_id"
rename = "credential_identifier"
)]
_credential_configuration_id: (),
_credential_identifier: (),
}

impl AuthorizationDetails {
pub fn new(credential_definition: CredentialDefinitionLD) -> Self {
Self {
credential_definition,
_credential_identifier: (),
}
}
field_getters_setters![
pub self [self] ["JWT VC LD authorization value"] {
set_credential_definition -> credential_definition[CredentialDefinitionLD],
}
];
}
impl AuthorizationDetailsProfile for AuthorizationDetails {}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Request {
credential_definition: CredentialDefinitionLD,

#[serde(
default,
skip_serializing,
Expand All @@ -43,16 +96,36 @@ pub struct Request {
}

impl Request {
pub fn new() -> Self {
pub fn new(credential_definition: CredentialDefinitionLD) -> Self {
Self {
credential_definition,
_credential_identifier: (),
}
}

field_getters_setters![
pub self [self] ["JWT VC request value"] {
set_credential_definition -> credential_definition[CredentialDefinitionLD],
}
];
}
impl CredentialRequestProfile for Request {
type Response = Response;
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Response {}
pub struct Response {
credential: String,
}

impl Response {
pub fn new(credential: String) -> Self {
Self { credential }
}
field_getters_setters![
pub self [self] ["JWT VC response value"] {
set_credential -> credential[String],
}
];
}
impl CredentialResponseProfile for Response {}
74 changes: 8 additions & 66 deletions src/core/profiles/w3c/ldp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,37 @@ use crate::profiles::{
CredentialRequestProfile, CredentialResponseProfile,
};

use super::{CredentialDefinition, CredentialOfferDefinition};
use super::{CredentialDefinitionLD, CredentialOfferDefinitionLD};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Metadata {
credential_signing_alg_values_supported: Option<Vec<String>>,
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
credentials_definition: CredentialDefinitionLD,
#[serde(flatten)]
credential_definition: CredentialDefinitionLD,
order: Option<Vec<String>>,
}

impl Metadata {
pub fn new(
context: Vec<serde_json::Value>,
credentials_definition: CredentialDefinitionLD,
) -> Self {
pub fn new(credential_definition: CredentialDefinitionLD) -> Self {
Self {
credential_signing_alg_values_supported: None,
context,
credentials_definition,
credential_definition,
order: None,
}
}
field_getters_setters![
pub self [self] ["LD VC metadata value"] {
set_credential_signing_alg_values_supported -> credential_signing_alg_values_supported[Option<Vec<String>>],
set_context -> context[Vec<serde_json::Value>],
set_credentials_definition -> credentials_definition[CredentialDefinitionLD],
set_credential_definition -> credential_definition[CredentialDefinitionLD],
set_order -> order[Option<Vec<String>>],
}
];
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialDefinitionLD {
#[serde(flatten)]
credential_definition: CredentialDefinition,
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
}

impl CredentialDefinitionLD {
pub fn new(
credential_definition: CredentialDefinition,
context: Vec<serde_json::Value>,
) -> Self {
Self {
credential_definition,
context,
}
}
field_getters_setters![
pub self [self] ["LD VC credential definition value"] {
set_credential_definition -> credential_definition[CredentialDefinition],
set_context -> context[Vec<serde_json::Value>],
}
];
}
impl CredentialMetadataProfile for Metadata {
type Request = Request;

fn to_request(&self) -> Self::Request {
Request::new(self.credentials_definition().clone())
Request::new(self.credential_definition().clone())
}
}

Expand All @@ -93,32 +61,6 @@ impl Offer {
}
];
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialOfferDefinitionLD {
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
#[serde(flatten)]
credential_offer_definite: CredentialOfferDefinition,
}

impl CredentialOfferDefinitionLD {
pub fn new(
context: Vec<serde_json::Value>,
credential_offer_definite: CredentialOfferDefinition,
) -> Self {
Self {
context,
credential_offer_definite,
}
}

field_getters_setters![
pub self [self] ["LD VC credential offer definition value"] {
set_context -> context[Vec<serde_json::Value>],
set_credential_offer_definite -> credential_offer_definite[CredentialOfferDefinition],
}
];
}
impl CredentialOfferProfile for Offer {}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
Expand Down Expand Up @@ -217,7 +159,7 @@ mod test {
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentials_definition": {
"credential_definition": {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
Expand Down
53 changes: 53 additions & 0 deletions src/core/profiles/w3c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ impl CredentialDefinition {
];
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialDefinitionLD {
#[serde(flatten)]
credential_definition: CredentialDefinition,
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
}

impl CredentialDefinitionLD {
pub fn new(
credential_definition: CredentialDefinition,
context: Vec<serde_json::Value>,
) -> Self {
Self {
credential_definition,
context,
}
}
field_getters_setters![
pub self [self] ["LD VC credential definition value"] {
set_credential_definition -> credential_definition[CredentialDefinition],
set_context -> context[Vec<serde_json::Value>],
}
];
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialOfferDefinition {
r#type: Vec<String>,
Expand All @@ -49,6 +75,33 @@ impl CredentialOfferDefinition {
];
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CredentialOfferDefinitionLD {
#[serde(flatten)]
credential_offer_definition: CredentialOfferDefinition,
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
}

impl CredentialOfferDefinitionLD {
pub fn new(
context: Vec<serde_json::Value>,
credential_offer_definition: CredentialOfferDefinition,
) -> Self {
Self {
context,
credential_offer_definition,
}
}

field_getters_setters![
pub self [self] ["LD VC credential offer definition value"] {
set_context -> context[Vec<serde_json::Value>],
set_credential_offer_definition -> credential_offer_definition[CredentialOfferDefinition],
}
];
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct CredentialSubjectClaims {
mandatory: Option<bool>,
Expand Down
1 change: 1 addition & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ where

field_getters_setters![
pub self [self] ["credential metadata value"] {
set_name -> name[Option<String>],
set_scope -> scope[Option<Scope>],
set_cryptographic_binding_methods_supported -> cryptographic_binding_methods_supported[Option<Vec<CryptographicBindingMethod>>],
set_proof_types_supported -> proof_types_supported[Option<Vec<KeyProofTypesSupported>>],
Expand Down

0 comments on commit ffe657c

Please sign in to comment.