|
4 | 4 | import com.danubetech.verifiablecredentials.VerifiableCredential; |
5 | 5 | import com.danubetech.verifiablecredentials.VerifiableCredentialV2; |
6 | 6 | import com.danubetech.verifiablecredentials.VerifiablePresentation; |
| 7 | +import com.danubetech.verifiablecredentials.VerifiablePresentationV2; |
7 | 8 | import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords; |
8 | 9 | import com.nimbusds.jwt.JWTClaimsSet; |
9 | 10 | import foundation.identity.jsonld.JsonLDKeywords; |
@@ -237,4 +238,45 @@ public static JwtVerifiableCredentialV2 toJwtVerifiableCredentialV2(VerifiableCr |
237 | 238 |
|
238 | 239 | return toJwtVerifiableCredentialV2(verifiableCredential, null, false, false); |
239 | 240 | } |
| 241 | + |
| 242 | + public static JwtVerifiablePresentationV2 toJwtVerifiablePresentation(VerifiablePresentationV2 verifiablePresentation, String aud) { |
| 243 | + |
| 244 | + JWTClaimsSet.Builder jwtPayloadBuilder = new JWTClaimsSet.Builder(); |
| 245 | + |
| 246 | + VerifiablePresentationV2 payloadVerifiablePresentation = VerifiablePresentationV2.builder() |
| 247 | + .defaultContexts(false) |
| 248 | + .defaultTypes(false) |
| 249 | + .build(); |
| 250 | + |
| 251 | + JsonLDUtils.jsonLdAddAll(payloadVerifiablePresentation, verifiablePresentation.getJsonObject()); |
| 252 | + |
| 253 | + URI id = verifiablePresentation.getId(); |
| 254 | + if (id != null) { |
| 255 | + jwtPayloadBuilder.jwtID(id.toString()); |
| 256 | + JsonLDUtils.jsonLdRemove(payloadVerifiablePresentation, JsonLDKeywords.JSONLD_TERM_ID); |
| 257 | + } |
| 258 | + |
| 259 | + URI holder = verifiablePresentation.getHolder(); |
| 260 | + if (holder != null) { |
| 261 | + jwtPayloadBuilder.issuer(holder.toString()); |
| 262 | + jwtPayloadBuilder.subject(holder.toString()); |
| 263 | + JsonLDUtils.jsonLdRemove(payloadVerifiablePresentation, VerifiableCredentialKeywords.JSONLD_TERM_HOLDER); |
| 264 | + } |
| 265 | + |
| 266 | + if (aud != null) { |
| 267 | + jwtPayloadBuilder.audience(aud); |
| 268 | + } |
| 269 | + |
| 270 | + Map<String, Object> vpContent = new LinkedHashMap<>(payloadVerifiablePresentation.getJsonObject()); |
| 271 | + jwtPayloadBuilder.claim(JwtKeywords.JWT_CLAIM_VP, vpContent); |
| 272 | + |
| 273 | + JWTClaimsSet jwtPayload = jwtPayloadBuilder.build(); |
| 274 | + |
| 275 | + return new JwtVerifiablePresentationV2(jwtPayload, payloadVerifiablePresentation, null, null); |
| 276 | + } |
| 277 | + |
| 278 | + public static JwtVerifiablePresentationV2 toJwtVerifiablePresentation(VerifiablePresentationV2 verifiablePresentation) { |
| 279 | + |
| 280 | + return toJwtVerifiablePresentation(verifiablePresentation, null); |
| 281 | + } |
240 | 282 | } |
0 commit comments