Ejemplo n.º 1
0
def get_seed_from_seed_data(words):

	if not _check_mmseed_format(words):
		msg("Invalid %s data" % g.seed_ext)
		return False

	stored_chk = words[0]
	seed_b58 = "".join(words[1:])

	chk = make_chksum_6(seed_b58)
	vmsg_r("Validating %s checksum..." % g.seed_ext)

	if compare_chksums(chk, "seed", stored_chk, "input"):
		seed = b58decode_pad(seed_b58)
		if seed == False:
			msg("Invalid b58 number: %s" % val)
			return False

		msg("Valid seed data for Seed ID %s" % make_chksum_8(seed))
		return seed
	else:
		msg("Invalid checksum for {pnm} seed".format(pnm=pnm))
		return False
Ejemplo n.º 2
0
	def _deformat(self):
		desc = self.desc
		ld = self.fmt_data.split()

		if not (7 <= len(ld) <= 12): # 6 <= padded b58 data (ld[1:]) <= 11
			msg("Invalid data length (%s) in %s" % (len(ld),desc))
			return False

		a,b = ld[0],"".join(ld[1:])

		if not is_chksum_6(a):
			msg("'%s': invalid checksum format in %s" % (a, desc))
			return False

		if not is_b58string(b):
			msg("'%s': not a base 58 string, in %s" % (b, desc))
			return False

		vmsg_r("Validating %s checksum..." % desc)

		if not compare_chksums(
				a,"checksum",make_chksum_6(b),"base 58 data"):
			return False

		ret = b58decode_pad(b)

		if ret == False:
			msg("Invalid base-58 encoded seed: %s" % val)
			return False

		self.seed = Seed(ret)
		self.ssdata.chksum = a
		self.ssdata.b58seed = b

		check_usr_seed_len(self.seed.length)

		return True
Ejemplo n.º 3
0
	def _deformat(self):

		def check_master_chksum(lines,desc):

			if len(lines) != 6:
				msg("Invalid number of lines (%s) in %s data" %
						(len(lines),desc))
				return False

			if not is_chksum_6(lines[0]):
				msg("Incorrect master checksum (%s) in %s data" %
						(lines[0],desc))
				return False

			chk = make_chksum_6(" ".join(lines[1:]))
			if not compare_chksums(lines[0],"master",chk,"computed",
						hdr="For wallet master checksum"):
				return False

			return True

		lines = self.fmt_data.splitlines()
		if not check_master_chksum(lines,self.desc): return False

		d = self.ssdata
		d.label = lines[1]

		d1,d2,d3,d4,d5 = lines[2].split()
		d.seed_id = d1.upper()
		d.key_id  = d2.upper()
		check_usr_seed_len(int(d3))
		d.pw_status,d.timestamp = d4,d5

		hpdata = lines[3].split()

		d.hash_preset = hp = hpdata[0][:-1]  # a string!
		qmsg("Hash preset of wallet: '%s'" % hp)
		if 'hash_preset' in opt.set_by_user:
			uhp = opt.hash_preset
			if uhp != hp:
				qmsg("Warning: ignoring user-requested hash preset '%s'" % uhp)

		hash_params = [int(i) for i in hpdata[1:]]

		if hash_params != get_hash_params(d.hash_preset):
			msg("Hash parameters '%s' don't match hash preset '%s'" %
					(" ".join(hash_params), d.hash_preset))
			return False

		lmin,lmax = b58_lens[0],b58_lens[-1] # 22,33,44
		for i,key in (4,"salt"),(5,"enc_seed"):
			l = lines[i].split(" ")
			chk = l.pop(0)
			b58_val = "".join(l)

			if len(b58_val) < lmin or len(b58_val) > lmax:
				msg("Invalid format for %s in %s: %s" % (key,self.desc,l))
				return False

			if not compare_chksums(chk,key,
					make_chksum_6(b58_val),"computed checksum"):
				return False

			val = b58decode_pad(b58_val)
			if val == False:
				msg("Invalid base 58 number: %s" % b58_val)
				return False

			setattr(d,key,val)

		return True