From 8874dabea097db571b64d26a2cbe5d4ef78fa65d Mon Sep 17 00:00:00 2001 From: philemon Date: Wed, 13 Jul 2016 16:22:17 +0300 Subject: [PATCH] Added --brain-params to walletconv, addrgen --- mmgen/globalvars.py | 2 +- mmgen/main_addrgen.py | 12 ++++++------ mmgen/main_txsign.py | 4 +--- mmgen/main_wallet.py | 2 ++ mmgen/opts.py | 4 ++-- mmgen/seed.py | 26 ++++++++++++++------------ 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index acc65353..62340b3d 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -58,7 +58,7 @@ version = '0.8.4' required_opts = [ 'quiet','verbose','debug','outdir','echo_passphrase','passwd_file', 'usr_randchars','stdout','show_hash_presets','label', - 'keep_passphrase','keep_hash_preset' + 'keep_passphrase','keep_hash_preset','brain_params' ] incompatible_opts = ( ('quiet','verbose'), diff --git a/mmgen/main_addrgen.py b/mmgen/main_addrgen.py index 3a0cdcc0..f2051f2f 100755 --- a/mmgen/main_addrgen.py +++ b/mmgen/main_addrgen.py @@ -34,7 +34,7 @@ By default, both addresses and secret keys are generated. """.strip() else: gen_what = 'addresses' - opt_filter = 'hcdeiHOKlpzPqSv' + opt_filter = 'hbcdeiHOKlpzPqSv' note1 = """ If available, the external 'keyconv' program will be used for address generation. @@ -48,6 +48,8 @@ opts_data = { 'options': """ -h, --help Print this help message. -A, --no-addresses Print only secret keys, no addresses. +-b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for brain- + wallet input. -c, --print-checksum Print address list checksum and exit. -d, --outdir= d Output files to directory 'd' instead of working dir. -e, --echo-passphrase Echo passphrase or mnemonic to screen upon entry. @@ -96,12 +98,10 @@ FMT CODES: cmd_args = opts.init(opts_data,add_opts=['b16'],opt_filter=opt_filter) nargs = 2 -if len(cmd_args) < nargs \ - and not opt.hidden_incog_input_params and not opt.in_fmt: +if len(cmd_args) < nargs and not (opt.hidden_incog_input_params or opt.in_fmt): + opts.usage() +elif len(cmd_args) > nargs - int(bool(opt.hidden_incog_input_params)): opts.usage() -elif len(cmd_args) > nargs \ - or (len(cmd_args) == nargs and opt.hidden_incog_input_params): - opts.usage() addrlist_arg = cmd_args.pop() addr_idxs = parse_addr_idxs(addrlist_arg) diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index 44bb0eb4..47cbb0f1 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -34,9 +34,7 @@ opts_data = { 'options': """ -h, --help Print this help message. -b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for brain- - wallet input. Required only if these parameters dif- - fer from those of an incognito wallet also being used - as a seed source. + wallet input. -d, --outdir= d Specify an alternate directory 'd' for output. -D, --tx-id Display transaction ID and exit. -e, --echo-passphrase Print passphrase to screen when typing it. diff --git a/mmgen/main_wallet.py b/mmgen/main_wallet.py index b7b96d5e..847daf51 100755 --- a/mmgen/main_wallet.py +++ b/mmgen/main_wallet.py @@ -63,6 +63,8 @@ opts_data = { 'usage': usage, 'options': """ -h, --help Print this help message. +-b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for brain- + wallet input. -d, --outdir= d Output files to directory 'd' instead of working dir. -e, --echo-passphrase Echo passphrases and other user input to screen. -i, --in-fmt= f {iaction} from wallet format 'f' (see FMT CODES below). diff --git a/mmgen/opts.py b/mmgen/opts.py index ed7b628c..39a43877 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -133,8 +133,8 @@ def init(opts_data,add_opts=[],opt_filter=None): # A special case - do this here, before opt gets set from g.dfl_vars if opt.usr_randchars: g.use_urandchars = True - # If user opt is set, convert its type based on value in mmgen.globalvars - # If unset, set it to default value in mmgen.globalvars (g): + # If user opt is set, convert its type based on value in mmgen.globalvars (g) + # If unset, set it to default value in mmgen.globalvars (g) setattr(opt,'set_by_user',[]) for k in g.dfl_vars: if k in opt.__dict__ and opt.__dict__[k] != None: diff --git a/mmgen/seed.py b/mmgen/seed.py index 13a4825f..a970e1e5 100755 --- a/mmgen/seed.py +++ b/mmgen/seed.py @@ -198,12 +198,13 @@ class SeedSource(MMGenObject): @classmethod def format_fmt_codes(cls): - d = [(c.__name__,','.join(c.fmt_codes)) for c in cls._get_subclasses() + d = [(c.__name__,('.'+c.ext if c.ext else c.ext),','.join(c.fmt_codes)) + for c in cls._get_subclasses() if hasattr(c,'fmt_codes')] - w = max([len(a) for a,b in d]) - ret = ['{:<{w}} {}'.format(a,b,w=w) for a,b in [ - ('Format','Valid codes'), - ('------','-----------') + w = max([len(a) for a,b,c in d]) + ret = ['{:<{w}} {:<9} {}'.format(a,b,c,w=w) for a,b,c in [ + ('Format','FileExt','Valid codes'), + ('------','-------','-----------') ] + sorted(d)] return '\n'.join(ret) + '\n' @@ -707,16 +708,19 @@ class Brainwallet (SeedSourceEnc): def _decrypt(self): d = self.ssdata - if hasattr(opt,'brain_params'): + if opt.brain_params: seed_len,d.hash_preset = self.get_bw_params() else: + m1 = 'Warning: using default seed length of %s' + m2 = 'If this is not what you want, use the --brain-params option' + qmsg((m1+'\n'+m2) % opt.seed_len) self._get_hash_preset() seed_len = opt.seed_len - vmsg_r('Hashing brainwallet data. Please wait...') + qmsg_r('Hashing brainwallet data. Please wait...') # Use buflen arg of scrypt.hash() to get seed of desired length seed = scrypt_hash_passphrase(self.brainpasswd, '', d.hash_preset, buflen=seed_len/8) - vmsg('Done') + qmsg('Done') self.seed = Seed(seed) msg('Seed ID: %s' % self.seed.sid) qmsg('Check this value against your records') @@ -805,8 +809,7 @@ to exit and re-run the program with the '--old-incog-fmt' option. d.salt + d.enc_seed, d.wrapper_key, int(hexlify(d.iv),16), - self.desc - ) + self.desc) def _filename(self): s = self.seed @@ -817,8 +820,7 @@ to exit and re-run the program with the '--old-incog-fmt' option. d.iv_id, s.length, d.hash_preset, - self.ext - ) + self.ext) def _deformat(self):