Having hassle making a Python operate that creates non-hardened HD pockets baby keys

I’m coding my very own keys (not to be used in manufacturing, strictly for studying). I’m efficiently creating 512 bit seeds from mnemonic phrases, nonetheless I’m failing on the step of deriving baby keys from these seeds. For reference I’m utilizing the next put up for testing:


What I’ll do is use that website to generate mnemonics for me, then utilizing the seed I attempt to match the kid keys within the Youngster Keys (Fundamental) part, to no avail. For example, I’ve the next phrase:

lash afraid any alter object subject pony deer helmet favourite chuckle carpet

which matches the seed and keys within the put up:

Prolonged key: e8448e8e6ac4ce400951f6d630a0963c40b263208dacee0c53b3a3ccf8be9a1540434b626e34b82f28e4fb60842d5a5470e2f8cc2777a559a3c68ac4e9f2559d
Personal key: e8448e8e6ac4ce400951f6d630a0963c40b263208dacee0c53b3a3ccf8be9a15
Chain code: 40434b626e34b82f28e4fb60842d5a5470e2f8cc2777a559a3c68ac4e9f2559d
Public key: 03cf895293b95a0ce2457593b82cc6fd646c757a1e2d393932b70dafddc2d9553b

Right here is the place I get tripped up. My tough python operate seems to be like this:

def create_child_keys(chain_code, public_key, kids):
    for n in vary(kids):
        hex_child_index = hex(n)[2:].zfill(8)
        print(hmac.new(bytes.fromhex(chain_code), msg=bytes.fromhex(public_key + hex_child_index), digestmod=hashlib.sha512).hexdigest())

create_child_keys(extended_key, 3)

This returns totally different hashes for the primary 3 kids than the hyperlink posted above. For example, in line with learnmeabitcoin the primary baby ought to have a personal key of:


however mine is:


Hoping one thing apparent stands out to these extra aware of this course of.

Leave a Reply

Your email address will not be published.

Back to top button