Skip to content

Commit 8ab13dd

Browse files
Merge pull request #31 from blu3beri/update-schema-data-model
Update schema data model
2 parents 0f331b9 + 06f2e2d commit 8ab13dd

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

anoncreds/src/data_types/anoncreds/schema.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ pub const MAX_ATTRIBUTES_COUNT: usize = 125;
88

99
impl_anoncreds_object_identifier!(SchemaId);
1010

11-
#[derive(Clone, Debug, Serialize, Deserialize)]
12-
#[serde(tag = "ver")]
13-
pub enum Schema {
14-
#[serde(rename = "1.0")]
15-
SchemaV1(SchemaV1),
16-
}
17-
1811
#[derive(Debug, Clone, Serialize, Deserialize)]
1912
#[serde(rename_all = "camelCase")]
20-
pub struct SchemaV1 {
13+
pub struct Schema {
2114
pub name: String,
2215
pub version: String,
2316
#[serde(rename = "attrNames")]
@@ -55,7 +48,7 @@ impl From<AttributeNames> for HashSet<String> {
5548
}
5649
}
5750

58-
impl Validatable for SchemaV1 {
51+
impl Validatable for Schema {
5952
fn validate(&self) -> Result<(), ValidationError> {
6053
self.attr_names.validate()?;
6154
Ok(())
@@ -88,13 +81,12 @@ mod test_schema_validation {
8881
fn test_valid_schema() {
8982
let schema_json = json!({
9083
"name": "gvt",
91-
"ver": "1.0",
9284
"version": "1.0",
9385
"attrNames": ["aaa", "bbb", "ccc"],
9486
})
9587
.to_string();
9688

97-
let schema: SchemaV1 = serde_json::from_str(&schema_json).unwrap();
89+
let schema: Schema = serde_json::from_str(&schema_json).unwrap();
9890
assert_eq!(schema.name, "gvt");
9991
assert_eq!(schema.version, "1.0");
10092
}
@@ -103,25 +95,23 @@ mod test_schema_validation {
10395
fn test_invalid_name_schema() {
10496
let schema_json = json!({
10597
"name": "gvt1",
106-
"ver": "1.0",
10798
"version": "1.0",
10899
"attrNames": ["aaa", "bbb", "ccc"],
109100
})
110101
.to_string();
111102

112-
serde_json::from_str::<SchemaV1>(&schema_json).unwrap();
103+
serde_json::from_str::<Schema>(&schema_json).unwrap();
113104
}
114105

115106
#[test]
116107
fn test_invalid_version_schema() {
117108
let schema_json = json!({
118109
"name": "gvt",
119-
"ver": "1.0",
120110
"version": "1.1",
121111
"attrNames": ["aaa", "bbb", "ccc"],
122112
})
123113
.to_string();
124114

125-
serde_json::from_str::<SchemaV1>(&schema_json).unwrap();
115+
serde_json::from_str::<Schema>(&schema_json).unwrap();
126116
}
127117
}

anoncreds/src/ffi/schema.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use ffi_support::FfiStr;
33
use super::error::{catch_error, ErrorCode};
44
use super::object::ObjectHandle;
55
use super::util::FfiStrList;
6-
use crate::services::{issuer::create_schema, types::Schema};
6+
use crate::data_types::anoncreds::schema::Schema;
7+
use crate::services::issuer::create_schema;
78

89
#[no_mangle]
910
pub extern "C" fn anoncreds_create_schema(

anoncreds/src/services/issuer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::data_types::anoncreds::{
1515
RevocationRegistryDefinitionV1, RevocationRegistryDefinitionValue,
1616
RevocationRegistryDefinitionValuePublicKeys,
1717
},
18-
schema::SchemaV1,
18+
schema::Schema,
1919
};
2020
use crate::error::Result;
2121
use crate::services::helpers::*;
@@ -38,12 +38,12 @@ pub fn create_schema(
3838
attr_names
3939
);
4040

41-
let schema = SchemaV1 {
41+
let schema = Schema {
4242
name: schema_name.to_string(),
4343
version: schema_version.to_string(),
4444
attr_names,
4545
};
46-
Ok(Schema::SchemaV1(schema))
46+
Ok(schema)
4747
}
4848

4949
pub fn create_credential_definition<SI>(
@@ -67,8 +67,6 @@ where
6767
);
6868
let schema_id = schema_id.try_into()?;
6969

70-
let Schema::SchemaV1(schema) = schema;
71-
7270
let credential_schema = build_credential_schema(&schema.attr_names.0)?;
7371
let non_credential_schema = build_non_credential_schema()?;
7472

anoncreds/src/services/prover.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::data_types::anoncreds::{
99
AttributeValue, Identifier, RequestedProof, RevealedAttributeGroupInfo,
1010
RevealedAttributeInfo, SubProofReferent,
1111
},
12-
schema::SchemaId,
12+
schema::{Schema, SchemaId},
1313
};
1414
use crate::error::Result;
1515
use crate::services::helpers::*;
@@ -170,7 +170,6 @@ pub fn create_presentation(
170170
let schema = *schemas
171171
.get(&credential.schema_id)
172172
.ok_or_else(|| err_msg!("Schema not provided for ID: {}", credential.schema_id))?;
173-
let Schema::SchemaV1(schema) = schema;
174173

175174
let cred_def_id = CredentialDefinitionId::new(credential.cred_def_id.clone())?;
176175
let cred_def = *cred_defs.get(&cred_def_id).ok_or_else(|| {

anoncreds/src/services/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use crate::data_types::anoncreds::{
1717
IssuanceType, RegistryType, RevocationRegistryDefinition,
1818
RevocationRegistryDefinitionPrivate,
1919
},
20-
schema::{AttributeNames, Schema},
20+
schema::AttributeNames,
2121
};
2222

2323
pub use indy_utils::did::DidValue;

anoncreds/src/services/verifier.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::types::*;
88
use crate::data_types::anoncreds::cred_def::CredentialDefinitionId;
99
use crate::data_types::anoncreds::rev_reg::RevocationRegistryId;
1010
use crate::data_types::anoncreds::rev_reg_def::RevocationRegistryDefinitionId;
11+
use crate::data_types::anoncreds::schema::Schema;
1112
use crate::data_types::anoncreds::schema::SchemaId;
1213
use crate::data_types::anoncreds::{
1314
nonce::Nonce,
@@ -83,7 +84,7 @@ pub fn verify_presentation(
8384
for sub_proof_index in 0..presentation.identifiers.len() {
8485
let identifier = presentation.identifiers[sub_proof_index].clone();
8586

86-
let Schema::SchemaV1(schema) = schemas
87+
let schema = schemas
8788
.get(&identifier.schema_id)
8889
.ok_or_else(|| err_msg!("Schema not provided for ID: {:?}", identifier.schema_id))?;
8990

0 commit comments

Comments
 (0)