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

Want to write a python script that hold private key with pycoin #327

Open
unchainedio opened this issue Jan 22, 2019 · 5 comments
Open

Want to write a python script that hold private key with pycoin #327

unchainedio opened this issue Jan 22, 2019 · 5 comments

Comments

@unchainedio
Copy link

unchainedio commented Jan 22, 2019

Hi,

im new into this, so apologies if its an obvious question.

i would like to have a pure python script using pycoin that holds the private key, sends, receives, etc... what is the best way to do that and at the same time keeping the private key secure within the app, so that i dont lose all my funds. Im assuming that is what pycoin was written to allow a user to do.

is there anything special i need to do to keep the privatekey secure within the app?

Also, how do i keep persistence of the private key? im assuming u create the private key once and thats its. Or is it better to hardcode it? So that the app can always access its funds?

im specifically interested in BTC, LTC, DASH.

I would like to have this script handle funds for trading. so, if pycoin is not the best use case for this please let me know.

thanks

@unchainedio
Copy link
Author

i looked through the closed issues and found a way to generate a private key programmatically but im getting an error...

import os
from pycoin.key import Key

se = os.urandom(256)
key = Key(secret_exponent=se)

print(key.address())

i get this error: what am i doing wrong?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/pycoin/key/Key.py", line 70, in __init__
    raise InvalidSecretExponentError()
pycoin.key.Key.InvalidSecretExponentError

@unchainedio
Copy link
Author

i tried running python3.7

and i now get this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pycoin/key/Key.py", line 68, in __init__
    if self._secret_exponent < 1 \
TypeError: '<' not supported between instances of 'bytes' and 'int'

@richardkiss
Copy link
Owner

os.urandom returns bytes and your secret exponent should be an int. Use pycoin.encoding.bytes32.from_bytes_32 to convert bytes to an int.

@richardkiss
Copy link
Owner

I would recommend using ku to generate the keys, since you won't be doing this often, and storing them as xprv or wif format, which is text, in an encrypted file, using gpg or something similar.

@reiven
Copy link

reiven commented Mar 11, 2019

Hi, i'm trying this too, but looks like the generator is needed now

>>> key = Key(secret_exponent=se)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaaaaaa/work/virtualenvs/vpycoin3/pycoin/pycoin/key/Key.py", line 55, in __init__
    raise ValueError("generator not specified when secret exponent specified")
ValueError: generator not specified when secret exponent specified````

Maybe it will be useful to have this in the documentation?

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