def get_keylist(opt): if opt.keys_from_file: l = get_lines_from_file(opt.keys_from_file,'key-address data',trim_comments=True) kal = KeyAddrList(keylist=[m.split()[0] for m in l]) # accept coin daemon wallet dumps kal.generate_addrs_from_keys() return kal return None
def txsign(tx,seed_files,kl,kal,tx_num_str=''): keys = MMGenList() # list of AddrListEntry objects non_mm_addrs = tx.get_non_mmaddrs('inputs') if non_mm_addrs: if not kl: die(2,'Transaction has non-{} inputs, but no flat key list is present'.format(g.proj_name)) tmp = KeyAddrList(addrlist=non_mm_addrs,do_chksum=False) tmp.add_wifs(kl) m = tmp.list_missing('sec') if m: die(2,wmsg['missing_keys_error'].format(suf(m,'es'),'\n '.join(m))) keys += tmp.data if opt.mmgen_keys_from_file: keys += add_keys(tx,'inputs',keyaddr_list=kal) add_keys(tx,'outputs',keyaddr_list=kal) keys += add_keys(tx,'inputs',seed_files,saved_seeds) add_keys(tx,'outputs',seed_files,saved_seeds) # this attr must not be written to file tx.delete_attrs('inputs','have_wif') tx.delete_attrs('outputs','have_wif') extra_sids = set(saved_seeds) - tx.get_input_sids() - tx.get_output_sids() if extra_sids: msg('Unused Seed ID{}: {}'.format(suf(extra_sids,'s'),' '.join(extra_sids))) if tx.sign(tx_num_str,keys): return tx else: die(3,red('Transaction {}could not be signed.'.format(tx_num_str)))
def txsign(tx,seed_files,kl,kal,tx_num_str=''): keys = MMGenList() # list of AddrListEntry objects non_mm_addrs = tx.get_non_mmaddrs('inputs') if non_mm_addrs: if not kl: die(2,'Transaction has non-{} inputs, but no flat key list is present'.format(g.proj_name)) tmp = KeyAddrList(addrlist=non_mm_addrs) tmp.add_wifs(kl) m = tmp.list_missing('sec') if m: die(2,wmsg['missing_keys_error'].format(suf(m,'es'),'\n '.join(m))) keys += tmp.data if opt.mmgen_keys_from_file: keys += add_keys(tx,'inputs',keyaddr_list=kal) add_keys(tx,'outputs',keyaddr_list=kal) keys += add_keys(tx,'inputs',seed_files,saved_seeds) add_keys(tx,'outputs',seed_files,saved_seeds) # this attr must not be written to file tx.delete_attrs('inputs','have_wif') tx.delete_attrs('outputs','have_wif') extra_sids = set(saved_seeds) - tx.get_input_sids() - tx.get_output_sids() if extra_sids: msg('Unused Seed ID{}: {}'.format(suf(extra_sids,'s'),' '.join(extra_sids))) return tx.sign(tx_num_str,keys) # returns True or False
async def open_wallet_user(self,user,wnum): data = self.users[user] silence() kal = KeyAddrList(self.proto,data.kafile,skip_key_address_validity_check=True) end_silence() return await data.wd_rpc.call( 'open_wallet', filename = os.path.basename(data.walletfile_fs.format(wnum)), password = kal.entry(wnum).wallet_passwd )
def process_wallets(): m = { 'create': ('Creat','Generat',create,False), 'sync': ('Sync', 'Sync', sync, True) } opt.accept_defaults = opt.accept_defaults or m[op][3] from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) data = [d for d in al.data if addrs == None or d.idx in AddrIdxList(addrs)] dl = len(data) assert dl,"No addresses in addrfile within range '{}'".format(addrs) gmsg('\n{}ing {} wallet{}'.format(m[op][0],dl,suf(dl))) for n,d in enumerate(data): # [d.sec,d.wallet_passwd,d.viewkey,d.addr] fn = os.path.join( opt.outdir or u'',u'{}-{}-MoneroWallet{}'.format( al.al_id.sid, d.idx, u'-α' if g.debug_utf8 else '')) gmsg(u'\n{}ing wallet {}/{} ({})'.format(m[op][1],n+1,dl,fn)) m[op][2](n,d,fn) gmsg('\n{} wallet{} {}ed'.format(dl,suf(dl),m[op][0].lower())) if op == 'sync': col1_w = max(map(len,bals)) + 1 fs = u'{:%s} {:18} {:18}' % col1_w msg('\n'+fs.format('Wallet',' Balance',' Unlocked Balance')) tbals = [Decimal('0'),Decimal('0')] for bal in bals: for i in (0,1): tbals[i] += bals[bal][i] msg(fs.format(bal+':',*bals[bal])) msg(fs.format('-'*col1_w,'-'*18,'-'*18)) msg(fs.format('TOTAL:',*tbals))
def process_wallets(): m = { 'create': ('Creat', 'Generat', create, False), 'sync': ('Sync', 'Sync', sync, True) } opt.accept_defaults = opt.accept_defaults or m[op][3] from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) data = [ d for d in al.data if addrs == None or d.idx in AddrIdxList(addrs) ] dl = len(data) assert dl, "No addresses in addrfile within range '{}'".format(addrs) gmsg('\n{}ing {} wallet{}'.format(m[op][0], dl, suf(dl))) for n, d in enumerate( data): # [d.sec,d.wallet_passwd,d.viewkey,d.addr] fn = os.path.join( opt.outdir or u'', u'{}-{}-MoneroWallet{}'.format(al.al_id.sid, d.idx, u'-α' if g.debug_utf8 else '')) gmsg(u'\n{}ing wallet {}/{} ({})'.format(m[op][1], n + 1, dl, fn)) m[op][2](n, d, fn) gmsg('\n{} wallet{} {}ed'.format(dl, suf(dl), m[op][0].lower())) if op == 'sync': msg('Balance: {:.12f}, Unlocked balance: {:.12f}'.format(*bals))
def generate_kals_for_mmgen_addrs(need_keys,infiles,saved_seeds): mmids = [e.mmid for e in need_keys] sids = set(i.sid for i in mmids) vmsg('Need seed{}: {}'.format(suf(sids,'s'),' '.join(sids))) d = MMGenList() from mmgen.addr import KeyAddrList for sid in sids: # Returns only if seed is found seed = get_seed_for_seed_id(sid,infiles,saved_seeds) for t in MMGenAddrType.mmtypes: idx_list = [i.idx for i in mmids if i.sid == sid and i.mmtype == t] if idx_list: addr_idxs = AddrIdxList(idx_list=idx_list) d.append(KeyAddrList(seed=seed,addr_idxs=addr_idxs,do_chksum=False,mmtype=MMGenAddrType(t))) return d
def Keyaddrfile_chksum(infile): from mmgen.addr import KeyAddrList KeyAddrList(infile, chksum_only=True)
def get_keyaddrlist(opt): if opt.mmgen_keys_from_file: return KeyAddrList(opt.mmgen_keys_from_file) return None
def Keyaddrfile_chksum(infile,mmtype=''): from mmgen.addr import KeyAddrList mmtype = None if not mmtype else MMGenAddrType(mmtype) KeyAddrList(infile,chksum_only=True,mmtype=mmtype)
def keyaddrfile_chksum(self,mmgen_keyaddrfile:str): "compute checksum for MMGen key-address file" opt.yes = True opt.quiet = True from mmgen.addr import KeyAddrList return KeyAddrList(mmgen_keyaddrfile).chksum
def Keyaddrlist2monerowallet(infile,blockheight=None): import pexpect if blockheight != None and int(blockheight) < 0: blockheight = 0 def run_cmd(cmd): import subprocess as sp p = sp.Popen(cmd,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE) return p def test_rpc(): p = run_cmd(['monero-wallet-cli','--version']) if p.stdout.read()[:6] != 'Monero': die(1,"Unable to run 'monero-wallet-cli'!") p = run_cmd(['monerod','status']) ret = p.stdout.read() if ret[:7] != 'Height:': die(1,'Unable to connect to monerod!') return int(ret[8:].split('/')[0]) cur_height = test_rpc() from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) sid = al.al_id.sid os.environ['LANG'] = 'C' def my_expect(p,m,s,regex=False): if m: msg_r(' {}...'.format(m)) ret = (p.expect_exact,p.expect)[regex](s) if not (ret == 0 or (type(s) == list and ret in (0,1))): die(2,"Expect failed: '{}' (return value: {})".format(s,ret)) if m: msg('OK') return ret def my_sendline(p,m,s,usr_ret): if m: msg_r(' {}...'.format(m)) ret = p.sendline(s) if ret != usr_ret: die(2,"Unable to send line '{}' (return value {})".format(s,ret)) if m: msg('OK') vmsg("sendline: '{}' => {}".format(s,ret)) def create(): gmsg('\nCreating {} wallet{}'.format(dl,suf(dl))) for n,d in enumerate(al.data): fn = '{}{}-{}-MoneroWallet'.format( (opt.outdir+'/' if opt.outdir else ''), sid,d.idx) gmsg("\nGenerating wallet {}/{} ({})".format(n+1,dl,fn)) try: os.stat(fn) except: pass else: die(1,"Wallet '{}' already exists!".format(fn)) # pmsg([d.sec,d.wallet_passwd,d.viewkey,d.addr,fn]) p = pexpect.spawn('monero-wallet-cli --generate-from-spend-key {}'.format(fn)) my_expect(p,'Awaiting initial prompt','Secret spend key: ') my_sendline(p,'',d.sec,65) my_expect(p,'','Enter new wallet password: '******'Sending password',d.wallet_passwd,33) my_expect(p,'','Confirm password: '******'Sending password again',d.wallet_passwd,33) my_expect(p,'','of your choice: ') my_sendline(p,'','1',2) my_expect(p,'monerod generating wallet','Generated new wallet: ') my_expect(p,'','\n') if d.addr not in p.before: die(3,'Addresses do not match!\n MMGen: {}\n Monero: {}'.format(d.addr,p.before)) my_expect(p,'','View key: ') my_expect(p,'','\n') if d.viewkey not in p.before: die(3,'View keys do not match!\n MMGen: {}\n Monero: {}'.format(d.viewkey,p.before)) my_expect(p,'','(YYYY-MM-DD): ') h = str(blockheight or cur_height-1) my_sendline(p,'',h,len(h)+1) ret = my_expect(p,'',['Starting refresh','Still apply restore height? (Y/Yes/N/No): ']) if ret == 1: my_sendline(p,'','Y',2) m = ' Warning: {}: blockheight argument is higher than current blockheight' ymsg(m.format(blockheight)) elif blockheight != None: p.logfile = sys.stderr my_expect(p,'Syncing wallet','\[wallet.*$',regex=True) p.logfile = None my_sendline(p,'Exiting','exit',5) p.read() dl = len(al.data) try: create() gmsg('\n{} wallet{} created'.format(dl,suf(dl))) except KeyboardInterrupt: rdie(1,'\nUser interrupt\n') except EOFError: rdie(2,'\nEnd of file\n') except Exception as e: rdie(1,'Program died: {!r}'.format(e))