Browse Source

autosign setup: support BIP39 entry

The MMGen Project 4 years ago
parent
commit
d5b0a2ac34
3 changed files with 31 additions and 8 deletions
  1. 16 2
      mmgen/main_autosign.py
  2. 1 0
      test/test_py_d/common.py
  3. 14 6
      test/test_py_d/ts_autosign.py

+ 16 - 2
mmgen/main_autosign.py

@@ -29,6 +29,11 @@ tx_dir       = '/mnt/tx/tx'
 part_label   = 'MMGEN_TX'
 wallet_dir   = '/dev/shm/autosign'
 key_fn       = 'autosign.key'
+mn_fmts      = {
+	'mmgen': 'words',
+	'bip39': 'bip39',
+}
+mn_fmt_dfl   = 'mmgen'
 
 from .common import *
 opts.UserOpts._set_ok += ('outdir','passwd_file')
@@ -46,6 +51,8 @@ opts_data = {
 -I, --no-insert-check Don’t check for device insertion
 -l, --led             Use status LED to signal standby, busy and error
 -m, --mountpoint=M    Specify an alternate mountpoint 'M' (default: '{mp}')
+-M, --mnemonic-fmt=F  During setup, prompt for mnemonic seed phrase of format
+                      'F' (choices: {mc}; default: '{md}')
 -n, --no-summary      Don’t print a transaction summary
 -s, --stealth-led     Stealth LED mode - signal busy and error only, and only
                       after successful authorization.
@@ -55,6 +62,8 @@ opts_data = {
 -q, --quiet           Produce quieter output
 -v, --verbose         Produce more verbose output
 """.format(
+		md = mn_fmt_dfl,
+		mc = fmt_list(mn_fmts,fmt='no_spc'),
 		mp = mountpoint
 	),
 	'notes': """
@@ -116,7 +125,6 @@ cmd_args = opts.init(
 	add_opts = ['mmgen_keys_from_file','hidden_incog_input_params'],
 	init_opts = {
 		'quiet': True,
-		'in_fmt': 'words',
 		'out_fmt': 'wallet',
 		'usr_randchars': 0,
 		'hash_preset': '1',
@@ -125,6 +133,12 @@ cmd_args = opts.init(
 
 exit_if_mswin('autosigning')
 
+if opt.mnemonic_fmt:
+	if opt.mnemonic_fmt not in mn_fmts:
+		die(1,'{!r}: invalid mnemonic format (must be one of: {})'.format(
+			opt.mnemonic_fmt,
+			fmt_list(mn_fmts,fmt='no_spc') ))
+
 import mmgen.tx
 from .wallet import Wallet
 from .txsign import txsign
@@ -347,7 +361,7 @@ def create_wallet_dir():
 def setup():
 	remove_wallet_dir()
 	gen_key(no_unmount=True)
-	ss_in = Wallet()
+	ss_in = Wallet(in_fmt=mn_fmts[opt.mnemonic_fmt or mn_fmt_dfl])
 	ss_out = Wallet(ss=ss_in)
 	ss_out.write_to_file(desc='autosign wallet',outdir=wallet_dir)
 

+ 1 - 0
test/test_py_d/common.py

@@ -46,6 +46,7 @@ non_mmgen_fn = 'coinkey'
 
 ref_dir = os.path.join('test','ref')
 dfl_words_file = os.path.join(ref_dir,'98831F3A.mmwords')
+dfl_bip39_file = os.path.join(ref_dir,'98831F3A.bip39')
 
 from mmgen.obj import MMGenTxLabel,TwComment
 

+ 14 - 6
test/test_py_d/ts_autosign.py

@@ -74,21 +74,24 @@ class TestSuiteAutosign(TestSuiteBase):
 				t.ok()
 				self.key_generated = True
 
-		def make_wallet(opts):
+		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 = '(setup)' )
+				extra_desc = f'(setup - {mn_desc} mnemonic)' )
 
 			t.expect('words: ','3')
 			t.expect('OK? (Y/n): ','\n')
-			mn_file = dfl_words_file
+			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('mmgen',entry_mode)
+			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')
@@ -186,7 +189,7 @@ class TestSuiteAutosign(TestSuiteBase):
 				t.expect("Stopping LED")
 			return t
 
-		def do_autosign(opts,mountpoint):
+		def do_autosign(opts,mountpoint,mn_type=None,short=False):
 
 			def autosign_expect(t,txcount):
 				t.expect('{} transactions signed'.format(txcount))
@@ -199,12 +202,15 @@ class TestSuiteAutosign(TestSuiteBase):
 
 			if not opt.skip_deps:
 				gen_key(opts)
-				make_wallet(opts)
+				make_wallet(opts,mn_type)
 
 			copy_files(mountpoint,include_bad_tx=True)
 			t = self.spawn('mmgen-autosign',opts+['--quiet','wait'],extra_desc='(sign)')
 			autosign_expect(t,txcount)
 
+			if short:
+				return t
+
 			copy_files(mountpoint,remove_signed_only=True)
 			t = self.spawn('mmgen-autosign',opts+['--full-summary','wait'],extra_desc='(sign - full summary)')
 			autosign_expect(t,txcount)
@@ -271,6 +277,8 @@ class TestSuiteAutosign(TestSuiteBase):
 			opts = ['--no-insert-check','--mountpoint='+mountpoint,'--coins='+','.join(coins)]
 			try: os.mkdir(joinpath(mountpoint,'tx'))
 			except: pass
+			foo = do_autosign(opts,mountpoint,mn_type='mmgen',short=True)
+			foo = do_autosign(opts,mountpoint,mn_type='bip39',short=True)
 			ret = do_autosign(opts,mountpoint)
 
 		stop_test_daemons(*network_ids)