def generate_addrs(seed, addrnums, source="addrgen"): from util import make_chksum_8 seed_id = make_chksum_8(seed) # Must do this before seed gets clobbered if 'a' in opt.gen_what: if opt.no_keyconv or test_for_keyconv() == False: msg("Using (slow) internal ECDSA library for address generation") from mmgen.bitcoin import privnum2addr keyconv = False else: from subprocess import check_output keyconv = "keyconv" addrnums = sorted(set(addrnums)) # don't trust the calling function t_addrs,num,pos,out = len(addrnums),0,0,[] w = { 'ka': ('key/address pair','s'), 'k': ('key','s'), 'a': ('address','es') }[opt.gen_what] from mmgen.addr import AddrInfoEntry,AddrInfo while pos != t_addrs: seed = sha512(seed).digest() num += 1 # round if num != addrnums[pos]: continue pos += 1 qmsg_r("\rGenerating %s #%s (%s of %s)" % (w[0],num,pos,t_addrs)) e = AddrInfoEntry() e.idx = num # Secret key is double sha256 of seed hash round /num/ sec = sha256(sha256(seed).digest()).hexdigest() wif = numtowif(int(sec,16)) if 'a' in opt.gen_what: if keyconv: e.addr = check_output([keyconv, wif]).split()[1] else: e.addr = privnum2addr(int(sec,16)) if 'k' in opt.gen_what: e.wif = wif if opt.b16: e.sec = sec out.append(e) m = w[0] if t_addrs == 1 else w[0]+w[1] qmsg("\r%s: %s %s generated%s" % (seed_id,t_addrs,m," "*15)) a = AddrInfo(has_keys='k' in opt.gen_what, source=source) a.initialize(seed_id,out) return a
def _parse_addrfile_body(lines,has_keys=False,check=False): if has_keys and len(lines) % 2: return "Key-address file has odd number of lines" ret = [] while lines: a = AddrInfoEntry() l = lines.pop(0) d = l.split(None,2) if not is_mmgen_idx(d[0]): return "'%s': invalid address num. in line: '%s'" % (d[0],l) if not is_btc_addr(d[1]): return "'%s': invalid Bitcoin address" % d[1] if len(d) == 3: check_addr_label(d[2]) else: d.append("") a.idx,a.addr,a.comment = int(d[0]),unicode(d[1]),unicode(d[2]) if has_keys: l = lines.pop(0) d = l.split(None,2) if d[0] != "wif:": return "Invalid key line in file: '%s'" % l if not is_wif(d[1]): return "'%s': invalid Bitcoin key" % d[1] a.wif = unicode(d[1]) ret.append(a) if has_keys and keypress_confirm("Check key-to-address validity?"): wif2addr_f = get_wif2addr_f() llen = len(ret) for n,e in enumerate(ret): msg_r("\rVerifying keys %s/%s" % (n+1,llen)) if e.addr != wif2addr_f(e.wif): return "Key doesn't match address!\n %s\n %s" % (e.wif,e.addr) msg(" - done") return ret