Bitcoin Forum
May 13, 2024, 05:54:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: problem with address key pair generation in python.  (Read 324 times)
jonald_fyookball (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
May 05, 2017, 03:24:53 AM
 #1

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?


1715622893
Hero Member
*
Offline Offline

Posts: 1715622893

View Profile Personal Message (Offline)

Ignore
1715622893
Reply with quote  #2

1715622893
Report to moderator
1715622893
Hero Member
*
Offline Offline

Posts: 1715622893

View Profile Personal Message (Offline)

Ignore
1715622893
Reply with quote  #2

1715622893
Report to moderator
1715622893
Hero Member
*
Offline Offline

Posts: 1715622893

View Profile Personal Message (Offline)

Ignore
1715622893
Reply with quote  #2

1715622893
Report to moderator
Bitcoin mining is now a specialized and very risky industry, just like gold mining. Amateur miners are unlikely to make much money, and may even lose money. Bitcoin is much more than just mining, though!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715622893
Hero Member
*
Offline Offline

Posts: 1715622893

View Profile Personal Message (Offline)

Ignore
1715622893
Reply with quote  #2

1715622893
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
May 06, 2017, 12:34:51 AM
 #2

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

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
jonald_fyookball (OP)
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
May 06, 2017, 03:12:04 AM
 #3

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.


Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!