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 y-coordinate

Both types of keys are encoded into StrKeys.

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

StrKey prefixes:

  • 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.

  • Thanks for expanding, still curious on what string is which. From the docs ``var pair = StellarSdk.Keypair.random();``` and pair.secret(); pair.publicKey(); is the pair's keys the StrKey or the unencoded keys that are first created from the elliptic curve? Also, you are saying that posting the unencoded private key is just as dangerous as posting a StrKey of the private key, correct? – Brutus123 Oct 29 '18 at 9:42
  • 1
    A Keypair contains a pair of keys, and is used for creating a signature, and for verifying a signature. pair.secret() returns a private key encoded as an StrKey, starting with 'S'. pair.publicKey() returns a public key encoded as an StrKey, starting with 'G'. – Johan Stén Oct 29 '18 at 10:31
  • 1
    Posting a raw, unencoded key would be less dangerous, as people most likely wouldn't know what it was. An StrKey, OTOH, would be a dead giveaway, and that's the point -- You can tell what is represents by looking at it. Mind you, people have posted private keys on forums before. I remember someone posting a private key for an account w/ almost 200k XLM in it, once. – Johan Stén Oct 29 '18 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.