replace global variables 'seed_lens' and 'dfl_seed_len'
- g.seed_lens -> Seed.lens - g.dfl_seed_len -> Seed.dfl_lens
This commit is contained in:
parent
b995cbf71e
commit
b46cbd1ddd
12 changed files with 45 additions and 27 deletions
|
|
@ -72,7 +72,6 @@ class GlobalContext(Lockable):
|
|||
err_disp_timeout = 0.7
|
||||
short_disp_timeout = 0.3
|
||||
min_time_precision = 18
|
||||
dfl_seed_len = 256
|
||||
|
||||
# Variables - these might be altered at runtime:
|
||||
|
||||
|
|
@ -262,7 +261,6 @@ class GlobalContext(Lockable):
|
|||
max_urandchars = 80
|
||||
min_urandchars = 10
|
||||
|
||||
seed_lens = 128,192,256
|
||||
scramble_hash_rounds = 10
|
||||
subseeds = 100
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ def help_notes_func(proto,po,k):
|
|||
|
||||
class help_notes:
|
||||
|
||||
def dfl_seed_len():
|
||||
from .seed import Seed
|
||||
return str(Seed.dfl_len)
|
||||
|
||||
def password_formats():
|
||||
from .passwdlist import PasswordList
|
||||
pwi_fs = '{:8} {:1} {:26} {:<7} {:<7} {}'
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ opts_data = {
|
|||
for {coin_id}: {kgs}
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
|
||||
for password hashing (default: '{g.dfl_hash_preset}')
|
||||
-z, --show-hash-presets Show information on available hash presets
|
||||
|
|
@ -105,10 +105,10 @@ FMT CODES:
|
|||
},
|
||||
'code': {
|
||||
'options': lambda proto,help_notes,s: s.format(
|
||||
seed_lens=', '.join(map(str,g.seed_lens)),
|
||||
dmat=help_notes('dfl_mmtype'),
|
||||
kgs=help_notes('keygen_backends'),
|
||||
coin_id=help_notes('coin_id'),
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
pnm=g.proj_name,
|
||||
what=gen_what,
|
||||
g=g,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ opts_data = {
|
|||
generate passwords of half the default length.
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
|
||||
for password hashing (default: '{g.dfl_hash_preset}')
|
||||
-z, --show-hash-presets Show information on available hash presets
|
||||
|
|
@ -114,9 +114,9 @@ FMT CODES:
|
|||
"""
|
||||
},
|
||||
'code': {
|
||||
'options': lambda s: s.format(
|
||||
seed_lens=', '.join(map(str,g.seed_lens)),
|
||||
'options': lambda help_notes,s: s.format(
|
||||
g=g,pnm=g.proj_name,
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
dpf=PasswordList.dfl_pw_fmt,
|
||||
),
|
||||
'notes': lambda help_notes,s: s.format(
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ opts_data = {
|
|||
-i, --in-fmt= f Input is from wallet format 'f' (see FMT CODES below)
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths.
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-k, --keys-from-file=f Provide additional keys for non-{pnm} addresses
|
||||
-K, --keygen-backend=n Use backend 'n' for public key generation. Options
|
||||
for {coin_id}: {kgs}
|
||||
|
|
@ -90,6 +90,7 @@ FMT CODES:
|
|||
fl=help_notes('fee_spec_letters'),
|
||||
kgs=help_notes('keygen_backends'),
|
||||
coin_id=help_notes('coin_id'),
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
cu=proto.coin),
|
||||
'notes': lambda help_notes,s: s.format(
|
||||
help_notes('fee'),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ opts_data = {
|
|||
outputs associated with each address will be included.
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths.
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-k, --keys-from-file=f Provide additional keys for non-{pnm} addresses
|
||||
-K, --keygen-backend=n Use backend 'n' for public key generation. Options
|
||||
for {coin_id}: {kgs}
|
||||
|
|
@ -104,6 +104,7 @@ FMT CODES:
|
|||
ss_max=SubSeedIdxRange.max_idx,
|
||||
fe_all=fmt_list(g.autoset_opts['fee_estimate_mode'].choices,fmt='no_spc'),
|
||||
fe_dfl=g.autoset_opts['fee_estimate_mode'].choices[0],
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
cu=proto.coin),
|
||||
'notes': lambda help_notes,s: s.format(
|
||||
help_notes('txcreate'),
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ opts_data = {
|
|||
-O, --old-incog-fmt Specify old-format incognito input
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths.
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-p, --hash-preset=p Use the scrypt hash parameters defined by preset 'p'
|
||||
for password hashing (default: '{g.dfl_hash_preset}')
|
||||
-z, --show-hash-presets Show information on available hash presets
|
||||
|
|
@ -85,6 +85,7 @@ FMT CODES:
|
|||
pnl=g.proj_name.lower(),
|
||||
kgs=help_notes('keygen_backends'),
|
||||
coin_id=help_notes('coin_id'),
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
ss=g.subseeds,
|
||||
ss_max=SubSeedIdxRange.max_idx,
|
||||
cu=proto.coin),
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ opts_data = {
|
|||
-K, --keep-hash-preset Reuse hash preset of input wallet for output wallet
|
||||
-l, --seed-len= l Specify wallet seed length of 'l' bits. This option
|
||||
is required only for brainwallet and incognito inputs
|
||||
with non-standard (< {g.dfl_seed_len}-bit) seed lengths.
|
||||
with non-standard (< {dsl}-bit) seed lengths.
|
||||
-L, --label= l Specify a label 'l' for output wallet
|
||||
-m, --keep-label Reuse label of input wallet for output wallet
|
||||
-M, --master-share=i Use a master share with index 'i' (min:{ms_min}, max:{ms_max})
|
||||
|
|
@ -126,11 +126,12 @@ FMT CODES:
|
|||
"""
|
||||
},
|
||||
'code': {
|
||||
'options': lambda s: s.format(
|
||||
'options': lambda help_notes,s: s.format(
|
||||
iaction=capfirst(iaction),
|
||||
oaction=capfirst(oaction),
|
||||
ms_min=MasterShareIdx.min_val,
|
||||
ms_max=MasterShareIdx.max_val,
|
||||
dsl=help_notes('dfl_seed_len'),
|
||||
g=g,
|
||||
),
|
||||
'notes': lambda help_notes,s: s.format(
|
||||
|
|
|
|||
|
|
@ -510,19 +510,21 @@ def check_usr_opts(usr_opts): # Raises an exception if any check fails
|
|||
chk_hidden_incog_output_params = chk_hidden_incog_input_params
|
||||
|
||||
def chk_seed_len(key,val,desc):
|
||||
from .seed import Seed
|
||||
opt_is_int(val,desc)
|
||||
opt_is_in_list(int(val),g.seed_lens,desc)
|
||||
opt_is_in_list(int(val),Seed.lens,desc)
|
||||
|
||||
def chk_hash_preset(key,val,desc):
|
||||
opt_is_in_list(val,list(g.hash_presets.keys()),desc)
|
||||
|
||||
def chk_brain_params(key,val,desc):
|
||||
from .seed import Seed
|
||||
a = val.split(',')
|
||||
if len(a) != 2:
|
||||
opt_display(key,val)
|
||||
raise UserOptError('Option requires two comma-separated arguments')
|
||||
opt_is_int(a[0],'seed length '+desc)
|
||||
opt_is_in_list(int(a[0]),g.seed_lens,'seed length '+desc)
|
||||
opt_is_in_list(int(a[0]),Seed.lens,'seed length '+desc)
|
||||
opt_is_in_list(a[1],list(g.hash_presets.keys()),'hash preset '+desc)
|
||||
|
||||
def chk_usr_randchars(key,val,desc):
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@
|
|||
seed.py: Seed-related classes and methods for the MMGen suite
|
||||
"""
|
||||
|
||||
from .common import *
|
||||
from .objmethods import Hilite,InitErrors
|
||||
from string import hexdigits
|
||||
|
||||
from .util import make_chksum_8
|
||||
from .objmethods import Hilite,InitErrors,MMGenObject
|
||||
from .obj import ImmutableAttr,get_obj
|
||||
|
||||
class SeedID(str,Hilite,InitErrors):
|
||||
|
|
@ -48,16 +50,21 @@ def is_seed_id(s):
|
|||
|
||||
class SeedBase(MMGenObject):
|
||||
|
||||
lens = ( 128, 192, 256 )
|
||||
dfl_len = 256
|
||||
|
||||
data = ImmutableAttr(bytes,typeconv=False)
|
||||
sid = ImmutableAttr(SeedID,typeconv=False)
|
||||
|
||||
def __init__(self,seed_bin=None):
|
||||
if not seed_bin:
|
||||
from .opts import opt
|
||||
from .crypto import get_random
|
||||
from hashlib import sha256
|
||||
# Truncate random data for smaller seed lengths
|
||||
seed_bin = sha256(get_random(1033)).digest()[:(opt.seed_len or g.dfl_seed_len)//8]
|
||||
elif len(seed_bin)*8 not in g.seed_lens:
|
||||
die(3,f'{len(seed_bin)}: invalid seed length')
|
||||
seed_bin = sha256(get_random(1033)).digest()[:(opt.seed_len or self.dfl_len)//8]
|
||||
elif len(seed_bin)*8 not in self.lens:
|
||||
die(3,f'{len(seed_bin)*8}: invalid seed bit length')
|
||||
|
||||
self.data = seed_bin
|
||||
self.sid = SeedID(seed=self)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
subseed.py: Subseed classes and methods for the MMGen suite
|
||||
"""
|
||||
|
||||
from .common import *
|
||||
from .color import green
|
||||
from .util import msg_r,msg,qmsg
|
||||
from .exception import SubSeedNonceRangeExceeded
|
||||
from .obj import MMGenRange,IndexedDict
|
||||
from .seed import *
|
||||
|
|
|
|||
|
|
@ -446,7 +446,7 @@ class Mnemonic(WalletUnenc):
|
|||
hexseed = bc.tohex( mn, 'seed' )
|
||||
rev = bc.fromhex( hexseed, 'seed' )
|
||||
|
||||
if len(hexseed) * 4 not in g.seed_lens:
|
||||
if len(hexseed) * 4 not in Seed.lens:
|
||||
msg('Invalid mnemonic (produces too large a number)')
|
||||
return False
|
||||
|
||||
|
|
@ -646,7 +646,7 @@ class PlainHexSeedFile(WalletUnenc):
|
|||
msg(f'{d!r}: not a lowercase hexadecimal string, in {desc}')
|
||||
return False
|
||||
|
||||
if not len(d)*4 in g.seed_lens:
|
||||
if not len(d)*4 in Seed.lens:
|
||||
msg(f'Invalid data length ({len(d)}) in {desc}')
|
||||
return False
|
||||
|
||||
|
|
@ -682,7 +682,7 @@ class MMGenHexSeedFile(WalletUnenc):
|
|||
msg(f'{self.fmt_data.strip()!r}: invalid {desc}')
|
||||
return False
|
||||
|
||||
if not len(hstr)*4 in g.seed_lens:
|
||||
if not len(hstr)*4 in Seed.lens:
|
||||
msg(f'Invalid data length ({len(hstr)}) in {desc}')
|
||||
return False
|
||||
|
||||
|
|
@ -900,10 +900,10 @@ class Brainwallet(WalletEnc):
|
|||
bw_seed_len,d.hash_preset = self.get_bw_params()
|
||||
else:
|
||||
if not opt.seed_len:
|
||||
qmsg(f'Using default seed length of {yellow(str(g.dfl_seed_len))} bits\n'
|
||||
qmsg(f'Using default seed length of {yellow(str(Seed.dfl_len))} bits\n'
|
||||
+ 'If this is not what you want, use the --seed-len option' )
|
||||
self._get_hash_preset()
|
||||
bw_seed_len = opt.seed_len or g.dfl_seed_len
|
||||
bw_seed_len = opt.seed_len or Seed.dfl_len
|
||||
qmsg_r('Hashing brainwallet data. Please wait...')
|
||||
# Use buflen arg of scrypt.hash() to get seed of desired length
|
||||
seed = scrypt_hash_passphrase(
|
||||
|
|
@ -954,7 +954,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
def _incog_data_size_chk(self):
|
||||
# valid sizes: 56, 64, 72
|
||||
dlen = len(self.fmt_data)
|
||||
seed_len = opt.seed_len or g.dfl_seed_len
|
||||
seed_len = opt.seed_len or Seed.dfl_len
|
||||
valid_dlen = self._get_incog_data_len(seed_len)
|
||||
if dlen == valid_dlen:
|
||||
return True
|
||||
|
|
@ -963,7 +963,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
msg('WARNING: old-style incognito format requested. Are you sure this is correct?')
|
||||
msg(f'Invalid incognito data size ({dlen} bytes) for this seed length ({seed_len} bits)')
|
||||
msg(f'Valid data size for this seed length: {valid_dlen} bytes')
|
||||
for sl in g.seed_lens:
|
||||
for sl in Seed.lens:
|
||||
if dlen == self._get_incog_data_len(sl):
|
||||
die(1,f'Valid seed length for this data size: {sl} bits')
|
||||
msg(f'This data size ({dlen} bytes) is invalid for all available seed lengths')
|
||||
|
|
@ -1144,7 +1144,7 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
qmsg(f'Getting hidden incog data from file {self.infile.name!r}')
|
||||
|
||||
# Already sanity-checked:
|
||||
d.target_data_len = self._get_incog_data_len(opt.seed_len or g.dfl_seed_len)
|
||||
d.target_data_len = self._get_incog_data_len(opt.seed_len or Seed.dfl_len)
|
||||
self._check_valid_offset(self.infile,'read')
|
||||
|
||||
flgs = os.O_RDONLY|os.O_BINARY if g.platform == 'win' else os.O_RDONLY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue