I want to develop SDKs for other languages and would like to start by generating keypairs so what would be the steps starting from scratch using a crypto lib?

The steps I am looking for are: generate a random seed N length, convert to base32, prepend 'G'? Is that it? Or simply use crypto.ed25519 and be done with it? What should be the length of the seed? What to prepend and append? What extra validation processes? Where does the G come from? Is that just an arbitrary selection?

I know it may look like an intro to cryptography, so where to start but explicitly related to Stellar?

3 Answers 3


I'm working on a Rust library so I had to implement this as well.

If you have a 32 byte secret seed, you can generate the ED25519 keypair using your favorite crypto library. Likewise for public keys only.

How to convert the secret and account id to bytes

Good reference for this operation is strkey in js-stellar-base, you want to look at decodeEd25519PublicKey and decodeEd25519SecretSeed. They are both identical except the first byte of the public key is G and of the secret seed is S.

The steps are roughly as follows:

  1. Decode from base32 int D
  2. Check the first byte of D to match the kind of key your are decoding
  3. The last 2 bytes of D are the checksum
  4. Calculate the checksum of the bytes from 0 to len-2, and verify it matches the checksum found in the previous step
  5. The seed data will be the bytes from 1 to len-2

The checksum is computed using CRC16-XMODEM.

  • Hey Francesco, your help has been invaluable but I am having an issue as public keys come out fine with 56 chars (32 bytes) but secret keys are resulting in 112 chars (64 bytes) so how to make them fit the 56 chars (32 bytes) as expected? A simple step I am missing?
    – Kuyawa
    Commented Jan 22, 2018 at 23:12
  • Yes, the secret key is 64 bytes, while the secret seed and public key are 32 bytes. So you generate the 32 bytes secret seed and from it you compute the 64 bytes secret key and 32 bytes public key. You then encode the secret seed (starting wit S) and use the secret key only to sign. To derive the keypair from a known secret seed, you decode the secret seed and generate the keypair like you did for the random seed.
    – Francesco
    Commented Jan 23, 2018 at 9:07
  • So I was stupidly trying to base32 the secret key instead of the seed facepalm, thanks for the correction, you're my hero.
    – Kuyawa
    Commented Jan 23, 2018 at 13:03
  • The secret key being 64 bytes is only really a sjcl thing. Their "secret key" is a concatenation of the 32 bit seed and the public key, in order to not having to regenerate the public key every time they need it. Commented Jan 30, 2018 at 0:14
  • Is it a possibility to generate Stellar key based on 64 bytes Substrate key, mentioned [here][1]. [1]: substrate.dev/docs/en/tutorials/start-a-private-network/… Commented Oct 19, 2020 at 14:56

I don’t know for sure how to do it, but if I would be in your shoes I’ll look how other stellar’s sdk do it, it is a good starting point

About key, the G prepend is not the only operation you have to do, you need to postpend the CRC too

Maybe this answer can help you (is related to how validate a key)

  • Sure, I downloaded all SDKs available for JS, Java, Go, C#, Ruby, Python, etc and I use them all for reference. I am looking for a user guide if there is any in the Stellar.org site or basic steps as explained by Francesco above. Thanks.
    – Kuyawa
    Commented Jan 21, 2018 at 16:45

Is it a possibility to generate Stellar key based on 64 bytes Substrate key, mentioned here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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