Skip to content

Commit b15ce62

Browse files
author
Sergey Kudryashov
committed
Test fixed
1 parent 02cfbc3 commit b15ce62

File tree

3 files changed

+70
-60
lines changed

3 files changed

+70
-60
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/credential.rs

+3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ pub struct VerifiableCredential {
4646
context: VerificationContext,
4747
#[serde(rename = "@id")]
4848
id: String,
49+
#[serde(rename = "type")]
4950
cred_type: String,
51+
#[serde(rename = "issuanceDate")]
5052
issuance_date: SystemTime,
53+
#[serde(rename = "credentialSubject")]
5154
subject: CredentialSubject,
5255
#[serde(flatten)]
5356
pub property_set: HashMap<String, Value>,

core/src/lib.rs

+53-46
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ mod credential;
22

33
use serde_json::{self, Value};
44
use credential::*;
5-
// use serde::{Deserialize, Serialize};
6-
// use serde_json::Result;
7-
use std::{collections::HashMap, error::Error};
5+
use std::{collections::HashMap};
86

97
pub mod error;
108
/// Verification of Data Integrity Proofs requires the resolution of the `verificationMethod` specified in the proof.
@@ -60,49 +58,48 @@ pub trait DocumentBuilder {
6058
}
6159

6260

63-
// // ed25519 cryptography key generation & DID Document creation
64-
// pub fn create_identity(
65-
// _mnemonic: &str,
66-
// _password: Option<String>,
67-
// ) -> Result<(), Error> {
68-
// unimplemented!();
69-
// }
70-
71-
// /// Given a JSON-LD document, c
72-
// /// reate a data integrity proof for the document.
73-
// /// Currently, only `Ed25519Signature2018` data integrity proofs in the JSON-LD format can be created.
74-
// pub fn create_data_integrity_proof<S: signature::Signature>(
75-
// _doc: serde_json::Value,
76-
// _signer: &impl signature::Signer<S>,
77-
// ) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
78-
// unimplemented!();
79-
// }
61+
// Commented due to failing cargo check
62+
// ed25519 cryptography key generation & DID Document creation
63+
pub fn create_identity(
64+
_mnemonic: &str,
65+
_password: Option<String>,
66+
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
67+
unimplemented!();
68+
}
69+
70+
/// Given a JSON-LD document, c
71+
/// reate a data integrity proof for the document.
72+
/// Currently, only `Ed25519Signature2018` data integrity proofs in the JSON-LD format can be created.
73+
pub fn create_data_integrity_proof<S: signature::Signature>(
74+
_doc: serde_json::Value,
75+
_signer: &impl signature::Signer<S>,
76+
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
77+
unimplemented!();
78+
}
8079

8180
// /// Given a JSON-LD document and a DIDResolver, verify the data integrity proof for the document.
8281
// /// This will by parsing the `verificationMethod` property of the data integrity proof and resolving it to a key that can be used to verify the proof.
8382
// /// Currently only `Ed25519Signature2018` is supported for data integrity proof verification.
84-
// pub fn verify_data_integrity_proof<S: signature::Signature>(
85-
// _doc: serde_json::Value,
86-
// _resolver: &impl DIDResolver,
87-
// _verifier: &impl signature::Verifier<S>,
88-
// ) -> Result<bool, Box<dyn std::error::Error>> {
89-
// unimplemented!();
90-
// }
91-
92-
// /// Given a JSON-LD document and a DIDResolver, verify the data integrity proof for the Verifiable Presentation.
93-
// /// Then each claimed Verifiable Credential must be verified for validity and ownership of the credential by the subject.
94-
// pub fn verify_presentation<S: signature::Signature>(
95-
// _doc: serde_json::Value,
96-
// _resolver: &impl DIDResolver,
97-
// _verifier: &impl signature::Verifier<S>,
98-
// ) -> Result<bool, Box<dyn std::error::Error>> {
99-
// unimplemented!();
100-
// }
83+
pub fn verify_data_integrity_proof<S: signature::Signature>(
84+
_doc: serde_json::Value,
85+
_resolver: &impl DIDResolver,
86+
_verifier: &impl signature::Verifier<S>,
87+
) -> Result<bool, Box<dyn std::error::Error>> {
88+
unimplemented!();
89+
}
90+
91+
/// Given a JSON-LD document and a DIDResolver, verify the data integrity proof for the Verifiable Presentation.
92+
/// Then each claimed Verifiable Credential must be verified for validity and ownership of the credential by the subject.
93+
pub fn create_presentation(
94+
_creds: Vec<serde_json::Value>,
95+
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
96+
unimplemented!();
97+
}
10198

10299
#[cfg(test)]
103100
mod tests {
104101
use crate::DocumentBuilder;
105-
use std::collections::HashMap;
102+
use std::{collections::HashMap, vec};
106103
use assert_json_diff::{assert_json_eq};
107104
use crate::serde_json::json;
108105

@@ -122,12 +119,12 @@ mod tests {
122119
let mut kv_body: HashMap<String, Value> = HashMap::new();
123120
let mut kv_subject: HashMap<String, Value> = HashMap::new();
124121

125-
let expect = json!({
122+
let _expect = json!({
126123
"@context": [
127124
"https://www.w3.org/2018/credentials/v1",
128-
"https://w3id.org/citizenship/v1"
125+
"https://www.w3.org/2018/credentials/examples/v1"
129126
],
130-
"id": "https://issuer.oidp.uscis.gov/credentials/83627465",
127+
"@id": "https://issuer.oidp.uscis.gov/credentials/83627465",
131128
"type": ["VerifiableCredential", "PermanentResidentCard"],
132129
"issuer": "did:example:28394728934792387",
133130
"identifier": "83627465",
@@ -151,19 +148,29 @@ mod tests {
151148
},
152149
});
153150

154-
// kv_body.entry("type".to_string()).insert_entry(Value::Array((["VerifiableCredential", "PermanentResidentCard"])));
151+
// let vc = serde_json::to_string("VerifiableCredential").unwrap();
152+
let type_rs = serde_json::to_value(["VerifiableCredential".to_string(), "PermanentResidentCard".to_string()]);
153+
if type_rs.is_ok() {
154+
kv_body.entry("type".to_string()).or_insert(type_rs.unwrap());
155+
}
156+
155157
kv_body.entry("issuer".to_string()).or_insert(Value::String("did:example:28394728934792387".to_string()));
156-
kv_body.entry("identifier".to_string()).or_insert(Value::String("did:example:28394728934792387".to_string()));
158+
kv_body.entry("identifier".to_string()).or_insert(Value::String("83627465".to_string()));
157159
kv_body.entry("name".to_string()).or_insert(Value::String("Permanent Resident Card".to_string()));
158160
kv_body.entry("description".to_string()).or_insert(Value::String("Government of Example Permanent Resident Card.".to_string()));
159161
kv_body.entry("issuanceDate".to_string()).or_insert(Value::String("2019-12-03T12:19:52Z".to_string()));
160162
kv_body.entry("expirationDate".to_string()).or_insert(Value::String("2029-12-03T12:19:52Z".to_string()));
161163

162164
kv_subject.entry("id".to_string()).or_insert(Value::String("did:example:b34ca6cd37bbf23".to_string()));
163-
// kv_subject.entry("type".to_string()).insert_entry(Value::Array((["PermanentResident", "Person"])));
165+
166+
let type_rs = serde_json::to_value(["PermanentResident".to_string(), "Person".to_string()]);
167+
if type_rs.is_ok() {
168+
kv_subject.entry("type".to_string()).or_insert(type_rs.unwrap());
169+
}
170+
164171
kv_subject.entry("givenName".to_string()).or_insert(Value::String("JOHN".to_string()));
165172
kv_subject.entry("familyName".to_string()).or_insert(Value::String("SMITH".to_string()));
166-
kv_subject.entry("gender".to_string()).or_insert(Value::String(("Male".to_string())));
173+
kv_subject.entry("gender".to_string()).or_insert(Value::String("Male".to_string()));
167174
kv_subject.entry("image".to_string()).or_insert(Value::String("data:image/png;base64,iVBORw0KGgo...kJggg==".to_string()));
168175
kv_subject.entry("residentSince".to_string()).or_insert(Value::String("2015-01-01".to_string()));
169176
kv_subject.entry("lprCategory".to_string()).or_insert(Value::String("C09".to_string()));
@@ -179,7 +186,7 @@ mod tests {
179186
"https://issuer.oidp.uscis.gov/credentials/83627465",
180187
);
181188
assert!(vc.is_ok());
182-
// assert_json_eq!(vc, expect);
189+
assert_json_eq!(_expect, vc.unwrap());
183190
Ok(())
184191
}
185192
}

0 commit comments

Comments
 (0)