From b3e3f4107308275860bd3c0db912f789cd894405 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 24 Apr 2023 13:23:43 +0000 Subject: [PATCH] Opts.py: new help_mod() function; add help.seedsplit mod --- mmgen/help/__init__.py | 92 ----------------------------------- mmgen/help/seedsplit.py | 105 ++++++++++++++++++++++++++++++++++++++++ mmgen/main_wallet.py | 4 +- mmgen/opts.py | 2 +- mmgen/share/Opts.py | 11 ++++- 5 files changed, 118 insertions(+), 96 deletions(-) create mode 100755 mmgen/help/seedsplit.py diff --git a/mmgen/help/__init__.py b/mmgen/help/__init__.py index 019d32b2..df005a11 100755 --- a/mmgen/help/__init__.py +++ b/mmgen/help/__init__.py @@ -239,98 +239,6 @@ default wallet. pnu = proto.name, pnl = gc.proj_name.lower() ) - def seedsplit(): - from ..seedsplit import SeedShareIdx,SeedShareCount,MasterShareIdx - return """ -COMMAND NOTES: - -This command generates shares one at a time. Shares may be output to any -MMGen wallet format, with one limitation: only one share in a given split may -be in hidden incognito format, and it must be the master share in the case of -a master-share split. - -If the command's optional first argument is omitted, the default wallet is -used for the split. - -The last argument is a seed split specifier consisting of an optional split -ID, a share index, and a share count, all separated by colons. The split ID -must be a valid UTF-8 string. If omitted, the ID 'default' is used. The -share index (the index of the share being generated) must be in the range -{si.min_val}-{si.max_val} and the share count (the total number of shares in the split) -in the range {sc.min_val}-{sc.max_val}. - -Master Shares - -Each seed has a total of {mi.max_val} master shares, which can be used as the first -shares in multiple splits if desired. To generate a master share, use the ---master-share (-M) option with an index in the range {mi.min_val}-{mi.max_val} and omit -the last argument. - -When creating and joining a split using a master share, ensure that the same -master share index is used in all split and join commands. - -EXAMPLES: - - Split a BIP39 seed phrase into two BIP39 shares. Rejoin the split: - - $ echo 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' > sample.bip39 - - $ mmgen-seedsplit -o bip39 sample.bip39 1:2 - BIP39 mnemonic data written to file '03BAE887-default-1of2[D51CB683][128].bip39' - - $ mmgen-seedsplit -o bip39 sample.bip39 2:2 - BIP39 mnemonic data written to file '03BAE887-default-2of2[67BFD36E][128].bip39' - - $ mmgen-seedjoin -o bip39 \\ - '03BAE887-default-2of2[67BFD36E][128].bip39' \\ - '03BAE887-default-1of2[D51CB683][128].bip39' - BIP39 mnemonic data written to file '03BAE887[128].bip39' - - $ cat '03BAE887[128].bip39' - zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong - - Create a 3-way default split of your default wallet, outputting all shares - to default wallet format. Rejoin the split: - - $ mmgen-seedsplit 1:3 # Step A - $ mmgen-seedsplit 2:3 # Step B - $ mmgen-seedsplit 3:3 # Step C - $ mmgen-seedjoin - - Create a 2-way split of your default wallet with ID string 'alice', - outputting shares to MMGen native mnemonic format. Rejoin the split: - - $ mmgen-seedsplit -o words alice:1:2 # Step D - $ mmgen-seedsplit -o words alice:2:2 # Step E - $ mmgen-seedjoin - - Create a 2-way split of your default wallet with ID string 'bob' using - master share #7, outputting share #1 (the master share) to default wallet - format and share #2 to BIP39 format. Rejoin the split: - - $ mmgen-seedsplit -M7 # Step X - $ mmgen-seedsplit -M7 -o bip39 bob:2:2 # Step Y - $ mmgen-seedjoin -M7 --id-str=bob - - Create a 2-way split of your default wallet with ID string 'alice' using - master share #7. Rejoin the split using master share #7 generated in the - previous example: - - $ mmgen-seedsplit -M7 -o bip39 alice:2:2 # Step Z - $ mmgen-seedjoin -M7 --id-str=alice - - Create a 2-way default split of your default wallet with an incognito-format - master share hidden in file 'my.hincog' at offset 1325. Rejoin the split: - - $ mmgen-seedsplit -M4 -o hincog -J my.hincog,1325 1:2 # Step M (share A) - $ mmgen-seedsplit -M4 -o bip39 2:2 # Step N (share B) - $ mmgen-seedjoin -M4 -H my.hincog,1325 - -""".strip().format( - si = SeedShareIdx, - sc = SeedShareCount, - mi = MasterShareIdx ) - def subwallet(): from ..subseed import SubSeedIdxRange return f""" diff --git a/mmgen/help/seedsplit.py b/mmgen/help/seedsplit.py new file mode 100755 index 00000000..45aa2794 --- /dev/null +++ b/mmgen/help/seedsplit.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +# +# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet +# Copyright (C)2013-2023 The MMGen Project +# Licensed under the GNU General Public License, Version 3: +# https://www.gnu.org/licenses +# Public project repositories: +# https://github.com/mmgen/mmgen +# https://gitlab.com/mmgen/mmgen + +""" +help.seedsplit: seedsplit help notes for MMGen suite +""" + +def help(proto,cfg): + from ..seedsplit import SeedShareIdx,SeedShareCount,MasterShareIdx + return """ +COMMAND NOTES: + +This command generates shares one at a time. Shares may be output to any +MMGen wallet format, with one limitation: only one share in a given split may +be in hidden incognito format, and it must be the master share in the case of +a master-share split. + +If the command's optional first argument is omitted, the default wallet is +used for the split. + +The last argument is a seed split specifier consisting of an optional split +ID, a share index, and a share count, all separated by colons. The split ID +must be a valid UTF-8 string. If omitted, the ID 'default' is used. The +share index (the index of the share being generated) must be in the range +{si.min_val}-{si.max_val} and the share count (the total number of shares in the split) +in the range {sc.min_val}-{sc.max_val}. + +Master Shares + +Each seed has a total of {mi.max_val} master shares, which can be used as the first +shares in multiple splits if desired. To generate a master share, use the +--master-share (-M) option with an index in the range {mi.min_val}-{mi.max_val} and omit +the last argument. + +When creating and joining a split using a master share, ensure that the same +master share index is used in all split and join commands. + +EXAMPLES: + + Split a BIP39 seed phrase into two BIP39 shares. Rejoin the split: + + $ echo 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' > sample.bip39 + + $ mmgen-seedsplit -o bip39 sample.bip39 1:2 + BIP39 mnemonic data written to file '03BAE887-default-1of2[D51CB683][128].bip39' + + $ mmgen-seedsplit -o bip39 sample.bip39 2:2 + BIP39 mnemonic data written to file '03BAE887-default-2of2[67BFD36E][128].bip39' + + $ mmgen-seedjoin -o bip39 \\ + '03BAE887-default-2of2[67BFD36E][128].bip39' \\ + '03BAE887-default-1of2[D51CB683][128].bip39' + BIP39 mnemonic data written to file '03BAE887[128].bip39' + + $ cat '03BAE887[128].bip39' + zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong + + Create a 3-way default split of your default wallet, outputting all shares + to default wallet format. Rejoin the split: + + $ mmgen-seedsplit 1:3 # Step A + $ mmgen-seedsplit 2:3 # Step B + $ mmgen-seedsplit 3:3 # Step C + $ mmgen-seedjoin + + Create a 2-way split of your default wallet with ID string 'alice', + outputting shares to MMGen native mnemonic format. Rejoin the split: + + $ mmgen-seedsplit -o words alice:1:2 # Step D + $ mmgen-seedsplit -o words alice:2:2 # Step E + $ mmgen-seedjoin + + Create a 2-way split of your default wallet with ID string 'bob' using + master share #7, outputting share #1 (the master share) to default wallet + format and share #2 to BIP39 format. Rejoin the split: + + $ mmgen-seedsplit -M7 # Step X + $ mmgen-seedsplit -M7 -o bip39 bob:2:2 # Step Y + $ mmgen-seedjoin -M7 --id-str=bob + + Create a 2-way split of your default wallet with ID string 'alice' using + master share #7. Rejoin the split using master share #7 generated in the + previous example: + + $ mmgen-seedsplit -M7 -o bip39 alice:2:2 # Step Z + $ mmgen-seedjoin -M7 --id-str=alice + + Create a 2-way default split of your default wallet with an incognito-format + master share hidden in file 'my.hincog' at offset 1325. Rejoin the split: + + $ mmgen-seedsplit -M4 -o hincog -J my.hincog,1325 1:2 # Step M (share A) + $ mmgen-seedsplit -M4 -o bip39 2:2 # Step N (share B) + $ mmgen-seedjoin -M4 -H my.hincog,1325 + +""".strip().format( + si = SeedShareIdx, + sc = SeedShareCount, + mi = MasterShareIdx ) diff --git a/mmgen/main_wallet.py b/mmgen/main_wallet.py index 12ec7691..116ac9e7 100755 --- a/mmgen/main_wallet.py +++ b/mmgen/main_wallet.py @@ -136,9 +136,9 @@ FMT CODES: cfg=cfg, gc=gc, ), - 'notes': lambda cfg,help_notes,s: s.format( + 'notes': lambda cfg,help_mod,help_notes,s: s.format( f=help_notes('fmt_codes'), - n_ss=('',help_notes('seedsplit')+'\n\n')[do_ss_note], + n_ss=('',help_mod('seedsplit')+'\n\n')[do_ss_note], n_sw=('',help_notes('subwallet')+'\n\n')[do_sw_note], n_pw=help_notes('passwd'), n_bw=('','\n\n'+help_notes('brainwallet'))[do_bw_note] diff --git a/mmgen/opts.py b/mmgen/opts.py index be0d006c..46cc6f8d 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -70,7 +70,7 @@ long_opts_data = { --, --alice Specify user “Alice” in MMGen regtest mode --, --carol Specify user “Carol” in MMGen regtest mode """, - 'code': lambda help_notes,proto,s: s.format( + 'code': lambda proto,s: s.format( pnm = gc.proj_name, cu_dfl = proto.coin, ) diff --git a/mmgen/share/Opts.py b/mmgen/share/Opts.py index f160bacd..3ecd0a5f 100755 --- a/mmgen/share/Opts.py +++ b/mmgen/share/Opts.py @@ -73,8 +73,17 @@ def make_help(cfg,proto,opts_data,opt_filter): def help_notes(k): return help_notes_func(proto,cfg,k) + def help_mod(modname): + import importlib + return importlib.import_module('mmgen.help.'+modname).help(proto,cfg) + def gen_arg_tuple(func,text): - d = {'proto': proto,'help_notes':help_notes,'cfg':cfg} + d = { + 'proto': proto, + 'help_notes': help_notes, + 'help_mod': help_mod, + 'cfg': cfg, + } for arg in func.__code__.co_varnames: yield d[arg] if arg in d else text