From 67dfa2e55a60c25ba43a036620c08d18e9b9717c Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 2 Oct 2024 19:12:51 +0300 Subject: [PATCH] Correcting functions to exclude network from schema and cred_def ids Signed-off-by: artem.ivanov --- .../credential_definition_registry.rs | 58 ++++++++-------- .../contracts/anoncreds/schema_registry.rs | 36 +++++----- .../anoncreds/types/credential_definition.rs | 3 +- .../types/credential_definition_id.rs | 69 ++++++++++++++++++- vdr/src/contracts/anoncreds/types/schema.rs | 2 + .../contracts/anoncreds/types/schema_id.rs | 18 ++++- 6 files changed, 134 insertions(+), 52 deletions(-) diff --git a/vdr/src/contracts/anoncreds/credential_definition_registry.rs b/vdr/src/contracts/anoncreds/credential_definition_registry.rs index 24b82650..a1047c2d 100644 --- a/vdr/src/contracts/anoncreds/credential_definition_registry.rs +++ b/vdr/src/contracts/anoncreds/credential_definition_registry.rs @@ -209,36 +209,36 @@ pub mod test { chain_id: CONFIG.chain_id, data: vec![ 182, 196, 9, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 226, 219, 108, 141, - 198, 198, 129, 187, 93, 106, 209, 33, 161, 7, 243, 0, 233, 178, 181, 2, 105, - 77, 198, 175, 52, 100, 14, 236, 5, 92, 96, 213, 30, 127, 142, 109, 135, 11, - 231, 119, 100, 109, 44, 92, 49, 82, 133, 141, 241, 182, 157, 0, 0, 0, 0, 0, 0, + 198, 198, 129, 187, 93, 106, 209, 33, 161, 7, 243, 0, 233, 178, 181, 252, 84, + 206, 140, 139, 17, 81, 102, 58, 13, 78, 38, 76, 85, 25, 157, 189, 250, 139, + 220, 160, 110, 164, 90, 238, 147, 145, 200, 16, 72, 81, 138, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, - 157, 102, 193, 205, 103, 90, 204, 163, 183, 21, 33, 209, 148, 81, 176, 246, 13, - 62, 210, 245, 196, 121, 156, 18, 158, 90, 17, 4, 158, 115, 117, 188, 0, 0, 0, + 224, 153, 168, 108, 167, 70, 3, 80, 108, 16, 229, 36, 115, 174, 106, 41, 145, + 23, 58, 161, 7, 125, 80, 82, 53, 89, 11, 100, 185, 142, 80, 20, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 51, 100, 105, 100, 58, 101, 116, 104, 114, 58, 48, 120, - 102, 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, - 100, 54, 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, - 98, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 42, 123, 34, 105, - 115, 115, 117, 101, 114, 73, 100, 34, 58, 34, 100, 105, 100, 58, 101, 116, 104, + 0, 0, 0, 0, 0, 0, 51, 100, 105, 100, 58, 101, 116, 104, 114, 58, 48, 120, 102, + 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, + 54, 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, + 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 42, 123, 34, 105, 115, + 115, 117, 101, 114, 73, 100, 34, 58, 34, 100, 105, 100, 58, 101, 116, 104, 114, + 58, 116, 101, 115, 116, 110, 101, 116, 58, 48, 120, 102, 48, 101, 50, 100, 98, + 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, 54, 97, 100, 49, 50, + 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, 53, 34, 44, 34, 115, + 99, 104, 101, 109, 97, 73, 100, 34, 58, 34, 100, 105, 100, 58, 101, 116, 104, 114, 58, 116, 101, 115, 116, 110, 101, 116, 58, 48, 120, 102, 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, 54, 97, 100, 49, - 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, 53, 34, 44, 34, - 115, 99, 104, 101, 109, 97, 73, 100, 34, 58, 34, 100, 105, 100, 58, 101, 116, - 104, 114, 58, 116, 101, 115, 116, 110, 101, 116, 58, 48, 120, 102, 48, 101, 50, - 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, 54, 97, 100, - 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, 53, 47, 97, - 110, 111, 110, 99, 114, 101, 100, 115, 47, 118, 48, 47, 83, 67, 72, 69, 77, 65, - 47, 70, 49, 68, 67, 108, 97, 70, 69, 122, 105, 51, 116, 47, 49, 46, 48, 46, 48, - 34, 44, 34, 99, 114, 101, 100, 68, 101, 102, 84, 121, 112, 101, 34, 58, 34, 67, - 76, 34, 44, 34, 116, 97, 103, 34, 58, 34, 100, 101, 102, 97, 117, 108, 116, 34, - 44, 34, 118, 97, 108, 117, 101, 34, 58, 123, 34, 110, 34, 58, 34, 55, 55, 57, - 46, 46, 46, 51, 57, 55, 34, 44, 34, 114, 99, 116, 120, 116, 34, 58, 34, 55, 55, - 52, 46, 46, 46, 57, 55, 55, 34, 44, 34, 115, 34, 58, 34, 55, 53, 48, 46, 46, - 56, 57, 51, 34, 44, 34, 122, 34, 58, 34, 54, 51, 50, 46, 46, 46, 48, 48, 53, - 34, 125, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, 53, 47, 97, 110, + 111, 110, 99, 114, 101, 100, 115, 47, 118, 48, 47, 83, 67, 72, 69, 77, 65, 47, + 70, 49, 68, 67, 108, 97, 70, 69, 122, 105, 51, 116, 47, 49, 46, 48, 46, 48, 34, + 44, 34, 99, 114, 101, 100, 68, 101, 102, 84, 121, 112, 101, 34, 58, 34, 67, 76, + 34, 44, 34, 116, 97, 103, 34, 58, 34, 100, 101, 102, 97, 117, 108, 116, 34, 44, + 34, 118, 97, 108, 117, 101, 34, 58, 123, 34, 110, 34, 58, 34, 55, 55, 57, 46, + 46, 46, 51, 57, 55, 34, 44, 34, 114, 99, 116, 120, 116, 34, 58, 34, 55, 55, 52, + 46, 46, 46, 57, 55, 55, 34, 44, 34, 115, 34, 58, 34, 55, 53, 48, 46, 46, 56, + 57, 51, 34, 44, 34, 122, 34, 58, 34, 54, 51, 50, 46, 46, 46, 48, 48, 53, 34, + 125, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], signature: None, hash: None, @@ -296,9 +296,9 @@ pub mod test { nonce: None, chain_id: CONFIG.chain_id, data: vec![ - 159, 136, 157, 181, 2, 105, 77, 198, 175, 52, 100, 14, 236, 5, 92, 96, 213, 30, - 127, 142, 109, 135, 11, 231, 119, 100, 109, 44, 92, 49, 82, 133, 141, 241, 182, - 157, + 159, 136, 157, 181, 252, 84, 206, 140, 139, 17, 81, 102, 58, 13, 78, 38, 76, + 85, 25, 157, 189, 250, 139, 220, 160, 110, 164, 90, 238, 147, 145, 200, 16, 72, + 81, 138, ], signature: None, hash: None, diff --git a/vdr/src/contracts/anoncreds/schema_registry.rs b/vdr/src/contracts/anoncreds/schema_registry.rs index 63f0026e..a2ae93ab 100644 --- a/vdr/src/contracts/anoncreds/schema_registry.rs +++ b/vdr/src/contracts/anoncreds/schema_registry.rs @@ -196,22 +196,22 @@ pub mod test { chain_id: CONFIG.chain_id, data: vec![ 131, 211, 251, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 226, 219, 108, 141, - 198, 198, 129, 187, 93, 106, 209, 33, 161, 7, 243, 0, 233, 178, 181, 157, 102, - 193, 205, 103, 90, 204, 163, 183, 21, 33, 209, 148, 81, 176, 246, 13, 62, 210, - 245, 196, 121, 156, 18, 158, 90, 17, 4, 158, 115, 117, 188, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, + 198, 198, 129, 187, 93, 106, 209, 33, 161, 7, 243, 0, 233, 178, 181, 224, 153, + 168, 108, 167, 70, 3, 80, 108, 16, 229, 36, 115, 174, 106, 41, 145, 23, 58, + 161, 7, 125, 80, 82, 53, 89, 11, 100, 185, 142, 80, 20, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 100, 105, 100, 58, 101, 116, 104, 114, 58, - 48, 120, 102, 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, - 98, 98, 53, 100, 54, 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, - 57, 98, 50, 98, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 141, - 123, 34, 105, 115, 115, 117, 101, 114, 73, 100, 34, 58, 34, 100, 105, 100, 58, - 101, 116, 104, 114, 58, 116, 101, 115, 116, 110, 101, 116, 58, 48, 120, 102, - 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, - 54, 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, - 53, 34, 44, 34, 110, 97, 109, 101, 34, 58, 34, 70, 49, 68, 67, 108, 97, 70, 69, + 0, 0, 0, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 100, 105, 100, 58, 101, 116, 104, 114, 58, 48, + 120, 102, 48, 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, + 98, 53, 100, 54, 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, + 98, 50, 98, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 141, 123, + 34, 105, 115, 115, 117, 101, 114, 73, 100, 34, 58, 34, 100, 105, 100, 58, 101, + 116, 104, 114, 58, 116, 101, 115, 116, 110, 101, 116, 58, 48, 120, 102, 48, + 101, 50, 100, 98, 54, 99, 56, 100, 99, 54, 99, 54, 56, 49, 98, 98, 53, 100, 54, + 97, 100, 49, 50, 49, 97, 49, 48, 55, 102, 51, 48, 48, 101, 57, 98, 50, 98, 53, + 34, 44, 34, 110, 97, 109, 101, 34, 58, 34, 70, 49, 68, 67, 108, 97, 70, 69, 122, 105, 51, 116, 34, 44, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 34, 49, 46, 48, 46, 48, 34, 44, 34, 97, 116, 116, 114, 78, 97, 109, 101, 115, 34, 58, 91, 34, 70, 105, 114, 115, 116, 32, 78, 97, 109, 101, 34, 93, 125, 0, 0, 0, @@ -263,9 +263,9 @@ pub mod test { nonce: None, chain_id: CONFIG.chain_id, data: vec![ - 174, 190, 203, 28, 157, 102, 193, 205, 103, 90, 204, 163, 183, 21, 33, 209, - 148, 81, 176, 246, 13, 62, 210, 245, 196, 121, 156, 18, 158, 90, 17, 4, 158, - 115, 117, 188, + 174, 190, 203, 28, 224, 153, 168, 108, 167, 70, 3, 80, 108, 16, 229, 36, 115, + 174, 106, 41, 145, 23, 58, 161, 7, 125, 80, 82, 53, 89, 11, 100, 185, 142, 80, + 20, ], signature: None, hash: None, diff --git a/vdr/src/contracts/anoncreds/types/credential_definition.rs b/vdr/src/contracts/anoncreds/types/credential_definition.rs index fd70deb3..77f89d18 100644 --- a/vdr/src/contracts/anoncreds/types/credential_definition.rs +++ b/vdr/src/contracts/anoncreds/types/credential_definition.rs @@ -153,7 +153,8 @@ pub mod test { }; use serde_json::json; - pub const _CREDENTIAL_DEFINITION_ID: &str = "did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/CLAIM_DEF/did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0/default"; + pub const CREDENTIAL_DEFINITION_ID: &str = "did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/CLAIM_DEF/did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5:F1DClaFEzi3t:1.0.0/default"; + pub const CREDENTIAL_DEFINITION_ID_WITHOUT_NETWORK: &str = "did:ethr:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/CLAIM_DEF/did:ethr:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5:F1DClaFEzi3t:1.0.0/default"; pub const CREDENTIAL_DEFINITION_TAG: &str = "default"; pub fn credential_definition_value() -> serde_json::Value { diff --git a/vdr/src/contracts/anoncreds/types/credential_definition_id.rs b/vdr/src/contracts/anoncreds/types/credential_definition_id.rs index 06ae3e1e..fb11d71e 100644 --- a/vdr/src/contracts/anoncreds/types/credential_definition_id.rs +++ b/vdr/src/contracts/anoncreds/types/credential_definition_id.rs @@ -89,11 +89,76 @@ impl TryFrom<&CredentialDefinitionId> for ParsedCredentialDefinitionId { } let issuer_id = DID::from(parts[0]); let parsed_issuer_id = ParsedDid::try_from(&issuer_id)?; + let parsed_schema_id = ParsedCredentialDefinitionSchemaId::try_from(parts[4])?; Ok(ParsedCredentialDefinitionId { issuer_id: DID::from(parts[0]), - schema_id: parts[3].to_string(), - tag: parts[4].to_string(), + schema_id: parsed_schema_id.as_short_id()?, + tag: parts[5].to_string(), network: parsed_issuer_id.network, }) } } + +#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)] +pub(crate) struct ParsedCredentialDefinitionSchemaId { + pub(crate) issuer_id: DID, + pub(crate) name: String, + pub(crate) version: String, + pub(crate) network: Option, +} + +impl ParsedCredentialDefinitionSchemaId { + pub(crate) fn as_short_id(&self) -> VdrResult { + Ok(format!( + "{}:{}:{}", + self.issuer_id.without_network()?.as_ref(), + self.name, + self.version + )) + } +} + +impl TryFrom<&str> for ParsedCredentialDefinitionSchemaId { + type Error = VdrError; + + fn try_from(schema_id: &str) -> Result { + let parts = schema_id.split(':').collect::>(); + if parts.len() == 6 { + return Ok(ParsedCredentialDefinitionSchemaId { + issuer_id: DID::build(parts[1], None, parts[3]), + name: parts[4].to_string(), + version: parts[5].to_string(), + network: Some(parts[2].to_string()), + }); + } + if parts.len() == 5 { + return Ok(ParsedCredentialDefinitionSchemaId { + issuer_id: DID::build(parts[1], None, parts[2]), + name: parts[3].to_string(), + version: parts[4].to_string(), + network: None, + }); + } + return Err(VdrError::CommonInvalidData( + "Invalid credential definition id provided".to_string(), + )); + } +} + +#[cfg(test)] +pub mod test { + use super::*; + use crate::contracts::anoncreds::types::credential_definition::test::{ + CREDENTIAL_DEFINITION_ID, CREDENTIAL_DEFINITION_ID_WITHOUT_NETWORK, + }; + + #[test] + fn cred_def_id_id_without_network() { + assert_eq!( + CredentialDefinitionId::from(CREDENTIAL_DEFINITION_ID_WITHOUT_NETWORK), + CredentialDefinitionId::from(CREDENTIAL_DEFINITION_ID) + .without_network() + .unwrap() + ) + } +} diff --git a/vdr/src/contracts/anoncreds/types/schema.rs b/vdr/src/contracts/anoncreds/types/schema.rs index 9b40f768..44b73416 100644 --- a/vdr/src/contracts/anoncreds/types/schema.rs +++ b/vdr/src/contracts/anoncreds/types/schema.rs @@ -149,6 +149,8 @@ pub mod test { pub const SCHEMA_ID: &str = "did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0"; + pub const SCHEMA_ID_WITHOUT_NETWORK: &str = + "did:ethr:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0"; pub const SCHEMA_NAME: &str = "F1DClaFEzi3t"; pub const SCHEMA_VERSION: &str = "1.0.0"; pub const SCHEMA_ATTRIBUTE_FIRST_NAME: &str = "First Name"; diff --git a/vdr/src/contracts/anoncreds/types/schema_id.rs b/vdr/src/contracts/anoncreds/types/schema_id.rs index d1224c69..c47a543e 100644 --- a/vdr/src/contracts/anoncreds/types/schema_id.rs +++ b/vdr/src/contracts/anoncreds/types/schema_id.rs @@ -97,9 +97,23 @@ impl TryFrom<&SchemaId> for ParsedSchemaId { let parsed_issuer_id = ParsedDid::try_from(&issuer_id)?; Ok(ParsedSchemaId { issuer_id: DID::from(parts[0]), - name: parts[3].to_string(), - version: parts[4].to_string(), + name: parts[4].to_string(), + version: parts[5].to_string(), network: parsed_issuer_id.network, }) } } + +#[cfg(test)] +pub mod test { + use super::*; + use crate::contracts::anoncreds::types::schema::test::{SCHEMA_ID, SCHEMA_ID_WITHOUT_NETWORK}; + + #[test] + fn schema_id_without_network() { + assert_eq!( + SchemaId::from(SCHEMA_ID_WITHOUT_NETWORK), + SchemaId::from(SCHEMA_ID).without_network().unwrap() + ) + } +}