Class Ed25519

java.lang.Object
com.codename1.security.Ed25519

public final class Ed25519 extends Object

Ed25519 signatures (RFC 8032): the signatures of Solana, Cardano, Stellar, Tezos, SSH keys and many protocols beside.

A private key is a 32-byte seed; the public key is 32 bytes and a signature 64. Signing is deterministic and constant time; verification is the cofactorless RFC 8032 check, rejecting a non-canonical S and a public key or R that does not decode, as libsodium does.

byte[] seed = SecureRandom.bytes(32);
byte[] message = "hello".getBytes();
byte[] pub = Ed25519.publicKey(seed);
byte[] sig = Ed25519.sign(seed, pub, message);
boolean ok = Ed25519.verify(message, sig, pub);
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Length of a private key (the seed).
    static final int
    Length of a public key.
    static final int
    Length of a signature.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isOnCurve(byte[] point)
    Whether 32 bytes are the encoding of a point on the curve.
    static byte[]
    publicKey(byte[] privateKey)
    The public key of a 32-byte seed.
    static byte[]
    sign(byte[] privateKey, byte[] message)
    Signs a message with a seed, deriving the public key first.
    static byte[]
    sign(byte[] privateKey, byte[] publicKey, byte[] message)
    Signs a message.
    static boolean
    verify(byte[] message, byte[] signature, byte[] publicKey)
    Verifies a signature.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PRIVATE_KEY_LENGTH

      public static final int PRIVATE_KEY_LENGTH
      Length of a private key (the seed).
      See Also:
    • PUBLIC_KEY_LENGTH

      public static final int PUBLIC_KEY_LENGTH
      Length of a public key.
      See Also:
    • SIGNATURE_LENGTH

      public static final int SIGNATURE_LENGTH
      Length of a signature.
      See Also:
  • Method Details

    • isOnCurve

      public static boolean isOnCurve(byte[] point)
      Whether 32 bytes are the encoding of a point on the curve. Solana's program-derived addresses are exactly the hashes for which this answers false.
    • publicKey

      public static byte[] publicKey(byte[] privateKey)

      The public key of a 32-byte seed.

      Throws
      • CryptoException: if the seed is not 32 bytes
    • sign

      public static byte[] sign(byte[] privateKey, byte[] message)
      Signs a message with a seed, deriving the public key first. When the public key is at hand, [#sign(byte[], byte[], byte[])] saves that work, which is most of the cost of a signature.
    • sign

      public static byte[] sign(byte[] privateKey, byte[] publicKey, byte[] message)

      Signs a message.

      Parameters
      • privateKey: the 32-byte seed

      • publicKey: the seed's public key, from publicKey(byte[]); a wrong one produces a signature nobody can verify

      • message: the message, of any length

      Returns

      the 64-byte signature

      Throws
      • CryptoException: if an argument is null or the wrong length
    • verify

      public static boolean verify(byte[] message, byte[] signature, byte[] publicKey)

      Verifies a signature.

      Returns

      true if signature was made over message by the key behind publicKey; false for any malformed or wrong signature or key