Skip to content

Commit

Permalink
fix: update code with the new ssi lib main
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasalfiti authored and nitin-vavdiya committed May 14, 2024
1 parent 8b5180a commit 3da1eff
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@

package org.eclipse.tractusx.managedidentitywallets.constant;

import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialType;

/**
* The type Miw verifiable credential type.
*/
public class MIWVerifiableCredentialType extends VerifiableCredentialType {
public class MIWVerifiableCredentialType {

public static final String DISMANTLER_CREDENTIAL = "DismantlerCredential";
public static final String VERIFIABLE_CREDENTIAL = "VerifiableCredential";

/** The constant MEMBERSHIP_CREDENTIAL. */
public static final String MEMBERSHIP_CREDENTIAL = "MembershipCredential";

public static final String DISMANTLER_CREDENTIAL = "DismantlerCredential";
/**
* The constant USE_CASE_FRAMEWORK_CONDITION_CX.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
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;
import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdSerializer;
import org.eclipse.tractusx.ssi.lib.serialization.jsonld.JsonLdSerializer;
import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedVerifiablePresentation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.eclipse.tractusx.managedidentitywallets.exception.PermissionViolationException;
import org.eclipse.tractusx.managedidentitywallets.utils.Validate;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver;
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.json.InvalidJsonLdException;
Expand All @@ -62,7 +62,7 @@
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.proof.LinkedDataProofValidation;
import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdSerializerImpl;
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;
import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedVerifiablePresentation;
Expand Down Expand Up @@ -180,8 +180,8 @@ private void buildVPJwtEdDSA(String audience, String callerBpn, Wallet callerWal
SerializedJwtPresentationFactory presentationFactory = new SerializedJwtPresentationFactoryImpl(
new SignedJwtFactory(new OctetKeyPairFactory()), new JsonLdSerializerImpl(), result.getKey());

x25519PrivateKey ed25519Key = (x25519PrivateKey) result.getRight();
x25519PrivateKey privateKey = new x25519PrivateKey(ed25519Key.asByte());
X25519PrivateKey ed25519Key = (X25519PrivateKey) result.getRight();
X25519PrivateKey privateKey = new X25519PrivateKey(ed25519Key.asByte());
SignedJWT presentation = presentationFactory.createPresentation(result.getLeft(), verifiableCredentials, audience, privateKey , "keyId" );

response.put(StringPool.VP, presentation.serialize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.eclipse.tractusx.managedidentitywallets.dao.repository.WalletKeyRepository;
import org.eclipse.tractusx.managedidentitywallets.exception.UnsupportedAlgorithmException;
import org.eclipse.tractusx.managedidentitywallets.utils.EncryptionUtils;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
import org.springframework.stereotype.Service;

import java.io.StringReader;
Expand Down Expand Up @@ -75,8 +75,8 @@ protected SpecificationUtil<WalletKey> getSpecificationUtil() {
@SneakyThrows
public byte[] getPrivateKeyByWalletIdAsBytes(long walletId, String algorithm) {
Object privateKey = getPrivateKeyByWalletIdAndAlgorithm(walletId, SupportedAlgorithms.valueOf(algorithm));
if (privateKey instanceof x25519PrivateKey x25519PrivateKey) {
return x25519PrivateKey.asByte();
if (privateKey instanceof X25519PrivateKey X25519PrivateKey) {
return X25519PrivateKey.asByte();
} else {
return ((ECPrivateKey) privateKey).getEncoded();
}
Expand All @@ -95,7 +95,7 @@ public Object getPrivateKeyByWalletIdAndAlgorithm(long walletId, SupportedAlgori
String privateKey = encryptionUtils.decrypt(wallet.getPrivateKey());
byte[] content = new PemReader(new StringReader(privateKey)).readPemObject().getContent();
if (SupportedAlgorithms.ED25519.equals(algorithm)) {
return new x25519PrivateKey(content);
return new X25519PrivateKey(content);
} else if (SupportedAlgorithms.ES256K.equals(algorithm)) {
KeyFactory kf = KeyFactory.getInstance(EC);
return kf.generatePrivate(new PKCS8EncodedKeySpec(content));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.eclipse.tractusx.ssi.lib.crypt.IKeyGenerator;
import org.eclipse.tractusx.ssi.lib.crypt.KeyPair;
import org.eclipse.tractusx.ssi.lib.crypt.jwk.JsonWebKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519Generator;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519Generator;
import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;
Expand Down Expand Up @@ -236,7 +236,7 @@ private Wallet createWallet(CreateWalletRequest request, boolean authority, Stri
validateCreateWallet(request, callerBpn);

//create private key pair
IKeyGenerator keyGenerator = new x25519Generator();
IKeyGenerator keyGenerator = new X25519Generator();
KeyPair keyPair = keyGenerator.generateKey();

//create did json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.eclipse.tractusx.managedidentitywallets.interfaces.SecureTokenIssuer;
import org.eclipse.tractusx.managedidentitywallets.utils.EncryptionUtils;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
import org.springframework.stereotype.Component;

import java.time.Instant;
Expand Down Expand Up @@ -103,7 +103,7 @@ private JWT createSignedJWT(KeyPair keyPair, JWTClaimsSet.Builder builder) {
SignedJWT signedJWT = new SignedJWT(header, body);
String privateKey = encryptionUtils.decrypt(keyPair.privateKey());
// todo bri: this should become dynamic in the future, as we want to support more key algos.
OctetKeyPair jwk = new OctetKeyPairFactory().fromPrivateKey(new x25519PrivateKey(privateKey, true));
OctetKeyPair jwk = new OctetKeyPairFactory().fromPrivateKey(new X25519PrivateKey(privateKey, true));
Ed25519Signer signer = new Ed25519Signer(jwk);
signedJWT.sign(signer);
log.debug("JWT signed for issuer '{}' and holder '{}'", builder.getClaims().get("iss"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.eclipse.tractusx.managedidentitywallets.exception.BadDataException;
import org.eclipse.tractusx.managedidentitywallets.service.WalletKeyService;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.json.TransformJsonLdException;
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPrivateKeyFormatException;
Expand Down Expand Up @@ -157,7 +157,7 @@ private static VerifiableCredential createVerifiableCredential(DidDocument issue
URI verificationMethod = issuerDoc.getVerificationMethods().get(0).getId();

JWSSignature2020 proof = new JWSSignature2020(generator.createProof(builder.build(), verificationMethod,
new x25519PrivateKey(privateKey)));
new X25519PrivateKey(privateKey)));

// Adding Proof to VC
builder.proof(proof);
Expand Down Expand Up @@ -192,7 +192,7 @@ public static String vcAsJwt(Wallet issuerWallet, Wallet holderWallet, Verifiabl
SerializedJwtVCFactoryImpl vcFactory = new SerializedJwtVCFactoryImpl(
new SignedJwtFactory(new OctetKeyPairFactory()));

x25519PrivateKey privateKey = (x25519PrivateKey) walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(issuerWallet.getId(), SupportedAlgorithms.ED25519);
X25519PrivateKey privateKey = (X25519PrivateKey) walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(issuerWallet.getId(), SupportedAlgorithms.ED25519);
// JWT Factory

SignedJWT vcJWT = vcFactory.createVCJwt(issuerDid, holderDid, vc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils;
import org.eclipse.tractusx.ssi.lib.crypt.KeyPair;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver;
import org.eclipse.tractusx.ssi.lib.exception.did.DidParseException;
import org.eclipse.tractusx.ssi.lib.exception.did.DidResolverException;
Expand Down Expand Up @@ -177,7 +177,7 @@ void shouldIssueCredentialAsJwt()
when(walletKey.getId()).thenReturn(42L);
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
Expand Down Expand Up @@ -230,7 +230,7 @@ void shouldIssueCredentialAsJwt()
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);

CredentialsResponse credentialsResponse = assertDoesNotThrow(
Expand Down Expand Up @@ -269,7 +269,7 @@ void shouldIssueCredentialAsJwt() throws IOException, InvalidPrivateKeyFormatExc
when(walletKey.getId()).thenReturn(42L);
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getPrivateKeyByWalletIdAsBytes(baseWallet.getId() , "ED25519")).thenReturn(keyPair.getPrivateKey()
.asByte());
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);
Expand Down Expand Up @@ -324,7 +324,7 @@ public HoldersCredential answer(InvocationOnMock invocation) throws Throwable {
when(baseWallet.getAlgorithm()).thenReturn("ED25519");
when(walletKey.getId()).thenReturn(42L);
when(walletKeyService.getPrivateKeyByWalletIdAndAlgorithm(baseWallet.getId() ,SupportedAlgorithms.valueOf(baseWallet.getAlgorithm())))
.thenReturn(new x25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
.thenReturn(new X25519PrivateKey(keyPair.getPrivateKey().asStringForStoring(), true));
when(walletKeyService.getWalletKeyIdByWalletId(baseWallet.getId())).thenReturn(walletKeyId);

CredentialsResponse credentialsResponse = assertDoesNotThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.tractusx.managedidentitywallets.dao.repository.IssuersCredentialRepository;
import org.eclipse.tractusx.ssi.lib.crypt.IPublicKey;
import org.eclipse.tractusx.ssi.lib.crypt.KeyPair;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519Generator;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519Generator;
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPrivateKeyFormatException;
import org.eclipse.tractusx.ssi.lib.exception.key.KeyGenerationException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedSignatureTypeException;
Expand Down Expand Up @@ -253,7 +253,7 @@ public IssuersCredential answer(InvocationOnMock invocation) throws Throwable {
}

public static KeyPair generateEDKeys() {
x25519Generator gen = new x25519Generator();
X25519Generator gen = new X25519Generator();
KeyPair baseWalletKeys;
try {
baseWalletKeys = gen.generateKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.eclipse.tractusx.managedidentitywallets.service.PresentationService;
import org.eclipse.tractusx.managedidentitywallets.service.WalletKeyService;
import org.eclipse.tractusx.managedidentitywallets.utils.TestUtils;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.X25519PrivateKey;
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;
Expand Down Expand Up @@ -114,7 +114,7 @@ private VerifiableCredential issueVC(String issuerDid, Wallet signerWallet) thro
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdAsBytes(signerWallet.getId(), signerWallet.getAlgorithm());

JWSSignature2020 proof =
(JWSSignature2020) generator.createProof(builder.build(), verificationMethod, new x25519PrivateKey(privateKeyBytes));
new JWSSignature2020(generator.createProof(builder.build(), verificationMethod, new X25519PrivateKey(privateKeyBytes)));

//Adding Proof to VC
builder.proof(proof);
Expand Down

0 comments on commit 3da1eff

Please sign in to comment.