Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private and public key #1

Open
deveshaggrawal19 opened this issue Nov 16, 2017 · 5 comments
Open

Private and public key #1

deveshaggrawal19 opened this issue Nov 16, 2017 · 5 comments

Comments

@deveshaggrawal19
Copy link

Thanks for making such a good module for.
Can you tell me how to get private and public keys to the generated address?

@deveshaggrawal19
Copy link
Author

deveshaggrawal19 commented Nov 21, 2017

Please help me find the keys so that the generated address can be used. I am not able to figure it out.

@michailbrynard
Copy link
Owner

This code is for generating addresses from an XPUB. When generating from an XPUB, you are only able to derive the public key and the address and not the corresponding private key.

acct_pub_key = HDKey.from_b58check('xpub6DKMR7KpgCJbiN4TdzcqcB1Nk84D9bsYUBhbk43EjRqH4RTjz7UgGLZxcQ4JdHBSHDmTUDLApMwYHRQCbbMCPQEtcbVofZEQjFazpGPT1nW')
keys = HDKey.from_path(acct_pub_key,'{change}/{index}'.format(change=0, index=0))
public_key = keys[-1]
print('Public key (hex, uncompressed): ' + public_key.to_hex())
print('Account address: ' + public_key.address())

If you're starting from the mnemonic, however, you can get the private key and public key:

master_key = HDPrivateKey.master_key_from_mnemonic('laundry snap patient survey sleep strategy finger bone real west arch protect')
root_keys = HDKey.from_path(master_key,"m/44'/60'/0'")
acct_priv_key = root_keys[-1]
keys = HDKey.from_path(acct_priv_key,'{change}/{index}'.format(change=0, index=0))
private_key = keys[-1]
public_key = private_key.public_key
print("Private key (hex): " + private_key.to_hex())
print("Public key (hex, uncompressed): " + public_key.to_hex())
print("Address: " + private_key.public_key.address())

Hope that helps!

@0xchetan
Copy link
Contributor

How can I get 64 characters private key or wif to sign a transaction?

@michailbrynard
Copy link
Owner

@csbadhe Hmmm, it looks like my example above is giving the hex representation of the HDPrivateKey object. It looks like if you keep everything the same as above, this should give the actual private key:
print("Private key (hex): " + private_key._key.to_hex())

@0xchetan
Copy link
Contributor

It worked. Thanks a lot, @michailbrynard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants