From 313f1d10c64152a4f8d12550f9583592b8c115fc Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 5 Sep 2023 12:00:59 -0700 Subject: [PATCH 1/4] remove RevocationRegistryId; simplify parameters to create_credential Signed-off-by: Andrew Whitehead --- src/data_types/credential.rs | 7 +++-- src/data_types/macros.rs | 3 +- src/data_types/pres_request.rs | 3 -- src/data_types/presentation.rs | 6 ++-- src/data_types/rev_reg.rs | 3 -- src/ffi/credential.rs | 56 ++++++++++++++++++---------------- src/ffi/object.rs | 1 - src/services/issuer.rs | 27 ++++++++-------- src/services/types.rs | 4 ++- src/services/verifier.rs | 5 ++- tests/anoncreds_demos.rs | 21 ++----------- tests/utils/mock.rs | 52 +++++++++++-------------------- tests/utils/mod.rs | 2 ++ tests/utils/storage.rs | 6 ++-- 14 files changed, 80 insertions(+), 116 deletions(-) diff --git a/src/data_types/credential.rs b/src/data_types/credential.rs index 03bf97d0..24f8bee0 100644 --- a/src/data_types/credential.rs +++ b/src/data_types/credential.rs @@ -5,13 +5,14 @@ use crate::cl::{CredentialSignature, RevocationRegistry, SignatureCorrectnessPro use crate::error::{ConversionError, ValidationError}; use crate::utils::validation::Validatable; -use super::{cred_def::CredentialDefinitionId, rev_reg::RevocationRegistryId, schema::SchemaId}; +use super::rev_reg_def::RevocationRegistryDefinitionId; +use super::{cred_def::CredentialDefinitionId, schema::SchemaId}; #[derive(Debug, Deserialize, Serialize)] pub struct Credential { pub schema_id: SchemaId, pub cred_def_id: CredentialDefinitionId, - pub rev_reg_id: Option, + pub rev_reg_id: Option, pub values: CredentialValues, pub signature: CredentialSignature, pub signature_correctness_proof: SignatureCorrectnessProof, @@ -73,7 +74,7 @@ pub struct CredentialInfo { pub attrs: ShortCredentialValues, pub schema_id: SchemaId, pub cred_def_id: CredentialDefinitionId, - pub rev_reg_id: Option, + pub rev_reg_id: Option, pub cred_rev_id: Option, } diff --git a/src/data_types/macros.rs b/src/data_types/macros.rs index 726eba73..4dab0d0e 100644 --- a/src/data_types/macros.rs +++ b/src/data_types/macros.rs @@ -44,8 +44,7 @@ macro_rules! impl_anoncreds_object_identifier { "IssuerId" => &LEGACY_DID_IDENTIFIER, "CredentialDefinitionId" => &LEGACY_CRED_DEF_IDENTIFIER, "SchemaId" => &LEGACY_SCHEMA_IDENTIFIER, - // TODO: we do not have correct validation for a revocation registry and definition id - "RevocationRegistryId" => &LEGACY_DID_IDENTIFIER, + // TODO: we do not have correct validation for a revocation registry definition id "RevocationRegistryDefinitionId" => &LEGACY_DID_IDENTIFIER, invalid_name => { return Err($crate::invalid!( diff --git a/src/data_types/pres_request.rs b/src/data_types/pres_request.rs index 41e6bcc6..d41f5b86 100644 --- a/src/data_types/pres_request.rs +++ b/src/data_types/pres_request.rs @@ -118,9 +118,6 @@ impl Serialize for PresentationRequest { } } -#[allow(unused)] -pub type PresentationRequestExtraQuery = HashMap; - #[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct NonRevokedInterval { pub from: Option, diff --git a/src/data_types/presentation.rs b/src/data_types/presentation.rs index f21db30e..fe506eba 100644 --- a/src/data_types/presentation.rs +++ b/src/data_types/presentation.rs @@ -4,7 +4,9 @@ use crate::cl::Proof; use crate::error::ValidationError; use crate::utils::validation::Validatable; -use super::{cred_def::CredentialDefinitionId, rev_reg::RevocationRegistryId, schema::SchemaId}; +use super::{ + cred_def::CredentialDefinitionId, rev_reg_def::RevocationRegistryDefinitionId, schema::SchemaId, +}; #[derive(Debug, Deserialize, Serialize)] pub struct Presentation { @@ -55,7 +57,7 @@ pub struct AttributeValue { pub struct Identifier { pub schema_id: SchemaId, pub cred_def_id: CredentialDefinitionId, - pub rev_reg_id: Option, + pub rev_reg_id: Option, pub timestamp: Option, } diff --git a/src/data_types/rev_reg.rs b/src/data_types/rev_reg.rs index 1e37f422..273b1122 100644 --- a/src/data_types/rev_reg.rs +++ b/src/data_types/rev_reg.rs @@ -1,7 +1,4 @@ use crate::cl::RevocationRegistry as CryptoRevocationRegistry; -use crate::impl_anoncreds_object_identifier; - -impl_anoncreds_object_identifier!(RevocationRegistryId); #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RevocationRegistry { diff --git a/src/ffi/credential.rs b/src/ffi/credential.rs index d314f0c3..0855650e 100644 --- a/src/ffi/credential.rs +++ b/src/ffi/credential.rs @@ -7,7 +7,6 @@ use super::error::{catch_error, ErrorCode}; use super::object::{AnoncredsObject, ObjectHandle}; use super::util::FfiStrList; use crate::data_types::link_secret::LinkSecret; -use crate::data_types::rev_reg::RevocationRegistryId; use crate::error::Result; use crate::services::{ issuer::create_credential, @@ -15,27 +14,49 @@ use crate::services::{ types::{Credential, CredentialRevocationConfig, MakeCredentialValues}, utils::encode_credential_attribute, }; +use crate::Error; #[derive(Debug)] #[repr(C)] pub struct FfiCredRevInfo { reg_def: ObjectHandle, reg_def_private: ObjectHandle, + status_list: ObjectHandle, reg_idx: i64, } struct RevocationConfig { reg_def: AnoncredsObject, reg_def_private: AnoncredsObject, + status_list: AnoncredsObject, reg_idx: u32, } -impl RevocationConfig { - pub fn as_ref_config(&self) -> Result { +impl TryFrom<&FfiCredRevInfo> for RevocationConfig { + type Error = Error; + + fn try_from(value: &FfiCredRevInfo) -> Result { + Ok(Self { + reg_def: value.reg_def.load()?, + reg_def_private: value.reg_def_private.load()?, + reg_idx: value + .reg_idx + .try_into() + .map_err(|_| err_msg!("Invalid revocation index"))?, + status_list: value.status_list.load()?, + }) + } +} + +impl<'a> TryFrom<&'a RevocationConfig> for CredentialRevocationConfig<'a> { + type Error = Error; + + fn try_from(value: &'a RevocationConfig) -> Result { Ok(CredentialRevocationConfig { - reg_def: self.reg_def.cast_ref()?, - reg_def_private: self.reg_def_private.cast_ref()?, - registry_idx: self.reg_idx, + reg_def: value.reg_def.cast_ref()?, + reg_def_private: value.reg_def_private.cast_ref()?, + registry_idx: value.reg_idx, + status_list: value.status_list.cast_ref()?, }) } } @@ -49,8 +70,6 @@ pub extern "C" fn anoncreds_create_credential( attr_names: FfiStrList, attr_raw_values: FfiStrList, attr_enc_values: FfiStrList, - rev_reg_id: FfiStr, - rev_status_list: ObjectHandle, revocation: *const FfiCredRevInfo, cred_p: *mut ObjectHandle, ) -> ErrorCode { @@ -64,10 +83,6 @@ pub extern "C" fn anoncreds_create_credential( "Mismatch between length of attribute names and raw values" )); } - let rev_reg_id = rev_reg_id - .as_opt_str() - .map(RevocationRegistryId::new) - .transpose()?; let enc_values = attr_enc_values.as_slice(); let mut cred_values = MakeCredentialValues::default(); for (attr_idx, (name, raw)) in attr_names @@ -99,14 +114,7 @@ pub extern "C" fn anoncreds_create_credential( None } else { let revocation = unsafe { &*revocation }; - Some(RevocationConfig { - reg_def: revocation.reg_def.load()?, - reg_def_private: revocation.reg_def_private.load()?, - reg_idx: revocation - .reg_idx - .try_into() - .map_err(|_| err_msg!("Invalid revocation index"))?, - }) + Some(RevocationConfig::try_from(revocation)?) }; let cred = create_credential( @@ -115,15 +123,9 @@ pub extern "C" fn anoncreds_create_credential( cred_offer.load()?.cast_ref()?, cred_request.load()?.cast_ref()?, cred_values.into(), - rev_reg_id, - rev_status_list - .opt_load()? - .as_ref() - .map(AnoncredsObject::cast_ref) - .transpose()?, revocation_config .as_ref() - .map(RevocationConfig::as_ref_config) + .map(TryInto::try_into) .transpose()?, )?; let cred = ObjectHandle::create(cred)?; diff --git a/src/ffi/object.rs b/src/ffi/object.rs index cbe30402..484d1be7 100644 --- a/src/ffi/object.rs +++ b/src/ffi/object.rs @@ -202,7 +202,6 @@ impl AnoncredsObjectList { Ok(Self(loaded)) } - #[allow(unused)] pub fn refs(&self) -> Result> where T: AnyAnoncredsObject + 'static, diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 13379963..7b682c81 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -1,7 +1,6 @@ use crate::cl::{Issuer, RevocationRegistry as CryptoRevocationRegistry}; use crate::data_types::cred_def::CredentialDefinitionId; use crate::data_types::issuer_id::IssuerId; -use crate::data_types::rev_reg::RevocationRegistryId; use crate::data_types::rev_reg_def::RevocationRegistryDefinitionId; use crate::data_types::schema::SchemaId; use crate::data_types::{ @@ -708,8 +707,6 @@ pub fn create_credential( cred_offer: &CredentialOffer, cred_request: &CredentialRequest, cred_values: CredentialValues, - rev_reg_id: Option, - rev_status_list: Option<&RevocationStatusList>, revocation_config: Option, ) -> Result { trace!("create_credential >>> cred_def: {:?}, cred_def_private: {:?}, cred_offer.nonce: {:?}, cred_request: {:?},\ @@ -724,12 +721,10 @@ pub fn create_credential( ))?; let credential_values = build_credential_values(&cred_values.0, None)?; - let (credential_signature, signature_correctness_proof, rev_reg, witness) = - if let (Some(revocation_config), Some(rev_status_list)) = - (revocation_config, rev_status_list) - { - let rev_reg_def = &revocation_config.reg_def.value; - let rev_reg: Option = rev_status_list.into(); + let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) = + if let Some(rev_config) = revocation_config { + let rev_reg_def: &RevocationRegistryDefinitionValue = &rev_config.reg_def.value; + let rev_reg: Option = rev_config.status_list.into(); let mut rev_reg = rev_reg.ok_or_else(|| { err_msg!( Unexpected, @@ -737,12 +732,13 @@ pub fn create_credential( ) })?; - let status = rev_status_list - .get(revocation_config.registry_idx as usize) + let status = rev_config + .status_list + .get(rev_config.registry_idx as usize) .ok_or_else(|| { err_msg!( "Revocation status list does not have the index {}", - revocation_config.registry_idx + rev_config.registry_idx ) })?; @@ -770,15 +766,16 @@ pub fn create_credential( &credential_values, &cred_public_key, &cred_def_private.value, - revocation_config.registry_idx, + rev_config.registry_idx, rev_reg_def.max_cred_num, issuance_by_default, &mut rev_reg, - &revocation_config.reg_def_private.value, + &rev_config.reg_def_private.value, )?; ( credential_signature, signature_correctness_proof, + rev_config.status_list.id(), Some(rev_reg), Some(witness), ) @@ -793,7 +790,7 @@ pub fn create_credential( &cred_public_key, &cred_def_private.value, )?; - (signature, correctness_proof, None, None) + (signature, correctness_proof, None, None, None) }; let credential = Credential { diff --git a/src/services/types.rs b/src/services/types.rs index 945728e9..f2861b0e 100644 --- a/src/services/types.rs +++ b/src/services/types.rs @@ -217,6 +217,7 @@ impl Validatable for CredentialRevocationState { pub struct CredentialRevocationConfig<'a> { pub reg_def: &'a RevocationRegistryDefinition, pub reg_def_private: &'a RevocationRegistryDefinitionPrivate, + pub status_list: &'a RevocationStatusList, pub registry_idx: u32, } @@ -224,9 +225,10 @@ impl<'a> std::fmt::Debug for CredentialRevocationConfig<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "CredentialRevocationConfig {{ reg_def: {:?}, private: {:?}, idx: {} }}", + "CredentialRevocationConfig {{ reg_def: {:?}, private: {:?}, status_list: {:?}, idx: {} }}", self.reg_def, secret!(self.reg_def_private), + self.status_list, secret!(self.registry_idx), ) } diff --git a/src/services/verifier.rs b/src/services/verifier.rs index 1db07f9c..5b660a8a 100644 --- a/src/services/verifier.rs +++ b/src/services/verifier.rs @@ -863,7 +863,6 @@ fn is_attr_operator(key: &str) -> bool { #[cfg(test)] mod tests { use super::*; - use crate::data_types::rev_reg::RevocationRegistryId; pub const SCHEMA_ID: &str = "123"; pub const SCHEMA_NAME: &str = "Schema Name"; @@ -1180,7 +1179,7 @@ mod tests { timestamp: Some(1234), schema_id: SchemaId::default(), cred_def_id: CredentialDefinitionId::default(), - rev_reg_id: Some(RevocationRegistryId::default()), + rev_reg_id: Some(RevocationRegistryDefinitionId::default()), }, ); res.insert( @@ -1189,7 +1188,7 @@ mod tests { timestamp: None, schema_id: SchemaId::default(), cred_def_id: CredentialDefinitionId::default(), - rev_reg_id: Some(RevocationRegistryId::default()), + rev_reg_id: Some(RevocationRegistryDefinitionId::default()), }, ); res diff --git a/tests/anoncreds_demos.rs b/tests/anoncreds_demos.rs index d13594b4..beef89a2 100644 --- a/tests/anoncreds_demos.rs +++ b/tests/anoncreds_demos.rs @@ -1,5 +1,4 @@ use anoncreds::data_types::cred_def::CredentialDefinitionId; -use anoncreds::data_types::rev_reg::RevocationRegistryId; use anoncreds::data_types::rev_reg_def::RevocationRegistryDefinitionId; use anoncreds::data_types::schema::SchemaId; use anoncreds::issuer; @@ -53,8 +52,6 @@ fn anoncreds_demo_works_for_single_issuer_single_prover() { &cred_request, cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -206,7 +203,7 @@ fn anoncreds_demo_works_with_revocation_for_single_issuer_single_prover() { let ((gvt_rev_reg_def, gvt_rev_reg_def_priv), gvt_rev_reg_def_id) = fixtures::create_rev_reg_def(&gvt_cred_def, &mut tf); - // Issuer creates reovcation status list - to be put on the ledger + // Issuer creates revocation status list - to be put on the ledger let time_create_rev_status_list = 12; let gvt_revocation_status_list = fixtures::create_revocation_status_list( &gvt_cred_def, @@ -239,7 +236,6 @@ fn anoncreds_demo_works_with_revocation_for_single_issuer_single_prover() { let cred_values = fixtures::credential_values("GVT"); let gvt_rev_reg_def_id = RevocationRegistryDefinitionId::new_unchecked(gvt_rev_reg_def_id); - let gvt_rev_reg_id = RevocationRegistryId::new_unchecked(gvt_rev_reg_def_id.clone()); // Get the location of the tails_file so it can be read let tails_location = gvt_rev_reg_def.value.tails_location.clone(); @@ -250,12 +246,11 @@ fn anoncreds_demo_works_with_revocation_for_single_issuer_single_prover() { &cred_offer, &cred_request, cred_values.into(), - Some(gvt_rev_reg_id), - Some(&gvt_revocation_status_list), Some(CredentialRevocationConfig { reg_def: &gvt_rev_reg_def, reg_def_private: &gvt_rev_reg_def_priv, registry_idx: fixtures::GVT_REV_IDX, + status_list: &gvt_revocation_status_list, }), ) .expect("Error creating credential"); @@ -452,8 +447,6 @@ fn anoncreds_demo_works_for_multiple_issuer_single_prover() { &gvt_cred_request, gvt_cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -494,8 +487,6 @@ fn anoncreds_demo_works_for_multiple_issuer_single_prover() { &emp_cred_request, emp_cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -624,8 +615,6 @@ fn anoncreds_demo_proof_does_not_verify_with_wrong_attr_and_predicates() { &cred_request, cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -753,8 +742,6 @@ fn anoncreds_demo_works_for_requested_attribute_in_upper_case() { &cred_request, cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -931,8 +918,6 @@ fn anoncreds_demo_works_for_twice_entry_of_attribute_from_different_credential() &gvt_cred_request, gvt_cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); @@ -973,8 +958,6 @@ fn anoncreds_demo_works_for_twice_entry_of_attribute_from_different_credential() &emp_cred_request, emp_cred_values.into(), None, - None, - None, ) .expect("Error creating credential"); diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index 042d969b..2fb5d190 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -10,7 +10,6 @@ use anoncreds::{ cred_offer::CredentialOffer, credential::Credential, presentation::Presentation, - rev_reg::RevocationRegistryId, rev_reg_def::RevocationRegistryDefinitionId, schema::{Schema, SchemaId}, }, @@ -23,23 +22,14 @@ use anoncreds::{ verifier, }; -#[allow(unused)] +#[derive(Debug)] pub struct TestError(String); -// {cred_def_id: { -// schema_id, credential_values, support_revocation, rev_reg_id, rev_idx -// }} -#[allow(unused)] pub type IssuerValues<'a> = HashMap<&'a str, (&'a str, HashMap<&'a str, &'a str>, bool, &'a str, u32)>; -// {cred_def_id: { -// attribute_per_credential, predicate_for_credential }} -#[allow(unused)] pub type ProverValues<'a> = HashMap<&'a str, (Vec<&'a str>, Vec<&'a str>)>; -// { rev_reg_def_id: {req_timestamp, override_timestamp} } -#[allow(unused)] pub type Override<'a> = HashMap>; #[derive(Debug)] @@ -52,7 +42,6 @@ pub struct Mock<'a> { } impl<'a> Mock<'a> { - #[allow(unused)] pub fn new( issuer_ids: &[&'a str], prover_ids: &[&'a str], @@ -77,7 +66,6 @@ impl<'a> Mock<'a> { } } - #[allow(unused)] pub fn verifer_verifies_presentations_for_requests( &self, presentations: &[Presentation], @@ -101,7 +89,7 @@ impl<'a> Mock<'a> { ); let mut rev_status_lists = vec![]; - self.ledger.revcation_list.iter().for_each(|(_, v)| { + self.ledger.revocation_list.iter().for_each(|(_, v)| { v.iter() .for_each(|(_, list)| rev_status_lists.push(list.clone())) }); @@ -132,7 +120,6 @@ impl<'a> Mock<'a> { // issuer wallet holds all data relating to cred def and rev def // prover wallet contains the cred offers from the credentials // ledger holds the rev reg def / rev reg info - #[allow(unused)] pub fn issuer_setup( &mut self, issuer_id: &'static str, @@ -202,7 +189,7 @@ impl<'a> Mock<'a> { ) .unwrap(); - self.ledger.revcation_list.insert( + self.ledger.revocation_list.insert( rev_reg_id, HashMap::from([(time_now, revocation_status_list)]), ); @@ -246,7 +233,6 @@ impl<'a> Mock<'a> { } } - #[allow(unused)] fn issuer_create_credential( &self, issuer_wallet: &IssuerWallet, @@ -262,7 +248,7 @@ impl<'a> Mock<'a> { let schema = self.ledger.schemas.get(&offer.schema_id).unwrap(); let revocation_list = self .ledger - .revcation_list + .revocation_list .get(rev_reg_id) .and_then(|h| h.get(&prev_rev_reg_time)); let mut cred_values = MakeCredentialValues::default(); @@ -280,17 +266,20 @@ impl<'a> Mock<'a> { } } - let (rev_config, rev_id) = match issuer_wallet.rev_defs.get(rev_reg_id) { - Some(stored_rev_def) => ( - Some(CredentialRevocationConfig { + let rev_config = issuer_wallet + .rev_defs + .get(rev_reg_id) + .map(|stored_rev_def| { + Result::<_, TestError>::Ok(CredentialRevocationConfig { reg_def: &stored_rev_def.public, reg_def_private: &stored_rev_def.private, registry_idx: rev_idx, - }), - Some(RevocationRegistryId::new_unchecked(rev_reg_id)), - ), - None => (None, None), - }; + status_list: revocation_list + .ok_or_else(|| TestError("Missing status list".to_string()))?, + }) + }) + .transpose() + .expect("Error creating revocation config"); let issue_cred = issuer::create_credential( ledger @@ -301,8 +290,6 @@ impl<'a> Mock<'a> { offer, cred_request, cred_values.into(), - rev_id, - revocation_list, rev_config, ) .expect("Error creating credential"); @@ -312,7 +299,6 @@ impl<'a> Mock<'a> { // prover requests and gets credential stored in their wallets // This updates ledger on revocation reg also - #[allow(unused)] pub fn issuer_create_credential_and_store_in_prover_wallet( &mut self, issuer_id: &'static str, @@ -380,7 +366,7 @@ impl<'a> Mock<'a> { if let Some(rev_def) = rev_def { let list = self .ledger - .revcation_list + .revocation_list .get(*rev_reg_id) .unwrap() .get(&time_prev_rev_reg) @@ -397,13 +383,12 @@ impl<'a> Mock<'a> { ) .unwrap(); - let map = self.ledger.revcation_list.get_mut(rev_reg_id).unwrap(); + let map = self.ledger.revocation_list.get_mut(rev_reg_id).unwrap(); map.insert(time_new_rev_reg, updated_list); } } } - #[allow(unused)] pub fn prover_creates_revocation_states( &mut self, prover_id: &'static str, @@ -414,7 +399,7 @@ impl<'a> Mock<'a> { if let Some(id) = &cred.rev_reg_id { let rev_status_list = self .ledger - .revcation_list + .revocation_list .get(id.to_string().as_str()) .unwrap() .get(&time_to_update_to) @@ -434,7 +419,6 @@ impl<'a> Mock<'a> { self.prover_wallets.get_mut(prover_id).unwrap().rev_states = rev_states; } - #[allow(unused)] pub fn prover_creates_presentation( &self, prover_id: &'static str, diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 793f6a03..08e2f4ae 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + pub mod fixtures; pub mod mock; pub mod storage; diff --git a/tests/utils/storage.rs b/tests/utils/storage.rs index c1bbb1f3..9d9f7185 100644 --- a/tests/utils/storage.rs +++ b/tests/utils/storage.rs @@ -1,7 +1,6 @@ use anoncreds::data_types::cred_def::{CredentialDefinition, CredentialDefinitionId}; use anoncreds::data_types::credential::Credential; use anoncreds::data_types::link_secret::LinkSecret; -use anoncreds::data_types::rev_reg::RevocationRegistryId; use anoncreds::data_types::rev_reg_def::{ RevocationRegistryDefinition, RevocationRegistryDefinitionId, RevocationRegistryDefinitionPrivate, @@ -31,7 +30,7 @@ pub struct Ledger<'a> { pub cred_defs: HashMap, pub schemas: HashMap, pub rev_reg_defs: HashMap, - pub revcation_list: HashMap<&'a str, HashMap>, + pub revocation_list: HashMap<&'a str, HashMap>, } // A struct for keeping all issuer-related objects together @@ -47,7 +46,8 @@ pub struct IssuerWallet<'a> { #[derive(Debug)] pub struct ProverWallet<'a> { pub credentials: Vec, - pub rev_states: HashMap, Option)>, + pub rev_states: + HashMap, Option)>, pub link_secret: LinkSecret, pub cred_offers: HashMap<&'a str, CredentialOffer>, pub cred_reqs: Vec<(CredentialRequest, CredentialRequestMetadata)>, From 63c186fe5aaa31961845a83b4c882ce46ed7eeaf Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 5 Sep 2023 12:01:13 -0700 Subject: [PATCH 2/4] update python wrapper Signed-off-by: Andrew Whitehead --- wrappers/python/anoncreds/bindings.py | 21 +++-- wrappers/python/anoncreds/types.py | 83 ++++++++++++------ wrappers/python/demo/test.py | 119 ++++++++------------------ 3 files changed, 105 insertions(+), 118 deletions(-) diff --git a/wrappers/python/anoncreds/bindings.py b/wrappers/python/anoncreds/bindings.py index bdf212fe..28122f8b 100644 --- a/wrappers/python/anoncreds/bindings.py +++ b/wrappers/python/anoncreds/bindings.py @@ -397,6 +397,7 @@ class RevocationConfig(Structure): _fields_ = [ ("rev_reg_def", ObjectHandle), ("rev_reg_def_private", ObjectHandle), + ("rev_status_list", ObjectHandle), ("rev_reg_index", c_int64), ] @@ -405,14 +406,16 @@ def create( cls, rev_reg_def: AnoncredsObject, rev_reg_def_private: AnoncredsObject, + rev_status_list: AnoncredsObject, rev_reg_index: int, ) -> "RevocationConfig": config = RevocationConfig( rev_reg_def=rev_reg_def.handle, rev_reg_def_private=rev_reg_def_private.handle, + rev_status_list=rev_status_list.handle, rev_reg_index=rev_reg_index, ) - keepalive(config, rev_reg_def, rev_reg_def_private) + keepalive(config, rev_reg_def, rev_reg_def_private, rev_status_list) return config @@ -632,8 +635,6 @@ def create_credential( cred_request: ObjectHandle, attr_raw_values: Mapping[str, str], attr_enc_values: Optional[Mapping[str, str]], - rev_reg_id: Optional[str], - rev_status_list: Optional[ObjectHandle], revocation_config: Optional[RevocationConfig], ) -> ObjectHandle: cred = ObjectHandle() @@ -656,9 +657,9 @@ def create_credential( names_list, raw_values_list, enc_values_list, - encode_str(rev_reg_id), - rev_status_list if rev_status_list else ObjectHandle(), - pointer(revocation_config) if revocation_config else POINTER(RevocationConfig)(), + pointer(revocation_config) + if revocation_config + else POINTER(RevocationConfig)(), byref(cred), ) return cred @@ -786,14 +787,16 @@ def verify_presentation( rev_reg_def_ids: Optional[Sequence[str]], rev_reg_defs: Optional[Sequence[ObjectHandle]], rev_status_lists: Optional[Sequence[ObjectHandle]], - nonrevoked_interval_overrides: Optional[Sequence[NonrevokedIntervalOverride]] + nonrevoked_interval_overrides: Optional[Sequence[NonrevokedIntervalOverride]], ) -> bool: verify = c_int8() nonrevoked_interval_overrides_list = NonrevokedIntervalOverrideList() if nonrevoked_interval_overrides: nonrevoked_interval_overrides_list.count = len(nonrevoked_interval_overrides) - nonrevoked_interval_overrides_list.data = (NonrevokedIntervalOverride * nonrevoked_interval_overrides.count)(*nonrevoked_interval_overrides) + nonrevoked_interval_overrides_list.data = ( + NonrevokedIntervalOverride * nonrevoked_interval_overrides.count + )(*nonrevoked_interval_overrides) do_call( "anoncreds_verify_presentation", @@ -899,7 +902,7 @@ def update_revocation_status_list_timestamp_only( "anoncreds_update_revocation_status_list_timestamp_only", c_int64(timestamp), rev_current_list.handle, - byref(new_revocation_status_list) + byref(new_revocation_status_list), ) return new_revocation_status_list diff --git a/wrappers/python/anoncreds/types.py b/wrappers/python/anoncreds/types.py index 6dc0ae07..46ab4f14 100644 --- a/wrappers/python/anoncreds/types.py +++ b/wrappers/python/anoncreds/types.py @@ -2,6 +2,7 @@ from . import bindings + class CredentialDefinition(bindings.AnoncredsObject): GET_ATTR = "anoncreds_credential_definition_get_attribute" @@ -124,7 +125,9 @@ def create( link_secret_id, cred_offer.handle, ) - return CredentialRequest(cred_def_handle), CredentialRequestMetadata(cred_def_metadata) + return CredentialRequest(cred_def_handle), CredentialRequestMetadata( + cred_def_metadata + ) @classmethod def load(cls, value: Union[dict, str, bytes, memoryview]) -> "CredentialRequest": @@ -144,6 +147,7 @@ def load( ) ) + class RevocationRegistryDefinition(bindings.AnoncredsObject): GET_ATTR = "anoncreds_revocation_registry_definition_get_attribute" @@ -158,10 +162,7 @@ def create( max_cred_num: int, *, tails_dir_path: str = None, - ) -> Tuple[ - "RevocationRegistryDefinition", - "RevocationRegistryDefinitionPrivate", - ]: + ) -> Tuple["RevocationRegistryDefinition", "RevocationRegistryDefinitionPrivate",]: if not isinstance(cred_def, bindings.AnoncredsObject): cred_def = CredentialDefinition.load(cred_def) ( @@ -223,6 +224,7 @@ def tails_location(self) -> str: ) ) + class Schema(bindings.AnoncredsObject): @classmethod def create( @@ -238,6 +240,7 @@ def create( def load(cls, value: Union[dict, str, bytes, memoryview]) -> "Schema": return Schema(bindings._object_from_json("anoncreds_schema_from_json", value)) + class Credential(bindings.AnoncredsObject): GET_ATTR = "anoncreds_credential_get_attribute" @@ -250,8 +253,6 @@ def create( cred_request: Union[str, CredentialRequest], attr_raw_values: Mapping[str, str], attr_enc_values: Optional[Mapping[str, str]] = None, - rev_reg_id: Optional[str] = None, - rev_status_list: Optional["RevocationStatusList"] = None, revocation_config: Optional["CredentialRevocationConfig"] = None, ) -> "Credential": if not isinstance(cred_def, bindings.AnoncredsObject): @@ -269,8 +270,6 @@ def create( cred_request.handle, attr_raw_values, attr_enc_values, - rev_reg_id, - rev_status_list.handle if rev_status_list else None, revocation_config._native if revocation_config else None, ) return Credential(cred) @@ -278,7 +277,7 @@ def create( def process( self, cred_req_metadata: Union[str, CredentialRequestMetadata], - link_secret: str, + link_secret: str, cred_def: Union[str, CredentialDefinition], rev_reg_def: Optional[Union[str, "RevocationRegistryDefinition"]] = None, ) -> "Credential": @@ -438,15 +437,15 @@ def create( ] creds = [] creds_prove = [] - for (cred, cred_ts) in present_creds.entries.items(): - for (timestamp, (attrs, preds, rev_state)) in cred_ts.items(): + for cred, cred_ts in present_creds.entries.items(): + for timestamp, (attrs, preds, rev_state) in cred_ts.items(): entry_idx = len(creds) creds.append( bindings.CredentialEntry.create( cred, timestamp, rev_state and rev_state ) ) - for (reft, reveal) in attrs: + for reft, reveal in attrs: creds_prove.append( bindings.CredentialProve.attribute(entry_idx, reft, reveal) ) @@ -479,9 +478,13 @@ def verify( pres_req: Union[str, PresentationRequest], schemas: Mapping[str, Union[str, Schema]], cred_defs: Mapping[str, Union[str, CredentialDefinition]], - rev_reg_defs: Optional[Mapping[str, Union[str, "RevocationRegistryDefinition"]]] = None, + rev_reg_defs: Optional[ + Mapping[str, Union[str, "RevocationRegistryDefinition"]] + ] = None, rev_status_lists: Optional[Sequence[Union[str, "RevocationStatusList"]]] = None, - nonrevoked_interval_overrides: Optional[Sequence["NonrevokedIntervalOverride"]] = None + nonrevoked_interval_overrides: Optional[ + Sequence["NonrevokedIntervalOverride"] + ] = None, ) -> bool: if not isinstance(pres_req, bindings.AnoncredsObject): pres_req = PresentationRequest.load(pres_req) @@ -508,7 +511,9 @@ def verify( rev_reg_def_ids = list(rev_reg_defs.keys()) rev_reg_def_handles = [ ( - RevocationRegistryDefinition.load(r) if not isinstance(r, bindings.AnoncredsObject) else r + RevocationRegistryDefinition.load(r) + if not isinstance(r, bindings.AnoncredsObject) + else r ).handle for r in rev_reg_defs.values() ] @@ -519,7 +524,9 @@ def verify( if rev_status_lists: rev_status_list_handles = [ ( - RevocationStatusList.load(r) if not isinstance(r, bindings.AnoncredsObject) else r + RevocationStatusList.load(r) + if not isinstance(r, bindings.AnoncredsObject) + else r ).handle for r in rev_status_lists ] @@ -564,7 +571,9 @@ def create( cred_def: Union[dict, str, bytes, CredentialDefinition], rev_reg_def_id: str, rev_reg_def: Union[dict, str, bytes, RevocationRegistryDefinition], - rev_reg_def_private: Union[dict, str, bytes, RevocationRegistryDefinitionPrivate], + rev_reg_def_private: Union[ + dict, str, bytes, RevocationRegistryDefinitionPrivate + ], issuer_id: str, issuance_by_default: bool = True, timestamp: Optional[int] = None, @@ -585,19 +594,27 @@ def create( ) @classmethod - def load(self, value: Union[dict, str, bytes, memoryview]) -> "RevocationStatusList": + def load( + self, value: Union[dict, str, bytes, memoryview] + ) -> "RevocationStatusList": return RevocationStatusList( - bindings._object_from_json("anoncreds_revocation_status_list_from_json", value) + bindings._object_from_json( + "anoncreds_revocation_status_list_from_json", value + ) ) def update_timestamp_only(self, timestamp: int): - self.handle = bindings.update_revocation_status_list_timestamp_only(timestamp, self.handle) + self.handle = bindings.update_revocation_status_list_timestamp_only( + timestamp, self.handle + ) def update( self, cred_def: Union[dict, str, bytes, CredentialDefinition], rev_reg_def: Union[dict, str, bytes, RevocationRegistryDefinition], - rev_reg_def_private: Union[dict, str, bytes, RevocationRegistryDefinitionPrivate], + rev_reg_def_private: Union[ + dict, str, bytes, RevocationRegistryDefinitionPrivate + ], issued: Optional[Sequence[int]], revoked: Optional[Sequence[int]], timestamp: Optional[int], @@ -624,11 +641,13 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "RevocationRegistry bindings._object_from_json("anoncreds_revocation_registry_from_json", value) ) + class CredentialRevocationConfig: def __init__( self, rev_reg_def: Union[str, "RevocationRegistryDefinition"], rev_reg_def_private: Union[str, "RevocationRegistryDefinitionPrivate"], + rev_status_list: Union[str, "RevocationStatusList"], rev_reg_index: int, ): if not isinstance(rev_reg_def, bindings.AnoncredsObject): @@ -638,7 +657,10 @@ def __init__( rev_reg_def_private = RevocationRegistryDefinitionPrivate.load( rev_reg_def_private ) + if not isinstance(rev_status_list, bindings.AnoncredsObject): + rev_status_list = RevocationStatusList.load(rev_status_list) self.rev_reg_def_private = rev_reg_def_private + self.rev_status_list = rev_status_list self.rev_reg_index = rev_reg_index @property @@ -646,15 +668,17 @@ def _native(self) -> bindings.RevocationConfig: return bindings.RevocationConfig.create( self.rev_reg_def, self.rev_reg_def_private, + self.rev_status_list, self.rev_reg_index, ) + class NonrevokedIntervalOverride: def __init__( self, rev_reg_def_id: str, requested_from_ts: int, - override_rev_status_list_ts: int + override_rev_status_list_ts: int, ): self.rev_reg_def_id = rev_reg_def_id self.requested_from_ts = requested_from_ts @@ -665,9 +689,10 @@ def _native(self) -> bindings.NonrevokedIntervalOverride: return bindings.NonrevokedIntervalOverride.create( self.rev_reg_def_id, self.requested_from_ts, - self.override_rev_status_list_ts + self.override_rev_status_list_ts, ) + class CredentialRevocationState(bindings.AnoncredsObject): @classmethod def create( @@ -688,7 +713,9 @@ def create( if rev_state and not isinstance(rev_state, bindings.AnoncredsObject): rev_state = CredentialRevocationState.load(rev_state) - if old_rev_status_list and not isinstance(old_rev_status_list, bindings.AnoncredsObject): + if old_rev_status_list and not isinstance( + old_rev_status_list, bindings.AnoncredsObject + ): old_rev_status_list = RevocationStatusList.load(old_rev_status_list) return CredentialRevocationState( @@ -722,7 +749,9 @@ def update( rev_reg_def = RevocationRegistryDefinition.load(rev_reg_def) if not isinstance(rev_status_list, bindings.AnoncredsObject): rev_status_list = RevocationStatusList.load(rev_status_list) - if old_rev_status_list and not isinstance(old_rev_status_list, bindings.AnoncredsObject): + if old_rev_status_list and not isinstance( + old_rev_status_list, bindings.AnoncredsObject + ): old_rev_status_list = RevocationStatusList.load(old_rev_status_list) self.handle = bindings.create_or_update_revocation_state( @@ -731,5 +760,5 @@ def update( rev_reg_index, tails_path, self.handle, - old_rev_status_list.handle if old_rev_status_list else None + old_rev_status_list.handle if old_rev_status_list else None, ) diff --git a/wrappers/python/demo/test.py b/wrappers/python/demo/test.py index b2da6d4b..14a1f4c1 100644 --- a/wrappers/python/demo/test.py +++ b/wrappers/python/demo/test.py @@ -15,31 +15,23 @@ Schema, ) -issuer_id = "mock:uri" -schema_id = "mock:uri" +issuer_id = "mock:uri" +schema_id = "mock:uri" cred_def_id = "mock:uri" -rev_reg_id = "mock:uri:revregid" -entropy = "entropy" +rev_reg_id = "mock:uri:revregid" +entropy = "entropy" rev_idx = 1 -schema = Schema.create("schema name", "schema version", issuer_id, ["name","age","sex","height"]) +schema = Schema.create( + "schema name", "schema version", issuer_id, ["name", "age", "sex", "height"] +) cred_def_pub, cred_def_priv, cred_def_correctness = CredentialDefinition.create( - schema_id, - schema, - issuer_id, - "tag", - "CL", - support_revocation=True + schema_id, schema, issuer_id, "tag", "CL", support_revocation=True ) (rev_reg_def_pub, rev_reg_def_private) = RevocationRegistryDefinition.create( - cred_def_id, - cred_def_pub, - issuer_id, - "some_tag", - "CL_ACCUM", - 10 + cred_def_id, cred_def_pub, issuer_id, "some_tag", "CL_ACCUM", 10 ) time_create_rev_status_list = 12 @@ -56,19 +48,10 @@ link_secret = create_link_secret() link_secret_id = "default" -cred_offer = CredentialOffer.create( - schema_id, - cred_def_id, - cred_def_correctness -) +cred_offer = CredentialOffer.create(schema_id, cred_def_id, cred_def_correctness) cred_request, cred_request_metadata = CredentialRequest.create( - entropy, - None, - cred_def_pub, - link_secret, - link_secret_id, - cred_offer + entropy, None, cred_def_pub, link_secret, link_secret_id, cred_offer ) issue_cred = Credential.create( @@ -76,27 +59,18 @@ cred_def_priv, cred_offer, cred_request, - { - "sex": "male", - "name": "Alex", - "height": "175", - "age": "28" - }, + {"sex": "male", "name": "Alex", "height": "175", "age": "28"}, None, - rev_reg_id, - revocation_status_list, CredentialRevocationConfig( rev_reg_def_pub, rev_reg_def_private, + revocation_status_list, rev_idx, ), ) recv_cred = issue_cred.process( - cred_request_metadata, - link_secret, - cred_def_pub, - rev_reg_def_pub + cred_request_metadata, link_secret, cred_def_pub, rev_reg_def_pub ) time_after_creating_cred = time_create_rev_status_list + 1 @@ -113,25 +87,18 @@ pres_req = PresentationRequest.load( { "nonce": nonce, - "name":"pres_req_1", - "version":"0.1", - "requested_attributes":{ - "attr1_referent":{ - "name":"name", - "issuer_id": issuer_id - }, - "attr2_referent":{ - "name":"sex" - }, - "attr3_referent":{"name":"phone"}, - "attr4_referent":{ - "names": ["name", "height"] - } + "name": "pres_req_1", + "version": "0.1", + "requested_attributes": { + "attr1_referent": {"name": "name", "issuer_id": issuer_id}, + "attr2_referent": {"name": "sex"}, + "attr3_referent": {"name": "phone"}, + "attr4_referent": {"names": ["name", "height"]}, }, - "requested_predicates":{ - "predicate1_referent":{"name":"age","p_type":">=","p_value":18} + "requested_predicates": { + "predicate1_referent": {"name": "age", "p_type": ">=", "p_value": 18} }, - "non_revoked": {"from": 10, "to": 200} + "non_revoked": {"from": 10, "to": 200}, } ) @@ -142,9 +109,9 @@ rev_reg_def_pub.tails_location, ) -schemas = { schema_id: schema } -cred_defs = { cred_def_id: cred_def_pub } -rev_reg_defs = { rev_reg_id: rev_reg_def_pub } +schemas = {schema_id: schema} +cred_defs = {cred_def_id: cred_def_pub} +rev_reg_defs = {rev_reg_id: rev_reg_def_pub} rev_status_lists = [issued_rev_status_list] present = PresentCredentials() @@ -154,7 +121,7 @@ "attr1_referent", reveal=True, timestamp=time_after_creating_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_attributes( @@ -162,7 +129,7 @@ "attr2_referent", reveal=False, timestamp=time_after_creating_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_attributes( @@ -170,14 +137,14 @@ "attr4_referent", reveal=True, timestamp=time_after_creating_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_predicates( recv_cred, "predicate1_referent", timestamp=time_after_creating_cred, - rev_state=rev_state + rev_state=rev_state, ) presentation = Presentation.create( @@ -190,11 +157,7 @@ ) verified = presentation.verify( - pres_req, - schemas, - cred_defs, - rev_reg_defs, - rev_status_lists + pres_req, schemas, cred_defs, rev_reg_defs, rev_status_lists ) assert verified @@ -226,7 +189,7 @@ "attr1_referent", reveal=True, timestamp=time_revoke_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_attributes( @@ -234,7 +197,7 @@ "attr2_referent", reveal=False, timestamp=time_revoke_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_attributes( @@ -242,23 +205,15 @@ "attr4_referent", reveal=True, timestamp=time_revoke_cred, - rev_state=rev_state + rev_state=rev_state, ) present.add_predicates( - recv_cred, - "predicate1_referent", - timestamp=time_revoke_cred, - rev_state=rev_state + recv_cred, "predicate1_referent", timestamp=time_revoke_cred, rev_state=rev_state ) presentation = Presentation.create( - pres_req, - present, - {"attr3_referent": "8-800-300"}, - link_secret, - schemas, - cred_defs + pres_req, present, {"attr3_referent": "8-800-300"}, link_secret, schemas, cred_defs ) verified = presentation.verify( From 98d6c29a755931922b0357be7838a1c008e640ad Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 5 Sep 2023 12:16:46 -0700 Subject: [PATCH 3/4] fix doc tests Signed-off-by: Andrew Whitehead --- src/services/issuer.rs | 2 -- src/services/prover.rs | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 7b682c81..f4aa8691 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -695,8 +695,6 @@ pub fn create_credential_offer( /// &credential_offer, /// &credential_request, /// credential_values.into(), -/// None, -/// None, /// None /// ).expect("Unable to create credential"); /// ``` diff --git a/src/services/prover.rs b/src/services/prover.rs index f80849ad..d58b94d5 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -228,8 +228,6 @@ pub fn create_credential_request( /// &credential_offer, /// &credential_request, /// credential_values.into(), -/// None, -/// None, /// None /// ).expect("Unable to create credential"); /// @@ -341,8 +339,6 @@ pub fn process_credential( /// &credential_offer, /// &credential_request, /// credential_values.into(), -/// None, -/// None, /// None /// ).expect("Unable to create credential"); /// From 557c8f4e696697a7e724d94008f79958651c1d83 Mon Sep 17 00:00:00 2001 From: Ariel Gentile Date: Thu, 7 Sep 2023 17:25:55 -0300 Subject: [PATCH 4/4] fix(js): create credential parameters Signed-off-by: Ariel Gentile --- include/libanoncreds.h | 3 +-- .../anoncreds-nodejs/src/NodeJSAnoncreds.ts | 25 ++++++------------- .../anoncreds-nodejs/src/ffi/structures.ts | 1 + .../anoncreds-nodejs/src/library/bindings.ts | 2 -- .../anoncreds-nodejs/test/api.test.ts | 6 ++--- .../anoncreds-nodejs/test/bindings.test.ts | 6 ++--- .../anoncreds-react-native/cpp/anoncreds.cpp | 9 +------ .../cpp/include/libanoncreds.h | 3 +-- .../src/NativeBindings.ts | 3 +-- .../src/ReactNativeAnoncreds.ts | 3 +-- .../anoncreds-shared/src/Anoncreds.ts | 3 +-- .../anoncreds-shared/src/api/Credential.ts | 11 +------- .../src/api/CredentialRevocationConfig.ts | 5 ++++ 13 files changed, 24 insertions(+), 56 deletions(-) diff --git a/include/libanoncreds.h b/include/libanoncreds.h index 875e3f69..26129996 100644 --- a/include/libanoncreds.h +++ b/include/libanoncreds.h @@ -176,6 +176,7 @@ typedef struct FfiList_FfiStr FfiStrList; typedef struct FfiCredRevInfo { ObjectHandle reg_def; ObjectHandle reg_def_private; + ObjectHandle status_list; int64_t reg_idx; } FfiCredRevInfo; @@ -263,8 +264,6 @@ ErrorCode anoncreds_create_credential(ObjectHandle cred_def, FfiStrList attr_names, FfiStrList attr_raw_values, FfiStrList attr_enc_values, - FfiStr rev_reg_id, - ObjectHandle rev_status_list, const struct FfiCredRevInfo *revocation, ObjectHandle *cred_p); diff --git a/wrappers/javascript/anoncreds-nodejs/src/NodeJSAnoncreds.ts b/wrappers/javascript/anoncreds-nodejs/src/NodeJSAnoncreds.ts index 20e60e75..83aa29f7 100644 --- a/wrappers/javascript/anoncreds-nodejs/src/NodeJSAnoncreds.ts +++ b/wrappers/javascript/anoncreds-nodejs/src/NodeJSAnoncreds.ts @@ -147,17 +147,10 @@ export class NodeJSAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record attributeEncodedValues?: Record - revocationRegistryId?: string - revocationStatusList?: ObjectHandle revocationConfiguration?: NativeCredentialRevocationConfig }): ObjectHandle { - const { - credentialDefinition, - credentialDefinitionPrivate, - credentialOffer, - credentialRequest, - revocationRegistryId, - } = serializeArguments(options) + const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = + serializeArguments(options) const attributeNames = StringListStruct({ count: Object.keys(options.attributeRawValues).length, @@ -178,15 +171,13 @@ export class NodeJSAnoncreds implements Anoncreds { let revocationConfiguration if (options.revocationConfiguration) { - const { - revocationRegistryDefinition: registryDefinition, - revocationRegistryDefinitionPrivate: registryDefinitionPrivate, - registryIndex, - } = serializeArguments(options.revocationConfiguration) + const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = + serializeArguments(options.revocationConfiguration) revocationConfiguration = CredRevInfoStruct({ - reg_def: registryDefinition, - reg_def_private: registryDefinitionPrivate, + reg_def: revocationRegistryDefinition, + reg_def_private: revocationRegistryDefinitionPrivate, + status_list: revocationStatusList, reg_idx: registryIndex, }) } @@ -200,8 +191,6 @@ export class NodeJSAnoncreds implements Anoncreds { attributeNames as unknown as Buffer, attributeRawValues as unknown as Buffer, attributeEncodedValues as unknown as Buffer, - revocationRegistryId, - options.revocationStatusList?.handle ?? 0, revocationConfiguration?.ref().address() ?? 0, credentialPtr ) diff --git a/wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts b/wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts index aba0ac3a..fbb408f7 100644 --- a/wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts +++ b/wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts @@ -50,6 +50,7 @@ export const I32ListStruct = CStruct({ export const CredRevInfoStruct = CStruct({ reg_def: FFI_OBJECT_HANDLE, reg_def_private: FFI_OBJECT_HANDLE, + status_list: FFI_OBJECT_HANDLE, reg_idx: FFI_INT64, }) diff --git a/wrappers/javascript/anoncreds-nodejs/src/library/bindings.ts b/wrappers/javascript/anoncreds-nodejs/src/library/bindings.ts index 02c11192..488ca383 100644 --- a/wrappers/javascript/anoncreds-nodejs/src/library/bindings.ts +++ b/wrappers/javascript/anoncreds-nodejs/src/library/bindings.ts @@ -31,8 +31,6 @@ export const nativeBindings = { StringListStruct, StringListStruct, StringListStruct, - FFI_STRING, - FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE, FFI_OBJECT_HANDLE_PTR, ], diff --git a/wrappers/javascript/anoncreds-nodejs/test/api.test.ts b/wrappers/javascript/anoncreds-nodejs/test/api.test.ts index a5a91557..c5adb60b 100644 --- a/wrappers/javascript/anoncreds-nodejs/test/api.test.ts +++ b/wrappers/javascript/anoncreds-nodejs/test/api.test.ts @@ -108,11 +108,10 @@ describe('API', () => { credentialOffer, credentialRequest, attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' }, - revocationRegistryId: 'mock:uri', - revocationStatusList, revocationConfiguration: new CredentialRevocationConfig({ registryDefinition: revocationRegistryDefinition, registryDefinitionPrivate: revocationRegistryDefinitionPrivate, + statusList: revocationStatusList, registryIndex: 9, }), }) @@ -431,11 +430,10 @@ test('create and verify presentation passing only JSON objects as parameters', ( credentialOffer: credentialOffer.toJson(), credentialRequest: credentialRequest.toJson(), attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' }, - revocationRegistryId: 'mock:uri', - revocationStatusList: revocationStatusList.toJson(), revocationConfiguration: new CredentialRevocationConfig({ registryDefinition: revocationRegistryDefinition, registryDefinitionPrivate: revocationRegistryDefinitionPrivate, + statusList: revocationStatusList, registryIndex: 9, }), }) diff --git a/wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts b/wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts index 0cb22363..f109c3df 100644 --- a/wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts +++ b/wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts @@ -292,11 +292,10 @@ describe('bindings', () => { credentialOffer, credentialRequest, attributeRawValues: { 'attr-1': 'test' }, - revocationRegistryId: 'mock:uri', - revocationStatusList, revocationConfiguration: { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, + revocationStatusList, registryIndex: 9, }, }) @@ -428,11 +427,10 @@ describe('bindings', () => { credentialOffer, credentialRequest, attributeRawValues: { name: 'Alex', height: '175', age: '28', sex: 'male' }, - revocationRegistryId: 'mock:uri', - revocationStatusList, revocationConfiguration: { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, + revocationStatusList, registryIndex: 9, }, }) diff --git a/wrappers/javascript/anoncreds-react-native/cpp/anoncreds.cpp b/wrappers/javascript/anoncreds-react-native/cpp/anoncreds.cpp index 27cb626b..98646a74 100644 --- a/wrappers/javascript/anoncreds-react-native/cpp/anoncreds.cpp +++ b/wrappers/javascript/anoncreds-react-native/cpp/anoncreds.cpp @@ -465,10 +465,6 @@ jsi::Value createCredential(jsi::Runtime &rt, jsi::Object options) { jsiToValue(rt, options, "attributeRawValues"); auto attributeEncodedValues = jsiToValue(rt, options, "attributeEncodedValues", true); - auto revocationRegistryId = - jsiToValue(rt, options, "revocationRegistryId", true); - auto revocationStatusList = - jsiToValue(rt, options, "revocationStatusList", true); auto revocation = jsiToValue(rt, options, "revocationConfiguration", true); @@ -477,10 +473,7 @@ jsi::Value createCredential(jsi::Runtime &rt, jsi::Object options) { ErrorCode code = anoncreds_create_credential( credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, - attributeEncodedValues, - revocationRegistryId.length() > 0 ? revocationRegistryId.c_str() - : nullptr, - revocationStatusList, revocation.reg_def ? &revocation : 0, &out); + attributeEncodedValues, revocation.reg_def ? &revocation : 0, &out); return createReturnValue(rt, code, &out); }; diff --git a/wrappers/javascript/anoncreds-react-native/cpp/include/libanoncreds.h b/wrappers/javascript/anoncreds-react-native/cpp/include/libanoncreds.h index 875e3f69..26129996 100644 --- a/wrappers/javascript/anoncreds-react-native/cpp/include/libanoncreds.h +++ b/wrappers/javascript/anoncreds-react-native/cpp/include/libanoncreds.h @@ -176,6 +176,7 @@ typedef struct FfiList_FfiStr FfiStrList; typedef struct FfiCredRevInfo { ObjectHandle reg_def; ObjectHandle reg_def_private; + ObjectHandle status_list; int64_t reg_idx; } FfiCredRevInfo; @@ -263,8 +264,6 @@ ErrorCode anoncreds_create_credential(ObjectHandle cred_def, FfiStrList attr_names, FfiStrList attr_raw_values, FfiStrList attr_enc_values, - FfiStr rev_reg_id, - ObjectHandle rev_status_list, const struct FfiCredRevInfo *revocation, ObjectHandle *cred_p); diff --git a/wrappers/javascript/anoncreds-react-native/src/NativeBindings.ts b/wrappers/javascript/anoncreds-react-native/src/NativeBindings.ts index 53a8c319..fe386fee 100644 --- a/wrappers/javascript/anoncreds-react-native/src/NativeBindings.ts +++ b/wrappers/javascript/anoncreds-react-native/src/NativeBindings.ts @@ -59,12 +59,11 @@ export interface NativeBindings { attributeNames: string[] attributeRawValues: string[] attributeEncodedValues?: string[] - revocationRegistryId?: string - revocationStatusList?: number revocationConfiguration?: { registryIndex: number revocationRegistryDefinition: number revocationRegistryDefinitionPrivate: number + revocationStatusList?: number } }): ReturnObject encodeCredentialAttributes(options: { attributeRawValues: Array }): ReturnObject diff --git a/wrappers/javascript/anoncreds-react-native/src/ReactNativeAnoncreds.ts b/wrappers/javascript/anoncreds-react-native/src/ReactNativeAnoncreds.ts index 9eb8152a..feaffd6a 100644 --- a/wrappers/javascript/anoncreds-react-native/src/ReactNativeAnoncreds.ts +++ b/wrappers/javascript/anoncreds-react-native/src/ReactNativeAnoncreds.ts @@ -120,8 +120,6 @@ export class ReactNativeAnoncreds implements Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record attributeEncodedValues?: Record - revocationRegistryId?: string - revocationStatusList?: ObjectHandle revocationConfiguration?: NativeCredentialRevocationConfig }): ObjectHandle { const attributeNames = Object.keys(options.attributeRawValues) @@ -142,6 +140,7 @@ export class ReactNativeAnoncreds implements Anoncreds { revocationRegistryDefinition: options.revocationConfiguration.revocationRegistryDefinition.handle, revocationRegistryDefinitionPrivate: options.revocationConfiguration.revocationRegistryDefinitionPrivate.handle, + revocationStatusList: options.revocationConfiguration.revocationStatusList.handle, } : undefined, }) diff --git a/wrappers/javascript/anoncreds-shared/src/Anoncreds.ts b/wrappers/javascript/anoncreds-shared/src/Anoncreds.ts index dbb40e27..a1c93433 100644 --- a/wrappers/javascript/anoncreds-shared/src/Anoncreds.ts +++ b/wrappers/javascript/anoncreds-shared/src/Anoncreds.ts @@ -31,6 +31,7 @@ export type NativeRevocationEntry = { export type NativeCredentialRevocationConfig = { revocationRegistryDefinition: ObjectHandle revocationRegistryDefinitionPrivate: ObjectHandle + revocationStatusList: ObjectHandle registryIndex: number } @@ -64,8 +65,6 @@ export interface Anoncreds { credentialRequest: ObjectHandle attributeRawValues: Record attributeEncodedValues?: Record - revocationRegistryId?: string - revocationStatusList?: ObjectHandle revocationConfiguration?: NativeCredentialRevocationConfig }): ObjectHandle diff --git a/wrappers/javascript/anoncreds-shared/src/api/Credential.ts b/wrappers/javascript/anoncreds-shared/src/api/Credential.ts index 0130a72a..226a4c55 100644 --- a/wrappers/javascript/anoncreds-shared/src/api/Credential.ts +++ b/wrappers/javascript/anoncreds-shared/src/api/Credential.ts @@ -1,6 +1,7 @@ import type { ObjectHandle } from '../ObjectHandle' import type { JsonObject } from '../types' import type { CredentialRevocationConfig } from './CredentialRevocationConfig' +import type { RevocationStatusList } from './RevocationStatusList' import { AnoncredsObject } from '../AnoncredsObject' import { anoncreds } from '../register' @@ -11,7 +12,6 @@ import { CredentialOffer } from './CredentialOffer' import { CredentialRequest } from './CredentialRequest' import { CredentialRequestMetadata } from './CredentialRequestMetadata' import { RevocationRegistryDefinition } from './RevocationRegistryDefinition' -import { RevocationStatusList } from './RevocationStatusList' import { pushToArray } from './utils' export type CreateCredentialOptions = { @@ -59,13 +59,6 @@ export class Credential extends AnoncredsObject { ? options.credentialRequest.handle : pushToArray(CredentialRequest.fromJson(options.credentialRequest).handle, objectHandles) - const revocationStatusList = - options.revocationStatusList instanceof RevocationStatusList - ? options.revocationStatusList.handle - : options.revocationStatusList !== undefined - ? pushToArray(RevocationStatusList.fromJson(options.revocationStatusList).handle, objectHandles) - : undefined - credential = anoncreds.createCredential({ credentialDefinition, credentialDefinitionPrivate, @@ -73,9 +66,7 @@ export class Credential extends AnoncredsObject { credentialRequest, attributeRawValues: options.attributeRawValues, attributeEncodedValues: options.attributeEncodedValues, - revocationRegistryId: options.revocationRegistryId, revocationConfiguration: options.revocationConfiguration?.native, - revocationStatusList, }) } finally { objectHandles.forEach((handle) => handle.clear()) diff --git a/wrappers/javascript/anoncreds-shared/src/api/CredentialRevocationConfig.ts b/wrappers/javascript/anoncreds-shared/src/api/CredentialRevocationConfig.ts index 70914762..16a73348 100644 --- a/wrappers/javascript/anoncreds-shared/src/api/CredentialRevocationConfig.ts +++ b/wrappers/javascript/anoncreds-shared/src/api/CredentialRevocationConfig.ts @@ -1,21 +1,25 @@ import type { NativeCredentialRevocationConfig } from '../Anoncreds' import type { RevocationRegistryDefinition } from './RevocationRegistryDefinition' import type { RevocationRegistryDefinitionPrivate } from './RevocationRegistryDefinitionPrivate' +import type { RevocationStatusList } from './RevocationStatusList' export type CredentialRevocationConfigOptions = { registryDefinition: RevocationRegistryDefinition registryDefinitionPrivate: RevocationRegistryDefinitionPrivate + statusList: RevocationStatusList registryIndex: number } export class CredentialRevocationConfig { private registryDefinition: RevocationRegistryDefinition private registryDefinitionPrivate: RevocationRegistryDefinitionPrivate + private statusList: RevocationStatusList private registryIndex: number public constructor(options: CredentialRevocationConfigOptions) { this.registryDefinition = options.registryDefinition this.registryDefinitionPrivate = options.registryDefinitionPrivate + this.statusList = options.statusList this.registryIndex = options.registryIndex } @@ -28,6 +32,7 @@ export class CredentialRevocationConfig { return { revocationRegistryDefinition: this.registryDefinition.handle, revocationRegistryDefinitionPrivate: this.registryDefinitionPrivate.handle, + revocationStatusList: this.statusList.handle, registryIndex: this.registryIndex, } }