Object Ed25519

  • All Implemented Interfaces:
    web5.sdk.crypto.KeyGenerator , web5.sdk.crypto.Signer

    
    public class Ed25519
     implements KeyGenerator, Signer
                        

    Implementation of the KeyGenerator and Signer interfaces, specifically utilizing the Ed25519 elliptic curve digital signature algorithm. This implementation provides functionality to generate key pairs, compute public keys from private keys, and sign/verify messages utilizing Ed25519.

    TODO: Insert example usage here.

    • Constructor Detail

    • Method Detail

      • generatePrivateKey

         Jwk generatePrivateKey(KeyGenOptions options)

        Generates a private key utilizing the Ed25519 algorithm.

        Parameters:
        options - (Optional) Additional options to control the key generation process.
        Returns:

        The generated private key in Jwk format.

      • computePublicKey

         Jwk computePublicKey(Jwk privateKey)

        Derives the public key corresponding to a given private key.

        Parameters:
        privateKey - The private key in Jwk format.
        Returns:

        The corresponding public key in Jwk format.

      • publicKeyToBytes

         ByteArray publicKeyToBytes(Jwk publicKey)

        Converts a public key to bytes. Applicable for asymmetric KeyGenerator implementations only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception

      • bytesToPublicKey

         Jwk bytesToPublicKey(ByteArray publicKeyBytes)

        Converts a public key as bytes into a Jwk. Applicable for asymmetric Key Generators only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception

      • sign

         ByteArray sign(Jwk privateKey, ByteArray payload, SignOptions options)

        Sign a given payload using a private key.

        This function takes a payload and a private key in Jwk (JSON Web Key) format, and returns a signature as a byte array. Additional options for the signing process can be provided via the options parameter.

        Parameters:
        privateKey - The private key in Jwk format to be used for signing.
        payload - The payload/data to be signed.
        options - Optional parameter containing additional options to control the signing process.
        Returns:

        A ByteArray representing the signature.

      • verify

         Unit verify(Jwk publicKey, ByteArray signedPayload, ByteArray signature, VerifyOptions options)

        Verify the signature of a given payload using a public key.

        This function attempts to verify the signature of a provided payload using a public key, supplied in Jwk (JSON Web Key) format, and a signature. The verification process checks the validity of the signature against the provided payload, respecting any optional verification options provided via VerifyOptions.

        Parameters:
        publicKey - The public key in Jwk format used for verifying the signature.
        signedPayload - The original payload/data that was signed, to be verified against its signature.
        signature - The signature to be verified against the payload and public key.
        options - Optional parameter containing additional options to control the verification process.
      • validatePublicKey

         final Unit validatePublicKey(Jwk key)

        Validates the provided Jwk (JSON Web Key) is a public key

        This function checks the following:

        • The key must be a public key

        • The key must be a valid Ed25519 key

        If any of these checks fail, this function throws an IllegalArgumentException with a descriptive error message.

        Parameters:
        key - The Jwk to validate.
      • validatePrivateKey

         final Unit validatePrivateKey(Jwk key)

        Validates the provided Jwk (JSON Web Key) to ensure it conforms to the expected key type and format.

        This function checks the following:

        • The key must be a private key

        • The key must be a valid Ed25519 key

        If any of these checks fail, this function throws an IllegalArgumentException with a descriptive error message.

        Parameters:
        key - The Jwk to validate.
      • getAlgorithm

         Jwa getAlgorithm()

        Specifies the JWS algorithm type. For Ed25519, this is EdDSA.