@@ -2,9 +2,7 @@ mod credential;
2
2
3
3
use serde_json:: { self , Value } ;
4
4
use credential:: * ;
5
- // use serde::{Deserialize, Serialize};
6
- // use serde_json::Result;
7
- use std:: { collections:: HashMap , error:: Error } ;
5
+ use std:: { collections:: HashMap } ;
8
6
9
7
pub mod error;
10
8
/// Verification of Data Integrity Proofs requires the resolution of the `verificationMethod` specified in the proof.
@@ -60,49 +58,48 @@ pub trait DocumentBuilder {
60
58
}
61
59
62
60
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
+ }
80
79
81
80
// /// Given a JSON-LD document and a DIDResolver, verify the data integrity proof for the document.
82
81
// /// 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.
83
82
// /// 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
+ }
101
98
102
99
#[ cfg( test) ]
103
100
mod tests {
104
101
use crate :: DocumentBuilder ;
105
- use std:: collections:: HashMap ;
102
+ use std:: { collections:: HashMap , vec } ;
106
103
use assert_json_diff:: { assert_json_eq} ;
107
104
use crate :: serde_json:: json;
108
105
@@ -122,12 +119,12 @@ mod tests {
122
119
let mut kv_body: HashMap < String , Value > = HashMap :: new ( ) ;
123
120
let mut kv_subject: HashMap < String , Value > = HashMap :: new ( ) ;
124
121
125
- let expect = json ! ( {
122
+ let _expect = json ! ( {
126
123
"@context" : [
127
124
"https://www.w3.org/2018/credentials/v1" ,
128
- "https://w3id. org/citizenship /v1"
125
+ "https://www.w3. org/2018/credentials/examples /v1"
129
126
] ,
130
- "id" : "https://issuer.oidp.uscis.gov/credentials/83627465" ,
127
+ "@ id" : "https://issuer.oidp.uscis.gov/credentials/83627465" ,
131
128
"type" : [ "VerifiableCredential" , "PermanentResidentCard" ] ,
132
129
"issuer" : "did:example:28394728934792387" ,
133
130
"identifier" : "83627465" ,
@@ -151,19 +148,29 @@ mod tests {
151
148
} ,
152
149
} ) ;
153
150
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
+
155
157
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 ( ) ) ) ;
157
159
kv_body. entry ( "name" . to_string ( ) ) . or_insert ( Value :: String ( "Permanent Resident Card" . to_string ( ) ) ) ;
158
160
kv_body. entry ( "description" . to_string ( ) ) . or_insert ( Value :: String ( "Government of Example Permanent Resident Card." . to_string ( ) ) ) ;
159
161
kv_body. entry ( "issuanceDate" . to_string ( ) ) . or_insert ( Value :: String ( "2019-12-03T12:19:52Z" . to_string ( ) ) ) ;
160
162
kv_body. entry ( "expirationDate" . to_string ( ) ) . or_insert ( Value :: String ( "2029-12-03T12:19:52Z" . to_string ( ) ) ) ;
161
163
162
164
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
+
164
171
kv_subject. entry ( "givenName" . to_string ( ) ) . or_insert ( Value :: String ( "JOHN" . to_string ( ) ) ) ;
165
172
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 ( ) ) ) ;
167
174
kv_subject. entry ( "image" . to_string ( ) ) . or_insert ( Value :: String ( "data:image/png;base64,iVBORw0KGgo...kJggg==" . to_string ( ) ) ) ;
168
175
kv_subject. entry ( "residentSince" . to_string ( ) ) . or_insert ( Value :: String ( "2015-01-01" . to_string ( ) ) ) ;
169
176
kv_subject. entry ( "lprCategory" . to_string ( ) ) . or_insert ( Value :: String ( "C09" . to_string ( ) ) ) ;
@@ -179,7 +186,7 @@ mod tests {
179
186
"https://issuer.oidp.uscis.gov/credentials/83627465" ,
180
187
) ;
181
188
assert ! ( vc. is_ok( ) ) ;
182
- // assert_json_eq!(vc, expect );
189
+ assert_json_eq ! ( _expect , vc . unwrap ( ) ) ;
183
190
Ok ( ( ) )
184
191
}
185
192
}
0 commit comments