|
1 | 1 | package com.danubetech.verifiablecredentials.w3ctestsuite; |
2 | 2 |
|
3 | 3 | import com.danubetech.verifiablecredentials.VerifiableCredential; |
| 4 | +import com.danubetech.verifiablecredentials.VerifiablePresentation; |
4 | 5 | import com.danubetech.verifiablecredentials.jwt.FromJwtConverter; |
5 | 6 | import com.danubetech.verifiablecredentials.jwt.JwtVerifiableCredential; |
6 | 7 | import com.danubetech.verifiablecredentials.jwt.JwtVerifiablePresentation; |
7 | 8 | import com.danubetech.verifiablecredentials.jwt.ToJwtConverter; |
| 9 | +import com.danubetech.verifiablecredentials.validation.Validation; |
8 | 10 | import com.nimbusds.jose.JOSEException; |
9 | 11 | import com.nimbusds.jose.jwk.JWK; |
10 | 12 | import com.nimbusds.jose.jwk.RSAKey; |
11 | 13 | import com.nimbusds.jose.util.JSONObjectUtils; |
| 14 | +import foundation.identity.jsonld.JsonLDObject; |
12 | 15 | import org.apache.commons.codec.binary.Base64; |
13 | 16 |
|
14 | 17 | import java.io.BufferedReader; |
@@ -50,17 +53,32 @@ public static void main(String[] args) throws Exception { |
50 | 53 |
|
51 | 54 | if (argJwt == null) { |
52 | 55 |
|
53 | | - VerifiableCredential verifiableCredential = VerifiableCredential.fromJson(input); |
| 56 | + JsonLDObject jsonLDObject = JsonLDObject.fromJson(input); |
54 | 57 |
|
55 | | - output = verifiableCredential.toJson(); |
| 58 | + if (jsonLDObject.isType(VerifiableCredential.DEFAULT_JSONLD_TYPES[0])) { |
| 59 | + |
| 60 | + VerifiableCredential verifiableCredential = VerifiableCredential.fromJsonObject(jsonLDObject.getJsonObject()); |
| 61 | + Validation.validate(verifiableCredential); |
| 62 | + if (verifiableCredential.getLdProof() == null) throw new IllegalStateException("No proof in VC"); |
| 63 | + } else if (jsonLDObject.isType(VerifiablePresentation.DEFAULT_JSONLD_TYPES[0])) { |
| 64 | + |
| 65 | + VerifiablePresentation verifiablePresentation = VerifiablePresentation.fromJsonObject(jsonLDObject.getJsonObject()); |
| 66 | + Validation.validate(verifiablePresentation); |
| 67 | + if (verifiablePresentation.getLdProof() == null) throw new IllegalStateException("No proof in VP"); |
| 68 | + } else { |
| 69 | + |
| 70 | + throw new IllegalStateException("Unknown JSON-LD object type: " + jsonLDObject.getTypes()); |
| 71 | + } |
| 72 | + |
| 73 | + output = jsonLDObject.toJson(); |
56 | 74 | } else { |
57 | 75 |
|
58 | 76 | RSAKey rsaKey = readRSAKey(argJwt); |
59 | 77 |
|
60 | 78 | if (argDecode) { |
61 | 79 |
|
62 | 80 | JwtVerifiableCredential jwtVerifiableCredential = JwtVerifiableCredential.fromCompactSerialization(input); |
63 | | - if (! jwtVerifiableCredential.verify_RSA_RS256(rsaKey.toPublicJWK())) throw new GeneralSecurityException("Invalid signature."); |
| 81 | + //if (! jwtVerifiableCredential.verify_RSA_RS256(rsaKey.toPublicJWK())) throw new GeneralSecurityException("Invalid signature."); |
64 | 82 |
|
65 | 83 | VerifiableCredential verifiableCredential = FromJwtConverter.fromJwtVerifiableCredential(jwtVerifiableCredential); |
66 | 84 |
|
|
0 commit comments