Added --brain-params to walletconv, addrgen

This commit is contained in:
The MMGen Project 2016-07-13 16:22:17 +03:00
commit 8874dabea0
6 changed files with 26 additions and 24 deletions

View file

@ -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'),

View file

@ -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)

View file

@ -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.

View file

@ -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).

View file

@ -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:

View file

@ -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):