<p>The difficulty is with the poorly named <code>BIP32Key.fromEntropy</code>.</p>

<p>Typically to create a new wallet, you:</p>

<ol>
<li>Get some entropy from a cryptographically secure random source, at least 128 bits and must be a multiple of 32 bits.</li>
<li>Convert the entropy to a mnemonic (this conversion is not a one-way function, it's bijective).</li>
<li>Convert the mnemonic to a 512-bit seed (this conversion is one way).</li>
<li>Convert the seed to an extended private key (also one way).</li>
<li>Do the BIP-32 derivation and all the rest....</li>
</ol>

<p><code>BIP32Key.fromEntropy</code> really should have been named <code>BIP32Key.fromSeed</code>.</p>

<p>Here's an example:</p>

<pre><code>from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
import os, bip39

strength_bits = 128
entropy = os.urandom(strength_bits // 8)
wallet_generator = bip39.Mnemonic('english')
mnemonic = wallet_generator.to_mnemonic(entropy)
assert wallet_generator.to_entropy(mnemonic) == entropy  # see, bijective!

# Or specify the mnemonic directly if you prefer:
mnemonic = 'aware report movie exile buyer drum poverty supreme gym oppose float elegant'

print mnemonic
seed = bip39.Mnemonic.to_seed(mnemonic)
key = BIP32Key.fromEntropy(seed)
account_number = 0
i = 0
print key.ChildKey(44 + BIP32_HARDEN) \
         .ChildKey(0 + BIP32_HARDEN) \
         .ChildKey(account_number + BIP32_HARDEN) \
         .ChildKey(0) \
         .ChildKey(i) \
         .Address()
</code></pre>

CC BY-SA 3.0
2017-11-17T23:49:55.050Z
2017-11-18T01:30:10.180Z
2017-11-18T01:30:10.180Z
Christopher Gurnee
<p>I am trying to re-generate the receiving addresses (and change addresses, for that matter) my mycelium wallet has generated.</p>

<p>So far I've used <a href="https://github.com/trezor/python-mnemonic" rel="nofollow noreferrer">trezor's implementation of BIP39</a> to generate the entropy from the 12 words, and <a href="https://github.com/prusnak/bip32utils" rel="nofollow noreferrer">a BIP32 implementation</a> I have used previously (successfully, to generate the same addresses as bitcoin core, which uses a different subkeys scheme but from a tpub, not from entropy), to produce the keys from the entropy.</p>

<p>Here's the code:</p>

<pre><code>from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
import bip39

wallet_generator = bip39.Mnemonic('english')
entropy = wallet_generator.to_entropy('12 words here')
key = BIP32Key.fromEntropy(entropy)
account_number = 0
i = 0
print key.ChildKey(44 + BIP32_HARDEN) \
         .ChildKey(0 + BIP32_HARDEN) \
         .ChildKey(account_number + BIP32_HARDEN) \
         .ChildKey(0) \
         .ChildKey(i) \
         .Address()
</code></pre>

<p>I am trying to follow BIP44's scheme as described <a href="https://github.com/bitcoin/bips/blob/1d371a58978fd2f313c9d162762de04d3b697bf5/bip-0044.mediawiki" rel="nofollow noreferrer">here</a>.</p>

<p>I am getting a key, but not the one that appear in my first mycelium transaction. I've tried to search the first 100 <code>i</code> with <code>account_number</code> 0 to 9, to no avail. Using <code>bip32gen</code> from the command line does not produce the correct key either:</p>

<pre><code>echo YOUR_ENTROPY_IN_HEX_HERE | \
    bip32gen -v \
    -i entropy -f - -x \
    -o addr -F - -X \
    m/44h/0h/0h/0/0
</code></pre>

<p>With <code>entropy</code> converted to hex with <code>print ''.join('{:02X}'.format(x) for x in entropy)</code></p>

<p>What am I missing? Is the entropy with BIP39 part wrong? Is that BIP32 library yielding erroneous addresses? What alternatives are there?</p>

<p><strong>UPDATE:</strong></p>

<p>Thanks to <a href="https://iancoleman.io/bip39/#english" rel="nofollow noreferrer">this site</a>, I've seen that the xprv generated from the 12 words is incorrect. So either the bip39 is faulty, or the way I'm using it is.</p>

CC BY-SA 3.0
2017-11-12T05:34:27.450Z
Try with the second to last part of the derivation path being hardened. Right now you have `m/44'/0'/0'/0/i`, try `m/44'/0'/0'/0'/i`.
Ava Chow
CC BY-SA 3.0
2017-11-12T14:59:19.883Z
@AndrewChow still nothing.
Gabriel
CC BY-SA 3.0
2017-11-16T11:34:10.297Z
not sure what exactly shall be achieved, but I know that every wallet has different type of implementations, as outlined here in a post: https://bitcoin.stackexchange.com/questions/60690/how-to-convert-electrum-12-words-seed-to-private-key/60905?noredirect=1#comment69615_60905 - maybe this helps...
pebwindkraft
<python><bip32-hd-wallets><mnemonic-seed><mycelium-wallet><bip44>
How to generate mycelium addresses from the 12 words in python
Gabriel
# How to generate mycelium addresses from the 12 words in python

(Asked by: username_0 on 2017-11-12)

I am trying to re-generate the receiving addresses (and change addresses, for that matter) my mycelium wallet has generated.

So far I've used [trezor's implementation of BIP39](https://github.com/trezor/python-mnemonic) to generate the entropy from the 12 words, and [a BIP32 implementation](https://github.com/prusnak/bip32utils) I have used previously (successfully, to generate the same addresses as bitcoin core, which uses a different subkeys scheme but from a tpub, not from entropy), to produce the keys from the entropy.

Here's the code:

```
from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
import bip39

wallet_generator = bip39.Mnemonic('english')
entropy = wallet_generator.to_entropy('12 words here')
key = BIP32Key.fromEntropy(entropy)
account_number = 0
i = 0
print key.ChildKey(44 + BIP32_HARDEN) \
         .ChildKey(0 + BIP32_HARDEN) \
         .ChildKey(account_number + BIP32_HARDEN) \
         .ChildKey(0) \
         .ChildKey(i) \
         .Address()

```

I am trying to follow BIP44's scheme as described [here](https://github.com/bitcoin/bips/blob/1d371a58978fd2f313c9d162762de04d3b697bf5/bip-0044.mediawiki).

I am getting a key, but not the one that appear in my first mycelium transaction. I've tried to search the first 100 `i` with `account_number` 0 to 9, to no avail. Using `bip32gen` from the command line does not produce the correct key either:

```
echo YOUR_ENTROPY_IN_HEX_HERE | \
    bip32gen -v \
    -i entropy -f - -x \
    -o addr -F - -X \
    m/44h/0h/0h/0/0

```

With `entropy` converted to hex with `print ''.join('{:02X}'.format(x) for x in entropy)`

What am I missing? Is the entropy with BIP39 part wrong? Is that BIP32 library yielding erroneous addresses? What alternatives are there?

**UPDATE:**

Thanks to [this site](https://iancoleman.io/bip39/#english), I've seen that the xprv generated from the 12 words is incorrect. So either the bip39 is faulty, or the way I'm using it is.

**Tags:** python, bip32-hd-wallets, mnemonic-seed, mycelium-wallet, bip44

> **Comments:**
> **username_1**: Try with the second to last part of the derivation path being hardened. Right now you have `m/44'/0'/0'/0/i`, try `m/44'/0'/0'/0'/i`.  
> **username_0**: @AndrewChow still nothing.  
> **username_2**: not sure what exactly shall be achieved, but I know that every wallet has different type of implementations, as outlined here in a post: https://bitcoin.stackexchange.com/questions/60690/how-to-convert-electrum-12-words-seed-to-private-key/60905?noredirect=1#comment69615_60905 - maybe this helps...  

---

## 1 answers

### Answer by username_3 on 2017-11-17. Score: 3 | Accepted answer

The difficulty is with the poorly named `BIP32Key.fromEntropy`.

Typically to create a new wallet, you:

1. Get some entropy from a cryptographically secure random source, at least 128 bits and must be a multiple of 32 bits.
2. Convert the entropy to a mnemonic (this conversion is not a one-way function, it's bijective).
3. Convert the mnemonic to a 512-bit seed (this conversion is one way).
4. Convert the seed to an extended private key (also one way).
5. Do the BIP-32 derivation and all the rest....

`BIP32Key.fromEntropy` really should have been named `BIP32Key.fromSeed`.

Here's an example:

```
from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
import os, bip39

strength_bits = 128
entropy = os.urandom(strength_bits // 8)
wallet_generator = bip39.Mnemonic('english')
mnemonic = wallet_generator.to_mnemonic(entropy)
assert wallet_generator.to_entropy(mnemonic) == entropy  # see, bijective!

# Or specify the mnemonic directly if you prefer:
mnemonic = 'aware report movie exile buyer drum poverty supreme gym oppose float elegant'

print mnemonic
seed = bip39.Mnemonic.to_seed(mnemonic)
key = BIP32Key.fromEntropy(seed)
account_number = 0
i = 0
print key.ChildKey(44 + BIP32_HARDEN) \
         .ChildKey(0 + BIP32_HARDEN) \
         .ChildKey(account_number + BIP32_HARDEN) \
         .ChildKey(0) \
         .ChildKey(i) \
         .Address()

```


---

