Skip to content

Commit be0dd56

Browse files
committed
fix: initial changes for updated web3id
1 parent 1c727c5 commit be0dd56

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

concordium-base

Submodule concordium-base updated 59 files

src/web3id.rs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
//! Functionality for retrieving, verifying, and registering web3id credentials.
22
3+
use std::collections::BTreeMap;
4+
35
use crate::{
46
cis4::{Cis4Contract, Cis4QueryError},
57
v2::{self, BlockIdentifier, IntoBlockIdentifier},
68
};
79
pub use concordium_base::web3id::*;
810
use concordium_base::{
9-
base::CredentialRegistrationID,
10-
cis4_types::CredentialStatus,
11-
contracts_common::AccountAddress,
12-
id::{constants::ArCurve, types::IpIdentity},
13-
web3id,
11+
base::CredentialRegistrationID, cis4_types::CredentialStatus, contracts_common::AccountAddress, id::{constants::{ArCurve, IpPairing}, types::{ArInfos, IpIdentity}}, web3id
1412
};
15-
use futures::TryStreamExt;
13+
use futures::{TryFutureExt, TryStreamExt};
1614

1715
#[derive(thiserror::Error, Debug)]
1816
pub enum CredentialLookupError {
@@ -46,7 +44,7 @@ pub struct CredentialWithMetadata {
4644
/// The status of the credential at a point in time.
4745
pub status: CredentialStatus,
4846
/// The extra public inputs needed for verification.
49-
pub inputs: CredentialsInputs<ArCurve>,
47+
pub inputs: CredentialsInputs<IpPairing, ArCurve>,
5048
}
5149

5250
/// Retrieve and validate credential metadata in a particular block.
@@ -146,6 +144,61 @@ pub async fn verify_credential_metadata(
146144

147145
Ok(CredentialWithMetadata { status, inputs })
148146
}
147+
148+
// TODO - Identity handling for credential
149+
CredentialMetadata::Identity { issuer, validity } => {
150+
151+
// get all the identity providers at current block
152+
let identity_providers = client.get_identity_providers(bi).await?
153+
.response
154+
.try_collect::<Vec<_>>()
155+
.map_err(|_e| CredentialLookupError::InvalidResponse("Error getting identity providers".into()))
156+
.await?;
157+
158+
// find the matching identity provider info
159+
let matching_idp = identity_providers.iter()
160+
.find(|idp| {
161+
idp.ip_identity.0 == issuer.0
162+
})
163+
.ok_or( CredentialLookupError::InvalidResponse("Error occurred while getting matching identity provider".into()))?;
164+
165+
// get anonymity revokers
166+
let anonymity_revokers = client.get_anonymity_revokers(bi).await?.response
167+
.try_collect::<Vec<_>>()
168+
.map_err(|e|
169+
CredentialLookupError::InvalidResponse("Error while getting annonymity revokers.".into(),
170+
))
171+
.await?;
172+
173+
// create a new BTreeMap to hold the Anonymity revoker identity -> the anonymity revoker info
174+
let mut anonymity_revoker_infos = BTreeMap::new();
175+
176+
for ar in anonymity_revokers {
177+
anonymity_revoker_infos.insert(ar.ar_identity, ar);
178+
}
179+
180+
// build inputs
181+
let inputs = CredentialsInputs::Identity { ip_info: matching_idp.clone(), ars_infos: ArInfos { anonymity_revokers: anonymity_revoker_infos } };
182+
183+
// TODO - change me, probably need to do something similar to how we handle the account - where we check the validity created at and valid to
184+
// validity.created_at
185+
// validity.valid_to
186+
let now = client.get_block_info(bi).await?.response.block_slot_time;
187+
188+
// TODO temporary dummy status for now
189+
let status = CredentialStatus::Active;
190+
/*
191+
let status = if &validity.valid_to.year < YearMonth::now() {
192+
CredentialStatus::Expired
193+
} else if &validity.valid_to >= YearMonth::now() {
194+
CredentialStatus::Active
195+
} else {
196+
CredentialStatus::NotActivated
197+
};
198+
*/
199+
200+
Ok(CredentialWithMetadata { inputs: inputs, status: status})
201+
}
149202
}
150203
}
151204

@@ -160,7 +213,7 @@ pub async fn verify_credential_metadata(
160213
pub async fn get_public_data(
161214
client: &mut v2::Client,
162215
network: web3id::did::Network,
163-
presentation: &web3id::Presentation<ArCurve, web3id::Web3IdAttribute>,
216+
presentation: &web3id::Presentation<IpPairing, ArCurve, web3id::Web3IdAttribute>,
164217
bi: impl IntoBlockIdentifier,
165218
) -> Result<Vec<CredentialWithMetadata>, CredentialLookupError> {
166219
let block = bi.into_block_identifier();

0 commit comments

Comments
 (0)