@@ -248,10 +248,11 @@ pub trait TrustchainVPAPI {
248
248
mod tests {
249
249
use crate :: api:: { TrustchainVCAPI , TrustchainVPAPI } ;
250
250
use crate :: TrustchainAPI ;
251
+ use did_ion:: sidetree:: PublicKeyEntry ;
251
252
use ssi:: jsonld:: ContextLoader ;
252
253
use ssi:: ldp:: now_ns;
253
254
use ssi:: one_or_many:: OneOrMany ;
254
- use ssi:: vc:: { Credential , CredentialOrJWT , Presentation , VCDateTime } ;
255
+ use ssi:: vc:: { Credential , CredentialOrJWT , CredentialSubject , Presentation , VCDateTime } ;
255
256
use trustchain_core:: utils:: init;
256
257
use trustchain_core:: vc:: CredentialError ;
257
258
use trustchain_core:: vp:: PresentationError ;
@@ -269,14 +270,8 @@ mod tests {
269
270
"https://www.w3.org/2018/credentials/examples/v1",
270
271
"https://w3id.org/citizenship/v1"
271
272
],
272
- "credentialSchema": {
273
- "id": "did:example:cdf:35LB7w9ueWbagPL94T9bMLtyXDj9pX5o",
274
- "type": "did:example:schema:22KpkXgecryx9k7N6XN1QoN3gXwBkSU8SfyyYQG"
275
- },
276
273
"type": ["VerifiableCredential"],
277
274
"issuer": "did:ion:test:EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q",
278
- "issuanceDate": "2023-09-06T12:15:08.630033Z",
279
- "image": "some_base64_representation",
280
275
"credentialSubject": {
281
276
"givenName": "Jane",
282
277
"familyName": "Doe",
@@ -289,6 +284,33 @@ mod tests {
289
284
}
290
285
"# ;
291
286
287
+ const UNSIGNED_DRIVERS_LICENCE_VC : & str = r###"{
288
+ "@context": [
289
+ "https://www.w3.org/2018/credentials/v1",
290
+ "https://w3id.org/vdl/v1"
291
+ ],
292
+ "type": [
293
+ "VerifiableCredential",
294
+ "Iso18013DriversLicense"
295
+ ],
296
+ "issuer": "did:ion:test:EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q",
297
+ "issuanceDate": "2023-11-23T11:43:26.806224Z",
298
+ "credentialSubject": {
299
+ "id": "did:example:12347abcd",
300
+ "Iso18013DriversLicense": {
301
+ "height": 1.8,
302
+ "weight": 70,
303
+ "nationality": "France",
304
+ "given_name": "Test",
305
+ "family_name": "A",
306
+ "issuing_country": "US",
307
+ "birth_date": "1958-07-17",
308
+ "age_in_years": 30,
309
+ "age_birth_year": 1958
310
+ }
311
+ }
312
+ }"### ;
313
+
292
314
#[ ignore = "requires a running Sidetree node listening on http://localhost:3000" ]
293
315
#[ tokio:: test]
294
316
async fn test_verify_credential ( ) {
@@ -328,6 +350,110 @@ mod tests {
328
350
}
329
351
}
330
352
353
+ #[ ignore = "requires a running Sidetree node listening on http://localhost:3000" ]
354
+ #[ tokio:: test]
355
+ async fn test_verify_rss_credential ( ) {
356
+ init ( ) ;
357
+
358
+ // DID with RSS verification method
359
+ let issuer_did_suffix = "EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q" ;
360
+ let resolver = trustchain_resolver ( "http://localhost:3000/" ) ;
361
+ let vc: Credential = serde_json:: from_str ( UNSIGNED_DRIVERS_LICENCE_VC ) . unwrap ( ) ;
362
+ let attestor = IONAttestor :: new ( issuer_did_suffix) ;
363
+
364
+ let signed_vc = attestor
365
+ . sign (
366
+ & vc,
367
+ None ,
368
+ Some ( "QDsGIX_7NfNEaXdEeV7PJ5e_CwoH5LlF3srsCp5dcHA" ) ,
369
+ & resolver,
370
+ & mut ContextLoader :: default ( ) ,
371
+ )
372
+ . await
373
+ . unwrap ( ) ;
374
+ println ! ( "{}" , serde_json:: to_string_pretty( & signed_vc) . unwrap( ) ) ;
375
+ let mut context_loader = ContextLoader :: default ( ) ;
376
+ let verifier = TrustchainVerifier :: new ( resolver) ;
377
+ let res = TrustchainAPI :: verify_credential (
378
+ & signed_vc,
379
+ None ,
380
+ ROOT_EVENT_TIME_1 ,
381
+ & verifier,
382
+ & mut context_loader,
383
+ )
384
+ . await ;
385
+ // println!("{:?}", &res);
386
+ assert ! ( res. is_ok( ) ) ;
387
+ }
388
+
389
+ #[ ignore = "requires a running Sidetree node listening on http://localhost:3000" ]
390
+ #[ tokio:: test]
391
+ async fn test_redact_verify_rss_credential ( ) {
392
+ init ( ) ;
393
+
394
+ // DID with RSS verification method
395
+ let issuer_did_suffix = "did:ion:test:EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q" ;
396
+ let resolver = trustchain_resolver ( "http://localhost:3000/" ) ;
397
+ let vc: Credential = serde_json:: from_str ( UNSIGNED_DRIVERS_LICENCE_VC ) . unwrap ( ) ;
398
+ let attestor = IONAttestor :: new ( issuer_did_suffix) ;
399
+
400
+ let mut signed_vc = attestor
401
+ . sign (
402
+ & vc,
403
+ None ,
404
+ Some ( "QDsGIX_7NfNEaXdEeV7PJ5e_CwoH5LlF3srsCp5dcHA" ) ,
405
+ & resolver,
406
+ & mut ContextLoader :: default ( ) ,
407
+ )
408
+ . await
409
+ . unwrap ( ) ;
410
+ // println!("{}", serde_json::to_string_pretty(&signed_vc).unwrap());
411
+ // derive redacted RSignature
412
+ let masked_cred_sub: CredentialSubject = serde_json:: from_str (
413
+ r###"{
414
+ "id": "did:example:12347abcd",
415
+ "Iso18013DriversLicense": {
416
+ "height": null,
417
+ "weight": null,
418
+ "nationality": null,
419
+ "given_name": null,
420
+ "family_name": null,
421
+ "issuing_country": "US",
422
+ "birth_date": null,
423
+ "age_in_years": 30,
424
+ "age_birth_year": null
425
+ }
426
+ }"### ,
427
+ )
428
+ . unwrap ( ) ;
429
+ let mut masked_copy = signed_vc. clone ( ) ;
430
+ masked_copy. credential_subject = OneOrMany :: One ( masked_cred_sub) ;
431
+
432
+ // produce redacted vc from redacted json
433
+ let mut context_loader = ContextLoader :: default ( ) ;
434
+ let verifier = TrustchainVerifier :: new ( resolver) ;
435
+ signed_vc
436
+ . rss_redact (
437
+ masked_copy,
438
+ & trustchain_resolver ( "http://localhost:3000/" ) ,
439
+ & mut context_loader,
440
+ )
441
+ . await
442
+ . unwrap ( ) ;
443
+ // println!("{}", serde_json::to_string_pretty(&signed_vc).unwrap());
444
+
445
+ let res = TrustchainAPI :: verify_credential (
446
+ & signed_vc,
447
+ None ,
448
+ ROOT_EVENT_TIME_1 ,
449
+ & verifier,
450
+ & mut context_loader,
451
+ )
452
+ . await ;
453
+
454
+ assert ! ( res. is_ok( ) ) ;
455
+ }
456
+
331
457
#[ ignore = "requires a running Sidetree node listening on http://localhost:3000" ]
332
458
#[ tokio:: test]
333
459
async fn test_verify_presentation ( ) {
@@ -444,4 +570,16 @@ mod tests {
444
570
. await
445
571
. unwrap ( )
446
572
}
573
+
574
+ #[ test]
575
+ fn get_key_entry ( ) {
576
+ use ps_sig:: keys:: Params ;
577
+ use ssi:: jwk:: rss:: generate_keys_jwk;
578
+ use ssi:: jwk:: JWK ;
579
+
580
+ let key: JWK = generate_keys_jwk ( 64 , & Params :: new ( "test" . to_string ( ) . as_bytes ( ) ) ) . unwrap ( ) ;
581
+ println ! ( "{}" , serde_json:: to_string_pretty( & key) . unwrap( ) ) ;
582
+ let entry: PublicKeyEntry = key. try_into ( ) . unwrap ( ) ;
583
+ println ! ( "{}" , serde_json:: to_string_pretty( & entry) . unwrap( ) ) ;
584
+ }
447
585
}
0 commit comments