Skip to content

Commit

Permalink
Merge branch 'dev' into feat/content-update-rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mader authored Dec 10, 2024
2 parents 3c6c3f7 + 41b5519 commit 2dfc856
Show file tree
Hide file tree
Showing 20 changed files with 480 additions and 293 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/format-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
working-directory: ./unime/src-tauri
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libsoup-3.0 javascriptcoregtk-4.1 webkit2gtk-4.1
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Format
working-directory: ./unime/src-tauri
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
working-directory: ./identity-wallet
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libsoup-3.0 javascriptcoregtk-4.1 webkit2gtk-4.1
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Format
working-directory: ./identity-wallet
Expand Down
8 changes: 7 additions & 1 deletion identity-wallet/resources/default_trust_list.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"id": "b01f4a74-3005-4749-a030-c5444bc4dab5",
"display_name": "Impierce Demos",
"entries": ["https://ngdil.com", "https://selv.iota.org", "https://thuiswinkel-agent.dev.impierce.com"]
"entries": [
"https://ngdil.com",
"https://selv.iota.org",
"https://thuiswinkel-agent.dev.impierce.com",
"https://mijnkvk.acc.credenco.com",
"https://agent.wallet.bd.demo.sphereon.com"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,60 +135,70 @@ pub async fn send_credential_request(state: AppState, action: Action) -> Result<
credential_configuration_ids.contains(credential_configuration_id)
});

let credentials: Vec<(String, serde_json::Value)> = match credential_configuration_ids.len() {
0 => vec![],
1 => {
let credential_configuration_id = credential_configuration_ids[0].clone();

let credential_configuration = credential_configurations_supported
.get(&credential_configuration_id)
.ok_or(UnknownCredentialConfigurationIdError(
credential_configuration_id.clone(),
))?;

// Get the credential.
let credential_response = wallet
.get_credential(credential_issuer_metadata, &token_response, credential_configuration)
.await
.map_err(GetCredentialError)?;

let credential = match credential_response.credential {
CredentialResponseType::Immediate { credential, .. } => credential,
_ => panic!("Credential was not a jwt_vc_json."),
};

vec![(credential_configuration_id, credential)]
}
_batch => {
let (credential_configuration_ids, credential_configurations): (Vec<_>, Vec<_>) =
credential_configurations_supported.clone().into_iter().unzip();

let batch_credential_response = wallet
.get_batch_credential(credential_issuer_metadata, &token_response, &credential_configurations)
.await
.map_err(GetBatchCredentialError)?;

credential_configuration_ids
.into_iter()
.zip(batch_credential_response.credential_responses.into_iter())
.filter_map(
|(credential_configuration_id, credential_response)| match credential_response {
CredentialResponseType::Immediate { credential, .. } => {
Some((credential_configuration_id, credential))
}
// TODO: add support for deffered credentials.
CredentialResponseType::Deferred { .. } => None,
},
)
.collect()
}
};
let credentials: Vec<(String, serde_json::Value, Vec<serde_json::Value>)> =
match credential_configuration_ids.len() {
0 => vec![],
1 => {
let credential_configuration_id = credential_configuration_ids[0].clone();

let credential_configuration = credential_configurations_supported
.get(&credential_configuration_id)
.ok_or(UnknownCredentialConfigurationIdError(
credential_configuration_id.clone(),
))?;

// Get the credential.
let credential_response = wallet
.get_credential(credential_issuer_metadata, &token_response, credential_configuration)
.await
.map_err(GetCredentialError)?;

let credential = match credential_response.credential {
CredentialResponseType::Immediate { credential, .. } => credential,
_ => panic!("Credential was not a jwt_vc_json."),
};

vec![(
credential_configuration_id,
credential,
credential_configuration.display.clone(),
)]
}
_batch => {
let (credential_configuration_ids, credential_configurations): (Vec<_>, Vec<_>) =
credential_configurations_supported.clone().into_iter().unzip();

let batch_credential_response = wallet
.get_batch_credential(credential_issuer_metadata, &token_response, &credential_configurations)
.await
.map_err(GetBatchCredentialError)?;

credential_configuration_ids
.into_iter()
.zip(batch_credential_response.credential_responses.into_iter())
.zip(credential_configurations.into_iter())
.filter_map(
|((credential_configuration_id, credential_response), credential_configuration)| {
match credential_response {
CredentialResponseType::Immediate { credential, .. } => Some((
credential_configuration_id,
credential,
credential_configuration.display,
)),
// TODO: add support for deferred credentials.
CredentialResponseType::Deferred { .. } => None,
}
},
)
.collect()
}
};

info!("credentials: {:?}", credentials);

let mut history_credentials = vec![];

for (credential_configuration_id, credential) in credentials.into_iter() {
for (credential_configuration_id, credential, display) in credentials.into_iter() {
let mut verifiable_credential_record: VerifiableCredentialRecord = credential.try_into()?;
verifiable_credential_record
.display_credential
Expand All @@ -211,11 +221,12 @@ pub async fn send_credential_request(state: AppState, action: Action) -> Result<

info!("generated hash-key: {:?}", key);

persist_asset(
format!("credential_{credential_configuration_id}").as_str(),
key.to_string().as_str(),
)
.ok();
display
.first()
.and_then(|display| display.get("logo"))
.and_then(|logo| logo.get("uri").or_else(|| logo.get("url")))
.and_then(|uri| uri.as_str())
.and_then(|uri| persist_asset(&hash(uri), key.to_string().as_str()).ok());

// Remove the old credential from the stronghold if it exists.
stronghold_manager.remove(key).map_err(StrongholdDeletionError)?;
Expand Down
19 changes: 14 additions & 5 deletions identity-wallet/src/state/did/validate_domain_linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn validate_domain_linkage(url: url::Url, did: &str) -> ValidationResu
Err(e) => {
return ValidationResult {
status: ValidationStatus::Unknown,
message: Some(e.to_string()),
message: Some(format!("Error while fetching configuration: {}", e)),
..Default::default()
};
}
Expand Down Expand Up @@ -142,10 +142,15 @@ async fn fetch_configuration(mut url: url::Url) -> Result<DomainLinkageConfigura
info!("Fetching DID configuration from: {}", url);

// 2. Fetch the resource
let response = reqwest::get(url).await.map_err(|e| e.to_string())?;
let response = reqwest::get(url.clone())
.await
.map_err(|_| format!("failed to get response from resource url: {}", url))?;

// 3. Parse to JSON value (mutable)
let mut json = response.json::<serde_json::Value>().await.map_err(|e| e.to_string())?;
let mut json = response
.json::<serde_json::Value>()
.await
.map_err(|_| "failed to parse response into JSON value".to_string())?;

// 4. Remove all non-string values from `linked_dids` (JSON-LD)
if let serde_json::Value::Object(ref mut root) = json {
Expand All @@ -156,7 +161,8 @@ async fn fetch_configuration(mut url: url::Url) -> Result<DomainLinkageConfigura
}

// 5. Deserialize to `DomainLinkageConfiguration`
let config = DomainLinkageConfiguration::from_json_value(json).map_err(|e| e.to_string())?;
let config = DomainLinkageConfiguration::from_json_value(json)
.map_err(|_| "failed to deserialize DomainLinkageConfiguration from JSON".to_string())?;
Ok(config)
}

Expand Down Expand Up @@ -240,7 +246,10 @@ mod tests {
result,
ValidationResult {
status: ValidationStatus::Unknown,
message: Some("failed to decode JSON".to_string()),
message: Some(
"Error while fetching configuration: failed to deserialize DomainLinkageConfiguration from JSON"
.to_string()
),
..Default::default()
}
);
Expand Down
Loading

0 comments on commit 2dfc856

Please sign in to comment.