Skip to content

Commit faf7ea1

Browse files
author
Sergey Kudryashov
committed
Challenge create
1 parent 6cc07df commit faf7ea1

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

src/credential.rs

+37-20
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11

2+
#![allow(unused_variables)]
3+
#![allow(dead_code)]
4+
5+
type CredentialSubject = serde_json::Value;
6+
type CredentialTypes = [VerifiableCredential];
7+
28

39
// #[derive(Deserialize, Debug)]
410
pub struct VerifiableCredential {
511
context: String,
612
id: String,
7-
credType: String,
13+
cred_type: String,
814
issuer: String,
9-
issuanceDate: String,
15+
issuance_date: String,
1016
subject: CredentialSubject,
1117
proof: *mut CredentialProof,
1218
}
1319

1420
impl <'a> VerifiableCredential {
15-
pub fn init(credType: &'a str, credSubject: serde_json::Value) -> Self {
21+
pub fn init(cred_type: &'a str, cred_subject: serde_json::Value) -> Self {
1622
Self {
17-
context: String::default(), // array defined by us
18-
id: String::default(), // provided by client
19-
credType: String::from(credType),
20-
issuer: String::default(), // provided by client
21-
issuanceDate: String::default(),
22-
subject: credSubject, //
23-
proof: &mut CredentialProof{ // we don't have it
24-
proofType:String::default(),
23+
/// context is a slice, it is defined by us based on parsed cred type and cred subject
24+
context: String::default(),
25+
/// provided by client
26+
id: String::default(),
27+
cred_type: String::from(cred_type),
28+
/// provided by client
29+
issuer: String::default(),
30+
issuance_date: String::default(),
31+
subject: cred_subject,
32+
/// created empty object on VerifiableCredential init step, will be filled on "create_data_integrity_proof" step
33+
proof: &mut CredentialProof {
34+
proof_type:String::default(),
2535
created:String::default(),
26-
verificationMethod:String::default(),
27-
proofPurpose:String::default(),
28-
proofValue:String::default(),
36+
verification_method:String::default(),
37+
proof_purpose:String::default(),
38+
proof_value:String::default(),
2939
},
3040
}
3141
}
42+
43+
pub fn serialize(self) -> serde_json::Value {
44+
return self.subject
45+
}
3246
}
3347

3448

3549
pub struct CredentialProof {
36-
proofType: String,
50+
proof_type: String,
3751
created: String,
38-
verificationMethod: String,
39-
proofPurpose: String,
40-
proofValue: String,
52+
verification_method: String,
53+
proof_purpose: String,
54+
proof_value: String,
4155
}
4256

43-
type CredentialSubject = serde_json::Value;
44-
57+
pub struct VerifiablePresentation {
58+
nonce: String,
59+
endpoint: String,
60+
credential_types: CredentialTypes,
61+
}

src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use serde_json;
33
use credential::*;
44
use serde::Deserialize;
55
use serde_json::Map;
6-
// pub use crate::map::Map;
76

87
/// Verification of Data Integrity Proofs requires the resolution of the `verificationMethod` specified in the proof.
98
/// The `verificationMethod` refers to a cryptographic key stored in some external source.
@@ -23,8 +22,7 @@ pub fn create_credential(
2322
_cred_subject: serde_json::Value,
2423
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
2524
let vc = VerifiableCredential::init(_cred_type, _cred_subject);
26-
Ok(_cred_subject)
27-
// let vcVec = serde_json::from_str(_cred_type.unwrap();
25+
Ok(vc.serialize())
2826
}
2927

3028
/// Given the set of credentials, create a unsigned JSON-LD Presentation of those credentials.

0 commit comments

Comments
 (0)