G-N354X1RGVT
BitcoinToday

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:

https://learnmeabitcoin.com/technical/hd-wallets

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:

d547eda1f3d7da655cafec4506d3e333f1add4415968b1994f30bd64b023e2d3

however mine is:

c9dd74741e44fbd9e763f47829f37d1b2165a5ad6e90697c719d95489c409326

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