Skip to content

Commit 06f2e2d

Browse files
author
blu3beri
committed
Update schema data model and remove V1 suffix
Work funded by the Government of Ontario. Signed-off-by: blu3beri <[email protected]>
1 parent 1dd9a60 commit 06f2e2d

File tree

7 files changed

+19
-43
lines changed

7 files changed

+19
-43
lines changed

anoncreds/src/data_types/anoncreds/schema.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ 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")]
2417
pub attr_names: AttributeNames,
25-
pub seq_no: Option<u32>,
2618
}
2719

2820
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
@@ -56,7 +48,7 @@ impl From<AttributeNames> for HashSet<String> {
5648
}
5749
}
5850

59-
impl Validatable for SchemaV1 {
51+
impl Validatable for Schema {
6052
fn validate(&self) -> Result<(), ValidationError> {
6153
self.attr_names.validate()?;
6254
Ok(())
@@ -89,13 +81,12 @@ mod test_schema_validation {
8981
fn test_valid_schema() {
9082
let schema_json = json!({
9183
"name": "gvt",
92-
"ver": "1.0",
9384
"version": "1.0",
9485
"attrNames": ["aaa", "bbb", "ccc"],
9586
})
9687
.to_string();
9788

98-
let schema: SchemaV1 = serde_json::from_str(&schema_json).unwrap();
89+
let schema: Schema = serde_json::from_str(&schema_json).unwrap();
9990
assert_eq!(schema.name, "gvt");
10091
assert_eq!(schema.version, "1.0");
10192
}
@@ -104,25 +95,23 @@ mod test_schema_validation {
10495
fn test_invalid_name_schema() {
10596
let schema_json = json!({
10697
"name": "gvt1",
107-
"ver": "1.0",
10898
"version": "1.0",
10999
"attrNames": ["aaa", "bbb", "ccc"],
110100
})
111101
.to_string();
112102

113-
serde_json::from_str::<SchemaV1>(&schema_json).unwrap();
103+
serde_json::from_str::<Schema>(&schema_json).unwrap();
114104
}
115105

116106
#[test]
117107
fn test_invalid_version_schema() {
118108
let schema_json = json!({
119109
"name": "gvt",
120-
"ver": "1.0",
121110
"version": "1.1",
122111
"attrNames": ["aaa", "bbb", "ccc"],
123112
})
124113
.to_string();
125114

126-
serde_json::from_str::<SchemaV1>(&schema_json).unwrap();
115+
serde_json::from_str::<Schema>(&schema_json).unwrap();
127116
}
128117
}

anoncreds/src/ffi/schema.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ 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(
1011
schema_name: FfiStr,
1112
schema_version: FfiStr,
1213
attr_names: FfiStrList,
13-
seq_no: i64,
1414
result_p: *mut ObjectHandle,
1515
) -> ErrorCode {
1616
catch_error(|| {
@@ -25,11 +25,6 @@ pub extern "C" fn anoncreds_create_schema(
2525
schema_name,
2626
schema_version,
2727
attr_names.to_string_vec()?.into(),
28-
if seq_no > 0 {
29-
Some(seq_no as u32)
30-
} else {
31-
None
32-
},
3328
)?;
3429
let handle = ObjectHandle::create(schema)?;
3530
unsafe { *result_p = handle };

anoncreds/src/services/issuer.rs

Lines changed: 3 additions & 7 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::*;
@@ -30,7 +30,6 @@ pub fn create_schema(
3030
schema_name: &str,
3131
schema_version: &str,
3232
attr_names: AttributeNames,
33-
seq_no: Option<u32>,
3433
) -> Result<Schema> {
3534
trace!(
3635
"create_schema >>> schema_name: {:?}, schema_version: {:?}, attr_names: {:?}",
@@ -39,13 +38,12 @@ pub fn create_schema(
3938
attr_names
4039
);
4140

42-
let schema = SchemaV1 {
41+
let schema = Schema {
4342
name: schema_name.to_string(),
4443
version: schema_version.to_string(),
4544
attr_names,
46-
seq_no,
4745
};
48-
Ok(Schema::SchemaV1(schema))
46+
Ok(schema)
4947
}
5048

5149
pub fn create_credential_definition<SI>(
@@ -69,8 +67,6 @@ where
6967
);
7068
let schema_id = schema_id.try_into()?;
7169

72-
let Schema::SchemaV1(schema) = schema;
73-
7470
let credential_schema = build_credential_schema(&schema.attr_names.0)?;
7571
let non_credential_schema = build_non_credential_schema()?;
7672

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

anoncreds/tests/anoncreds_demos.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use self::utils::anoncreds::{IssuerWallet, ProverWallet};
1313

1414
mod utils;
1515

16-
pub static GVT_SCHEMA_NAME: &'static str = "gvt";
17-
pub static GVT_SCHEMA_ATTRIBUTES: &[&'static str; 4] = &["name", "age", "sex", "height"];
1816
pub static SCHEMA_ID: &str = "mock:uri";
1917
pub static CRED_DEF_ID: &str = "mock:uri";
18+
pub const GVT_SCHEMA_NAME: &str = "gvt";
19+
pub const GVT_SCHEMA_ATTRIBUTES: &[&str; 4] = &["name", "age", "sex", "height"];
2020

2121
#[test]
2222
fn anoncreds_works_for_single_issuer_single_prover() {
@@ -27,13 +27,9 @@ fn anoncreds_works_for_single_issuer_single_prover() {
2727
let mut prover_wallet = ProverWallet::default();
2828

2929
// Issuer creates Schema - would be published to the ledger
30-
let gvt_schema = issuer::create_schema(
31-
GVT_SCHEMA_NAME,
32-
"1.0",
33-
GVT_SCHEMA_ATTRIBUTES[..].into(),
34-
None,
35-
)
36-
.expect("Error creating gvt schema for issuer");
30+
let gvt_schema =
31+
issuer::create_schema(GVT_SCHEMA_NAME, "1.0", GVT_SCHEMA_ATTRIBUTES[..].into())
32+
.expect("Error creating gvt schema for issuer");
3733

3834
// Issuer creates Credential Definition
3935
let cred_def_parts = issuer::create_credential_definition(

0 commit comments

Comments
 (0)