Exemplo n.º 1
0
def End2End(cur):
	"""
		Generate a BIP key using random entropy each time
		Decrypt BIP Key to get compressed WIF Key
		Encrypt WIF Key to test that same BIP Key is generated.
		Also check the generated public address at each stage
	"""
	#build the entropy
	entropy = []
	count = 0
	while count <= 52:
		count+=1
		entropy.append((int(random.getrandbits(52)),int(random.getrandbits(52))))
	#generate a BIP key and address using the entropy above
	BIP_1, publicAddress_1 = gen.genBIPKey(cur, 'End2EndTest', entropy)
	#decrypt the BIP key to give a WIF key and address
	WIF, publicAddress_2 = gen.decBIPKey(BIP_1, 'End2EndTest', cur)
	#encrypt the WIF key to give a BIP Key and address
	BIP_2, publicAddress_3 = gen.encBIPKey(WIF, cur, 'End2EndTest')
	#chekc that the BIP Keys are the same
	if BIP_1 != BIP_2:
		print(cur + ' BIP Keys do not match\n' + BIP_1 + ' != ' + BIP_2)
		return False
	#check that the public keys are the same
	if publicAddress_1 != publicAddress_2 != publicAddress_3:
		print(cur + ' public addresses do not match\n' + publicAddress_1 + ' != ' + publicAddress_2 + ' != ' + publicAddress_3)
		return False
	return True
Exemplo n.º 2
0
def End2End(cur):
    """
		Generate a BIP key using random entropy each time
		Decrypt BIP Key to get compressed WIF Key
		Encrypt WIF Key to test that same BIP Key is generated.
		Also check the generated public address at each stage
	"""
    #build the entropy
    entropy = []
    count = 0
    while count <= 52:
        count += 1
        entropy.append(
            (int(random.getrandbits(52)), int(random.getrandbits(52))))
    #generate a BIP key and address using the entropy above
    BIP_1, publicAddress_1 = gen.genBIPKey(cur, 'End2EndTest', entropy)
    #decrypt the BIP key to give a WIF key and address
    WIF, publicAddress_2 = gen.decBIPKey(BIP_1, 'End2EndTest', cur)
    #encrypt the WIF key to give a BIP Key and address
    BIP_2, publicAddress_3 = gen.encBIPKey(WIF, cur, 'End2EndTest')
    #chekc that the BIP Keys are the same
    if BIP_1 != BIP_2:
        print(cur + ' BIP Keys do not match\n' + BIP_1 + ' != ' + BIP_2)
        return False
    #check that the public keys are the same
    if publicAddress_1 != publicAddress_2 != publicAddress_3:
        print(cur + ' public addresses do not match\n' + publicAddress_1 +
              ' != ' + publicAddress_2 + ' != ' + publicAddress_3)
        return False
    return True
Exemplo n.º 3
0
def encryptKnown(cur):
	"""
		Using known good keys, encrypt and then decrypt to check the results
		The good keys were all exported from the specified currencies default QT wallet
	"""
	#fetch the known key details for the chosen currency
	keys = json.load(open('unitTestKeys.json', 'r'))
	for key in keys:
		if key['currency'] == cur:
			break
	#check that the end of the list wasn't reached due to un-found keys
	if key['currency'] != cur or key['privK'] == '':
		print('No key details found for ' + cur)
		return False
	#encrypt the WIF privateKey
	BIP_1, publicAddress_1 = gen.encBIPKey(key['privK'], cur, 'encryptKnownTest')
	#decrypt the BIP key to produce a WIF Key and Address
	WIF_1, publicAddress_2 = gen.decBIPKey(BIP_1, 'encryptKnownTest', cur)
	#check that the saved BIP key and generated BIP key are the same
	if BIP_1 != key['bip']:
		print(cur + ' BIP Keys do not match\n' + BIP_1 + ' != ' + key['bip'])
		return False
	#check that the decrypted WIF key is the same as the known WIF key
	if WIF_1 != key['privK']:
		print(cur + ' the WIF Private Keys do not match\n' + WIF_1 + ' != ' + key['privK'])
		return False
	#check that the addresses are the same
	if publicAddress_1 != publicAddress_2 != key['address']:
		print(cur + ' public addresses do not match\n' + publicAddress_1 + ' != ' + publicAddress_2 + ' != ' + key['address'])
		return False
	return True
Exemplo n.º 4
0
def encryptKnown(cur):
    """
		Using known good keys, encrypt and then decrypt to check the results
		The good keys were all exported from the specified currencies default QT wallet
	"""
    #fetch the known key details for the chosen currency
    keys = json.load(open('res/json/unitTestKeys.json', 'r'))
    for key in keys:
        if key['currency'] == cur:
            break
    #check that the end of the list wasn't reached due to un-found keys
    if key['currency'] != cur or key['privK'] == '':
        print('No key details found for ' + cur)
        return False
    #encrypt the WIF privateKey
    BIP_1, publicAddress_1 = gen.encBIPKey(key['privK'], cur,
                                           'encryptKnownTest')
    #decrypt the BIP key to produce a WIF Key and Address
    WIF_1, publicAddress_2 = gen.decBIPKey(BIP_1, 'encryptKnownTest', cur)
    #check that the saved BIP key and generated BIP key are the same
    if BIP_1 != key['bip']:
        print(cur + ' BIP Keys do not match\n' + BIP_1 + ' != ' + key['bip'])
        return False
    #check that the decrypted WIF key is the same as the known WIF key
    if WIF_1 != key['privK']:
        print(cur + ' the WIF Private Keys do not match\n' + WIF_1 + ' != ' +
              key['privK'])
        return False
    #check that the addresses are the same
    if publicAddress_1 != publicAddress_2 != key['address']:
        print(cur + ' public addresses do not match\n' + publicAddress_1 +
              ' != ' + publicAddress_2 + ' != ' + key['address'])
        return False
    return True
Exemplo n.º 5
0
 def decrypt(self, dt):
     """
         Perform the decryption using the saved details
     """
     WIF, bAddress, sAddress = gen.decBIPKey(self.privateKey, self.passphrase)
     resultsScreen = self.NuBippyApp.mainScreenManager.get_screen('Results')
     resultsScreen.display_wif(WIF, bAddress, sAddress)
     # clear the UI
     Clock.schedule_once(self.reset_ui, 5)
     return
Exemplo n.º 6
0
 def decrypt(self, dt):
     """
         Perform the decryption using the saved details
     """
     WIF, bAddress, sAddress = gen.decBIPKey(self.privateKey,
                                             self.passphrase)
     resultsScreen = self.NuBippyApp.mainScreenManager.get_screen('Results')
     resultsScreen.display_wif(WIF, bAddress, sAddress)
     # clear the UI
     Clock.schedule_once(self.reset_ui, 5)
     return
Exemplo n.º 7
0
	def decrypt(self, dt):
		"""
			Perform the decryption using the saved details
		"""
		self.BippyApp.check_chosen_currency()
		WIF, Address = gen.decBIPKey(self.privateKey, self.passphrase, self.BippyApp.chosenCurrency)
		resultsScreen = self.BippyApp.mainScreenManager.get_screen(self.BippyApp.get_string('Results_Screen'))
		resultsScreen.display_wif(WIF, Address)
		#clear the UI
		Clock.schedule_once(self.reset_ui, 5)
		return
Exemplo n.º 8
0
    def decrypt(self, dt):
        """
			Perform the decryption using the saved details
		"""
        self.BippyApp.check_chosen_currency()
        WIF, Address = gen.decBIPKey(self.privateKey, self.passphrase,
                                     self.BippyApp.chosenCurrency)
        resultsScreen = self.BippyApp.mainScreenManager.get_screen(
            self.BippyApp.get_string('Results_Screen'))
        resultsScreen.display_wif(WIF, Address)
        #clear the UI
        Clock.schedule_once(self.reset_ui, 5)
        return
Exemplo n.º 9
0
	def decBIP(self, dt):
		"""
			Second part of the decryption routine to allow UI to update
		"""
		PrivateKey, PublicAddress = gen.decBIPKey(self.PrivateKey, self.Password, self.selectedCurrency)
		if PrivateKey is False:
			self.MainLabel.text = 'BIP0038 Decryption was unsuccessful.\n\nAre you sure the passphrase was correct?'
			self.rightBox.remove_widget(self.prog)
			self.rightBox.remove_widget(self.decButton)
			self.rightBox.add_widget(self.resetButton)
			return
		self.MainLabel.text = 'BIP0038 Decryption was successful.\n\nSee below for your private key and address.'
		self.PrivKLabel.text = 'Decrypted\nPrivate Key'
		self.PassLabel.text = 'Address'
		self.PasswordEnter.password = False
		self.PrivK.text = PrivateKey
		self.PasswordEnter.text = PublicAddress
		#unbind the private key and password entry boxes so that the user can copy out the key and address
		self.PrivK.unbind(focus=self.checkPrivK)
		self.PasswordEnter.unbind(focus=self.checkPassword)
		self.rightBox.remove_widget(self.prog)
		self.rightBox.remove_widget(self.decButton)
		self.rightBox.add_widget(self.resetButton)
		return