Skip to content

Commit

Permalink
Process review comments
Browse files Browse the repository at this point in the history
Signed-off-by: artem.ivanov <[email protected]>
  • Loading branch information
Artemkaaas committed Dec 21, 2023
1 parent 5648b15 commit cb837a5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 47 deletions.
19 changes: 10 additions & 9 deletions docs/design/w3c/w3c-representation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ Methods purpose - have to forms of credentials (probably even duplicate in walle
/// Convert credential in legacy form into W3C AnonCreds credential form
///
/// # Params
/// cred: object handle pointing to credential in legacy form to convert
/// cred_def: object handle pointing to the credential definition
/// version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain converted credential (in W3C form) instance pointer
/// cred: object handle pointing to credential in legacy form to convert
/// cred_def: object handle pointing to the credential definition
/// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain converted credential (in W3C form) instance pointer
///
/// # Returns
/// Error code
#[no_mangle]
pub extern "C" fn anoncreds_credential_to_w3c(
cred: ObjectHandle,
cred_def: ObjectHandle,
version: FfiStr,
w3c_version: FfiStr,
cred_p: *mut ObjectHandle,
) -> ErrorCode {}

Expand Down Expand Up @@ -114,7 +114,7 @@ The reasons for adding duplication methods:
/// attr_names: list of attribute names
/// attr_raw_values: list of attribute raw values
/// revocation: object handle pointing to the credential revocation info
/// version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain credential (in W3C form) instance pointer
///
/// # Returns
Expand All @@ -128,7 +128,7 @@ pub extern "C" fn anoncreds_create_w3c_credential(
attr_names: FfiStrList,
attr_raw_values: FfiStrList,
revocation: *const FfiCredRevInfo,
version: *const FfiStr,
w3c_version: *const FfiStr,
cred_p: *mut ObjectHandle,
) -> ErrorCode {}

Expand Down Expand Up @@ -161,7 +161,7 @@ pub extern "C" fn anoncreds_process_w3c_credential(
///
/// # Params
/// handle: object handle pointing to the credential (in W3 form)
/// result_p: reference that will contain credential information
/// cred_proof_info_p: reference that will contain credential information
///
/// # Returns
/// Error code
Expand All @@ -182,7 +182,7 @@ pub extern "C" fn anoncreds_w3c_credential_get_integrity_proof_details(
/// schema_ids: list of schemas ids
/// cred_defs: list of credential definitions
/// cred_def_ids: list of credential definitions ids
/// version: version of w3c verifiable presentation specification (1.1 or 2.0) to use
/// w3c_version: version of w3c verifiable presentation specification (1.1 or 2.0) to use
/// presentation_p: reference that will contain created presentation (in W3C form) instance pointer.
///
/// # Returns
Expand All @@ -198,6 +198,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation(
cred_defs: FfiList<ObjectHandle>,
cred_def_ids: FfiStrList,
presentation_p: *mut ObjectHandle,
w3c_version: FfiStr,
) -> ErrorCode {}

/// Verity W3C styled Presentation
Expand Down
30 changes: 9 additions & 21 deletions src/data_types/w3c/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct W3CCredential {
pub id: Option<URI>,

// for VC 1.1 `issuance_date` property must be used
// for VC 2.0 `valid_from` property must be used
// for VC 2.0 there is optional `valid_from` which we leave empty in case of anoncreds
#[serde(skip_serializing_if = "Option::is_none")]
pub issuance_date: Option<IssuanceDate>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -72,23 +72,22 @@ impl W3CCredential {
proof: DataIntegrityProof,
version: Option<&VerifiableCredentialSpecVersion>,
) -> Self {
let time = Utc::now();
let version = version.cloned().unwrap_or_default();
let (issuance_date, valid_from) = match version {
VerifiableCredentialSpecVersion::V1_1 => (Some(time), None),
VerifiableCredentialSpecVersion::V2_0 => (None, Some(time)),
let issuance_date = match version {
VerifiableCredentialSpecVersion::V1_1 => Some(Utc::now()),
VerifiableCredentialSpecVersion::V2_0 => None,
};
Self {
context: Contexts::get(&version),
type_: ANONCREDS_CREDENTIAL_TYPES.clone(),
issuance_date,
valid_from,
issuer,
credential_subject: CredentialSubject {
id: None,
attributes,
},
proof: OneOrMany::Many(vec![CredentialProof::DataIntegrityProof(proof)]),
valid_from: None,
id: None,
}
}
Expand Down Expand Up @@ -152,21 +151,10 @@ impl W3CCredential {
return Err(err_msg!("Credential does not contain w3c credential type"));
}

match version {
VerifiableCredentialSpecVersion::V1_1 => {
if self.issuance_date.is_none() {
return Err(err_msg!(
"V1.1 Credential must include `issuanceDate` property"
));
}
}
VerifiableCredentialSpecVersion::V2_0 => {
if self.valid_from.is_none() {
return Err(err_msg!(
"V1.1 Credential must include `validFrom` property"
));
}
}
if version == VerifiableCredentialSpecVersion::V1_1 && self.issuance_date.is_none() {
return Err(err_msg!(
"V1.1 Credential must include `issuanceDate` property"
));
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/data_types/w3c/proof.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::data_types::cred_def::CredentialDefinitionId;
use crate::data_types::rev_reg_def::RevocationRegistryDefinitionId;
use crate::data_types::schema::SchemaId;
use crate::Result;
use crate::utils::base64;
use crate::Result;
use anoncreds_clsignatures::{
AggregatedProof, CredentialSignature as CLCredentialSignature, RevocationRegistry,
SignatureCorrectnessProof, SubProof, Witness,
Expand Down
25 changes: 13 additions & 12 deletions src/ffi/w3c/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl_anoncreds_object_from_json!(W3CCredential, anoncreds_w3c_credential_from_js
/// attr_names: list of attribute names
/// attr_raw_values: list of attribute raw values
/// revocation: object handle pointing to the credential revocation info
/// version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain credential (in W3C form) instance pointer
///
/// # Returns
Expand All @@ -44,15 +44,15 @@ pub extern "C" fn anoncreds_create_w3c_credential(
attr_names: FfiStrList,
attr_raw_values: FfiStrList,
revocation: *const FfiCredRevInfo,
version: FfiStr,
w3c_version: FfiStr,
cred_p: *mut ObjectHandle,
) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(cred_p);

let cred_values = _credential_attributes(attr_names, attr_raw_values)?;
let revocation_config = _revocation_config(revocation)?;
let version = match version.as_opt_str() {
let w3c_version = match w3c_version.as_opt_str() {
Some(value) => Some(VerifiableCredentialSpecVersion::try_from(value)?),
None => None,
};
Expand All @@ -67,7 +67,7 @@ pub extern "C" fn anoncreds_create_w3c_credential(
.as_ref()
.map(TryInto::try_into)
.transpose()?,
version,
w3c_version,
)?;
let cred = ObjectHandle::create(cred)?;
unsafe {
Expand Down Expand Up @@ -124,31 +124,32 @@ pub extern "C" fn anoncreds_process_w3c_credential(
/// Convert credential in legacy form into W3C AnonCreds credential form
///
/// # Params
/// cred: object handle pointing to credential in legacy form to convert
/// cred_def: object handle pointing to the credential definition
/// version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain converted credential (in W3C form) instance pointer
/// cred: object handle pointing to credential in legacy form to convert
/// cred_def: object handle pointing to the credential definition
/// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// cred_p: reference that will contain converted credential (in W3C form) instance pointer
///
/// # Returns
/// Error code
#[no_mangle]
pub extern "C" fn anoncreds_credential_to_w3c(
cred: ObjectHandle,
cred_def: ObjectHandle,
version: FfiStr,
w3c_version: FfiStr,
cred_p: *mut ObjectHandle,
) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(cred_p);

let credential = cred.load()?;
let credential = credential.cast_ref::<Credential>()?;
let version = match version.as_opt_str() {
let w3c_version = match w3c_version.as_opt_str() {
Some(value) => Some(VerifiableCredentialSpecVersion::try_from(value)?),
None => None,
};

let w3c_credential = credential_to_w3c(credential, cred_def.load()?.cast_ref()?, version)?;
let w3c_credential =
credential_to_w3c(credential, cred_def.load()?.cast_ref()?, w3c_version)?;
let w3c_cred = ObjectHandle::create(w3c_credential)?;

unsafe { *cred_p = w3c_cred };
Expand Down Expand Up @@ -190,7 +191,7 @@ pub extern "C" fn anoncreds_credential_from_w3c(
///
/// # Params
/// handle: object handle pointing to the credential (in W3 form)
/// result_p: reference that will contain credential information
/// cred_proof_info_p: reference that will contain credential information
///
/// # Returns
/// Error code
Expand Down
8 changes: 4 additions & 4 deletions src/ffi/w3c/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl_anoncreds_object_from_json!(W3CPresentation, anoncreds_w3c_presentation_fro
/// schema_ids: list of schemas ids
/// cred_defs: list of credential definitions
/// cred_def_ids: list of credential definitions ids
/// version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// w3c_version: version of w3c verifiable credential specification (1.1 or 2.0) to use
/// presentation_p: reference that will contain created presentation (in W3C form) instance pointer.
///
/// # Returns
Expand All @@ -42,7 +42,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation(
schema_ids: FfiStrList,
cred_defs: FfiList<ObjectHandle>,
cred_def_ids: FfiStrList,
version: FfiStr,
w3c_version: FfiStr,
presentation_p: *mut ObjectHandle,
) -> ErrorCode {
catch_error(|| {
Expand All @@ -53,7 +53,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation(
let schemas = _prepare_schemas(schemas, schema_ids)?;
let credentials = _credentials(credentials)?;
let present_creds = _present_credentials(&credentials, credentials_prove)?;
let version = match version.as_opt_str() {
let w3c_version = match w3c_version.as_opt_str() {
Some(value) => Some(VerifiableCredentialSpecVersion::try_from(value)?),
None => None,
};
Expand All @@ -64,7 +64,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation(
&link_secret,
&schemas,
&cred_defs,
version,
w3c_version,
)?;

let presentation = ObjectHandle::create(presentation)?;
Expand Down

0 comments on commit cb837a5

Please sign in to comment.