Algorithm to go from seed to 20 (or more) addresses

1

I'm currently reading the Electrum sourcecode to figure out how to go from seed (12 words) to addresses (in usual format). Does someone have the big picture of this process in mind?

More precisely I'm looking for Python code (standalone, runnable out of Electrum) that can produce this.

  1. Take a seed s (can be 12 words from the 2048-words dictionary but not necessary)

  2. Let's assume s is a valid seed (i.e. is_new_seed(s) is True, this means that bh2u(hmac_sha_512(b"Seed version", s.encode('utf8'))) has prefix '01'); code for is_new_seed here.

  3. For our goal (get addresses), should we first create the private key from s? How?

or

  1. Should we create a master public key from s? How?

  2. Given 3. or 4., how to create the 20 first public addresses?


Example of input: s = 'x8' (yes this is a valid (unsecure because too simple) seed, you can try it in Electrum - Create a wallet from existing seed)

Example of output:

1LNvv5h6QHoYv1nJcqrp13T2TBkD2sUGn1
1P6rnf6VUfSUUWES6wTyjfx9dTFqXdrjLM
1AQ6TNtD2eEdQjwpVpkPSdcvJiiLKziKZz
...

Basj

Posted 2017-12-24T16:30:43.860

Reputation: 324

Not exactly @fredsben, the output should be (public) adresses, not private keys. Or maybe can these adresses be easily deduced from pvt keys?Basj 2017-12-24T17:34:28.480

I think that tool shows private keys, public keys, and addresses. The private keys are generated from the seed. The public keys are generated from the private keys. The addresses are generated from the public keys. So yes, addresses can be deduced from private keys.4276 2017-12-24T18:21:00.620

Answers

2

Electrum uses BIP 32 to go from a seed value to private and public keys. Addresses are then derived from those keys. Public keys are also derived from the private keys, except in the case for watch-only wallets.

The full BIP 32 specification is available here.

Andrew Chow

Posted 2017-12-24T16:30:43.860

Reputation: 40 910