Skip to content

Commit

Permalink
feat: change in create VP API, type and name removed from summary VC
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya committed Jun 13, 2023
1 parent c5ad2a1 commit d7f9096
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,6 @@ private void updateSummeryCredentials(DidDocument issuerDidDocument, byte[] issu

Map<String, Object> subject = Map.of(StringPool.ID, holderDid,
StringPool.HOLDER_IDENTIFIER, holderBpn,
StringPool.TYPE, MIWVerifiableCredentialType.SUMMARY_LIST_CREDENTIAL,
StringPool.NAME, StringPool.CX_CREDENTIALS,
StringPool.ITEMS, items,
StringPool.CONTRACT_TEMPLATES, miwSettings.contractTemplatesUrl());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,30 @@ public Map<String, Object> createPresentation(Map<String, Object> data, boolean
List<VerifiableCredential> verifiableCredentials = new ArrayList<>(verifiableCredentialList.size());
verifiableCredentialList.forEach(map -> {
VerifiableCredential verifiableCredential = new VerifiableCredential(map);
validateCredential(verifiableCredential, holderIdentifier);

verifiableCredentials.add(verifiableCredential);
});

String issuerDidString = URLDecoder.decode(verifiableCredentials.get(0).getIssuer().toString(), Charset.defaultCharset());
Did issuerDid = DidParser.parse(verifiableCredentials.get(0).getIssuer());
commonService.getWalletByIdentifier(issuerDidString);

//validate BPN access - Issuer(Creator) of VP must be caller
//validate BPN access - Issuer(Creator) of VP must be caller Issuer of VP must be holder of VC
Validate.isFalse(holderWallet.getBpn().equalsIgnoreCase(callerBpn)).launch(new ForbiddenException("Issuer wallet BPN is not matching with request BPN(from the token)"));

if (asJwt) {

Validate.isFalse(StringUtils.hasText(audience)).launch(new BadDataException("Audience needed to create VP as JWT"));

//Issuer of VP is holder of VC
Did vpIssuerDid = DidParser.parse(holderWallet.getDid());

//JWT Factory
SerializedJwtPresentationFactory presentationFactory = new SerializedJwtPresentationFactoryImpl(
new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), issuerDid);
new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), vpIssuerDid);

//Build JWT
SignedJWT presentation = presentationFactory.createPresentation(
issuerDid, verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId()));
SignedJWT presentation = presentationFactory.createPresentation(vpIssuerDid
, verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId()));

response.put(StringPool.VP, presentation.serialize());
} else {
Expand Down Expand Up @@ -251,9 +252,4 @@ private boolean validateAudience(String audience, SignedJWT signedJWT) {
return true;
}
}

private void validateCredential(VerifiableCredential verifiableCredential, String holderIdentifier) {
//check holders
Validate.isFalse(verifiableCredential.getCredentialSubject().get(0).get(StringPool.ID).toString().equals(holderIdentifier)).launch(new ForbiddenException("VC " + verifiableCredential.getTypes() + " is not match with holder identifier " + holderIdentifier));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import org.eclipse.tractusx.managedidentitywallets.ManagedIdentityWalletsApplication;
import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer;
Expand Down Expand Up @@ -53,6 +54,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -177,13 +179,19 @@ void validateVPAsJwtWithValidAudienceAndDateValidation() throws JsonProcessingEx
}

@Test
void createPresentationAsJWT201() throws JsonProcessingException {
void createPresentationAsJWT201() throws JsonProcessingException, ParseException {
String bpn = UUID.randomUUID().toString();
String did = "did:web:localhost:" + bpn;
String audience = "smartSense";
ResponseEntity<Map> vpResponse = createBpnVCAsJwt(bpn, audience);
Assertions.assertEquals(vpResponse.getStatusCode().value(), HttpStatus.CREATED.value());
String jwt = vpResponse.getBody().get("vp").toString();
SignedJWT signedJWT = SignedJWT.parse(jwt);
JWTClaimsSet claimsSet = signedJWT.getJWTClaimsSet();
String iss = claimsSet.getStringClaim("iss");


//issuer of VP is must be holder of VP
Assertions.assertEquals(iss, did);
}

private ResponseEntity<Map> createBpnVCAsJwt(String bpn, String audience) throws JsonProcessingException {
Expand Down

0 comments on commit d7f9096

Please sign in to comment.