diff --git a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/constant/StringPool.java b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/constant/StringPool.java index dc137b8b..c14c7530 100644 --- a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/constant/StringPool.java +++ b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/constant/StringPool.java @@ -94,4 +94,11 @@ private StringPool() { public static final String AS_JWT = "asJwt"; public static final String BPN_CREDENTIAL = "BpnCredential"; + + public static final String ASSERTION_METHOD = "assertionMethod"; + public static final String SERVICE_ENDPOINT = "serviceEndpoint"; + public static final String SERVICE = "service"; + public static final String SECURITY_TOKEN_SERVICE = "SecurityTokenService"; + public static final String CREDENTIAL_SERVICE = "CredentialService"; + public static final String HTTPS_SCHEME = "https://"; } diff --git a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/JwtPresentationES256KService.java b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/JwtPresentationES256KService.java index 1d057d74..084e06b1 100644 --- a/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/JwtPresentationES256KService.java +++ b/miw/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/JwtPresentationES256KService.java @@ -36,14 +36,17 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.text.StringEscapeUtils; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; +import org.eclipse.tractusx.managedidentitywallets.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.exception.BadDataException; import org.eclipse.tractusx.managedidentitywallets.exception.SignatureFailureException; import org.eclipse.tractusx.managedidentitywallets.exception.UnsupportedAlgorithmException; +import org.eclipse.tractusx.ssi.lib.model.JsonLdObject; import org.eclipse.tractusx.ssi.lib.model.did.Did; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; import org.eclipse.tractusx.ssi.lib.model.did.DidDocumentBuilder; import org.eclipse.tractusx.ssi.lib.model.did.JWKVerificationMethod; import org.eclipse.tractusx.ssi.lib.model.did.VerificationMethod; +import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation; import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentationBuilder; @@ -130,7 +133,22 @@ public DidDocument buildDidDocument(String bpn, Did did, List ids = new ArrayList<>(); + jwkVerificationMethods.forEach((verificationMethod) -> { + ids.add(verificationMethod.getId()); + }); + didDocument.put(StringPool.ASSERTION_METHOD, ids); + //add service + Map tokenServiceData = Map.of(Verifiable.ID, did.toUri()+"#"+StringPool.SECURITY_TOKEN_SERVICE, Verifiable.TYPE, StringPool.SECURITY_TOKEN_SERVICE, + StringPool.SERVICE_ENDPOINT, StringPool.HTTPS_SCHEME + miwSettings.host() + "/api/token"); + org.eclipse.tractusx.ssi.lib.model.did.Service tokenService = new org.eclipse.tractusx.ssi.lib.model.did.Service(tokenServiceData); + Map credentialServiceData = Map.of(Verifiable.ID, did.toUri()+"#"+StringPool.CREDENTIAL_SERVICE, Verifiable.TYPE, StringPool.CREDENTIAL_SERVICE, + StringPool.SERVICE_ENDPOINT, StringPool.HTTPS_SCHEME + miwSettings.host()); + org.eclipse.tractusx.ssi.lib.model.did.Service credentialService = new org.eclipse.tractusx.ssi.lib.model.did.Service(credentialServiceData); + didDocument.put(StringPool.SERVICE, List.of(tokenService,credentialService)); + didDocument = DidDocument.fromJson(didDocument.toJson()); log.debug("did document created for bpn ->{}", StringEscapeUtils.escapeJava(bpn)); return didDocument; diff --git a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java index 8371a0fe..7095a256 100644 --- a/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java +++ b/miw/src/test/java/org/eclipse/tractusx/managedidentitywallets/wallet/WalletTest.java @@ -23,10 +23,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.nimbusds.jose.jwk.Curve; import org.eclipse.tractusx.managedidentitywallets.ManagedIdentityWalletsApplication; import org.eclipse.tractusx.managedidentitywallets.config.MIWSettings; import org.eclipse.tractusx.managedidentitywallets.config.TestContextInitializer; import org.eclipse.tractusx.managedidentitywallets.constant.RestURI; +import org.eclipse.tractusx.managedidentitywallets.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.constant.SupportedAlgorithms; import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential; import org.eclipse.tractusx.managedidentitywallets.dao.entity.Wallet; @@ -40,6 +42,8 @@ import org.eclipse.tractusx.managedidentitywallets.utils.AuthenticationUtils; import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils; import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory; +import org.eclipse.tractusx.ssi.lib.model.did.JWKVerificationMethod; +import org.eclipse.tractusx.ssi.lib.model.did.VerificationMethod; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -60,6 +64,8 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -168,7 +174,25 @@ void createWalletTest201() throws JsonProcessingException, JSONException { Assertions.assertNotNull(response.getBody()); Assertions.assertNotNull(wallet.getDidDocument()); - Assertions.assertEquals(2, wallet.getDidDocument().getVerificationMethods().size()); + List verificationMethods = wallet.getDidDocument().getVerificationMethods(); + Assertions.assertEquals(2, verificationMethods.size()); + + // both public keys will include the publicKeyJwk format to express the public key + List curves = verificationMethods.stream().map(vm -> (LinkedHashMap) vm.get(JWKVerificationMethod.PUBLIC_KEY_JWK)) + .map(lhm -> lhm.get(JWKVerificationMethod.JWK_CURVE).toString()).toList(); + List algorithms = Arrays.asList(Curve.SECP256K1.toString(),Curve.Ed25519.toString()); + // both the Ed25519 and the secp256k1 curve keys must be present in the verificationMethod of a did document + Assertions.assertTrue(curves.containsAll(algorithms)); + List assertionMethod = (List)wallet.getDidDocument().get(StringPool.ASSERTION_METHOD); + // both public keys must be expressed in the assertionMethod + Assertions.assertEquals(2, assertionMethod.size()); + // both public keys will use the JsonWebKey2020 verification method type + Assertions.assertTrue(verificationMethods.get(0).getType().equals(JWKVerificationMethod.DEFAULT_TYPE) && + verificationMethods.get(1).getType().equals(JWKVerificationMethod.DEFAULT_TYPE)); + // the controller for the keys is the MIW + Assertions.assertEquals(verificationMethods.get(0).getController().toString(), wallet.getDid()); + Assertions.assertEquals(verificationMethods.get(1).getController().toString(), wallet.getDid()); + List context = wallet.getDidDocument().getContext(); miwSettings.didDocumentContextUrls().forEach(uri -> { Assertions.assertTrue(context.contains(uri));