예제 #1
0
 def _mn2hex(self,
             fmt,
             entry_mode='full',
             mn=None,
             pad_entry=False,
             enter_for_dfl=False):
     mn = mn or sample_mn[fmt]['mn'].split()
     t = self.spawn(
         'mmgen-tool',
         ['mn2hex_interactive', 'fmt=' + fmt, 'mn_len=12', 'print_mn=1'])
     from mmgen.mn_entry import mn_entry
     mne = mn_entry(fmt, entry_mode)
     t.expect('Type a number.*: ',
              ('\n' if enter_for_dfl else
               str(mne.entry_modes.index(entry_mode) + 1)),
              regex=True)
     t.expect('Using (.+) entry mode', regex=True)
     mode = strip_ansi_escapes(t.p.match.group(1)).lower()
     assert mode == mne.em.name.lower(), '{} != {}'.format(
         mode, mne.em.name.lower())
     stealth_mnemonic_entry(t,
                            mne,
                            mn,
                            entry_mode=entry_mode,
                            pad_entry=pad_entry)
     t.expect(sample_mn[fmt]['hex'])
     t.read()
     return t
예제 #2
0
        def make_wallet(opts, mn_type=None):
            mn_desc = mn_type or 'default'
            mn_type = mn_type or 'mmgen'

            t = self.spawn(
                'mmgen-autosign',
                opts +
                ([] if mn_desc == 'default' else [f'--mnemonic-fmt={mn_type}'])
                + ['setup'],
                extra_desc=f'(setup - {mn_desc} mnemonic)')

            t.expect('words: ', '3')
            t.expect('OK? (Y/n): ', '\n')
            mn_file = {
                'mmgen': dfl_words_file,
                'bip39': dfl_bip39_file
            }[mn_type]
            mn = read_from_file(mn_file).strip().split()
            from mmgen.mn_entry import mn_entry
            entry_mode = 'full'
            mne = mn_entry(mn_type, entry_mode)
            t.expect('Type a number.*: ',
                     str(mne.entry_modes.index(entry_mode) + 1),
                     regex=True)
            stealth_mnemonic_entry(t, mne, mn, entry_mode)
            wf = t.written_to_file('Autosign wallet')
            t.ok()
예제 #3
0
	def run_test(self,name,ut):

		msg_r('Testing MnemonicEntry methods...')

		from mmgen.mn_entry import mn_entry

		msg_r('\nTesting computed wordlist constants...')
		usl = {}
		for wl_id in self.vectors:
			for j,k in (('uniq_ss_len','usl'),('shortest_word','sw'),('longest_word','lw')):
				a = getattr(mn_entry(wl_id),j)
				b = self.vectors[wl_id][k]
				assert a == b, '{}:{} {} != {}'.format(wl_id,j,a,b)
		msg('OK')

		msg_r('Testing idx()...')
		qmsg('')
		junk = 'a g z aa gg zz aaa ggg zzz aaaa gggg zzzz aaaaaaaaaaaaaa gggggggggggggg zzzzzzzzzzzzzz'
		for wl_id in self.vectors:
			m = mn_entry(wl_id)
			qmsg('Wordlist: '+wl_id)
			for entry_mode in ('full','short'):
				for a,word in enumerate(m.wl):
					b = m.idx(word,entry_mode)
					assert a == b, '{} != {} ({!r} - entry mode: {!r})'.format(a,b,word,entry_mode)
				a = None
				for word in junk.split():
					b = m.idx(word,entry_mode)
					assert a == b, '{} != {} ({!r} - entry mode: {!r})'.format(a,b,word,entry_mode)
			if 'idx_minimal' in self.vectors[wl_id]:
				for vec in self.vectors[wl_id]['idx_minimal']:
					chk = vec[1]
					b = m.idx(vec[0],'minimal')
					if chk is False:
						assert b is None, (b,None)
					elif chk is None:
						assert type(b) == tuple, (type(b),tuple)
					elif type(chk) is int:
						assert b == chk, (b,chk)
		msg('OK')

		return True
예제 #4
0
 def _user_seed_entry(self,
                      fmt,
                      usr_rand=False,
                      out_fmt=None,
                      entry_mode='full',
                      mn=None):
     wcls = Wallet.fmt_code_to_type(fmt)
     wf = os.path.join(ref_dir, 'FE3C6545.{}'.format(wcls.ext))
     if wcls.wclass == 'mnemonic':
         mn = mn or read_from_file(wf).strip().split()
     elif wcls.wclass == 'dieroll':
         mn = mn or list(
             read_from_file(wf).strip().translate(
                 dict((ord(ws), None) for ws in '\t\n ')))
         for idx, val in ((5, 'x'), (18, '0'), (30, '7'), (44, '9')):
             mn.insert(idx, val)
     t = self.spawn('mmgen-walletconv',
                    ['-r10', '-S', '-i', fmt, '-o', out_fmt or fmt])
     t.expect('{} type:.*{}'.format(capfirst(wcls.wclass), wcls.mn_type),
              regex=True)
     t.expect(wcls.choose_seedlen_prompt, '1')
     t.expect('(Y/n): ', 'y')
     if wcls.wclass == 'mnemonic':
         t.expect('Type a number.*: ', '6', regex=True)
         t.expect('invalid')
         from mmgen.mn_entry import mn_entry
         mne = mn_entry(fmt, entry_mode)
         t.expect('Type a number.*: ',
                  str(mne.entry_modes.index(entry_mode) + 1),
                  regex=True)
         t.expect('Using (.+) entry mode', regex=True)
         mode = strip_ansi_escapes(t.p.match.group(1)).lower()
         assert mode == mne.em.name.lower(), '{} != {}'.format(
             mode, mne.em.name.lower())
         stealth_mnemonic_entry(t, mne, mn, entry_mode=entry_mode)
     elif wcls.wclass == 'dieroll':
         user_dieroll_entry(t, mn)
         if usr_rand:
             t.expect(wcls.user_entropy_prompt, 'y')
             t.usr_rand(10)
         else:
             t.expect(wcls.user_entropy_prompt, 'n')
     if not usr_rand:
         sid_chk = 'FE3C6545'
         sid = t.expect_getend('Valid {} for Seed ID '.format(wcls.desc))
         sid = strip_ansi_escapes(sid.split(',')[0])
         assert sid == sid_chk, 'Seed ID mismatch! {} != {}'.format(
             sid, sid_chk)
     t.expect('to confirm: ', 'YES\n')
     t.read()
     return t
예제 #5
0
        def make_wallet(opts):
            t = self.spawn('mmgen-autosign',
                           opts + ['gen_key'],
                           extra_desc='(gen_key)')
            t.expect_getend('Wrote key file ')
            t.ok()

            t = self.spawn('mmgen-autosign',
                           opts + ['setup'],
                           extra_desc='(setup)')
            t.expect('words: ', '3')
            t.expect('OK? (Y/n): ', '\n')
            mn_file = dfl_words_file
            mn = read_from_file(mn_file).strip().split()
            from mmgen.mn_entry import mn_entry
            entry_mode = 'full'
            mne = mn_entry('mmgen', entry_mode)
            t.expect('Entry mode: ',
                     str(mne.entry_modes.index(entry_mode) + 1))
            stealth_mnemonic_entry(t, mne, mn, entry_mode)
            wf = t.written_to_file('Autosign wallet')
            t.ok()
예제 #6
0
 def mnemonic_entry_mmgen_minimal(self):
     from mmgen.mn_entry import mn_entry
     # erase_chars: '\b\x7f'
     m = mn_entry('mmgen', 'minimal')
     np = 2
     mn = (
         'z',
         'aa',
         '1d2ud',
         'fo{}ot{}#'.format('1' * np, '2' *
                            (m.em.pad_max - np)),  # substring of 'football'
         'des1p)%erate\n',  # substring of 'desperately'
         '#t!(ie',
         '!)sto8o',
         'the123m8!%s',
         '349t(5)rip',
         'di\b\bdesce',
         'cea',
         'bu\x7f\x7fsuic',
         'app\bpl',
         'wd',
         'busy')
     return self._user_seed_entry('words', entry_mode='minimal', mn=mn)