Beispiel #1
0
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