Skip to content

Commit

Permalink
fix: correcting from 21559 to 25519
Browse files Browse the repository at this point in the history
  • Loading branch information
koptan committed Feb 6, 2024
1 parent fa72104 commit fb477f9
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 90 deletions.
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static VerifiableCredential createVCWithoutProof() {

```

5. To Generate VerifiableCredential with ED21559/JWS proof:
5. To Generate VerifiableCredential with ED25519/JWS proof:


```java
Expand All @@ -202,7 +202,7 @@ import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCreden
import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofGenerator;


public static VerifiableCredential createVCWithED21559Proof(
public static VerifiableCredential createVCWithED25519Proof(
VerifiableCredential credential, byte[] privateKey, Did issuer) {

// VC Builder
Expand All @@ -217,7 +217,7 @@ import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofGenerator;
.type(credential.getTypes());

// Ed25519 Proof Builder
final LinkedDataProofGenerator generator = LinkedDataProofGenerator.newInstance(SignatureType.ED21559);
final LinkedDataProofGenerator generator = LinkedDataProofGenerator.newInstance(SignatureType.ED25519);
final Ed25519Signature2020 proof =
(Ed25519Signature2020) generator.createProof(
builder.build(), URI.create(issuer + "#key-1"), privateKey);
Expand Down Expand Up @@ -370,7 +370,7 @@ import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation;
import org.eclipse.tractusx.ssi.lib.resolver.DidDocumentResolverRegistryImpl;
import org.eclipse.tractusx.ssi.lib.model.proof.jws.JWSSignature2020;

public static boolean verifyED21559LD(VerifiableCredential verifiableCredential) {
public static boolean verifyED25519LD(VerifiableCredential verifiableCredential) {
// DID Resolver Constracture params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
Expand All @@ -381,7 +381,7 @@ import org.eclipse.tractusx.ssi.lib.model.proof.jws.JWSSignature2020;
new DidWebDocumentResolver(httpClient, didParser, enforceHttps));

LinkedDataProofValidation proofValidation =
LinkedDataProofValidation.newInstance(SignatureType.ED21559,didDocumentResolverRegistry);
LinkedDataProofValidation.newInstance(SignatureType.ED25519,didDocumentResolverRegistry);
return proofValidation.verify(verifiableCredential);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -27,7 +27,7 @@
import org.eclipse.tractusx.ssi.lib.crypt.IKeyGenerator;
import org.eclipse.tractusx.ssi.lib.crypt.IPublicKey;
import org.eclipse.tractusx.ssi.lib.crypt.KeyPair;
import org.eclipse.tractusx.ssi.lib.crypt.x21559.x21559Generator;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519Generator;
import org.eclipse.tractusx.ssi.lib.did.web.DidWebFactory;
import org.eclipse.tractusx.ssi.lib.exception.key.KeyGenerationException;
import org.eclipse.tractusx.ssi.lib.model.MultibaseString;
Expand All @@ -54,7 +54,7 @@ public static DidDocument buildDidDocument(String hostName) throws KeyGeneration

// Extracting keys
// final Ed25519KeySet keySet = new Ed25519KeySet(privateKey, publicKey);
IKeyGenerator keyGenerator = new x21559Generator();
IKeyGenerator keyGenerator = new x25519Generator();
KeyPair keyPair = keyGenerator.generateKey();
IPublicKey publicKey = keyPair.getPublicKey();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -30,8 +30,8 @@
import org.eclipse.tractusx.ssi.lib.crypt.IPrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.IPublicKey;
import org.eclipse.tractusx.ssi.lib.crypt.jwk.JsonWebKey;
import org.eclipse.tractusx.ssi.lib.crypt.x21559.x21559PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x21559.x21559PublicKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.x25519.x25519PublicKey;
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 All @@ -54,8 +54,8 @@ public static DidDocument buildDidDocument(String hostName) {
final Did did = DidWebFactory.fromHostname(hostName);
OctetKeyPair octetKeyPair = new OctetKeyPairGenerator(Curve.Ed25519).keyID("1").generate();

IPrivateKey privateKey = new x21559PrivateKey(octetKeyPair.getDecodedD());
IPublicKey publicKey = new x21559PublicKey(octetKeyPair.getDecodedX());
IPrivateKey privateKey = new x25519PrivateKey(octetKeyPair.getDecodedD());
IPublicKey publicKey = new x25519PublicKey(octetKeyPair.getDecodedX());

// JWK
JsonWebKey jwk = new JsonWebKey(octetKeyPair.getKeyID(), publicKey, privateKey);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/eclipse/tractusx/ssi/examples/VC.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -31,7 +31,7 @@
import org.eclipse.tractusx.ssi.lib.exception.proof.SignatureGenerateFailedException;
import org.eclipse.tractusx.ssi.lib.exception.proof.UnsupportedSignatureTypeException;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.proof.ed21559.Ed25519Signature2020;
import org.eclipse.tractusx.ssi.lib.model.proof.ed25519.Ed25519Signature2020;
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 @@ -72,7 +72,7 @@ public static VerifiableCredential createVCWithoutProof() {
}

/**
* Create verifiable credential with ED21559 proof
* Create verifiable credential with ED25519 proof
*
* @param credential the credential
* @param privateKey the private key
Expand All @@ -82,7 +82,7 @@ public static VerifiableCredential createVCWithoutProof() {
* @throws SsiException the ssi exception
* @throws InvalidePrivateKeyFormat the invalide private key format
*/
public static VerifiableCredential createVCWithED21559Proof(
public static VerifiableCredential createVCWithED25519Proof(
VerifiableCredential credential, IPrivateKey privateKey, Did issuer)
throws UnsupportedSignatureTypeException, InvalidPrivateKeyFormatException,
SignatureGenerateFailedException, TransformJsonLdException {
Expand All @@ -100,7 +100,7 @@ public static VerifiableCredential createVCWithED21559Proof(

// Ed25519 Proof Builder
final LinkedDataProofGenerator generator =
LinkedDataProofGenerator.newInstance(SignatureType.ED21559);
LinkedDataProofGenerator.newInstance(SignatureType.ED25519);
final Ed25519Signature2020 proof =
(Ed25519Signature2020)
generator.createProof(builder.build(), URI.create(issuer + "#key-1"), privateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void verifyJWT(SignedJWT jwt)
}

/**
* Verify ed21559 signed ld.
* Verify ed25519 signed ld.
*
* @param verifiableCredential the verifiable credential
* @return the boolean
Expand All @@ -82,7 +82,7 @@ public static void verifyJWT(SignedJWT jwt)
* @throws UnsupportedSignatureTypeException
* @throws SignatureVerificationFailedException
*/
public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)
public static boolean verifyED25519LD(VerifiableCredential verifiableCredential)
throws UnsupportedSignatureTypeException, SignatureParseException, DidParseException,
InvalidPublicKeyFormatException, SignatureVerificationException,
NoVerificationKeyFoundException, TransformJsonLdException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.crypt.x21559;
package org.eclipse.tractusx.ssi.lib.crypt.x25519;

import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
Expand All @@ -33,8 +33,8 @@
import org.eclipse.tractusx.ssi.lib.exception.key.InvalidPublicKeyFormatException;
import org.eclipse.tractusx.ssi.lib.exception.key.KeyGenerationException;

/** X21559 key generator. */
public class x21559Generator implements IKeyGenerator {
/** X25519 key generator. */
public class x25519Generator implements IKeyGenerator {

@Override
public KeyPair generateKey() throws KeyGenerationException {
Expand All @@ -48,18 +48,18 @@ public KeyPair generateKey() throws KeyGenerationException {
Ed25519PrivateKeyParameters privateKey = (Ed25519PrivateKeyParameters) keyPair.getPrivate();
Ed25519PublicKeyParameters publicKey = (Ed25519PublicKeyParameters) keyPair.getPublic();

x21559PrivateKey x21559PrivateKey;
x25519PrivateKey x25519PrivateKey;
try {
x21559PrivateKey = new x21559PrivateKey(privateKey.getEncoded());
x25519PrivateKey = new x25519PrivateKey(privateKey.getEncoded());
} catch (InvalidPrivateKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
x21559PublicKey x21559PublicKey;
x25519PublicKey x25519PublicKey;
try {
x21559PublicKey = new x21559PublicKey(publicKey.getEncoded());
x25519PublicKey = new x25519PublicKey(publicKey.getEncoded());
} catch (InvalidPublicKeyFormatException e) {
throw new KeyGenerationException(e.getCause());
}
return new KeyPair(x21559PublicKey, x21559PrivateKey);
return new KeyPair(x25519PublicKey, x25519PrivateKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.crypt.x21559;
package org.eclipse.tractusx.ssi.lib.crypt.x25519;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -36,34 +36,34 @@
import org.eclipse.tractusx.ssi.lib.model.base.EncodeType;
import org.eclipse.tractusx.ssi.lib.model.base.MultibaseFactory;

/** The type X21559 private key. */
public class x21559PrivateKey implements IPrivateKey {
/** The type X25519 private key. */
public class x25519PrivateKey implements IPrivateKey {

private final int KEY_LENGTH = 32;
private final @NonNull byte[] key;

/**
* Instantiates a new X 21559 private key.
* Instantiates a new X 25519 private key.
*
* @param privateKey the private key
* @throws InvalidePrivateKeyFormat the invalide private key format
*/
public x21559PrivateKey(byte[] privateKey) throws InvalidPrivateKeyFormatException {
public x25519PrivateKey(byte[] privateKey) throws InvalidPrivateKeyFormatException {
if (this.getKeyLength() != privateKey.length) {
throw new InvalidPrivateKeyFormatException(getKeyLength(), privateKey.length);
}
this.key = privateKey;
}

/**
* Instantiates a new X 21559 private key.
* Instantiates a new X 25519 private key.
*
* @param privateKey the private key
* @param pemFormat the pem format
* @throws InvalidePrivateKeyFormat the invalide private key format
* @throws IOException the io exception
*/
public x21559PrivateKey(String privateKey, boolean PEMFormat)
public x25519PrivateKey(String privateKey, boolean PEMFormat)
throws InvalidPrivateKeyFormatException {
if (PEMFormat) {
StringReader sr = new StringReader(privateKey);
Expand All @@ -90,7 +90,7 @@ public x21559PrivateKey(String privateKey, boolean PEMFormat)
@Override
public String asStringForStoring() throws KeyTransformationException {

PemObject pemObject = new PemObject("ED21559 Private Key", this.key);
PemObject pemObject = new PemObject("ED25519 Private Key", this.key);
StringWriter sw = new StringWriter();
PemWriter writer = new PemWriter(sw);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.crypt.x21559;
package org.eclipse.tractusx.ssi.lib.crypt.x25519;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -36,34 +36,34 @@
import org.eclipse.tractusx.ssi.lib.model.base.EncodeType;
import org.eclipse.tractusx.ssi.lib.model.base.MultibaseFactory;

/** The type X 21559 public key. */
public class x21559PublicKey implements IPublicKey {
/** The type X 25519 public key. */
public class x25519PublicKey implements IPublicKey {

private final int KEY_LENGTH = 32;
private final @NonNull byte[] originalKey;

/**
* Instantiates a new X 21559 public key.
* Instantiates a new X 25519 public key.
*
* @param publicKey the public key
* @throws InvalidePublicKeyFormat the invalide public key format
*/
public x21559PublicKey(byte[] publicKey) throws InvalidPublicKeyFormatException {
public x25519PublicKey(byte[] publicKey) throws InvalidPublicKeyFormatException {
if (this.getKeyLength() != publicKey.length) {
throw new InvalidPublicKeyFormatException(getKeyLength(), publicKey.length);
}
this.originalKey = publicKey;
}

/**
* Instantiates a new X21559 public key.
* Instantiates a new X25519 public key.
*
* @param publicKey the public key
* @param pemFormat the pe mformat
* @throws InvalidePublicKeyFormat the invalide public key format
* @throws IOException the io exception
*/
public x21559PublicKey(String publicKey, boolean PEMformat)
public x25519PublicKey(String publicKey, boolean PEMformat)
throws InvalidPublicKeyFormatException, IOException {

if (PEMformat) {
Expand All @@ -85,7 +85,7 @@ public x21559PublicKey(String publicKey, boolean PEMformat)

@Override
public String asStringForStoring() throws KeyTransformationException {
PemObject pemObject = new PemObject("ED21559 Public Key", this.originalKey);
PemObject pemObject = new PemObject("ED25519 Public Key", this.originalKey);
StringWriter sw = new StringWriter();
PemWriter writer = new PemWriter(sw);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -19,7 +19,7 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.model.proof.ed21559;
package org.eclipse.tractusx.ssi.lib.model.proof.ed25519;

import java.net.URI;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -19,7 +19,7 @@
* *******************************************************************************
*/

package org.eclipse.tractusx.ssi.lib.model.proof.ed21559;
package org.eclipse.tractusx.ssi.lib.model.proof.ed25519;

import java.net.URI;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.eclipse.tractusx.ssi.lib.model.MultibaseString;
import org.eclipse.tractusx.ssi.lib.model.base.MultibaseFactory;
import org.eclipse.tractusx.ssi.lib.model.proof.Proof;
import org.eclipse.tractusx.ssi.lib.model.proof.ed21559.Ed25519Signature2020;
import org.eclipse.tractusx.ssi.lib.model.proof.ed21559.Ed25519Signature2020Builder;
import org.eclipse.tractusx.ssi.lib.model.proof.ed25519.Ed25519Signature2020;
import org.eclipse.tractusx.ssi.lib.model.proof.ed25519.Ed25519Signature2020Builder;
import org.eclipse.tractusx.ssi.lib.model.proof.jws.JWSSignature2020;
import org.eclipse.tractusx.ssi.lib.model.proof.jws.JWSSignature2020Builder;
import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable;
Expand All @@ -58,7 +58,7 @@ public class LinkedDataProofGenerator {
*/
public static LinkedDataProofGenerator newInstance(SignatureType type)
throws UnsupportedSignatureTypeException {
if (type == SignatureType.ED21559) {
if (type == SignatureType.ED25519) {
return new LinkedDataProofGenerator(
type, new LinkedDataHasher(), new LinkedDataTransformer(), new Ed25519ProofSigner());
} else if (type == SignatureType.JWS) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public Proof createProof(Verifiable document, URI verificationMethodId, IPrivate
byte[] signature;
signature = signer.sign(new HashedLinkedData(hashedData.getValue()), privateKey);

if (type == SignatureType.ED21559) {
if (type == SignatureType.ED25519) {

final MultibaseString multibaseString = MultibaseFactory.create(signature);
return new Ed25519Signature2020Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean verify(Verifiable verifiable) {
IVerifier verifier = null;

if (type != null && !type.isBlank()) {
if (type.equals(SignatureType.ED21559.toString())) {
if (type.equals(SignatureType.ED25519.toString())) {
verifier = new Ed25519ProofVerifier(this.didResolver);
} else if (type.equals(SignatureType.JWS.toString())) {
verifier = new JWSProofVerifier(this.didResolver);
Expand Down
Loading

0 comments on commit fb477f9

Please sign in to comment.