Skip to content

Commit 158a920

Browse files
author
Sergey Kudryashov
committed
Verifiable credentials creation
1 parent 04f465c commit 158a920

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ edition = "2021"
88
[dependencies]
99
serde_json = "1.0.81"
1010
signature = "1.5.0"
11+
map = "0.0.0"
12+
serde = "1.0.137"

src/credential.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
#[derive(Deserialize, Debug)]
3+
pub struct VerifiableCredential {
4+
context: String,
5+
id: String,
6+
credType: String,
7+
issuer: String,
8+
issuanceDate: String,
9+
subject: CredentialSubject,
10+
proof: *mut CredentialProof,
11+
}
12+
13+
impl <'a> VerifiableCredential {
14+
pub fn init(credType: &str, credSubject: serde_json::Value) -> Self {
15+
Self {
16+
context: String::default(),
17+
id: String::default(),
18+
credType: String::from(credType),
19+
issuer: String::default(),
20+
issuanceDate: String::default(),
21+
subject: credSubject,
22+
proof: &mut CredentialProof{
23+
proofType:String::default(),
24+
created:String::default(),
25+
verificationMethod:String::default(),
26+
proofPurpose:String::default(),
27+
proofValue:String::default(),
28+
},
29+
}
30+
}
31+
}
32+
33+
34+
pub struct CredentialProof {
35+
proofType: String,
36+
created: String,
37+
verificationMethod: String,
38+
proofPurpose: String,
39+
proofValue: String,
40+
}
41+
42+
pub enum CredentialSubject {
43+
String,
44+
Value,
45+
Object(serde_json::Map<String, serde_json::Value>),
46+
}

src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
mod credential;
2+
use serde_json;
3+
use credential::*;
4+
use serde::Deserialize;
5+
use serde_json::Map;
6+
// pub use crate::map::Map;
7+
18
/// Verification of Data Integrity Proofs requires the resolution of the `verificationMethod` specified in the proof.
29
/// The `verificationMethod` refers to a cryptographic key stored in some external source.
310
/// The DIDResolver is responsible for resolving the `verificationMethod` to a key that can be used to verify the proof.
@@ -15,7 +22,9 @@ pub fn create_credential(
1522
_cred_type: &str,
1623
_cred_subject: serde_json::Value,
1724
) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
18-
unimplemented!();
25+
let vc = VerifiableCredential::init(_cred_type, _cred_subject);
26+
Ok(_cred_subject)
27+
// let vcVec = serde_json::from_str(_cred_type.unwrap();
1928
}
2029

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

0 commit comments

Comments
 (0)