The problem and the keys
Alice sends Bob "Pay Bob 10" over the internet. Bob cannot see who sent it, or whether someone changed it on the way. A digital signature lets him check both: who signed it (authenticity) and that it is unchanged (integrity).
Signatures use public-key cryptography. Line 1 makes a private key, which Alice keeps secret: only it can sign. Line 2 derives the matching public key, which anyone may have: it can only check. Each Ed25519 key is 32 bytes.
Alice gives Bob her public key ahead of time. Sharing it is safe: it cannot sign, and the private key cannot practically be worked out from it. Bob must be sure the key really is Alice's; certificates exist to vouch for that.
Sign and verify
Line 3 stores the message as bytes. Signing runs it through a hash function, which turns any input into a short, fixed-size fingerprint. Change one character and the fingerprint changes completely. Ed25519 uses SHA-512 inside, a 64-byte hash.
Line 4 signs. The maths mixes the message's hash with Alice's private key. Out comes the signature: 64 bytes that only her private key could make, for exactly this message. Signing does not hide anything: the message stays readable.
Alice sends the message with the signature attached. Both cross the internet in the open; nothing here is secret. The protection is that nobody without her private key can make a signature that matches a message.
Line 5 checks message, signature and Alice's public key against each other. They match, so verify() simply returns. Bob now knows the message is unchanged and was signed with Alice's private key.
Suppose someone on the way changes 10 to 99 and keeps the signature. The new message no longer matches it, so line 6 raises InvalidSignature and Bob rejects it. Making a new matching signature would need Alice's private key.
What it proves
Only Alice holds the private key, so a valid signature is evidence she signed. She cannot easily deny it later: NIST calls this non-repudiation. It holds only while the key stays secret, so guard it, ideally in hardware, and replace it if it leaks.
Software updates, HTTPS certificates and signed code all rely on this. NIST FIPS 186-5 approves RSA, ECDSA and EdDSA. Common mistakes: skipping the check, carrying on after it fails, or trusting a public key without knowing whose it is.
What happens
;; step 1/10 · problem message "Pay Bob 10", sent in the open question 1 did Alice really send it? (authenticity) question 2 is it exactly what she sent? (integrity) tool a digital signature answers both
Ed25519 does not sign one hash of the message. RFC 8032 hashes the message twice with SHA-512, mixed with key material, inside the signing maths; the figure draws this as one "hash, then sign" box. The figure uses RFC 8032's published test key so its numbers are reproducible. It is public: never use a test key for anything real; generate your own as in line 1.