Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Ed25519
- Object
- Ed25519
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);
Fields
public static final int PRIVATE_KEY_LENGTH = 32 | Length of a private key (the seed). |
public static final int PUBLIC_KEY_LENGTH = 32 | Length of a public key. |
public static final int SIGNATURE_LENGTH = 64 | Length of a signature. |
Methods
public static boolean isOnCurve(byte[] point) | Whether 32 bytes are the encoding of a point on the curve. |
public static byte[] publicKey(byte[] privateKey) | The public key of a 32-byte seed. |
public static byte[] sign(byte[] privateKey, byte[] message) | Signs a message with a seed, deriving the public key first. |
public static byte[] sign(byte[] privateKey, byte[] publicKey, byte[] message) | Signs a message. |
public static boolean verify(byte[] message, byte[] signature, byte[] publicKey) | Verifies a signature. |
Inherited methods
Field details
PRIVATE_KEY_LENGTH
public static final int PRIVATE_KEY_LENGTH = 32Length of a private key (the seed).
PUBLIC_KEY_LENGTH
public static final int PUBLIC_KEY_LENGTH = 32Length of a public key.
SIGNATURE_LENGTH
public static final int SIGNATURE_LENGTH = 64Length of a signature.
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
privateKeybyte[]- the 32-byte seed
publicKeybyte[]- the seed’s public key, from
publicKey; a wrong one produces a signature nobody can verify messagebyte[]- 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