Skip to content

Commit

Permalink
doc: add basic java docs and java doc maven plugin (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-vavdiya authored Nov 9, 2023
1 parent dfd8e4d commit 23fe5e4
Show file tree
Hide file tree
Showing 146 changed files with 1,895 additions and 34 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ SPDX-License-Identifier: Apache-2.0
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.dash</groupId>
<artifactId>license-tool-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@
import org.eclipse.tractusx.ssi.lib.model.did.Ed25519VerificationMethodBuilder;
import org.eclipse.tractusx.ssi.lib.model.did.VerificationMethod;

/** This is example class to demonstrate how to create @{@link DidDocument} using Ed25519 key */
public class BuildDIDDocEd25519VerificationKey2020 {

/**
* Build did document
*
* @param hostName the host name
* @return the did document
* @throws KeyGenerationException the key generation exception
*/
public static DidDocument buildDidDocument(String hostName) throws KeyGenerationException {
final Did did = DidWebFactory.fromHostname(hostName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
import org.eclipse.tractusx.ssi.lib.model.did.JWKVerificationMethodBuilder;
import org.eclipse.tractusx.ssi.lib.model.did.VerificationMethod;

/** This is example class to demonstrate how to create @{@link DidDocument} using Json web key */
public class BuildDIDDocJsonWebKey2020 {
/**
* Build did document.
*
* @param hostName the host name
* @return the did document
*/
@SneakyThrows
public static DidDocument buildDidDocument(String hostName) {
// Building DID and Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;
import org.eclipse.tractusx.ssi.lib.model.did.DidMethod;

/** This is an example class to demonstrate did document resolve from given did web url */
public class ResolveDIDDoc {
/**
* Resolve did document.
*
* @param didUrl the did url
* @return the did document
* @throws DidDocumentResolverNotRegisteredException the did document resolver not registered
* exception
*/
public static DidDocument ResovleDocument(String didUrl)
throws DidDocumentResolverNotRegisteredException {

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/eclipse/tractusx/ssi/examples/VC.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofGenerator;
import org.eclipse.tractusx.ssi.lib.proof.SignatureType;

/** This is example class to demonstrate how create Verifiable Credentials */
public class VC {
/**
* Create verifiable credential without proof
*
* @return the verifiable credential
*/
public static VerifiableCredential createVCWithoutProof() {

// VC Bulider
Expand All @@ -64,6 +70,17 @@ public static VerifiableCredential createVCWithoutProof() {
return credentialWithoutProof;
}

/**
* Create verifiable credential with ED21559 proof
*
* @param credential the credential
* @param privateKey the private key
* @param issuer the issuer
* @return the verifiable credential
* @throws UnsupportedSignatureTypeException the unsupported signature type exception
* @throws SsiException the ssi exception
* @throws InvalidePrivateKeyFormat the invalide private key format
*/
public static VerifiableCredential createVCWithED21559Proof(
VerifiableCredential credential, IPrivateKey privateKey, Did issuer)
throws UnsupportedSignatureTypeException, SsiException, InvalidePrivateKeyFormat {
Expand Down Expand Up @@ -92,6 +109,17 @@ public static VerifiableCredential createVCWithED21559Proof(
return builder.build();
}

/**
* Create vc with jws proof verifiable credential.
*
* @param credential the credential
* @param privateKey the private key
* @param issuer the issuer
* @return the verifiable credential
* @throws UnsupportedSignatureTypeException the unsupported signature type exception
* @throws SsiException the ssi exception
* @throws InvalidePrivateKeyFormat the invalide private key format
*/
public static VerifiableCredential createVCWithJWSProof(
VerifiableCredential credential, IPrivateKey privateKey, Did issuer)
throws UnsupportedSignatureTypeException, SsiException, InvalidePrivateKeyFormat {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/eclipse/tractusx/ssi/examples/VP.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@
import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedJwtPresentationFactory;
import org.eclipse.tractusx.ssi.lib.serialization.jwt.SerializedJwtPresentationFactoryImpl;

/**
* This is an example class to demonstrate how to create a Verifiable Presentation in JSON-LD and
* JWT format
*/
class VP {

/**
* Create a verifiable presentation.
*
* @param issuer the issuer
* @param credentials the credentials
* @return the verifiable presentation
*/
public static VerifiablePresentation createVP(
Did issuer, List<VerifiableCredential> credentials) {
final VerifiablePresentationBuilder verifiablePresentationBuilder =
Expand All @@ -52,6 +63,17 @@ public static VerifiablePresentation createVP(
return verifiablePresentation;
}

/**
* Create vp as a signed jwt.
*
* @param issuer the issuer
* @param credentials the credentials
* @param audience the audience
* @param privateKey the private key
* @param publicKey the public key
* @return the signed jwt
* @throws IOException the io exception
*/
public static SignedJWT createVPAsJWT(
Did issuer,
List<VerifiableCredential> credentials,
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/eclipse/tractusx/ssi/examples/Validation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,30 @@
import org.eclipse.tractusx.ssi.lib.exception.JwtExpiredException;
import org.eclipse.tractusx.ssi.lib.jwt.SignedJwtValidator;

/** This is example class to demonstrate how to validate JWT expiry date and audience */
public class Validation {
/**
* Validate jwt date.
*
* @param signedJWT the signed jwt
* @param audience the audience
* @throws JwtAudienceCheckFailedException the jwt audience check failed exception
* @throws JwtExpiredException the jwt expired exception
*/
public static void validateJWTDate(SignedJWT signedJWT, String audience)
throws JwtAudienceCheckFailedException, JwtExpiredException {
SignedJwtValidator jwtValidator = new SignedJwtValidator();
jwtValidator.validateDate(signedJWT);
}

/**
* Validate jwt audiences.
*
* @param signedJWT the signed jwt
* @param audience the audience
* @throws JwtAudienceCheckFailedException the jwt audience check failed exception
* @throws JwtExpiredException the jwt expired exception
*/
public static void validateJWTAudiences(SignedJWT signedJWT, String audience)
throws JwtAudienceCheckFailedException, JwtExpiredException {
SignedJwtValidator jwtValidator = new SignedJwtValidator();
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/eclipse/tractusx/ssi/examples/Verification.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.eclipse.tractusx.ssi.lib.proof.LinkedDataProofValidation;

/**
* This is example class to demonstrate how to verify @{@link SignedJWT} and {@link
* VerifiableCredential}
*/
public class Verification {

/**
* Verify jwt.
*
* @param jwt the jwt
*/
public static void verifyJWT(SignedJWT jwt) {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
Expand All @@ -50,6 +59,12 @@ public static void verifyJWT(SignedJWT jwt) {
}
}

/**
* Verify ed21559 signed ld.
*
* @param verifiableCredential the verifiable credential
* @return the boolean
*/
public static boolean verifyED21559LD(VerifiableCredential verifiableCredential) {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
Expand All @@ -61,6 +76,12 @@ public static boolean verifyED21559LD(VerifiableCredential verifiableCredential)
return proofValidation.verify(verifiableCredential);
}

/**
* Verify jws signed ld.
*
* @param verifiableCredential the verifiable credential
* @return the boolean
*/
public static boolean verifyJWSLD(VerifiableCredential verifiableCredential) {
// DID Resolver constructor params
DidWebParser didParser = new DidWebParser();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/eclipse/tractusx/ssi/lib/SsiLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import net.i2p.crypto.eddsa.EdDSASecurityProvider;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

/** The type SSI library. */
public final class SsiLibrary {
/** Initialize. */
public static void initialize() {
Security.addProvider(new EdDSASecurityProvider());
Security.addProvider(new BouncyCastleProvider());
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/org/eclipse/tractusx/ssi/lib/crypt/IKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,36 @@
import java.io.IOException;
import org.eclipse.tractusx.ssi.lib.model.base.EncodeType;

/** The interface Key. */
public interface IKey {
// TODO add docs
/**
* Gets key length.
*
* @return the key length
*/
int getKeyLength();

/**
* Convert the key to a string for storing
*
* @return the string
* @throws IOException the io exception
*/
String asStringForStoring() throws IOException;

/**
* Convert the key to a string for exchange.
*
* @param encodeType the encode type
* @return the string
* @throws IOException the io exception
*/
String asStringForExchange(EncodeType encodeType) throws IOException;

/**
* Convert the key to a byte array.
*
* @return the byte [ ]
*/
byte[] asByte();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@

import org.eclipse.tractusx.ssi.lib.exception.KeyGenerationException;

/** The interface KeyGenerator. */
public interface IKeyGenerator {

/**
* Generate key pair.
*
* @return the key pair
* @throws KeyGenerationException the key generation exception
*/
KeyPair generateKey() throws KeyGenerationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

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

/** The interface private key. */
public interface IPrivateKey extends IKey {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

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

/** The interface public key. */
public interface IPublicKey extends IKey {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import lombok.Data;
import lombok.RequiredArgsConstructor;

/** The type key pair. */
@RequiredArgsConstructor
@Data
public class KeyPair {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,62 @@
package org.eclipse.tractusx.ssi.lib.crypt.jwk;

import com.nimbusds.jose.jwk.OctetKeyPair;
import java.io.IOException;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.ssi.lib.crypt.IPrivateKey;
import org.eclipse.tractusx.ssi.lib.crypt.IPublicKey;
import org.eclipse.tractusx.ssi.lib.crypt.octet.OctetKeyPairFactory;

/** The type JsonWebKey. */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class JsonWebKey {
private final OctetKeyPair keyPair;

public JsonWebKey(String id, IPublicKey publicKey, IPrivateKey privateKey) throws IOException {
/**
* Instantiates a new JsonWebKey.
*
* @param id the id
* @param publicKey the public key
* @param privateKey the private key
*/
public JsonWebKey(String id, IPublicKey publicKey, IPrivateKey privateKey) {
OctetKeyPairFactory keyPairFactory = new OctetKeyPairFactory();
OctetKeyPair keyOctetKeyPair = keyPairFactory.fromKeyPairWithKeyID(id, publicKey, privateKey);

this.keyPair = keyOctetKeyPair;
}

/**
* Gets the curve name of the key pair.
*
* @return the curve
*/
public String getCurv() {
return keyPair.getCurve().getName();
}

/**
* Gets key id.
*
* @return the key id
*/
public String getKeyID() {
return keyPair.getKeyID();
}

/**
* Gets key type.
*
* @return the key type
*/
public String getKeyType() {
return this.keyPair.getKeyType().getValue();
}

/**
* Gets the x member contains the x coordinate for the elliptic curve point.
*
* @return the x
*/
public String getX() {
return this.keyPair.getX().toString();
}
Expand Down
Loading

0 comments on commit 23fe5e4

Please sign in to comment.