Skip to content

Seeds and Private Keys

Milan Miladinovic edited this page May 4, 2020 · 2 revisions

What is the difference

Seeds are not the same as private keys, at least most of the time. You can think of a seed as the input to some function and a private key as the output.

Seeds can range anywhere from 0 to 32 characters in length (ASCII/UTF-8, as long as 1 character = 1 byte ). Private keys are always 32 bytes, because they're actually 256 bit numbers. Seeds can vary in length because the conversion functions that we use ensure the output will always be 32 characters long.

By default, this software has a few methods for converting seeds to private keys, however you can implement your own very easily.

Current Conversion Methods

Three methods have been implemented in this software. The first two take the seed and fill it with '0's until it's 32 characters long. The third puts the seed through the hash function sha256() that results in 256 bits, which is converted to a 64 character hex string and cut in half.

So if we have the seed satoshi, our private keys will be

  • 0000000000000000000000000satoshi
  • satoshi0000000000000000000000000
  • da2876b3eb31edb4436fa4650673fc6f

and the P2PKH addresses will be

  • 1L8qQTDTbcTVQVBQAY1D4NueNZ9jpCveTd
  • 16TQV9Wnnkben4CyvgWRTBhPoSSQc39qxy
  • 1DiyJgLf9ieoktrFdLwLbL9tSSSU6LLCCa

Adding and Removing Conversion Methods

The conversion methods require three things.

  • A macro called PRIVATE_KEY_TYPES that refers to the number of private keys we will generate from any given seed
  • An array called priv_gen_functions, which stores pointers to conversion functions.
  • The conversion function itself.

Adding Methods

  1. Increment PRIVATE_KEY_TYPES.
  2. Write a function (in key_funcs.c) that does the conversion (an example is front_pad_pkey()).
    • Make sure the prototype is the same.
  3. Add it to the priv_gen_functions array.

Removing Methods

  1. Decrement PRIVATE_KEY_TYPES.
  2. Remove it from priv_gen_functions.

The prototypes are restrictive, but you can get away with type conversions via casting.