44import com .danubetech .verifiablecredentials .VerifiableCredential ;
55import com .danubetech .verifiablecredentials .VerifiableCredentialV2 ;
66import com .danubetech .verifiablecredentials .VerifiablePresentation ;
7+ import com .danubetech .verifiablecredentials .VerifiablePresentationV2 ;
78import com .danubetech .verifiablecredentials .jsonld .VerifiableCredentialKeywords ;
89import com .nimbusds .jwt .JWTClaimsSet ;
910import foundation .identity .jsonld .JsonLDUtils ;
@@ -66,9 +67,7 @@ public static VerifiableCredential fromJwtVerifiableCredential(JwtVerifiableCred
6667 verifiableCredentialBuilder .expirationDate (expirationTime );
6768 }
6869
69- VerifiableCredential verifiableCredential = verifiableCredentialBuilder .build ();
70-
71- return verifiableCredential ;
70+ return verifiableCredentialBuilder .build ();
7271 }
7372
7473 public static VerifiablePresentation fromJwtVerifiablePresentation (JwtVerifiablePresentation jwtVerifiablePresentation ) {
@@ -92,9 +91,7 @@ public static VerifiablePresentation fromJwtVerifiablePresentation(JwtVerifiable
9291 verifiablePresentationBuilder .holder (URI .create (issuer ));
9392 }
9493
95- VerifiablePresentation verifiablePresentation = verifiablePresentationBuilder .build ();
96-
97- return verifiablePresentation ;
94+ return verifiablePresentationBuilder .build ();
9895 }
9996
10097 public static VerifiablePresentation fromJwtVerifiableCredentialToVerifiablePresentation (JwtVerifiableCredential jwtVerifiableCredential ) {
@@ -160,4 +157,29 @@ public static VerifiableCredentialV2 fromJwtVerifiableCredentialV2(JwtVerifiable
160157
161158 return verifiableCredentialBuilder .build ();
162159 }
160+
161+ public static VerifiablePresentationV2 fromJwtVerifiablePresentationV2 (JwtVerifiablePresentationV2 jwtVerifiablePresentation ) {
162+
163+ VerifiablePresentationV2 payloadVerifiablePresentation = VerifiablePresentationV2 .fromJson (jwtVerifiablePresentation .getPayloadObject ().toString ());
164+
165+ VerifiablePresentationV2 .Builder <? extends VerifiablePresentationV2 .Builder <?>> verifiablePresentationBuilder = VerifiablePresentationV2 .builder ()
166+ .base (payloadVerifiablePresentation )
167+ .defaultContexts (false )
168+ .defaultTypes (false );
169+
170+ JWTClaimsSet payload = jwtVerifiablePresentation .getPayload ();
171+
172+ String jwtId = payload .getJWTID ();
173+ if (jwtId != null && payloadVerifiablePresentation .getId () == null ) {
174+ verifiablePresentationBuilder .id (URI .create (jwtId ));
175+ }
176+
177+ String issuer = payload .getIssuer ();
178+ if (issuer != null && payloadVerifiablePresentation .getHolder () == null ) {
179+ verifiablePresentationBuilder .holder (URI .create (issuer ));
180+ }
181+
182+ return verifiablePresentationBuilder .build ();
183+ }
184+
163185}
0 commit comments