AddrList, passgen: minor fixes; add altcoin ref file tests

This commit is contained in:
The MMGen Project 2019-10-16 10:42:46 +00:00
commit 8a68f00ab7
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 40 additions and 26 deletions

View file

@ -610,7 +610,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
for e in self.data:
c = ' '+e.label if enable_comments and e.label else ''
if type(self) == KeyList:
out.append(fs.format(e.idx,'{} {}'.format(self.al_id.mmtype.wif_label,e.sec.wif),c))
out.append(fs.format(e.idx,'{}: {}'.format(self.al_id.mmtype.wif_label,e.sec.wif),c))
elif type(self) == PasswordList:
out.append(fs.format(e.idx,e.passwd,c))
else: # First line with idx
@ -618,7 +618,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
if self.has_keys:
if opt.b16:
out.append(fs.format('', 'orig_hex: '+e.sec.orig_hex,c))
out.append(fs.format('','{} {}'.format(self.al_id.mmtype.wif_label,e.sec.wif),c))
out.append(fs.format('','{}: {}'.format(self.al_id.mmtype.wif_label,e.sec.wif),c))
for k in ('viewkey','wallet_passwd'):
v = getattr(e,k)
if v: out.append(fs.format('','{}: {}'.format(k,v),c))
@ -638,6 +638,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
ret = AddrListList()
le = self.entry_type
iifs = "{!r}: invalid identifier [expected '{}:']"
while lines:
idx,addr,lbl = self.get_line(lines)
@ -649,12 +650,12 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
if self.has_keys: # order: wif,(orig_hex),viewkey,wallet_passwd
d = self.get_line(lines)
assert d[0] == self.al_id.mmtype.wif_label,"Invalid line in file: '{}'".format(' '.join(d))
assert d[0] == self.al_id.mmtype.wif_label+':',iifs.format(d[0],self.al_id.mmtype.wif_label)
a.sec = PrivKey(wif=d[1])
for k,dtype in (('viewkey',ViewKey),('wallet_passwd',WalletPassword)):
if k in self.al_id.mmtype.extra_attrs:
d = self.get_line(lines)
assert d[0] == k+':',"Invalid line in file: '{}'".format(' '.join(d))
assert d[0] == k+':',iifs.format(d[0],k)
setattr(a,k,dtype(d[1]))
ret.append(a)
@ -741,7 +742,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
data = self.parse_file_body(lines[1:-1])
assert isinstance(data,list),'Invalid file body data'
except Exception as e:
lcs = ', list item {}'.format(self.line_ctr) if self.line_ctr else ''
lcs = ', content line {}'.format(self.line_ctr) if self.line_ctr else ''
m = 'Invalid data in {} list file {!r}{} ({})'.format(self.data_desc,self.infile,lcs,e.args[0])
if exit_on_error: die(3,m)
msg(msg)
@ -810,8 +811,8 @@ Record this checksum: it will be used to verify the password file in the future
dfl_pw_fmt = 'b58'
pwinfo = namedtuple('passwd_info',['min_len','max_len','dfl_len','valid_lens','desc','chk_func'])
pw_info = {
'b32': pwinfo(10, 42 ,24, None, 'base32 password', is_b32_str),
'b58': pwinfo(8, 36 ,20, None, 'base58 password', is_b58_str),
'b32': pwinfo(10, 42 ,24, None, 'base32 password', is_b32_str), # 32**24 < 2**128
'b58': pwinfo(8, 36 ,20, None, 'base58 password', is_b58_str), # 58**20 < 2**128
'hex': pwinfo(32, 64 ,64, [32,48,64], 'hexadecimal password', is_hex_str),
}
chksum_rec_f = lambda foo,e: (str(e.idx), e.passwd)

View file

@ -88,13 +88,14 @@ EXAMPLES:
{g.prog_name} alice@nowhere.com 1-10
Generate ten base58 passwords of length 16 for Alice's email account:
{g.prog_name} -L16 alice@nowhere.com 1-10
{g.prog_name} --passwd-len=16 alice@nowhere.com 1-10
Generate ten base32 passwords of length {i32.dfl_len} for Alice's email account:
{g.prog_name} -b alice@nowhere.com 1-10
{g.prog_name} --passwd-fmt=b32 alice@nowhere.com 1-10
The three sets of passwords are completely unrelated to each other, so
Alice doesn't need to worry about password reuse.
All passwords are cryptographically unlinkable with each other, including
passwords with the same format but different length, so Alice needn't worry
about inadvertent reuse of private data.
NOTES FOR ALL GENERATOR COMMANDS

View file

@ -878,7 +878,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
'compressed':False,
'gen_method':'ethereum',
'addr_fmt':'ethereum',
'wif_label':'privkey:',
'wif_label':'privkey',
'extra_attrs': ('wallet_passwd',),
'desc':'Ethereum address' },
'Z': { 'name':'zcash_z',
@ -893,7 +893,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
'compressed':False,
'gen_method':'monero',
'addr_fmt':'monero',
'wif_label':'spendkey:',
'wif_label':'spendkey',
'extra_attrs': ('viewkey','wallet_passwd'),
'desc':'Monero address'}
}
@ -911,7 +911,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
assert me in g.proto.mmtypes + ('P',), (
"'{}': invalid address type for {}".format(me.name,g.proto.__name__))
me.extra_attrs = v['extra_attrs'] if 'extra_attrs' in v else ()
me.wif_label = v['wif_label'] if 'wif_label' in v else 'wif:'
me.wif_label = v['wif_label'] if 'wif_label' in v else 'wif'
return me
raise ValueError('not found')
except Exception as e:

View file

@ -164,38 +164,50 @@ class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
def ref_addrfile_chk_eth(self):
return self.ref_addrfile_chk(ftype='addr',coin='ETH',subdir='ethereum',pfx='-ETH')
return self.ref_addrfile_chk(ftype='addr',coin='ETH',subdir='ethereum',pfx='-ETH',
pat='ETH Mainnet.*Ethereum')
def ref_addrfile_chk_etc(self):
return self.ref_addrfile_chk(ftype='addr',coin='ETC',subdir='ethereum_classic',pfx='-ETC')
return self.ref_addrfile_chk(ftype='addr',coin='ETC',subdir='ethereum_classic',pfx='-ETC',
pat='ETH Mainnet.*Ethereum')
def ref_addrfile_chk_dash(self):
return self.ref_addrfile_chk(ftype='addr',coin='DASH',subdir='dash',pfx='-DASH-C')
return self.ref_addrfile_chk(ftype='addr',coin='DASH',subdir='dash',pfx='-DASH-C',
pat='DASH Mainnet.*Compressed')
def ref_addrfile_chk_zec(self):
return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-C')
return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-C',
pat='ZEC Mainnet.*Compressed')
def ref_addrfile_chk_zec_z(self):
return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z')
return self.ref_addrfile_chk(ftype='addr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z',
pat='ZEC Mainnet.*Zcash_z')
def ref_addrfile_chk_xmr(self):
return self.ref_addrfile_chk(ftype='addr',coin='XMR',subdir='monero',pfx='-XMR-M')
return self.ref_addrfile_chk(ftype='addr',coin='XMR',subdir='monero',pfx='-XMR-M',
pat='XMR Mainnet.*Monero')
def ref_keyaddrfile_chk_eth(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='ETH',subdir='ethereum',pfx='-ETH')
return self.ref_addrfile_chk(ftype='keyaddr',coin='ETH',subdir='ethereum',pfx='-ETH',
pat='ETH Mainnet.*Ethereum')
def ref_keyaddrfile_chk_etc(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='ETC',subdir='ethereum_classic',pfx='-ETC')
return self.ref_addrfile_chk(ftype='keyaddr',coin='ETC',subdir='ethereum_classic',pfx='-ETC',
pat='ETH Mainnet.*Ethereum')
def ref_keyaddrfile_chk_dash(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='DASH',subdir='dash',pfx='-DASH-C')
return self.ref_addrfile_chk(ftype='keyaddr',coin='DASH',subdir='dash',pfx='-DASH-C',
pat='DASH Mainnet.*Compressed')
def ref_keyaddrfile_chk_zec(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-C')
return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-C',
pat='ZEC Mainnet.*Compressed')
def ref_keyaddrfile_chk_zec_z(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z')
return self.ref_addrfile_chk(ftype='keyaddr',coin='ZEC',subdir='zcash',pfx='-ZEC-Z',mmtype='z',
pat='ZEC Mainnet.*Zcash_z')
def ref_keyaddrfile_chk_xmr(self):
return self.ref_addrfile_chk(ftype='keyaddr',coin='XMR',subdir='monero',pfx='-XMR-M')
return self.ref_addrfile_chk(ftype='keyaddr',coin='XMR',subdir='monero',pfx='-XMR-M',
pat='XMR Mainnet.*Monero')