Author

Topic: problem with address key pair generation in python. (Read 353 times)

legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
thanks for the reply.

I am assuming its the Electrum 2 (bip32) seeds... I am familiar with both; in 2014 I compiled a script that did the address/key generation using electrum functions for the old seeds.

I was able to get the xpub/xprv values for the new seeds, and in fact I can generate the public key for the addresses, but the private key is giving me trouble for some reason and i'm not sure why.

if all else fails i'll have to try to run from python source and put some debug statements but hoping someone can point me in the right direction.

HCP
legendary
Activity: 2086
Merit: 4361
I assume it it an issue with the derivation path... and possibly also related to this "gem" in mnemonic.py:

Quote
class Mnemonic(object):
    # Seed derivation no longer follows BIP39
    # Mnemonic phrase uses a hash based checksum, instead of a wordlist-dependent checksum

looking at the code in keystore.py and bitcoin.py, electrum figures out seed_type(x) as 'old' or 'standard' and then you get

Code:
def from_seed(seed, passphrase):
    t = seed_type(seed)
    if t == 'old':
        keystore = Old_KeyStore({})
        keystore.add_seed(seed)
    elif t in ['standard', 'segwit']:
        keystore = BIP32_KeyStore({})
        keystore.add_seed(seed)
        keystore.passphrase = passphrase
        bip32_seed = Mnemonic.mnemonic_to_seed(seed, passphrase)
        xtype = 0 if t == 'standard' else 1
        keystore.add_xprv_from_seed(bip32_seed, xtype, "m/")
    return keystore

So my guess would be that your issue is likely in the part where it generates the actual seed from the Mnemonic (Mnemonic.mnemonic_to_seed), or during the creation of the xprv (keystore.add_xprv_from_seed)

During some recent efforts to help others with moving from one wallet to another and/or rescuing funds from 'broken' wallets, I've been struggling with the lack of consistency across all the HD wallets... they all seem to be doing different things Sad
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
i'm trying to recreate electrum address key pair generation in python.

Not sure what I am doing wrong, but once I have the xprv and xpub (which I believe I have correctly),
at least I am sure the xpub is right, not sure if we can see the master private key in the gui.

anyway
I am doing this:

def get_private_key(sequence, password,xprv):
        _, _, _, _, c, k = deserialize_xprv(xprv)
   pk = bip32_private_key(sequence, k, c)
    return pk

sequen=1;
jon1priv=get_private_key((sequen,),None,xprv);
print ("a privkey ")
print jon1priv;

but it gives me a wrong private key.  Any idea what I'm doing wrong?

Jump to: