Esempio n. 1
0
def genAll(bip=False):
	import random
	import num.rand as rand
	import system.address as address
	import num.enc as enc
	import encrypt.bip38 as bip38
	import hashlib
	
	genFile = open('allKeys', 'w')
	genFile.close()
	
	conn = db.open()
	c = conn.cursor()
	c.execute('select currency from eskimo_currencies order by currency;')
	currencies = c.fetchall()
	for cur in currencies:
		c.execute('select v.version,v.prefix,v.length,c.id,c.longName from eskimo_versions as v inner join eskimo_currencies as c on c.version = v.id where c.currency=?;', (cur[0].upper(),))
		version = c.fetchone()
		if version is None:
			continue
		#randomly choose a prefix if multiples exist
		prefixes = version[1].split('|') 
		prefix = prefixes[random.randint(0, (len(prefixes)-1))] 
		#generate the private and public keys
		privateKey = rand.randomKey(random.getrandbits(512))
		privK256 = enc.encode(privateKey, 256, 32)
		WIF = address.privateKey2Wif(privateKey, version[0], prefix,  version[2])
		publicAddress = address.publicKey2Address(address.privateKey2PublicKey(privateKey), version[0], prefix,  version[2])
		if bip is True:
			BIP = bip38.encrypt(privK256, publicAddress, 'biptest', 1)
			privK, addresshash = bip38.decrypt(BIP, 'biptest', 1)
			#decode the privK from base 256
			privK = enc.decode(privK, 256)
			#hash the address to check the decryption
			addr = address.publicKey2Address(address.privateKey2PublicKey(privK), version[0], prefix,  version[2])
			fail = False
			if hashlib.sha256(hashlib.sha256(addr).digest()).digest()[0:4] != addresshash:
				fail = True
				reason = 'Address Hash doesn\'t match'
			if privK != privateKey:
				fail = True
				reason = 'Private Keys don\'t match'
			BIPWIF =  address.privateKey2Wif(privK, version[0], prefix,  version[2])
		with open('allKeys', 'a') as outfile:
			outfile.write('####### ' + cur[0].upper() + ' - ' + version[4] + ' #######\n')
			outfile.write('Address = ' + publicAddress + '\n')
			outfile.write('WIF     = ' + WIF + '\n')
			if bip is True:
				outfile.write('BIP     = ' + BIP + '\n')
				if fail is True:
					outfile.write('BIP Failed - ' + reason + '\n')
				else:
					outfile.write('BIPWIF  = ' + BIPWIF + '\n')
			outfile.write('\n')
		outfile.close()
	db.close(conn)
	return True
Esempio n. 2
0
def generate(cur, bip=False):
	"""
		public and private key generator.
		optional BIP0038 encryption
	"""
	#check that the given currency is in the system
	conn = db.open()
	c = conn.cursor()
	#pull the version details from the database
	c.execute('select v.version,v.prefix,v.length,c.id,c.longName,c.version from inuit_versions as v inner join inuit_currencies as c on c.version = v.id where c.currency=?;', (cur.upper(),))
	version = c.fetchone()
	if version is None:
		print(cur.upper() + ' is not currently listed as a currency')
		return False
	#randomly choose a prefix if multiples exist
	prefixes = version[1].split('|') 
	prefix = prefixes[random.randint(0, (len(prefixes)-1))] 
	#generate the private and public keys
	privateKey = rand.randomKey(inp.keyboardEntropy())
	privK256 = enc.encode(privateKey, 256, 32)
	publicAddress = publicKey2Address(privateKey2PublicKey(privateKey), version[0], prefix,  version[2])
	#optional BIP0038 encryption
	get.flushKeybuffer(get._Getch())
	encrypt = 'y'
	if encrypt == 'y':
		bipPass1 = 'pass1' 
		bipPass2 = 'pass2'
		while bipPass1 != bipPass2 or len(bipPass1) < 1:
			bipPass1 = inp.secure_passphrase('Enter your BIP0038 passphrase')
			bipPass2 = inp.secure_passphrase('Re-enter your passphrase to confirm')
			if bipPass1 != bipPass2:
				print('The passphrases entered did not match.')
			elif len(bipPass1) < 1:
				print('No passphrase was entered!')
		reminder = raw_input('Enter an optional reminder for your password : '******'')
		#print('Enter the number of rounds of encryption.')
		#p = raw_input('A smaller number means quicker but less secure. (8) : ').strip()
		#p = 8 if p == '' else int(p)
		p = 8
		privK = bip38.encrypt(privK256, publicAddress, bipPass1, p)
		isBip = True
	else:
		privK = privateKey
		isBip = False
	#save details to the database
	c.execute('insert into inuit_privK (privK, currency) values (?,?);', (str(privK).encode('base64','strict'), version[3]))
	privKid = c.lastrowid
	c.execute('insert into inuit_addresses (address, currency) values (?,?);', (publicAddress.encode('base64','strict'), version[3]))
	addId = c.lastrowid
	c.execute('insert into inuit_master (address, privK, version) values (?,?,?);', (addId, privKid, version[5]))
	if isBip is True:
		c.execute('insert into inuit_bip (privK, reminder, p) values (?,?,?);', (privKid, reminder, p))
	db.close(conn)
	print('')
	print(version[4] + ' Address : ' + publicAddress)
	return privK, publicAddress
Esempio n. 3
0
def genBIPKey(passphrase, entropy='', privateKey=''):
    """
        Generate a BIP38 private key + public addresses
    """
    # generate the private and public keys
    if privateKey == '':
        privateKey = int(rand.randomKey(rand.entropy(entropy)))
    privK256 = enc.encode(privateKey, 256, 32)
    bPublicAddress, sPublicAddress = address.publicKey2Address(
        address.privateKey2PublicKey(privateKey))
    #BIP38 encryption
    BIP = bip38.encrypt(privK256, bPublicAddress, sPublicAddress,
                        str(passphrase))
    return BIP, bPublicAddress, sPublicAddress
Esempio n. 4
0
def vanity(currency, string):
	"""
		Generate a vanity address
	"""
	#using the currencies.json file, get the currency data
	with open('currencies.json', 'r') as dataFile:
		currencies = json.load(dataFile)
	for cur in currencies:
		if cur['currency'] == currency:
			break
	#randomly choose a prefix if multiples exist
	prefixes = cur['prefix'].split('|')
	prefix = prefixes[random.randint(0, (len(prefixes)-1))]
	#generate the private and public keys
	vanityAddress = ''
	while vanityAddress[:(len(string)+1)] != prefix + string:
		privateKey = int(rand.randomKey(random.getrandbits(512)))
		vanityAddress = address.publicKey2Address(address.privateKey2PublicKey(privateKey), int(cur['version']), prefix, int(cur['length']))
		print(vanityAddress)
	print(vanityAddress, privateKey)
	return
Esempio n. 5
0
def genBIPKey(currency, passphrase, entropy='', privateKey='', isCompressed=True):
	"""
	Generate a BIP38 privatekey + public address#
	"""
	#using the currencies.json file, get the currency data
	with open('res/json/currencies.json', 'r') as dataFile:
		currencies = json.load(dataFile)
	for cur in currencies:
		if cur['currency'] == currency:
			break
	#randomly choose a prefix if multiples exist
	prefixes = cur['prefix'].split('|') 
	prefix = prefixes[random.randint(0, (len(prefixes) - 1))]
	#generate the private and public keys
	if privateKey == '':
		privateKey = int(rand.randomKey(rand.entropy(entropy)))
	privK256 = enc.encode(privateKey, 256, 32)
	publicAddress = address.publicKey2Address(address.privateKey2PublicKey(privateKey, isCompressed), int(cur['version']), prefix, int(cur['length']))
	#BIP38 encryption
	BIP = bip38.encrypt(privK256, publicAddress, str(passphrase), 8)
	return BIP, publicAddress