diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java index 5a9e643c3..903f2502a 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/IssuersCredentialService.java @@ -46,6 +46,8 @@ import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.utils.CommonUtils; import org.eclipse.tractusx.managedidentitywallets.utils.Validate; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistry; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistryImpl; import org.eclipse.tractusx.ssi.lib.did.web.DidWebDocumentResolver; import org.eclipse.tractusx.ssi.lib.did.web.util.DidWebParser; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; @@ -53,8 +55,7 @@ import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialSubject; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType; import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation; -import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistry; -import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistryImpl; +import org.eclipse.tractusx.ssi.lib.proof.SignatureType; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.stereotype.Service; @@ -423,8 +424,11 @@ public Map credentialsValidation(Map data) { didDocumentResolverRegistry.register( new DidWebDocumentResolver(HttpClient.newHttpClient(), new DidWebParser(), miwSettings.enforceHttps())); - LinkedDataProofValidation proofValidation = LinkedDataProofValidation.newInstance(didDocumentResolverRegistry); - Boolean valid = proofValidation.checkProof(verifiableCredential); +// LinkedDataProofValidation proofValidation = LinkedDataProofValidation.newInstance(didDocumentResolverRegistry); + LinkedDataProofValidation proofValidation = LinkedDataProofValidation.newInstance(SignatureType.JWS, + didDocumentResolverRegistry); +// Boolean valid = proofValidation.checkProof(verifiableCredential); + Boolean valid = proofValidation.verifiyProof(verifiableCredential); Map response = new HashMap<>(); response.put(StringPool.VALID, valid); response.put("vc", verifiableCredential); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java index 215822e5c..5b474dc02 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/PresentationService.java @@ -36,6 +36,9 @@ import org.eclipse.tractusx.managedidentitywallets.exception.BadDataException; import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.utils.Validate; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistry; +import org.eclipse.tractusx.ssi.lib.did.resolver.DidDocumentResolverRegistryImpl; +import org.eclipse.tractusx.ssi.lib.did.resolver.OctetKeyPairFactory; import org.eclipse.tractusx.ssi.lib.did.web.DidWebDocumentResolver; import org.eclipse.tractusx.ssi.lib.did.web.util.DidWebParser; import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtFactory; @@ -47,9 +50,6 @@ import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation; import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentationBuilder; import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentationType; -import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistry; -import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistryImpl; -import org.eclipse.tractusx.ssi.lib.resolver.OctetKeyPairFactory; import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdSerializerImpl; import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedJwtPresentationFactory; import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedJwtPresentationFactoryImpl; diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java index 3bb927460..b20a99fd0 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/service/WalletService.java @@ -52,10 +52,12 @@ import org.eclipse.tractusx.managedidentitywallets.exception.ForbiddenException; import org.eclipse.tractusx.managedidentitywallets.utils.EncryptionUtils; import org.eclipse.tractusx.managedidentitywallets.utils.Validate; -import org.eclipse.tractusx.ssi.lib.base.MultibaseFactory; +import org.eclipse.tractusx.ssi.lib.crypt.ed25519.Ed25519Key; import org.eclipse.tractusx.ssi.lib.crypt.ed25519.Ed25519KeySet; +import org.eclipse.tractusx.ssi.lib.crypt.jwk.JsonWebKey; import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory; import org.eclipse.tractusx.ssi.lib.model.MultibaseString; +import org.eclipse.tractusx.ssi.lib.model.base.MultibaseFactory; import org.eclipse.tractusx.ssi.lib.model.did.*; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType; @@ -66,6 +68,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.StringWriter; +import java.net.URI; import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -220,23 +223,32 @@ private Wallet createWallet(CreateWalletRequest request, boolean authority) { Did did = DidWebFactory.fromHostname(miwSettings.host() + ":" + request.getBpn()); //Extracting keys - Ed25519KeySet keySet = new Ed25519KeySet(keyPair.getPrivateKey(), keyPair.getPublicKey()); - MultibaseString publicKeyBase = MultibaseFactory.create(keySet.getPublicKey()); +// Ed25519KeySet keySet = new Ed25519KeySet(keyPair.getPrivateKey(), keyPair.getPublicKey()); + Ed25519Key privateKey = Ed25519Key.asPrivateKey(keyPair.getPrivateKey()); + Ed25519Key publicKey = Ed25519Key.asPrivateKey(keyPair.getPublicKey()); + MultibaseString publicKeyBase = MultibaseFactory.create(publicKey.getEncoded()); //Building Verification Methods: - List verificationMethods = new ArrayList<>(); - Ed25519VerificationKey2020Builder builder = new Ed25519VerificationKey2020Builder(); - Ed25519VerificationKey2020 key = - builder - .id(did.toUri()) +// List verificationMethods = new ArrayList<>(); +// Ed25519VerificationKey2020Builder builder = new Ed25519VerificationKey2020Builder(); + Ed25519VerificationMethodBuilder ed25519VerificationKey2020Builder = + new Ed25519VerificationMethodBuilder(); + Ed25519VerificationMethod ed25519VerificationMethod = + ed25519VerificationKey2020Builder + .id(URI.create(did + "#key-1")) .controller(did.toUri()) .publicKeyMultiBase(publicKeyBase) .build(); - verificationMethods.add(key); +// verificationMethods.add(key); + + // JWK + JsonWebKey jwk = JsonWebKey.fromED21559("", publicKey.getEncoded(), privateKey.getEncoded());//#key-2 + JWKVerificationMethod jwkVerificationMethod = + new JWKVerificationMethodBuilder().did(did).jwk(jwk).build(); DidDocumentBuilder didDocumentBuilder = new DidDocumentBuilder(); didDocumentBuilder.id(did.toUri()); - didDocumentBuilder.verificationMethods(verificationMethods); + didDocumentBuilder.verificationMethods(List.of(jwkVerificationMethod));//ed25519VerificationMethod DidDocument didDocument = didDocumentBuilder.build(); didDocument = DidDocument.fromJson(URLDecoder.decode(didDocument.toJson(), StandardCharsets.UTF_8)); log.debug("did document created for bpn ->{}", request.getBpn()); diff --git a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java index 637885a92..d9dfa3dde 100644 --- a/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java +++ b/src/main/java/org/eclipse/tractusx/managedidentitywallets/utils/CommonUtils.java @@ -23,16 +23,14 @@ import org.eclipse.tractusx.managedidentitywallets.constant.StringPool; import org.eclipse.tractusx.managedidentitywallets.dao.entity.HoldersCredential; -import org.eclipse.tractusx.ssi.lib.model.Ed25519Signature2020; import org.eclipse.tractusx.ssi.lib.model.did.DidDocument; +import org.eclipse.tractusx.ssi.lib.model.proof.jws.JWSSignature2020; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialBuilder; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialSubject; import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType; import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofGenerator; -import org.eclipse.tractusx.ssi.lib.proof.hash.LinkedDataHasher; -import org.eclipse.tractusx.ssi.lib.proof.transform.LinkedDataTransformer; -import org.eclipse.tractusx.ssi.lib.proof.verify.LinkedDataSigner; +import org.eclipse.tractusx.ssi.lib.proof.SignatureType; import java.net.URI; import java.net.URLDecoder; @@ -117,11 +115,19 @@ private static VerifiableCredential createVerifiableCredential(DidDocument issue //Ed25519 Proof Builder - LinkedDataProofGenerator generator = new LinkedDataProofGenerator( - new LinkedDataHasher(), new LinkedDataTransformer(), new LinkedDataSigner()); +// LinkedDataProofGenerator generator = new LinkedDataProofGenerator( +// new LinkedDataHasher(), new LinkedDataTransformer(), new LinkedDataSigner()); + LinkedDataProofGenerator generator = LinkedDataProofGenerator.newInstance(SignatureType.JWS); URI verificationMethod = issuerDoc.getVerificationMethods().get(0).getId(); - Ed25519Signature2020 proof = generator.createEd25519Signature2020(builder.build(), verificationMethod, - privateKey); +// Ed25519Signature2020 proof = generator.createEd25519Signature2020(builder.build(), verificationMethod, +// privateKey); +// Ed25519Signature2020 proof = +// (Ed25519Signature2020) generator.createProof( +// builder.build(), verificationMethod, privateKey); + JWSSignature2020 proof = + (JWSSignature2020) generator.createProof( + builder.build(), verificationMethod, privateKey); + //Adding Proof to VC builder.proof(proof);