1

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.

2 Answers 2

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.

1
  • 1
    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
    Commented Mar 5, 2022 at 9:40
0

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

2
  • So provide the solution for others to learn from, and an account of where you had gone wring
    – HansBKK
    Commented Mar 5, 2022 at 14:28
  • 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
    Commented Mar 5, 2022 at 22:41

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.