<p>It looks like the example I was using provide false informations and my hmac implementation is working.</p>
<p>Edit so maybe it's a bit clearer :</p>
<p>I checked it by pasting my BIP39 seed here :
<a href="https://iancoleman.io/bip39/" rel="nofollow noreferrer">https://iancoleman.io/bip39/</a></p>
<p>and decoding the base58 with this site :
<a href="https://appdevtools.com/base58-encoder-decoder" rel="nofollow noreferrer">https://appdevtools.com/base58-encoder-decoder</a></p>
<p>and checked the decoded result with the return of my functions to see if it match</p>
<p>result of hmac matched</p>

CC BY-SA 4.0
2022-03-05T14:28:21.403Z
So provide the solution for others to learn from, and an account of where you had gone wring
HansBKK
CC BY-SA 4.0
2022-03-05T22:41:47.223Z
The answer is given in the statement 
I'll synthetize it for you :

I tought the BIP32 master_key for this BIP39 seed : 0x77cdf1d92225adc0e67b1b4f5a31820251d518b3af074df25a07b751947fd07ebd29a4d0e57b84ea9de03a9123e2a6ea1e3ed739d4c562efec21f1bb0a54a879
should be :
0x300b155f751964276c0536230bd9b16fe7a86533c3cbaa7575e8d0431dbedf23f9945bb8b052bd0b0802c10c7c852e7765b69b61ce7233d9fe5a35ab108ca3b6

but the BIP32 master_key for this example is :
0xc661464729610902524d0919cc3000af9bfbd4fa003e78979b6026bb24d150ae99c5f70573e3eaf1b04ab3c735adc7e410bb65557e1f35cdf29f87825f9699c5
hmac was correct
leslie
CC BY-SA 4.0
2022-03-05T13:16:29.797Z
2022-03-05T22:46:26.033Z
2022-03-05T22:46:26.033Z
leslie
<p>Look at the recommended FOSS implementations in the specs and tutorials. Reread the specs docs of course, parse closely.</p>
<p>Not just Python, even CLI software like BX and bash tools, scripts etc; get a clear understanding as a user before trying to code.</p>

CC BY-SA 4.0
2022-03-05T09:40:39.143Z
I've read a lot of documentation , the official bip32 repo, learnmeabitcoin, read books and so on...
I think I have some good understanding of the functionning of HD Wallets
I'm not asking how it works , I'm asking why this function doesnt work and even hmac doesnt. Is my use of binascii.a2b_hex or pbkdf2 flawed ?
You can still forward me some documentation if you think I missed something.
Thanks
leslie
CC BY-SA 4.0
2022-03-04T14:36:41.770Z
2022-03-04T14:36:41.770Z
HansBKK
<p>I'm trying to understandand implement the functioning of Hierarchical deterministic wallets.
But I can't get the bip32masterkey
based on this tutorial : <a href="https://medium.com/mycrypto/the-journey-from-mnemonic-phrase-to-address-6c5e86e11e14" rel="nofollow noreferrer">https://medium.com/mycrypto/the-journey-from-mnemonic-phrase-to-address-6c5e86e11e14</a></p>
<p>this mnemonic seed : 0x77cdf1d92225adc0e67b1b4f5a31820251d518b3af074df25a07b751947fd07ebd29a4d0e57b84ea9de03a9123e2a6ea1e3ed739d4c562efec21f1bb0a54a879</p>
<p>should give me this bip32masterkey : 0x300b155f751964276c0536230bd9b16fe7a86533c3cbaa7575e8d0431dbedf23f9945bb8b052bd0b0802c10c7c852e7765b69b61ce7233d9fe5a35ab108ca3b6</p>
<p>but instead I have (pbkdf2) : 0x11df5cd2d2095dde0a46a8de0c2aba91a565e16dd0e5877d21285e605659d587bd3b3c72cba372ecf3b26fdf27151d9dc5d9f341760784cb04540f95d193c383</p>
<p>and this (hmac-sha512):
0xc661464729610902524d0919cc3000af9bfbd4fa003e78979b6026bb24d150ae99c5f70573e3eaf1b04ab3c735adc7e410bb65557e1f35cdf29f87825f9699c5</p>
<p>here's the code i'm using :</p>
<pre><code>def get_bip32masterkey(seed):
    master_key = pbkdf2_hmac(&quot;SHA512&quot;, bytes(binascii.a2b_hex(seed)), bytes(&quot;Bitcoin seed&quot;.encode()), 1).hex()
    return (master_key)
</code></pre>
<p>I also tried with hmac instead of pbkdf2 but I cant get the right bip32masterkey, does someone see the point i'm missing ?</p>
<p>that's the code I'm using with hmac :</p>
<pre><code>def bip32masterkey(seed):
    seed = binascii.a2b_hex(seed)
    masterkey = hmac.new(key=bytes(&quot;Bitcoin seed&quot;.encode()), msg=seed, digestmod=sha512).hexdigest()
    return (masterkey)
</code></pre>
<p>(I'm not a python dev I'm just trying to understand the basis)</p>
<p>Thank you in advance to all for your answers</p>
<p>EDIT : It looks like the example I was using provide false information and my hmac implementation is working.</p>

<wallet><bip32-hd-wallets><python><mnemonic-seed><deterministic-wallets>
Can't get the bip32masterkey from mnemonic seed (Python)
leslie
# Can't get the bip32masterkey from mnemonic seed (Python)

(Asked by: username_0 on 2022-03-03)

I'm trying to understandand implement the functioning of Hierarchical deterministic wallets.
But I can't get the bip32masterkey
based on this tutorial : <https://medium.com/mycrypto/the-journey-from-mnemonic-phrase-to-address-6c5e86e11e14>

this mnemonic seed : 0x77cdf1d92225adc0e67b1b4f5a31820251d518b3af074df25a07b751947fd07ebd29a4d0e57b84ea9de03a9123e2a6ea1e3ed739d4c562efec21f1bb0a54a879

should give me this bip32masterkey : 0x300b155f751964276c0536230bd9b16fe7a86533c3cbaa7575e8d0431dbedf23f9945bb8b052bd0b0802c10c7c852e7765b69b61ce7233d9fe5a35ab108ca3b6

but instead I have (pbkdf2) : 0x11df5cd2d2095dde0a46a8de0c2aba91a565e16dd0e5877d21285e605659d587bd3b3c72cba372ecf3b26fdf27151d9dc5d9f341760784cb04540f95d193c383

and this (hmac-sha512):
0xc661464729610902524d0919cc3000af9bfbd4fa003e78979b6026bb24d150ae99c5f70573e3eaf1b04ab3c735adc7e410bb65557e1f35cdf29f87825f9699c5

here's the code i'm using :

```
def get_bip32masterkey(seed):
    master_key = pbkdf2_hmac("SHA512", bytes(binascii.a2b_hex(seed)), bytes("Bitcoin seed".encode()), 1).hex()
    return (master_key)

```

I also tried with hmac instead of pbkdf2 but I cant get the right bip32masterkey, does someone see the point i'm missing ?

that's the code I'm using with hmac :

```
def bip32masterkey(seed):
    seed = binascii.a2b_hex(seed)
    masterkey = hmac.new(key=bytes("Bitcoin seed".encode()), msg=seed, digestmod=sha512).hexdigest()
    return (masterkey)

```

(I'm not a python dev I'm just trying to understand the basis)

Thank you in advance to all for your answers

EDIT : It looks like the example I was using provide false information and my hmac implementation is working.

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


---

## 2 answers

### Answer by username_0 on 2022-03-05. Score: 0 | Accepted answer

It looks like the example I was using provide false informations and my hmac implementation is working.

Edit so maybe it's a bit clearer :

I checked it by pasting my BIP39 seed here :
<https://iancoleman.io/bip39/>

and decoding the base58 with this site :
<https://appdevtools.com/base58-encoder-decoder>

and checked the decoded result with the return of my functions to see if it match

result of hmac matched

> **Comments:**
> **username_1**: So provide the solution for others to learn from, and an account of where you had gone wring  
> **username_0**: The answer is given in the statement  I'll synthetize it for you :  I tought the BIP32 master_key for this BIP39 seed : 0x77cdf1d92225adc0e67b1b4f5a31820251d518b3af074df25a07b751947fd07ebd29a4d0e57b84ea9de03a9123e2a6ea1e3ed739d4c562efec21f1bb0a54a879 should be : 0x300b155f751964276c0536230bd9b16fe7a86533c3cbaa7575e8d0431dbedf23f9945bb8b052bd0b0802c10c7c852e7765b69b61ce7233d9fe5a35ab108ca3b6  but the BIP32 master_key for this example is : 0xc661464729610902524d0919cc3000af9bfbd4fa003e78979b6026bb24d150ae99c5f70573e3eaf1b04ab3c735adc7e410bb65557e1f35cdf29f87825f9699c5 hmac was correct  

---

### Answer by username_1 on 2022-03-04. Score: 0

Look at the recommended FOSS implementations in the specs and tutorials. Reread the specs docs of course, parse closely.

Not just Python, even CLI software like BX and bash tools, scripts etc; get a clear understanding as a user before trying to code.

> **Comments:**
> **username_0**: I've read a lot of documentation , the official bip32 repo, learnmeabitcoin, read books and so on... I think I have some good understanding of the functionning of HD Wallets I'm not asking how it works , I'm asking why this function doesnt work and even hmac doesnt. Is my use of binascii.a2b_hex or pbkdf2 flawed ? You can still forward me some documentation if you think I missed something. Thanks  

---

