I am curious on what is done when a public/private key pair is created on Stellar. I understand a key pair is generated with ed25519, but why are there additional pre-fix/postfix involved? Why would one not use the raw ed25519 hashes? Also is there any encoding done on these addresses?
A private key is just a random 256-bit number. A public key is just another 256-bit number, generated from a private key.
Quite simplified (and wrong in almost every way that matters), you generate a public key by
- taking the hash of a private key
- multiplying it with a point on an elliptic curve
- keeping the
Both types of keys are encoded into
StrKeys are there to create human readable values, that are easy to validate and distinguish the types of, for the various 256-bit number types used within the system.
- add a one-byte prefix onto the 256-bit value
- calculate a four-byte checksum
- append the checksum to the 33 bytes
- convert the raw bytes to base32 character encoding
- G - public ed25519 key
- S - private ed25519 key
- T - transaction hash used as a signer for pre-authorized transaction
- X - sha-256 hash used as a signer for hash locks
This is done so people can know what a particular
StrKey represents -- E.g., you don't want to accidentally paste your private key somewhere.