From 0c2168ac377ea652be5d4d1017e2c83a13d02e95 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 11:59:27 +0300 Subject: [PATCH 1/8] Fixing clippy lints Signed-off-by: Bogdan Mircea --- src/data_types/rev_status_list.rs | 2 +- src/utils/query.rs | 10 ++++----- tests/multiple-credentials.rs | 10 ++++----- tests/utils/mock.rs | 37 ++++++++++++++----------------- tests/utils/storage.rs | 11 +-------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/data_types/rev_status_list.rs b/src/data_types/rev_status_list.rs index cae1525e..481f8636 100644 --- a/src/data_types/rev_status_list.rs +++ b/src/data_types/rev_status_list.rs @@ -253,7 +253,7 @@ mod rev_reg_tests { list.update(None, Some(BTreeSet::from([0u32])), None, Some(1245)) .unwrap(); - assert_eq!(list.get(0usize).unwrap(), false); + assert!(!list.get(0usize).unwrap()); assert_eq!(list.timestamp().unwrap(), 1245); } } diff --git a/src/utils/query.rs b/src/utils/query.rs index 03d57247..e5cf5684 100644 --- a/src/utils/query.rs +++ b/src/utils/query.rs @@ -2860,9 +2860,9 @@ mod tests { #[test] fn test_old_format_empty() { - let json = format!(r#"[]"#); + let json = r#"[]"#; - let query: Query = ::serde_json::from_str(&json).unwrap(); + let query: Query = ::serde_json::from_str(json).unwrap(); let expected = Query::And(vec![]); @@ -2876,8 +2876,8 @@ mod tests { let value1 = _random_string(10); let json = json!(vec![ - json ! ({name1.clone(): value1.clone()}), - json!({ name2.clone(): ::serde_json::Value::Null }) + json!({ &name1: value1 }), + json!({ name2: ::serde_json::Value::Null }) ]) .to_string(); @@ -2901,7 +2901,7 @@ mod tests { fn test_optimise_or() { let json = r#"[]"#; - let query: Query = ::serde_json::from_str(&json).unwrap(); + let query: Query = ::serde_json::from_str(json).unwrap(); assert_eq!(query.optimise(), None); } diff --git a/tests/multiple-credentials.rs b/tests/multiple-credentials.rs index 431d94db..00a19a0b 100644 --- a/tests/multiple-credentials.rs +++ b/tests/multiple-credentials.rs @@ -33,10 +33,10 @@ const SCHEMA_ID_1: &str = "mock:uri:schema1"; const SCHEMA_ID_2: &str = "mock:uri:schema2"; const SCHEMA_1: &str = r#"{"name":"gvt","version":"1.0","attrNames":["name","sex","age","height"],"issuerId":"mock:issuer_id/path&q=bar"}"#; const SCHEMA_2: &str = r#"{"name":"hogwarts","version":"1.0","attrNames":["wand","house","year"],"issuerId":"mock:issuer_id/path&q=hogwarts"}"#; -static CRED_DEF_ID_1: &'static str = "mock:uri:1"; -static CRED_DEF_ID_2: &'static str = "mock:uri:2"; -static REV_REG_ID_1: &'static str = "mock:uri:revregid1"; -static REV_REG_ID_2: &'static str = "mock:uri:revregid2"; +static CRED_DEF_ID_1: &str = "mock:uri:1"; +static CRED_DEF_ID_2: &str = "mock:uri:2"; +static REV_REG_ID_1: &str = "mock:uri:revregid1"; +static REV_REG_ID_2: &str = "mock:uri:revregid2"; fn create_request(input: &ReqInput) -> PresentationRequest { let nonce = verifier::generate_nonce().unwrap(); @@ -222,7 +222,7 @@ fn anoncreds_with_multiple_credentials_per_request() { // [4]: no NRP required let reqs: Vec = test_requests_generate() .iter() - .map(|x| create_request(&x)) + .map(create_request) .collect(); // 1: Issuer setup (credate cred defs, rev defs(optional), cred_offers) diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index e85e3d2e..5937242c 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -98,7 +98,7 @@ impl<'a> Mock<'a> { for (i, presentation) in presentations.iter().enumerate() { let valid = verifier::verify_presentation( - &presentation, + presentation, &reqs[i], &schemas, &cred_defs, @@ -165,7 +165,7 @@ impl<'a> Mock<'a> { let iw_mut = self.issuer_wallets.get_mut(issuer_id).unwrap(); iw_mut.rev_defs.insert( - &rev_reg_id, + rev_reg_id, StoredRevDef { public: rev_reg_def_pub.clone(), private: rev_reg_def_priv, @@ -250,8 +250,7 @@ impl<'a> Mock<'a> { .ledger .revcation_list .get(rev_reg_id) - .map(|h| h.get(&prev_rev_reg_time)) - .flatten(); + .and_then(|h| h.get(&prev_rev_reg_time)); let mut cred_values = MakeCredentialValues::default(); let names: Vec = schema.attr_names.clone().0.into_iter().collect(); for (i, v) in names.iter().enumerate() { @@ -286,7 +285,7 @@ impl<'a> Mock<'a> { }; let issue_cred = issuer::create_credential( - &ledger + ledger .cred_defs .get(&CredentialDefinitionId::new_unchecked(cred_def_id)) .unwrap(), @@ -319,16 +318,16 @@ impl<'a> Mock<'a> { let cred_def = self .ledger .cred_defs - .get(&CredentialDefinitionId::new_unchecked(cred_def_id.clone())) + .get(&CredentialDefinitionId::new_unchecked(*cred_def_id)) .unwrap(); // Prover creates a Credential Request let cred_req_data = prover::create_credential_request( Some("entropy"), None, - &cred_def, + cred_def, &self.prover_wallets[prover_id].link_secret, "default", - &offer, + offer, ) .expect("Error creating credential request"); @@ -337,8 +336,8 @@ impl<'a> Mock<'a> { &self.issuer_wallets[issuer_id], &self.ledger, &cred_req_data.0, - &offer, - *rev_reg_id, + offer, + rev_reg_id, cred_def_id, cred_values, time_prev_rev_reg, @@ -360,7 +359,7 @@ impl<'a> Mock<'a> { &mut recv_cred, &cred_req_data.1, &self.prover_wallets[prover_id].link_secret, - &cred_def, + cred_def, rev_def, ) .expect("Error processing credential"); @@ -390,7 +389,7 @@ impl<'a> Mock<'a> { ) .unwrap(); - let map = self.ledger.revcation_list.get_mut(&*rev_reg_id).unwrap(); + let map = self.ledger.revcation_list.get_mut(rev_reg_id).unwrap(); map.insert(time_new_rev_reg, updated_list); } } @@ -446,31 +445,29 @@ impl<'a> Mock<'a> { .unwrap(); { let (rev_state, timestamp) = if let Some(id) = &cred.rev_reg_id { - self.prover_wallets[prover_id].rev_states.get(&id).unwrap() + self.prover_wallets[prover_id].rev_states.get(id).unwrap() } else { &(None, None) }; let mut cred1 = present.add_credential(cred, *timestamp, rev_state.as_ref()); for a in &values.0 { - cred1.add_requested_attribute(a.clone(), true); + cred1.add_requested_attribute(*a, true); } for p in &values.1 { - cred1.add_requested_predicate(p.clone()); + cred1.add_requested_predicate(*p); } } } - let presentation = prover::create_presentation( + prover::create_presentation( req, present, - Some(self_attested.clone()), + Some(self_attested), &self.prover_wallets[prover_id].link_secret, &schemas, &cred_defs, ) - .expect("Error creating presentation"); - - presentation + .expect("Error creating presentation") } } diff --git a/tests/utils/storage.rs b/tests/utils/storage.rs index adbffab5..c1bbb1f3 100644 --- a/tests/utils/storage.rs +++ b/tests/utils/storage.rs @@ -35,7 +35,7 @@ pub struct Ledger<'a> { } // A struct for keeping all issuer-related objects together -#[derive(Debug)] +#[derive(Debug, Default)] pub struct IssuerWallet<'a> { // cred_def_id: StoredRevDef pub cred_defs: HashMap<&'a str, StoredCredDef>, @@ -43,15 +43,6 @@ pub struct IssuerWallet<'a> { pub rev_defs: HashMap<&'a str, StoredRevDef>, } -impl<'a> Default for IssuerWallet<'a> { - fn default() -> Self { - Self { - cred_defs: HashMap::new(), - rev_defs: HashMap::new(), - } - } -} - // A struct for keeping all issuer-related objects together #[derive(Debug)] pub struct ProverWallet<'a> { From 63e3a4602af7519d6b2c342449a5a819befe457a Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 12:11:04 +0300 Subject: [PATCH 2/8] Simplified create_schema signature Signed-off-by: Bogdan Mircea --- src/data_types/cred_def.rs | 2 +- src/data_types/cred_request.rs | 3 ++- src/ffi/schema.rs | 3 ++- src/services/issuer.rs | 16 +++++++--------- src/services/prover.rs | 10 ++++++++-- tests/utils/fixtures.rs | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/data_types/cred_def.rs b/src/data_types/cred_def.rs index 248880a1..de327a79 100644 --- a/src/data_types/cred_def.rs +++ b/src/data_types/cred_def.rs @@ -97,7 +97,7 @@ mod test_cred_def { issuer::create_schema( "name", "1.0", - "did:example", + "did:example".try_into().unwrap(), vec!["name".to_owned(), "age".to_owned()].into(), ) .expect("Unable to create Schema") diff --git a/src/data_types/cred_request.rs b/src/data_types/cred_request.rs index fc9c9246..22f5c7aa 100644 --- a/src/data_types/cred_request.rs +++ b/src/data_types/cred_request.rs @@ -125,7 +125,8 @@ mod cred_req_tests { let credential_definition_issuer_id = "sample:id"; let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); - let schema = create_schema("schema:name", "1.0", "sample:uri", attr_names)?; + let issuer_id = "sample:uri".try_into()?; + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( "schema:id", &schema, diff --git a/src/ffi/schema.rs b/src/ffi/schema.rs index c407ad5e..88cd36b2 100644 --- a/src/ffi/schema.rs +++ b/src/ffi/schema.rs @@ -24,7 +24,8 @@ pub extern "C" fn anoncreds_create_schema( .ok_or_else(|| err_msg!("Missing schema version"))?; let issuer_id = issuer_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing issuer_id"))?; + .ok_or_else(|| err_msg!("Missing issuer_id"))? + .try_into()?; let schema = create_schema( schema_name, schema_version, diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 61c1a0fa..6617866f 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -45,22 +45,18 @@ use super::types::{ /// attribute_names.into() /// ).expect("Unable to create schema"); /// ``` -pub fn create_schema( +pub fn create_schema( schema_name: &str, schema_version: &str, - issuer_id: II, + issuer_id: IssuerId, attr_names: AttributeNames, -) -> Result -where - II: TryInto, -{ +) -> Result { trace!( "create_schema >>> schema_name: {}, schema_version: {}, attr_names: {:?}", schema_name, schema_version, attr_names, ); - let issuer_id = issuer_id.try_into()?; let schema = Schema { name: schema_name.to_string(), @@ -816,7 +812,8 @@ mod tests { let revocation_registry_definition_issuer_id = credential_definition_issuer_id; let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); - let schema = create_schema("schema:name", "1.0", "sample:uri", attr_names)?; + let issuer_id = "sample:uri".try_into()?; + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( "schema:id", &schema, @@ -848,7 +845,8 @@ mod tests { let revocation_registry_definition_issuer_id = "another:id"; let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); - let schema = create_schema("schema:name", "1.0", "sample:uri", attr_names)?; + let issuer_id = "sample:uri".try_into()?; + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( "schema:id", &schema, diff --git a/src/services/prover.rs b/src/services/prover.rs index 825bbfbc..3cb7d1fc 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -1135,7 +1135,13 @@ mod tests { } fn _schema() -> Schema { - create_schema("test", "1.0", ISSUER_ID, ["a", "b", "c"][..].into()).unwrap() + create_schema( + "test", + "1.0", + ISSUER_ID.try_into().unwrap(), + ["a", "b", "c"][..].into(), + ) + .unwrap() } fn _cred_def_and_key_correctness_proof( @@ -1162,7 +1168,7 @@ mod tests { create_schema( "test", "1.0", - LEGACY_DID_IDENTIFIER, + LEGACY_DID_IDENTIFIER.try_into().unwrap(), ["a", "b", "c"][..].into(), ) .unwrap() diff --git a/tests/utils/fixtures.rs b/tests/utils/fixtures.rs index 26a8b12c..16bd5216 100644 --- a/tests/utils/fixtures.rs +++ b/tests/utils/fixtures.rs @@ -55,7 +55,7 @@ pub fn create_schema(name: &str) -> (Schema, &str) { issuer::create_schema( GVT_SCHEMA_NAME, GVT_SCHEMA_VERSION, - GVT_ISSUER_ID, + GVT_ISSUER_ID.try_into().unwrap(), GVT_SCHEMA_ATTRIBUTES[..].into(), ) .expect("error while creating GVT schema"), @@ -65,7 +65,7 @@ pub fn create_schema(name: &str) -> (Schema, &str) { issuer::create_schema( EMP_SCHEMA_NAME, EMP_SCHEMA_VERSION, - EMP_ISSUER_ID, + EMP_ISSUER_ID.try_into().unwrap(), EMP_SCHEMA_ATTRIBUTES[..].into(), ) .expect("error while creating EMP schema"), From 88d525b4e099f64abab4c5581c222b95cda2b011 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 12:17:17 +0300 Subject: [PATCH 3/8] Improved the Validatable impl on AttributeNames Signed-off-by: Bogdan Mircea --- src/data_types/schema.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/data_types/schema.rs b/src/data_types/schema.rs index 119c161d..d160f5ea 100644 --- a/src/data_types/schema.rs +++ b/src/data_types/schema.rs @@ -17,6 +17,7 @@ pub struct Schema { pub issuer_id: IssuerId, } +// QUESTION: If these must be unique, why not directly store them as a set? #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct AttributeNames(pub Vec); @@ -55,11 +56,7 @@ impl Validatable for Schema { impl Validatable for AttributeNames { fn validate(&self) -> Result<(), ValidationError> { let mut unique = HashSet::new(); - let is_unique = self - .0 - .clone() - .into_iter() - .all(move |name| unique.insert(name)); + let is_unique = self.0.iter().all(move |name| unique.insert(name)); if !is_unique { return Err("Attributes inside the schema must be unique".into()); From 7eba2b81a9f573162be5e3a472341d15e3d38388 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 12:27:16 +0300 Subject: [PATCH 4/8] Removed more generics from function signatures Signed-off-by: Bogdan Mircea --- src/data_types/cred_def.rs | 8 +++--- src/data_types/cred_request.rs | 9 +++--- src/data_types/rev_status_list.rs | 9 ++---- src/ffi/cred_def.rs | 7 +++-- src/ffi/revocation.rs | 6 ++-- src/services/issuer.rs | 48 ++++++++++++++----------------- src/services/prover.rs | 8 +++--- tests/utils/fixtures.rs | 16 +++++------ tests/utils/mock.rs | 8 +++--- 9 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/data_types/cred_def.rs b/src/data_types/cred_def.rs index de327a79..88f0d17e 100644 --- a/src/data_types/cred_def.rs +++ b/src/data_types/cred_def.rs @@ -110,9 +110,9 @@ mod test_cred_def { ) { let schema = schema(); issuer::create_credential_definition( - "did:example/schema", + "did:example/schema".try_into().unwrap(), &schema, - "did:exampple", + "did:exampple".try_into().unwrap(), "default-tag", SignatureType::CL, CredentialDefinitionConfig::default(), @@ -124,9 +124,9 @@ mod test_cred_def { fn should_create_credential_definition() { let schema = schema(); let result = issuer::create_credential_definition( - "did:example/schema", + "did:example/schema".try_into().unwrap(), &schema, - "did:exampple", + "did:exampple".try_into().unwrap(), "default-tag", SignatureType::CL, CredentialDefinitionConfig::default(), diff --git a/src/data_types/cred_request.rs b/src/data_types/cred_request.rs index 22f5c7aa..8a7a3755 100644 --- a/src/data_types/cred_request.rs +++ b/src/data_types/cred_request.rs @@ -122,13 +122,14 @@ mod cred_req_tests { const LINK_SECRET_ID: &str = "link:secret:id"; fn cred_def() -> Result<(CredentialDefinition, CredentialKeyCorrectnessProof)> { - let credential_definition_issuer_id = "sample:id"; - - let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); let issuer_id = "sample:uri".try_into()?; + let schema_id = "schema:id".try_into()?; + let credential_definition_issuer_id = "sample:id".try_into()?; + let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( - "schema:id", + schema_id, &schema, credential_definition_issuer_id, "default", diff --git a/src/data_types/rev_status_list.rs b/src/data_types/rev_status_list.rs index 481f8636..c539ad92 100644 --- a/src/data_types/rev_status_list.rs +++ b/src/data_types/rev_status_list.rs @@ -41,12 +41,9 @@ impl TryFrom<&RevocationStatusList> for Option { type Error = Error; fn try_from(value: &RevocationStatusList) -> std::result::Result { - let value = match value.registry { - Some(registry) => Some(RevocationRegistry { - value: registry.into(), - }), - None => None, - }; + let value = value.registry.map(|registry| RevocationRegistry { + value: registry.into(), + }); Ok(value) } diff --git a/src/ffi/cred_def.rs b/src/ffi/cred_def.rs index ac1f3ce5..66c809e2 100644 --- a/src/ffi/cred_def.rs +++ b/src/ffi/cred_def.rs @@ -32,7 +32,8 @@ pub extern "C" fn anoncreds_create_credential_definition( let tag = tag.as_opt_str().ok_or_else(|| err_msg!("Missing tag"))?; let schema_id = schema_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing schema id"))?; + .ok_or_else(|| err_msg!("Missing schema id"))? + .try_into()?; let signature_type = { let stype = signature_type .as_opt_str() @@ -41,7 +42,9 @@ pub extern "C" fn anoncreds_create_credential_definition( }; let issuer_id = issuer_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing issuer id"))?; + .ok_or_else(|| err_msg!("Missing issuer id"))? + .try_into()?; + let (cred_def, cred_def_pvt, key_proof) = create_credential_definition( schema_id, schema.load()?.cast_ref()?, diff --git a/src/ffi/revocation.rs b/src/ffi/revocation.rs index 1567eb74..ab8e15bb 100644 --- a/src/ffi/revocation.rs +++ b/src/ffi/revocation.rs @@ -148,10 +148,12 @@ pub extern "C" fn anoncreds_create_revocation_registry_def( let tag = tag.as_opt_str().ok_or_else(|| err_msg!("Missing tag"))?; let cred_def_id = cred_def_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing cred def id"))?; + .ok_or_else(|| err_msg!("Missing cred def id"))? + .try_into()?; let issuer_id = issuer_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing issuer id"))?; + .ok_or_else(|| err_msg!("Missing issuer id"))? + .try_into()?; let rev_reg_type = { let rtype = rev_reg_type .as_opt_str() diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 6617866f..09bb5d6c 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -106,10 +106,10 @@ pub fn create_schema( /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// ``` -pub fn create_credential_definition( - schema_id: SI, +pub fn create_credential_definition( + schema_id: SchemaId, schema: &Schema, - issuer_id: II, + issuer_id: IssuerId, tag: &str, signature_type: SignatureType, config: CredentialDefinitionConfig, @@ -117,18 +117,12 @@ pub fn create_credential_definition( CredentialDefinition, CredentialDefinitionPrivate, CredentialKeyCorrectnessProof, -)> -where - SI: TryInto, - II: TryInto, -{ +)> { trace!( "create_credential_definition >>> schema: {:?}, config: {:?}", schema, config ); - let issuer_id = issuer_id.try_into()?; - let schema_id = schema_id.try_into()?; let credential_schema = build_credential_schema(&schema.attr_names.0)?; let non_credential_schema = build_non_credential_schema()?; @@ -215,8 +209,8 @@ where /// ``` pub fn create_revocation_registry_def( cred_def: &CredentialDefinition, - cred_def_id: impl TryInto, - issuer_id: impl TryInto, + cred_def_id: CredentialDefinitionId, + issuer_id: IssuerId, tag: &str, rev_reg_type: RegistryType, max_cred_num: u32, @@ -230,8 +224,6 @@ where { trace!("create_revocation_registry >>> cred_def: {:?}, tag: {:?}, max_cred_num: {:?}, rev_reg_type: {:?}", cred_def, tag, max_cred_num, rev_reg_type); - let cred_def_id = cred_def_id.try_into()?; - let issuer_id = issuer_id.try_into()?; if issuer_id != cred_def.issuer_id { return Err(err_msg!( @@ -808,14 +800,16 @@ mod tests { #[test] fn test_issuer_id_equal_in_revocation_registry_definiton_and_credential_definition( ) -> Result<()> { - let credential_definition_issuer_id = "sample:id"; - let revocation_registry_definition_issuer_id = credential_definition_issuer_id; - - let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); let issuer_id = "sample:uri".try_into()?; + let schema_id = "schema:id".try_into()?; + let cred_def_id = "sample:uri".try_into()?; + let credential_definition_issuer_id: IssuerId = "sample:id".try_into()?; + let revocation_registry_definition_issuer_id = credential_definition_issuer_id.clone(); + let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( - "schema:id", + schema_id, &schema, credential_definition_issuer_id, "default", @@ -826,7 +820,7 @@ mod tests { )?; let res = create_revocation_registry_def( &cred_def.0, - "sample:uri", + cred_def_id, revocation_registry_definition_issuer_id, "default", RegistryType::CL_ACCUM, @@ -841,14 +835,16 @@ mod tests { #[test] fn test_issuer_id_unequal_in_revocation_registry_definiton_and_credential_definition( ) -> Result<()> { - let credential_definition_issuer_id = "sample:id"; - let revocation_registry_definition_issuer_id = "another:id"; - - let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); let issuer_id = "sample:uri".try_into()?; + let schema_id = "schema:id".try_into()?; + let cred_def_id = "sample:uri".try_into()?; + let credential_definition_issuer_id: IssuerId = "sample:id".try_into()?; + let revocation_registry_definition_issuer_id = credential_definition_issuer_id.clone(); + let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( - "schema:id", + schema_id, &schema, credential_definition_issuer_id, "default", @@ -859,7 +855,7 @@ mod tests { )?; let res = create_revocation_registry_def( &cred_def.0, - "sample:uri", + cred_def_id, revocation_registry_definition_issuer_id, "default", RegistryType::CL_ACCUM, diff --git a/src/services/prover.rs b/src/services/prover.rs index 3cb7d1fc..e61d7fae 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -1147,9 +1147,9 @@ mod tests { fn _cred_def_and_key_correctness_proof( ) -> (CredentialDefinition, CredentialKeyCorrectnessProof) { let (cred_def, _, key_correctness_proof) = create_credential_definition( - SCHEMA_ID, + SCHEMA_ID.try_into().unwrap(), &_schema(), - ISSUER_ID, + ISSUER_ID.try_into().unwrap(), "tag", SignatureType::CL, CredentialDefinitionConfig { @@ -1177,9 +1177,9 @@ mod tests { fn _legacy_cred_def_and_key_correctness_proof( ) -> (CredentialDefinition, CredentialKeyCorrectnessProof) { let (cred_def, _, key_correctness_proof) = create_credential_definition( - LEGACY_SCHEMA_IDENTIFIER, + LEGACY_SCHEMA_IDENTIFIER.try_into().unwrap(), &_legacy_schema(), - LEGACY_DID_IDENTIFIER, + LEGACY_DID_IDENTIFIER.try_into().unwrap(), "tag", SignatureType::CL, CredentialDefinitionConfig { diff --git a/tests/utils/fixtures.rs b/tests/utils/fixtures.rs index 16bd5216..eea22643 100644 --- a/tests/utils/fixtures.rs +++ b/tests/utils/fixtures.rs @@ -89,9 +89,9 @@ pub fn create_cred_def( match schema.name.as_str() { GVT_SCHEMA_NAME => ( issuer::create_credential_definition( - GVT_SCHEMA_ID, + GVT_SCHEMA_ID.try_into().unwrap(), schema, - GVT_ISSUER_ID, + GVT_ISSUER_ID.try_into().unwrap(), GVT_CRED_DEF_TAG, anoncreds::types::SignatureType::CL, anoncreds::types::CredentialDefinitionConfig { support_revocation }, @@ -101,9 +101,9 @@ pub fn create_cred_def( ), EMP_SCHEMA_NAME => ( issuer::create_credential_definition( - EMP_SCHEMA_ID, + EMP_SCHEMA_ID.try_into().unwrap(), schema, - EMP_ISSUER_ID, + EMP_ISSUER_ID.try_into().unwrap(), EMP_CRED_DEF_TAG, anoncreds::types::SignatureType::CL, anoncreds::types::CredentialDefinitionConfig { support_revocation }, @@ -129,8 +129,8 @@ pub fn create_rev_reg_def<'a>( GVT_CRED_DEF_TAG => ( issuer::create_revocation_registry_def( cred_def, - GVT_CRED_DEF_ID, - GVT_ISSUER_ID, + GVT_CRED_DEF_ID.try_into().unwrap(), + GVT_ISSUER_ID.try_into().unwrap(), GVT_REV_REG_TAG, anoncreds::types::RegistryType::CL_ACCUM, GVT_REV_MAX_CRED_NUM, @@ -142,8 +142,8 @@ pub fn create_rev_reg_def<'a>( EMP_CRED_DEF_TAG => ( issuer::create_revocation_registry_def( cred_def, - EMP_CRED_DEF_ID, - EMP_ISSUER_ID, + EMP_CRED_DEF_ID.try_into().unwrap(), + EMP_ISSUER_ID.try_into().unwrap(), EMP_REV_REG_TAG, anoncreds::types::RegistryType::CL_ACCUM, EMP_REV_MAX_CRED_NUM, diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index 5937242c..2d5cb4d2 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -128,9 +128,9 @@ impl<'a> Mock<'a> { for (cred_def_id, (schema_id, _, support_revocation, rev_reg_id, _)) in values.iter() { let (cred_def_pub, cred_def_priv, cred_def_correctness) = issuer::create_credential_definition( - schema_id.to_string(), + (*schema_id).try_into().unwrap(), &self.ledger.schemas[&SchemaId::new_unchecked(*schema_id)], - issuer_id, + issuer_id.try_into().unwrap(), "tag", SignatureType::CL, CredentialDefinitionConfig { @@ -154,8 +154,8 @@ impl<'a> Mock<'a> { let mut tf = TailsFileWriter::new(Some(self.tails_path.to_owned())); let (rev_reg_def_pub, rev_reg_def_priv) = issuer::create_revocation_registry_def( &cred_def_pub, - *cred_def_id, - issuer_id, + (*cred_def_id).try_into().unwrap(), + issuer_id.try_into().unwrap(), "some_tag", RegistryType::CL_ACCUM, self.max_cred_num, From 4cb11729eb7c796b4720c1036072018ff09afa37 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 13:13:26 +0300 Subject: [PATCH 5/8] Removed redundant issuer_id as it's taken from cred_def Signed-off-by: Bogdan Mircea --- src/ffi/revocation.rs | 6 ------ src/services/issuer.rs | 15 +++------------ tests/utils/fixtures.rs | 2 -- tests/utils/mock.rs | 1 - 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/ffi/revocation.rs b/src/ffi/revocation.rs index ab8e15bb..f4484ea1 100644 --- a/src/ffi/revocation.rs +++ b/src/ffi/revocation.rs @@ -134,7 +134,6 @@ pub extern "C" fn anoncreds_update_revocation_status_list_timestamp_only( pub extern "C" fn anoncreds_create_revocation_registry_def( cred_def: ObjectHandle, cred_def_id: FfiStr, - issuer_id: FfiStr, tag: FfiStr, rev_reg_type: FfiStr, max_cred_num: i64, @@ -150,10 +149,6 @@ pub extern "C" fn anoncreds_create_revocation_registry_def( .as_opt_str() .ok_or_else(|| err_msg!("Missing cred def id"))? .try_into()?; - let issuer_id = issuer_id - .as_opt_str() - .ok_or_else(|| err_msg!("Missing issuer id"))? - .try_into()?; let rev_reg_type = { let rtype = rev_reg_type .as_opt_str() @@ -164,7 +159,6 @@ pub extern "C" fn anoncreds_create_revocation_registry_def( let (reg_def, reg_def_private) = create_revocation_registry_def( cred_def.load()?.cast_ref()?, cred_def_id, - issuer_id, tag, rev_reg_type, max_cred_num diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 09bb5d6c..f9e01ad6 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -134,6 +134,8 @@ pub fn create_credential_definition( config.support_revocation, )?; + // should be better to deconstruct the key than cloning it here + // as it's only being used here let cred_def = CredentialDefinition { schema_id, signature_type, @@ -210,7 +212,6 @@ pub fn create_credential_definition( pub fn create_revocation_registry_def( cred_def: &CredentialDefinition, cred_def_id: CredentialDefinitionId, - issuer_id: IssuerId, tag: &str, rev_reg_type: RegistryType, max_cred_num: u32, @@ -225,12 +226,6 @@ where trace!("create_revocation_registry >>> cred_def: {:?}, tag: {:?}, max_cred_num: {:?}, rev_reg_type: {:?}", cred_def, tag, max_cred_num, rev_reg_type); - if issuer_id != cred_def.issuer_id { - return Err(err_msg!( - "Issuer id must be the same as the issuer id in the credential definition" - )); - } - let credential_pub_key = cred_def.get_public_key().map_err(err_map!( Unexpected, "Error fetching public key from credential definition" @@ -256,7 +251,7 @@ where let revoc_reg_def = RevocationRegistryDefinition { revoc_def_type: rev_reg_type, - issuer_id, + issuer_id: cred_def.issuer_id.clone(), tag: tag.to_string(), cred_def_id, value: revoc_reg_def_value, @@ -804,7 +799,6 @@ mod tests { let schema_id = "schema:id".try_into()?; let cred_def_id = "sample:uri".try_into()?; let credential_definition_issuer_id: IssuerId = "sample:id".try_into()?; - let revocation_registry_definition_issuer_id = credential_definition_issuer_id.clone(); let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; @@ -821,7 +815,6 @@ mod tests { let res = create_revocation_registry_def( &cred_def.0, cred_def_id, - revocation_registry_definition_issuer_id, "default", RegistryType::CL_ACCUM, 1, @@ -839,7 +832,6 @@ mod tests { let schema_id = "schema:id".try_into()?; let cred_def_id = "sample:uri".try_into()?; let credential_definition_issuer_id: IssuerId = "sample:id".try_into()?; - let revocation_registry_definition_issuer_id = credential_definition_issuer_id.clone(); let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; @@ -856,7 +848,6 @@ mod tests { let res = create_revocation_registry_def( &cred_def.0, cred_def_id, - revocation_registry_definition_issuer_id, "default", RegistryType::CL_ACCUM, 1, diff --git a/tests/utils/fixtures.rs b/tests/utils/fixtures.rs index eea22643..1fe03fdc 100644 --- a/tests/utils/fixtures.rs +++ b/tests/utils/fixtures.rs @@ -130,7 +130,6 @@ pub fn create_rev_reg_def<'a>( issuer::create_revocation_registry_def( cred_def, GVT_CRED_DEF_ID.try_into().unwrap(), - GVT_ISSUER_ID.try_into().unwrap(), GVT_REV_REG_TAG, anoncreds::types::RegistryType::CL_ACCUM, GVT_REV_MAX_CRED_NUM, @@ -143,7 +142,6 @@ pub fn create_rev_reg_def<'a>( issuer::create_revocation_registry_def( cred_def, EMP_CRED_DEF_ID.try_into().unwrap(), - EMP_ISSUER_ID.try_into().unwrap(), EMP_REV_REG_TAG, anoncreds::types::RegistryType::CL_ACCUM, EMP_REV_MAX_CRED_NUM, diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index 2d5cb4d2..e479dbac 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -155,7 +155,6 @@ impl<'a> Mock<'a> { let (rev_reg_def_pub, rev_reg_def_priv) = issuer::create_revocation_registry_def( &cred_def_pub, (*cred_def_id).try_into().unwrap(), - issuer_id.try_into().unwrap(), "some_tag", RegistryType::CL_ACCUM, self.max_cred_num, From 3e9b33cd49430be8cea7f70853a6ff01ac4d13c5 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Mon, 31 Jul 2023 13:45:54 +0300 Subject: [PATCH 6/8] Simplified signature for create_revocation_status_list Signed-off-by: Bogdan Mircea --- src/ffi/revocation.rs | 10 ++++------ src/services/issuer.rs | 13 ++----------- tests/utils/fixtures.rs | 6 ++---- tests/utils/mock.rs | 3 +-- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/ffi/revocation.rs b/src/ffi/revocation.rs index f4484ea1..ea109f69 100644 --- a/src/ffi/revocation.rs +++ b/src/ffi/revocation.rs @@ -24,7 +24,7 @@ pub extern "C" fn anoncreds_create_revocation_status_list( rev_reg_def_id: FfiStr, rev_reg_def: ObjectHandle, reg_rev_priv: ObjectHandle, - issuer_id: FfiStr, + _issuer_id: FfiStr, // leaving it here not to break existing code issuance_by_default: i8, timestamp: i64, rev_status_list_p: *mut ObjectHandle, @@ -33,10 +33,9 @@ pub extern "C" fn anoncreds_create_revocation_status_list( check_useful_c_ptr!(rev_status_list_p); let rev_reg_def_id = rev_reg_def_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing rev_reg_def_id"))?; - let issuer_id = issuer_id - .as_opt_str() - .ok_or_else(|| err_msg!("Missing issuer_id"))?; + .ok_or_else(|| err_msg!("Missing rev_reg_def_id"))? + .try_into()?; + let timestamp = if timestamp <= 0 { None } else { @@ -48,7 +47,6 @@ pub extern "C" fn anoncreds_create_revocation_status_list( rev_reg_def_id, rev_reg_def.load()?.cast_ref()?, reg_rev_priv.load()?.cast_ref()?, - issuer_id, issuance_by_default != 0, timestamp, )?; diff --git a/src/services/issuer.rs b/src/services/issuer.rs index f9e01ad6..8d80bb8e 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -325,24 +325,15 @@ where /// ``` pub fn create_revocation_status_list( cred_def: &CredentialDefinition, - rev_reg_def_id: impl TryInto, + rev_reg_def_id: RevocationRegistryDefinitionId, rev_reg_def: &RevocationRegistryDefinition, rev_reg_priv: &RevocationRegistryDefinitionPrivate, - issuer_id: impl TryInto, issuance_by_default: bool, timestamp: Option, ) -> Result { let max_cred_num = rev_reg_def.value.max_cred_num; - let rev_reg_def_id = rev_reg_def_id.try_into()?; - let issuer_id = issuer_id.try_into()?; let mut rev_reg = RevocationRegistry::from(CLSignaturesRevocationRegistry::empty()?); - if issuer_id != rev_reg_def.issuer_id { - return Err(err_msg!( - "Issuer id must be the same as the issuer id in the revocation registry definition" - )); - } - let list = if issuance_by_default { let cred_pub_key = cred_def.get_public_key()?; let issued = (1..=max_cred_num).collect::>(); @@ -362,7 +353,7 @@ pub fn create_revocation_status_list( RevocationStatusList::new( Some(rev_reg_def_id.to_string().as_str()), - issuer_id, + rev_reg_def.issuer_id.clone(), list, Some(rev_reg.into()), timestamp, diff --git a/tests/utils/fixtures.rs b/tests/utils/fixtures.rs index 1fe03fdc..65452dc9 100644 --- a/tests/utils/fixtures.rs +++ b/tests/utils/fixtures.rs @@ -164,20 +164,18 @@ pub fn create_revocation_status_list( match rev_reg_def.tag.as_str() { GVT_REV_REG_TAG => issuer::create_revocation_status_list( cred_def, - GVT_REV_REG_DEF_ID, + GVT_REV_REG_DEF_ID.try_into().unwrap(), rev_reg_def, rev_reg_priv, - GVT_ISSUER_ID, issuance_by_default, time, ) .expect("Error while creating GVT rev status list"), EMP_REV_REG_TAG => issuer::create_revocation_status_list( cred_def, - EMP_REV_REG_DEF_ID, + EMP_REV_REG_DEF_ID.try_into().unwrap(), rev_reg_def, rev_reg_priv, - EMP_ISSUER_ID, issuance_by_default, time, ) diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index e479dbac..286ae6c7 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -178,10 +178,9 @@ impl<'a> Mock<'a> { let revocation_status_list = issuer::create_revocation_status_list( &cred_def_pub, - *rev_reg_id, + (*rev_reg_id).try_into().unwrap(), &rev_reg_def_pub, rev_reg_def_priv, - issuer_id, issuance_by_default, Some(time_now), ) From d9936b953a807229769169f3fb8045358edc5c97 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Tue, 1 Aug 2023 14:33:15 +0300 Subject: [PATCH 7/8] Simplified signature for create_credential_offer Signed-off-by: Bogdan Mircea --- src/data_types/cred_request.rs | 12 ++++++++---- src/ffi/cred_offer.rs | 6 ++++-- src/services/issuer.rs | 17 ++++++++--------- src/services/prover.rs | 11 ++++++++--- tests/anoncreds_demos.rs | 32 ++++++++++++++++---------------- tests/utils/mock.rs | 4 ++-- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/data_types/cred_request.rs b/src/data_types/cred_request.rs index 8a7a3755..e2dcde63 100644 --- a/src/data_types/cred_request.rs +++ b/src/data_types/cred_request.rs @@ -126,7 +126,7 @@ mod cred_req_tests { let schema_id = "schema:id".try_into()?; let credential_definition_issuer_id = "sample:id".try_into()?; let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); - + let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; let cred_def = create_credential_definition( schema_id, @@ -152,12 +152,16 @@ mod cred_req_tests { ) -> Result { if is_legacy { create_credential_offer( - LEGACY_SCHEMA_IDENTIFIER, - LEGACY_CRED_DEF_IDENTIFIER, + LEGACY_SCHEMA_IDENTIFIER.try_into()?, + LEGACY_CRED_DEF_IDENTIFIER.try_into()?, &correctness_proof, ) } else { - create_credential_offer(NEW_IDENTIFIER, NEW_IDENTIFIER, &correctness_proof) + create_credential_offer( + NEW_IDENTIFIER.try_into()?, + NEW_IDENTIFIER.try_into()?, + &correctness_proof, + ) } } diff --git a/src/ffi/cred_offer.rs b/src/ffi/cred_offer.rs index 0d59af3c..7d3aed71 100644 --- a/src/ffi/cred_offer.rs +++ b/src/ffi/cred_offer.rs @@ -15,10 +15,12 @@ pub extern "C" fn anoncreds_create_credential_offer( check_useful_c_ptr!(cred_offer_p); let schema_id = schema_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing schema ID"))?; + .ok_or_else(|| err_msg!("Missing schema ID"))? + .try_into()?; let cred_def_id = cred_def_id .as_opt_str() - .ok_or_else(|| err_msg!("Missing cred def ID"))?; + .ok_or_else(|| err_msg!("Missing cred def ID"))? + .try_into()?; let cred_offer = create_credential_offer(schema_id, cred_def_id, key_proof.load()?.cast_ref()?)?; let cred_offer = ObjectHandle::create(cred_offer)?; diff --git a/src/services/issuer.rs b/src/services/issuer.rs index 8d80bb8e..b16ecf7e 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -10,7 +10,7 @@ use crate::data_types::{ rev_reg_def::{RevocationRegistryDefinitionValue, RevocationRegistryDefinitionValuePublicKeys}, schema::Schema, }; -use crate::error::{Error, ErrorKind, Result, ValidationError}; +use crate::error::{Error, ErrorKind, Result}; use crate::services::helpers::{ build_credential_schema, build_credential_values, build_non_credential_schema, }; @@ -573,12 +573,10 @@ pub fn update_revocation_status_list( /// ).expect("Unable to create Credential Offer"); /// ``` pub fn create_credential_offer( - schema_id: impl TryInto, - cred_def_id: impl TryInto, + schema_id: SchemaId, + cred_def_id: CredentialDefinitionId, correctness_proof: &CredentialKeyCorrectnessProof, ) -> Result { - let schema_id = schema_id.try_into()?; - let cred_def_id = cred_def_id.try_into()?; trace!("create_credential_offer >>> cred_def_id: {:?}", cred_def_id); let nonce = Nonce::new().map_err(err_map!(Unexpected, "Error creating nonce"))?; @@ -678,10 +676,11 @@ pub fn create_credential( cred_def, secret!(&cred_def_private), &cred_offer.nonce, &cred_request, secret!(&cred_values), revocation_config, ); - let cred_public_key = cred_def.get_public_key().map_err(err_map!( - Unexpected, - "Error fetching public key from credential definition" - ))?; + let cred_public_key: anoncreds_clsignatures::CredentialPublicKey = + cred_def.get_public_key().map_err(err_map!( + Unexpected, + "Error fetching public key from credential definition" + ))?; let credential_values = build_credential_values(&cred_values.0, None)?; let (credential_signature, signature_correctness_proof, rev_reg, witness) = diff --git a/src/services/prover.rs b/src/services/prover.rs index e61d7fae..b4457ffe 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -1161,7 +1161,12 @@ mod tests { } fn _cred_offer(key_correctness_proof: CredentialKeyCorrectnessProof) -> CredentialOffer { - create_credential_offer(SCHEMA_ID, CRED_DEF_ID, &key_correctness_proof).unwrap() + create_credential_offer( + SCHEMA_ID.try_into().unwrap(), + CRED_DEF_ID.try_into().unwrap(), + &key_correctness_proof, + ) + .unwrap() } fn _legacy_schema() -> Schema { @@ -1194,8 +1199,8 @@ mod tests { key_correctness_proof: CredentialKeyCorrectnessProof, ) -> CredentialOffer { create_credential_offer( - LEGACY_SCHEMA_IDENTIFIER, - LEGACY_CRED_DEF_IDENTIFIER, + LEGACY_SCHEMA_IDENTIFIER.try_into().unwrap(), + LEGACY_CRED_DEF_IDENTIFIER.try_into().unwrap(), &key_correctness_proof, ) .unwrap() diff --git a/tests/anoncreds_demos.rs b/tests/anoncreds_demos.rs index c4163ea4..9f76e8d2 100644 --- a/tests/anoncreds_demos.rs +++ b/tests/anoncreds_demos.rs @@ -27,8 +27,8 @@ fn anoncreds_demo_works_for_single_issuer_single_prover() { // Issuer creates a Credential Offer let cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Error creating credential offer"); @@ -218,8 +218,8 @@ fn anoncreds_demo_works_with_revocation_for_single_issuer_single_prover() { // Issuer creates a Credential Offer let cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Error creating credential offer"); @@ -428,8 +428,8 @@ fn anoncreds_demo_works_for_multiple_issuer_single_prover() { fixtures::create_cred_def(&emp_schema, false); let gvt_cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Unable to create credential offer"); @@ -471,8 +471,8 @@ fn anoncreds_demo_works_for_multiple_issuer_single_prover() { prover_wallet.credentials.push(gvt_recv_cred); let emp_cred_offer = issuer::create_credential_offer( - emp_schema_id, - emp_cred_def_id, + emp_schema_id.try_into().unwrap(), + emp_cred_def_id.try_into().unwrap(), &emp_cred_key_correctness_proof, ) .expect("Unable to create credential offer"); @@ -600,8 +600,8 @@ fn anoncreds_demo_proof_does_not_verify_with_wrong_attr_and_predicates() { // Issuer creates a Credential Offer let cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Error creating credential offer"); @@ -729,8 +729,8 @@ fn anoncreds_demo_works_for_requested_attribute_in_upper_case() { // Issuer creates a Credential Offer let cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Error creating credential offer"); @@ -907,8 +907,8 @@ fn anoncreds_demo_works_for_twice_entry_of_attribute_from_different_credential() fixtures::create_cred_def(&emp_schema, false); let gvt_cred_offer = issuer::create_credential_offer( - gvt_schema_id, - gvt_cred_def_id, + gvt_schema_id.try_into().unwrap(), + gvt_cred_def_id.try_into().unwrap(), &gvt_cred_key_correctness_proof, ) .expect("Unable to create credential offer"); @@ -950,8 +950,8 @@ fn anoncreds_demo_works_for_twice_entry_of_attribute_from_different_credential() prover_wallet.credentials.push(gvt_recv_cred); let emp_cred_offer = issuer::create_credential_offer( - emp_schema_id, - emp_cred_def_id, + emp_schema_id.try_into().unwrap(), + emp_cred_def_id.try_into().unwrap(), &emp_cred_key_correctness_proof, ) .expect("Unable to create credential offer"); diff --git a/tests/utils/mock.rs b/tests/utils/mock.rs index 286ae6c7..fe0486a9 100644 --- a/tests/utils/mock.rs +++ b/tests/utils/mock.rs @@ -199,8 +199,8 @@ impl<'a> Mock<'a> { // Issuer creates a Credential Offer let cred_offer = issuer::create_credential_offer( - schema_id.to_string(), - *cred_def_id, + schema_id.to_string().try_into().unwrap(), + (*cred_def_id).try_into().unwrap(), &cred_def_correctness, ) .expect("Error creating credential offer"); From 764a3df905a3cd192eaf0a390393c19a6ed48ca1 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Fri, 4 Aug 2023 11:39:14 +0300 Subject: [PATCH 8/8] Accommodate issuer_id being taken from rev_reg_def Signed-off-by: Bogdan Mircea --- src/ffi/cred_def.rs | 2 +- src/ffi/revocation.rs | 1 + src/services/issuer.rs | 166 +++++++++++++++++++++++------------------ src/services/prover.rs | 70 +++++++++++------ 4 files changed, 142 insertions(+), 97 deletions(-) diff --git a/src/ffi/cred_def.rs b/src/ffi/cred_def.rs index 66c809e2..4ca68e1e 100644 --- a/src/ffi/cred_def.rs +++ b/src/ffi/cred_def.rs @@ -44,7 +44,7 @@ pub extern "C" fn anoncreds_create_credential_definition( .as_opt_str() .ok_or_else(|| err_msg!("Missing issuer id"))? .try_into()?; - + let (cred_def, cred_def_pvt, key_proof) = create_credential_definition( schema_id, schema.load()?.cast_ref()?, diff --git a/src/ffi/revocation.rs b/src/ffi/revocation.rs index ea109f69..b335292a 100644 --- a/src/ffi/revocation.rs +++ b/src/ffi/revocation.rs @@ -132,6 +132,7 @@ pub extern "C" fn anoncreds_update_revocation_status_list_timestamp_only( pub extern "C" fn anoncreds_create_revocation_registry_def( cred_def: ObjectHandle, cred_def_id: FfiStr, + _issuer_id: FfiStr, // leaving it here not to break existing code tag: FfiStr, rev_reg_type: FfiStr, max_cred_num: i64, diff --git a/src/services/issuer.rs b/src/services/issuer.rs index b16ecf7e..47ef40c5 100644 --- a/src/services/issuer.rs +++ b/src/services/issuer.rs @@ -37,11 +37,14 @@ use super::types::{ /// /// ```rust /// use anoncreds::issuer; +/// use anoncreds::data_types::issuer_id::IssuerId; /// /// let attribute_names: &[&str] = &["name", "age"]; /// +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// /// let schema = issuer::create_schema("schema name", -/// "1.0", "did:web:xyz", +/// "1.0", issuer_id, /// attribute_names.into() /// ).expect("Unable to create schema"); /// ``` @@ -89,18 +92,23 @@ pub fn create_schema( /// use anoncreds::issuer; /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id, /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() @@ -179,18 +187,25 @@ pub fn create_credential_definition( /// use anoncreds::types::SignatureType; /// use anoncreds::types::RegistryType; /// use anoncreds::tails::TailsFileWriter; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def").expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id, /// &schema, -/// "did:web:xyz", +/// issuer_id.clone(), /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig { @@ -201,8 +216,7 @@ pub fn create_credential_definition( /// let mut tw = TailsFileWriter::new(None); /// let (rev_reg_def, rev_reg_def_priv) = /// issuer::create_revocation_registry_def(&cred_def, -/// "did:web:xyz/resource/cred-def", -/// "did:web:xyz", +/// cred_def_id, /// "default-tag", /// RegistryType::CL_ACCUM, /// 1000, @@ -283,18 +297,27 @@ where /// use anoncreds::types::SignatureType; /// use anoncreds::types::RegistryType; /// use anoncreds::tails::TailsFileWriter; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; +/// use anoncreds::data_types::rev_reg_def::RevocationRegistryDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// let rev_reg_def_id = RevocationRegistryDefinitionId::new("did:web:xyz/resource/rev-reg-def").expect("Invalid revocation registry definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id, /// &schema, -/// "did:web:xyz", +/// issuer_id.clone(), /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig { @@ -305,8 +328,7 @@ where /// let mut tw = TailsFileWriter::new(None); /// let (rev_reg_def, rev_reg_def_priv) = /// issuer::create_revocation_registry_def(&cred_def, -/// "did:web:xyz/resource/cred-def", -/// "did:web:xyz", +/// cred_def_id, /// "default-tag", /// RegistryType::CL_ACCUM, /// 1000, @@ -315,10 +337,9 @@ where /// /// let rev_status_list = /// issuer::create_revocation_status_list(&cred_def, -/// "did:web:xyz/resource/rev-reg-def", +/// rev_reg_def_id, /// &rev_reg_def, /// &rev_reg_def_priv, -/// "did:web:xyz", /// true, /// None /// ).expect("Unable to create revocation status list"); @@ -373,18 +394,27 @@ pub fn create_revocation_status_list( /// use anoncreds::types::SignatureType; /// use anoncreds::types::RegistryType; /// use anoncreds::tails::TailsFileWriter; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; +/// use anoncreds::data_types::rev_reg_def::RevocationRegistryDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// let rev_reg_def_id = RevocationRegistryDefinitionId::new("did:web:xyz/resource/rev-reg-def").expect("Invalid revocation registry definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id, /// &schema, -/// "did:web:xyz", +/// issuer_id.clone(), /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig { @@ -395,8 +425,7 @@ pub fn create_revocation_status_list( /// let mut tw = TailsFileWriter::new(None); /// let (rev_reg_def, rev_reg_def_priv) = /// issuer::create_revocation_registry_def(&cred_def, -/// "did:web:xyz/resource/cred-def", -/// "did:web:xyz", +/// cred_def_id, /// "default-tag", /// RegistryType::CL_ACCUM, /// 1000, @@ -404,10 +433,9 @@ pub fn create_revocation_status_list( /// ).expect("Unable to create revocation registry"); /// /// let rev_status_list = issuer::create_revocation_status_list(&cred_def, -/// "did:web:xyz/resource/rev-reg-def", +/// rev_reg_def_id, /// &rev_reg_def, /// &rev_reg_def_priv, -/// "did:web:xyz", /// true, /// None /// ).expect("Unable to create revocation status list"); @@ -434,24 +462,35 @@ pub fn update_revocation_status_list_timestamp_only( /// # Example /// /// ```rust +/// use std::collections::BTreeSet; +/// /// use anoncreds::issuer; /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; /// use anoncreds::types::RegistryType; /// use anoncreds::tails::TailsFileWriter; -/// use std::collections::BTreeSet; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; +/// use anoncreds::data_types::rev_reg_def::RevocationRegistryDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// let rev_reg_def_id = RevocationRegistryDefinitionId::new("did:web:xyz/resource/rev-reg-def").expect("Invalid revocation registry definition ID"); + +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id, /// &schema, -/// "did:web:xyz", +/// issuer_id.clone(), /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig { @@ -462,8 +501,7 @@ pub fn update_revocation_status_list_timestamp_only( /// let mut tw = TailsFileWriter::new(None); /// let (rev_reg_def, rev_reg_def_priv) = /// issuer::create_revocation_registry_def(&cred_def, -/// "did:web:xyz/resource/cred-def", -/// "did:web:xyz", +/// cred_def_id, /// "default-tag", /// RegistryType::CL_ACCUM, /// 1000, @@ -471,10 +509,9 @@ pub fn update_revocation_status_list_timestamp_only( /// ).expect("Unable to create revocation registry"); /// /// let rev_status_list = issuer::create_revocation_status_list(&cred_def, -/// "did:web:xyz/resource/rev-reg-def", +/// rev_reg_def_id, /// &rev_reg_def, /// &rev_reg_def_priv, -/// "did:web:xyz", /// true, /// None /// ).expect("Unable to create revocation status list"); @@ -549,26 +586,33 @@ pub fn update_revocation_status_list( /// use anoncreds::issuer; /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// /// let credential_offer = -/// issuer::create_credential_offer("did:web:xyz/resource/schema", -/// "did:web:xyz/resource/cred-def", +/// issuer::create_credential_offer(schema_id, +/// cred_def_id, /// &key_correctness_proof, /// ).expect("Unable to create Credential Offer"); /// ``` @@ -610,26 +654,33 @@ pub fn create_credential_offer( /// /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// /// let credential_offer = -/// issuer::create_credential_offer("did:web:xyz/resource/schema", -/// "did:web:xyz/resource/cred-def", +/// issuer::create_credential_offer(schema_id, +/// cred_def_id, /// &key_correctness_proof, /// ).expect("Unable to create Credential Offer"); /// @@ -815,39 +866,6 @@ mod tests { Ok(()) } - #[test] - fn test_issuer_id_unequal_in_revocation_registry_definiton_and_credential_definition( - ) -> Result<()> { - let issuer_id = "sample:uri".try_into()?; - let schema_id = "schema:id".try_into()?; - let cred_def_id = "sample:uri".try_into()?; - let credential_definition_issuer_id: IssuerId = "sample:id".try_into()?; - let attr_names = AttributeNames::from(vec!["name".to_owned(), "age".to_owned()]); - - let schema = create_schema("schema:name", "1.0", issuer_id, attr_names)?; - let cred_def = create_credential_definition( - schema_id, - &schema, - credential_definition_issuer_id, - "default", - SignatureType::CL, - CredentialDefinitionConfig { - support_revocation: true, - }, - )?; - let res = create_revocation_registry_def( - &cred_def.0, - cred_def_id, - "default", - RegistryType::CL_ACCUM, - 1, - &mut TailsFileWriter::new(None), - ); - - assert!(res.is_err()); - Ok(()) - } - #[test] fn test_encode_attribute() { assert_eq!( diff --git a/src/services/prover.rs b/src/services/prover.rs index b4457ffe..80766212 100644 --- a/src/services/prover.rs +++ b/src/services/prover.rs @@ -62,26 +62,33 @@ pub fn create_link_secret() -> Result { /// /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// /// let credential_offer = -/// issuer::create_credential_offer("did:web:xyz/resource/schema", -/// "did:web:xyz/resource/cred-def", +/// issuer::create_credential_offer(schema_id, +/// cred_def_id, /// &key_correctness_proof, /// ).expect("Unable to create Credential Offer"); /// @@ -169,26 +176,33 @@ pub fn create_credential_request( /// /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// /// let credential_offer = -/// issuer::create_credential_offer("did:web:xyz/resource/schema", -/// "did:web:xyz/resource/cred-def", +/// issuer::create_credential_offer(schema_id, +/// cred_def_id, /// &key_correctness_proof, /// ).expect("Unable to create Credential Offer"); /// @@ -275,28 +289,33 @@ pub fn process_credential( /// use anoncreds::types::PresentCredentials; /// use anoncreds::types::CredentialDefinitionConfig; /// use anoncreds::types::SignatureType; +/// use anoncreds::data_types::issuer_id::IssuerId; /// use anoncreds::data_types::schema::SchemaId; /// use anoncreds::data_types::cred_def::CredentialDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id, /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig::default() /// ).expect("Unable to create Credential Definition"); /// /// let credential_offer = -/// issuer::create_credential_offer("did:web:xyz/resource/schema", -/// "did:web:xyz/resource/cred-def", +/// issuer::create_credential_offer(schema_id, +/// cred_def_id, /// &key_correctness_proof, /// ).expect("Unable to create Credential Offer"); /// @@ -563,18 +582,27 @@ pub fn create_revocation_state_with_witness( /// use anoncreds::types::SignatureType; /// use anoncreds::types::RegistryType; /// use anoncreds::tails::TailsFileWriter; +/// use anoncreds::data_types::issuer_id::IssuerId; +/// use anoncreds::data_types::schema::SchemaId; +/// use anoncreds::data_types::cred_def::CredentialDefinitionId; +/// use anoncreds::data_types::rev_reg_def::RevocationRegistryDefinitionId; /// /// let attribute_names: &[&str] = &["name", "age"]; +/// let issuer_id = IssuerId::new("did:web:xyz").expect("Invalid issuer ID"); +/// let schema_id = SchemaId::new("did:web:xyz/resource/schema").expect("Invalid schema ID"); +/// let cred_def_id = CredentialDefinitionId::new("did:web:xyz/resource/cred-def",).expect("Invalid credential definition ID"); +/// let rev_reg_def_id = RevocationRegistryDefinitionId::new("did:web:xyz/resource/rev-reg-def").expect("Invalid revocation registry definition ID"); +/// /// let schema = issuer::create_schema("schema name", /// "1.0", -/// "did:web:xyz", +/// issuer_id.clone(), /// attribute_names.into() /// ).expect("Unable to create schema"); /// /// let (cred_def, cred_def_priv, key_correctness_proof) = -/// issuer::create_credential_definition("did:web:xyz/resource/schema", +/// issuer::create_credential_definition(schema_id.clone(), /// &schema, -/// "did:web:xyz", +/// issuer_id.clone(), /// "default-tag", /// SignatureType::CL, /// CredentialDefinitionConfig { @@ -585,8 +613,7 @@ pub fn create_revocation_state_with_witness( /// let mut tw = TailsFileWriter::new(None); /// let (rev_reg_def, rev_reg_def_priv) = /// issuer::create_revocation_registry_def(&cred_def, -/// "did:web:xyz/resource/cred-def", -/// "did:web:xyz", +/// cred_def_id, /// "default-tag", /// RegistryType::CL_ACCUM, /// 1000, @@ -595,10 +622,9 @@ pub fn create_revocation_state_with_witness( /// /// let rev_status_list = /// issuer::create_revocation_status_list(&cred_def, -/// "did:web:xyz/resource/rev-reg-def", +/// rev_reg_def_id, /// &rev_reg_def, /// &rev_reg_def_priv, -/// "did:web:xyz", /// true, /// Some(10) /// ).expect("Unable to create revocation status list");