Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting functions to exclude network from schema and cred_def ids #102

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions vdr/src/contracts/anoncreds/credential_definition_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 18 additions & 18 deletions vdr/src/contracts/anoncreds/schema_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion vdr/src/contracts/anoncreds/types/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
69 changes: 67 additions & 2 deletions vdr/src/contracts/anoncreds/types/credential_definition_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl ParsedCredentialDefinitionSchemaId {
pub(crate) fn as_short_id(&self) -> VdrResult<String> {
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<Self, Self::Error> {
let parts = schema_id.split(':').collect::<Vec<&str>>();
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()
)
}
}
2 changes: 2 additions & 0 deletions vdr/src/contracts/anoncreds/types/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 16 additions & 2 deletions vdr/src/contracts/anoncreds/types/schema_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
Loading