Skip to content

Commit d108c66

Browse files
committed
chore: Update W3C test suite generator class.
Signed-off-by: Markus Sabadello <[email protected]>
1 parent b32d183 commit d108c66

File tree

1 file changed

+21
-3
lines changed
  • src/main/java/com/danubetech/verifiablecredentials/w3ctestsuite

1 file changed

+21
-3
lines changed

src/main/java/com/danubetech/verifiablecredentials/w3ctestsuite/Generator.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.danubetech.verifiablecredentials.w3ctestsuite;
22

33
import com.danubetech.verifiablecredentials.VerifiableCredential;
4+
import com.danubetech.verifiablecredentials.VerifiablePresentation;
45
import com.danubetech.verifiablecredentials.jwt.FromJwtConverter;
56
import com.danubetech.verifiablecredentials.jwt.JwtVerifiableCredential;
67
import com.danubetech.verifiablecredentials.jwt.JwtVerifiablePresentation;
78
import com.danubetech.verifiablecredentials.jwt.ToJwtConverter;
9+
import com.danubetech.verifiablecredentials.validation.Validation;
810
import com.nimbusds.jose.JOSEException;
911
import com.nimbusds.jose.jwk.JWK;
1012
import com.nimbusds.jose.jwk.RSAKey;
1113
import com.nimbusds.jose.util.JSONObjectUtils;
14+
import foundation.identity.jsonld.JsonLDObject;
1215
import org.apache.commons.codec.binary.Base64;
1316

1417
import java.io.BufferedReader;
@@ -50,17 +53,32 @@ public static void main(String[] args) throws Exception {
5053

5154
if (argJwt == null) {
5255

53-
VerifiableCredential verifiableCredential = VerifiableCredential.fromJson(input);
56+
JsonLDObject jsonLDObject = JsonLDObject.fromJson(input);
5457

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();
5674
} else {
5775

5876
RSAKey rsaKey = readRSAKey(argJwt);
5977

6078
if (argDecode) {
6179

6280
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.");
6482

6583
VerifiableCredential verifiableCredential = FromJwtConverter.fromJwtVerifiableCredential(jwtVerifiableCredential);
6684

0 commit comments

Comments
 (0)