Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CredentialProvider/wasm/matcher-rs/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ unsafe extern "C" {
set_id: *const c_char,
set_index: i32,
);
pub fn SetDelegationTypeForEntryInSet(
cred_id: *const c_char,
delegation_type: i32,
set_id: *const c_char,
set_index: i32,
);
pub fn AddFieldToEntrySet(
cred_id: *const c_char,
field_display_name: *const c_char,
Expand Down
21 changes: 21 additions & 0 deletions CredentialProvider/wasm/matcher-rs/src/credman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::bindings::{
AddMetadataDisplayTextToEntrySet, AddPaymentEntryToSetV2, AddStringIdEntry, GetCredentialsSize,
GetRequestBuffer, GetRequestSize, GetWasmVersion, ReadCredentialsBuffer, SelfDeclarePackageInfo,
};
use crate::openid4vp_models::DelegationType;

pub trait CredmanApi {
fn get_request_buffer(&self) -> Vec<u8>;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub trait CredmanApi {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: DelegationType,
);
fn add_field_to_entry_set(
&mut self,
Expand All @@ -63,6 +65,7 @@ pub trait CredmanApi {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: DelegationType,
);
fn add_inline_issuance_entry(
&mut self,
Expand Down Expand Up @@ -238,6 +241,7 @@ impl CredmanApi for CredmanApiImpl {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: DelegationType,
) {
let cred_id_c = CString::new(cred_id).unwrap();
let title_c = if title.is_empty() {
Expand Down Expand Up @@ -289,6 +293,14 @@ impl CredmanApi for CredmanApiImpl {
set_id_c.as_ptr(),
set_index,
);
if self.get_wasm_version() >= 7 && delegation_type != DelegationType::None {
crate::bindings::SetDelegationTypeForEntryInSet(
cred_id_c.as_ptr(),
delegation_type as i32,
set_id_c.as_ptr(),
set_index,
);
}
}
}
fn add_field_to_entry_set(
Expand Down Expand Up @@ -334,6 +346,7 @@ impl CredmanApi for CredmanApiImpl {
metadata: &str,
set_id: &str,
set_index: i32,
delegation_type: DelegationType,
) {
let cred_id_c = CString::new(cred_id).unwrap();
let merchant_name_c = if merchant_name.is_empty() {
Expand Down Expand Up @@ -415,6 +428,14 @@ impl CredmanApi for CredmanApiImpl {
set_id_c.as_ptr(),
set_index,
);
if self.get_wasm_version() >= 7 && delegation_type != DelegationType::None {
crate::bindings::SetDelegationTypeForEntryInSet(
cred_id_c.as_ptr(),
delegation_type as i32,
set_id_c.as_ptr(),
set_index,
);
}
}
}
fn add_inline_issuance_entry(
Expand Down
9 changes: 9 additions & 0 deletions CredentialProvider/wasm/matcher-rs/src/dcql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn match_candidate_claims<'a>(
add_all_claims(&mut matched_claim_names, &candidate.paths);
return Some(MatchedCredential {
id: &candidate.id,
delegation_type: candidate.delegation_type,
display: &candidate.display,
matched_claim_names,
matched_claim_metadata: Vec::new(),
Expand Down Expand Up @@ -216,6 +217,7 @@ fn match_candidate_claims<'a>(
);
Some(MatchedCredential {
id: &candidate.id,
delegation_type: candidate.delegation_type,
display: &candidate.display,
matched_claim_names: current_set_names,
matched_claim_metadata: current_set_metadata,
Expand Down Expand Up @@ -256,6 +258,7 @@ fn match_candidate_claims<'a>(
log::debug!("Candidate {}: all claims matched", candidate.id);
Some(MatchedCredential {
id: &candidate.id,
delegation_type: candidate.delegation_type,
display: &candidate.display,
matched_claim_names,
matched_claim_metadata,
Expand Down Expand Up @@ -587,6 +590,7 @@ mod tests {
);
creds.push(RegistryCredential {
id: "mdoc_cred_1".to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths,
});
Expand Down Expand Up @@ -629,6 +633,7 @@ mod tests {
);
creds.push(RegistryCredential {
id: "mdoc_cred_1".to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths,
});
Expand Down Expand Up @@ -674,6 +679,7 @@ mod tests {
);
creds.push(RegistryCredential {
id: "mdoc_cred_1".to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths,
});
Expand Down Expand Up @@ -709,6 +715,7 @@ mod tests {
let mut creds = Vec::new();
creds.push(RegistryCredential {
id: "mdoc_cred_1".to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths: DeterministicMap::new(),
});
Expand Down Expand Up @@ -863,6 +870,7 @@ mod tests {

RegistryCredential {
id: id.to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths,
}
Expand Down Expand Up @@ -950,6 +958,7 @@ mod tests {

let cred1 = RegistryCredential {
id: "cred1".to_string(),
delegation_type: DelegationType::None,
display: RegistryDisplay::default(),
paths,
};
Expand Down
4 changes: 3 additions & 1 deletion CredentialProvider/wasm/matcher-rs/src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ mod test {
_metadata: &str,
_set_id: &str,
_set_index: i32,
_delegation_type: crate::openid4vp_models::DelegationType,
) {
}
fn add_field_to_entry_set(
Expand All @@ -312,6 +313,7 @@ mod test {
_metadata: &str,
_set_id: &str,
_set_index: i32,
_delegation_type: crate::openid4vp_models::DelegationType,
) {
}
fn add_inline_issuance_entry(
Expand Down Expand Up @@ -429,7 +431,7 @@ mod test {
}
}
]
"#,
}"#,
registered_json: r#"
{
"entry_id": "C",
Expand Down
44 changes: 44 additions & 0 deletions CredentialProvider/wasm/matcher-rs/src/openid4vp_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,38 @@ pub struct RegistryCredentials {
pub issuance: Option<RegistryIssuance>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(i32)]
pub enum DelegationType {
#[default]
None = 0,
Full = 1,
}

impl From<i32> for DelegationType {
fn from(val: i32) -> Self {
match val {
1 => DelegationType::Full,
_ => DelegationType::None,
}
}
}

impl nanoserde::DeJson for DelegationType {
fn de_json(
state: &mut nanoserde::DeJsonState,
input: &mut std::str::Chars,
) -> Result<Self, nanoserde::DeJsonErr> {
let val = i32::de_json(state, input)?;
Ok(DelegationType::from(val))
}
}

#[derive(DeJson, Debug, Clone, Default)]
#[nserde(default)]
pub struct RegistryCredential {
pub id: String,
pub delegation_type: DelegationType,
pub display: RegistryDisplay,
pub paths: DeterministicMap<String, JsonValue>, // Recursive structure
}
Expand Down Expand Up @@ -120,6 +148,7 @@ pub struct MatchedClaim<'a> {
#[derive(Debug, Clone)]
pub struct MatchedCredential<'a> {
pub id: &'a str,
pub delegation_type: DelegationType,
pub display: &'a RegistryDisplay,
pub matched_claim_names: Vec<&'a JsonValue>, // RegistryClaimDisplay
pub matched_claim_metadata: Vec<&'a [String]>,
Expand Down Expand Up @@ -436,4 +465,19 @@ mod tests {
// Validate that the string can be parsed into JsonValue
let _: JsonValue = DeJson::deserialize_json(&json).expect("Serialized JSON is invalid");
}

#[test]
fn test_parse_delegation_type() {
let json_none = r#"{"id":"c1","delegation_type":0,"display":{"verification":{"title":"","subtitle":"","explainer":"","warning":"","metadata_display_text":""}},"paths":{}}"#;
let cred_none: RegistryCredential = DeJson::deserialize_json(json_none).unwrap();
assert_eq!(cred_none.delegation_type, DelegationType::None);

let json_full = r#"{"id":"c2","delegation_type":1,"display":{"verification":{"title":"","subtitle":"","explainer":"","warning":"","metadata_display_text":""}},"paths":{}}"#;
let cred_full: RegistryCredential = DeJson::deserialize_json(json_full).unwrap();
assert_eq!(cred_full.delegation_type, DelegationType::Full);

let json_default = r#"{"id":"c3","display":{"verification":{"title":"","subtitle":"","explainer":"","warning":"","metadata_display_text":""}},"paths":{}}"#;
let cred_default: RegistryCredential = DeJson::deserialize_json(json_default).unwrap();
assert_eq!(cred_default.delegation_type, DelegationType::None);
}
}
Loading