def txsign(self, wf, txfile, pf='', bumpf='', save=True, has_label=False, extra_opts=[], extra_desc='', view='n', dfl_wallet=False): opts = extra_opts + ['-d', self.tmpdir, txfile] + ([wf] if wf else []) t = self.spawn('mmgen-txsign', opts, extra_desc) t.license() t.view_tx(view) wcls = MMGenWallet if dfl_wallet else Wallet.ext_to_type( get_extension(wf)) pw = issubclass(wcls, WalletEnc) and wcls != Brainwallet if pw: t.passphrase(wcls.desc, self.wpasswd) if save: self.txsign_end(t, has_label=has_label) else: t.do_comment(False, has_label=has_label) t.expect('Save signed transaction? (Y/n): ', 'n') t.req_exit_val = 1 return t
def _walletconv_export(self, wf, uargs=[], out_fmt='w', pf=None): opts = ['-d',self.tmpdir,'-o',out_fmt] + uargs + \ ([],[wf])[bool(wf)] + ([],['-P',pf])[bool(pf)] t = self.spawn('mmgen-walletconv', opts) t.license() if not pf: icls = Wallet.ext_to_type(get_extension(wf)) t.passphrase(icls.desc, self.wpasswd) ocls = Wallet.fmt_code_to_type(out_fmt) out_pw = issubclass(ocls, WalletEnc) and ocls != Brainwallet if out_pw: t.passphrase_new('new ' + ocls.desc, self.wpasswd) t.usr_rand(self.usr_rand_chars) if ocls.__name__.startswith('Incog'): m = 'Encrypting OS random data with key' t.expect(m) t.expect(m) incog_id = t.expect_getend('New Incog Wallet ID: ') t.expect(m) if ocls == IncogWalletHidden: self.write_to_tmpfile(incog_id_fn, incog_id) t.hincog_create(hincog_bytes) elif ocls == MMGenWallet: t.label() return t.written_to_file(capfirst(ocls.desc), oo=True), t
def txsign3(self, wf1, wf2, txf2): t = self.spawn('mmgen-txsign', ['-d', self.tmpdir, wf1, wf2, txf2]) t.license() t.view_tx('n') for cnum, wf in (('1', wf1), ('3', wf2)): wcls = Wallet.ext_to_type(get_extension(wf)) t.passphrase(wcls.desc, self.cfgs[cnum]['wpasswd']) self.txsign_end(t) return t
def subwalletgen_mnemonic(self, wf): icls = Wallet.ext_to_type(get_extension(wf)) ocls = MMGenMnemonic args = [ self.usr_rand_arg, '-p1', '-d', self.tr.trash_dir, '-o', ocls.fmt_codes[0], wf, '3L' ] t = self.spawn('mmgen-subwalletgen', args) t.license() t.passphrase(icls.desc, self.cfgs['1']['wpasswd']) t.expect('Generating subseed 3L') fn = t.written_to_file(capfirst(ocls.desc)) ext = get_extension(fn) assert ext == ocls.ext, 'incorrect file extension: {}'.format(ext) return t
def txsign5(self, wf, txf, bad_vsize=True, add_args=[]): non_mm_file = joinpath(self.tmpdir, non_mmgen_fn) t = self.spawn( 'mmgen-txsign', add_args + ['-d', self.tmpdir, '-k', non_mm_file, txf, wf]) t.license() t.view_tx('n') wcls = Wallet.ext_to_type(get_extension(wf)) t.passphrase(wcls.desc, self.cfgs['20']['wpasswd']) if bad_vsize: t.expect('Estimated transaction vsize') t.expect('1 transaction could not be signed') exit_val = 2 else: t.do_comment(False) t.expect('Save signed transaction? (Y/n): ', 'y') exit_val = 0 t.read() t.req_exit_val = exit_val return t
def addrgen(self, wf, pf=None, check_ref=False, ftype='addr', id_str=None, extra_args=[], mmtype=None, stdout=False, dfl_wallet=False): passgen = ftype[:4] == 'pass' if not mmtype and not passgen: mmtype = self.segwit_mmtype cmd_pfx = (ftype, 'pass')[passgen] t = self.spawn( 'mmgen-{}gen'.format(cmd_pfx), ['-d', self.tmpdir] + extra_args + ([], ['--type=' + str(mmtype)])[bool(mmtype)] + ([], ['--stdout'])[stdout] + ([], [wf])[bool(wf)] + ([], [id_str])[bool(id_str)] + [getattr(self, '{}_idx_list'.format(cmd_pfx))], extra_desc='({})'.format(mmtype) if mmtype in ('segwit', 'bech32') else '') t.license() wcls = MMGenWallet if dfl_wallet else Wallet.ext_to_type( get_extension(wf)) t.passphrase(wcls.desc, self.wpasswd) t.expect('Passphrase is OK') desc = ('address', 'password')[passgen] chk = t.expect_getend(r'Checksum for {} data .*?: '.format(desc), regex=True) if passgen: t.expect('Encrypt password list? (y/N): ', 'N') t.read() if stdout else t.written_to_file( ('Addresses', 'Password list')[passgen]) if check_ref: chk_ref = ( self.chk_data[self.test_name] if passgen else self.chk_data[self.test_name][self.fork][self.proto.testnet]) cmp_or_die(chk, chk_ref, desc='{}list data checksum'.format(ftype)) return t
def keyaddrgen(self, wf, pf=None, check_ref=False, mmtype=None): if not mmtype: mmtype = self.segwit_mmtype args = ['-d', self.tmpdir, self.usr_rand_arg, wf, self.addr_idx_list] t = self.spawn( 'mmgen-keygen', ([], ['--type=' + str(mmtype)])[bool(mmtype)] + args, extra_desc='({})'.format(mmtype) if mmtype in ('segwit', 'bech32') else '') t.license() wcls = Wallet.ext_to_type(get_extension(wf)) t.passphrase(wcls.desc, self.wpasswd) chk = t.expect_getend(r'Checksum for key-address data .*?: ', regex=True) if check_ref: chk_ref = self.chk_data[self.test_name][self.fork][g.proto.testnet] cmp_or_die(chk, chk_ref, desc='key-address list data checksum') t.expect('Encrypt key list? (y/N): ', 'y') t.usr_rand(self.usr_rand_chars) t.hash_preset('new key list', '1') t.passphrase_new('new key list', self.kapasswd) t.written_to_file('Encrypted secret keys', oo=True) return t
def walletchk(self, wf, pf, wcls=None, add_args=[], sid=None, extra_desc='', dfl_wallet=False): hp = self.hash_preset if hasattr(self, 'hash_preset') else '1' wcls = wcls or Wallet.ext_to_type(get_extension(wf)) t = self.spawn('mmgen-walletchk', ([] if dfl_wallet else ['-i', wcls.fmt_codes[0]]) + add_args + ['-p', hp] + ([wf] if wf else []), extra_desc=extra_desc) if wcls != IncogWalletHidden: t.expect("Getting {} from file '".format(wcls.desc)) pw = issubclass(wcls, WalletEnc) and wcls != Brainwallet if pw: t.passphrase(wcls.desc, self.wpasswd) t.expect(['Passphrase is OK', 'Passphrase.* are correct'], regex=True) chk = t.expect_getend('Valid {} for Seed ID '.format(wcls.desc))[:8] if sid: cmp_or_die(chk, sid) return t