diff --git a/docs/design/w3c/w3c-representation.md b/docs/design/w3c/w3c-representation.md index 5c6e0d44..c6e97642 100644 --- a/docs/design/w3c/w3c-representation.md +++ b/docs/design/w3c/w3c-representation.md @@ -47,10 +47,10 @@ 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 @@ -58,7 +58,7 @@ Methods purpose - have to forms of credentials (probably even duplicate in walle pub extern "C" fn anoncreds_credential_to_w3c( cred: ObjectHandle, cred_def: ObjectHandle, - version: FfiStr, + w3c_version: FfiStr, cred_p: *mut ObjectHandle, ) -> ErrorCode {} @@ -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 @@ -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 {} @@ -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 @@ -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 @@ -198,6 +198,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation( cred_defs: FfiList, cred_def_ids: FfiStrList, presentation_p: *mut ObjectHandle, + w3c_version: FfiStr, ) -> ErrorCode {} /// Verity W3C styled Presentation diff --git a/src/data_types/w3c/credential.rs b/src/data_types/w3c/credential.rs index 58093540..5fe7b64a 100644 --- a/src/data_types/w3c/credential.rs +++ b/src/data_types/w3c/credential.rs @@ -34,7 +34,7 @@ pub struct W3CCredential { pub id: Option, // 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, #[serde(skip_serializing_if = "Option::is_none")] @@ -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, } } @@ -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(()) diff --git a/src/data_types/w3c/proof.rs b/src/data_types/w3c/proof.rs index 979ca212..a20dfa96 100644 --- a/src/data_types/w3c/proof.rs +++ b/src/data_types/w3c/proof.rs @@ -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, diff --git a/src/ffi/w3c/credential.rs b/src/ffi/w3c/credential.rs index a7f45119..b2f5b9e6 100644 --- a/src/ffi/w3c/credential.rs +++ b/src/ffi/w3c/credential.rs @@ -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 @@ -44,7 +44,7 @@ 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(|| { @@ -52,7 +52,7 @@ pub extern "C" fn anoncreds_create_w3c_credential( 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, }; @@ -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 { @@ -124,10 +124,10 @@ 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 @@ -135,7 +135,7 @@ pub extern "C" fn anoncreds_process_w3c_credential( 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(|| { @@ -143,12 +143,13 @@ pub extern "C" fn anoncreds_credential_to_w3c( let credential = cred.load()?; let credential = credential.cast_ref::()?; - 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 }; @@ -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 diff --git a/src/ffi/w3c/presentation.rs b/src/ffi/w3c/presentation.rs index ac30d986..01f6d64a 100644 --- a/src/ffi/w3c/presentation.rs +++ b/src/ffi/w3c/presentation.rs @@ -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 @@ -42,7 +42,7 @@ pub extern "C" fn anoncreds_create_w3c_presentation( schema_ids: FfiStrList, cred_defs: FfiList, cred_def_ids: FfiStrList, - version: FfiStr, + w3c_version: FfiStr, presentation_p: *mut ObjectHandle, ) -> ErrorCode { catch_error(|| { @@ -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, }; @@ -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)?;