pycoin icon indicating copy to clipboard operation
pycoin copied to clipboard

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

Open unchainedio opened this issue 6 years ago • 5 comments

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 avatar Jan 22 '19 09:01 unchainedio

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 avatar Jan 22 '19 15:01 unchainedio

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'

unchainedio avatar Jan 22 '19 15:01 unchainedio

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 avatar Jan 24 '19 19:01 richardkiss

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.

richardkiss avatar Jan 24 '19 19:01 richardkiss

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?

reiven avatar Mar 11 '19 18:03 reiven