Exemple #1
0
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
Exemple #2
0
	def add_wallet_data(self,c):
		vmsg_r("Getting account data from wallet...")
		data,accts,i = {},c.listaccounts(minconf=0,includeWatchonly=True),0
		for acct in accts:
			ma,comment = parse_mmgen_label(acct)
			if ma:
				i += 1
				addrlist = c.getaddressesbyaccount(acct)
				if len(addrlist) != 1:
					msg(wmsg['too_many_acct_addresses'] % acct)
					sys.exit(2)
				seed_id,idx = ma.split(":")
				if seed_id not in data:
					data[seed_id] = []
				a = AddrInfoEntry()
				a.idx,a.addr,a.comment = \
					int(idx),unicode(addrlist[0]),unicode(comment)
				data[seed_id].append(a)
		vmsg("{n} {pnm} addresses found, {m} accounts total".format(
				n=i,pnm=pnm,m=len(accts)))
		for sid in data:
			self.add(AddrInfo(sid=sid,adata=data[sid]))
Exemple #3
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
Exemple #4
0
This command can also be used to update the comment fields of addresses already
in the tracking wallet.
"""
}

cmd_args = opt.opts.init(opts_data)

if len(cmd_args) == 1:
	infile = cmd_args[0]
	check_infile(infile)
	if opt.addrlist:
		lines = get_lines_from_file(
			infile,"non-{pnm} addresses".format(pnm=g.proj_name),trim_comments=True)
		ai,adata = AddrInfo(),[]
		for btcaddr in lines:
			a = AddrInfoEntry()
			a.idx,a.addr,a.comment = None,btcaddr,None
			adata.append(a)
		ai.initialize(None,adata)
	else:
		ai = AddrInfo(infile,has_keys=opt.keyaddr_file)
else:
	msg("""
You must specify an {pnm} address file (or a list of non-{pnm} addresses
with the '--addrlist' option)
""".strip().format(pnm=g.proj_name))
	sys.exit(1)

from mmgen.bitcoin import verify_addr
qmsg_r("Validating addresses...")
for e in ai.addrdata: