trezor / python-shamir-mnemonic

MIT License
165 stars 59 forks source link

add main.py to be able to run as script from checkout #31

Closed Huge closed 3 years ago

Huge commented 3 years ago

So far, after git clone you would not be able to run and debug the source code obtained as relative imports would fail:

$python shamir_mnemonic/cli.py
  File "shamir_mnemonic/cli.py", line 10, in <module>
    from .constants import GROUP_PREFIX_LENGTH_WORDS
ImportError: attempted relative import with no known parent package

Including the script adapter for the package like this, cli script runs nice and smoothly.

matejcik commented 3 years ago

you are not supposed to be running cli.py directly, but through the shamir command

Huge commented 3 years ago

you are not supposed to be running cli.py directly, but through the shamir command

So just to clarify, when I'm interested to see the secret splitting or combining process step-by-step, the recommended way is like this:

python setup.py develop
pudb3 my_path_to/python-shamir-mnemonic/.venv/bin/shamir create 2of2

?

That seems workable, although the boilerplate the script starts through felt somewhat overwhelming at first.

matejcik commented 3 years ago

Presumably, yes. I mean, for your purpose it might be easier to use the main.py you submitted, but I see no point in including it in the upstream repository.

matejcik commented 3 years ago

also bear in mind that a lot of the boilerplate you see comes from Click, which is a library for handling command-line options. You would actually be much better off by writing a simple script that does the steps you want directly, so e.g.:

from shamir_mnemonic import generate_mnemonics

secret = b"my secret"
passphrase = b""
generate_mnemonics(group_threshold=2, groups=[(1,3), (1,1)], master_secret=secret, passphrase=passphrase)