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
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
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
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
def encrypt(self, dt): """ Perform the actual encryption """ BIP, bAddress, sAddress = gen.encBIPKey(self.privkey, self.passphrase) resultsScreen = self.NuBippyApp.mainScreenManager.get_screen('Results') resultsScreen.display_bip(BIP, bAddress, sAddress) # clear the UI Clock.schedule_once(self.reset_ui, 5)
def encrypt(self, dt): """ Perform the actual encryption """ BIP, Address = gen.encBIPKey(self.privkey, self.BippyApp.chosenCurrency, self.passphrase) resultsScreen = self.BippyApp.mainScreenManager.get_screen(self.BippyApp.get_string('Results_Screen')) resultsScreen.display_bip(BIP, Address) #clear the UI Clock.schedule_once(self.reset_ui, 5)
def genBIP(self, dt): """ This is the second part of the generate BIP method. It's split into two like this as otherwise the UI doesn't update to show that encryption has started """ if self.PrivateKey is None: BIP, Address = gen.genBIPKey(self.selectedCurrency, self.Password, self.entropy) else: BIP, Address = gen.encBIPKey(self.PrivateKey, self.selectedCurrency, self.Password) self.setBIP(BIP, Address) return
def encrypt(self, dt): """ Perform the actual encryption """ BIP, Address = gen.encBIPKey(self.privkey, self.BippyApp.chosenCurrency, self.passphrase) resultsScreen = self.BippyApp.mainScreenManager.get_screen( self.BippyApp.get_string('Results_Screen')) resultsScreen.display_bip(BIP, Address) #clear the UI Clock.schedule_once(self.reset_ui, 5)
def encrypt(self, dt): """ Perform the actual encryption """ if self.newKey is True: BIP, bAddress, sAddress = gen.genBIPKey(self.passphrase, self.entropy, '', ) else: # otherwise, we encrypt the existing key BIP, bAddress, sAddress = gen.encBIPKey(self.privateKey, self.passphrase) resultsScreen = self.NuBippyApp.mainScreenManager.get_screen('Results') resultsScreen.display_bip(BIP, bAddress, sAddress) # clear the UI Clock.schedule_once(self.reset_ui, 5) return
def encrypt(self, dt): """ Perform the actual encryption """ self.BippyApp.check_chosen_currency() if self.newKey is True: BIP, Address = gen.genBIPKey(self.BippyApp.chosenCurrency, self.passphrase, self.entropy, '', self.isCompressed) else: #otherwise, we encrypt the existing key BIP, Address = gen.encBIPKey(self.privateKey, self.BippyApp.chosenCurrency, self.passphrase, self.isCompressed) resultsScreen = self.BippyApp.mainScreenManager.get_screen(self.BippyApp.get_string('Results_Screen')) resultsScreen.display_bip(BIP, Address) #clear the UI Clock.schedule_once(self.reset_ui, 5) return
def encrypt(self, dt): """ Perform the actual encryption """ self.BippyApp.check_chosen_currency() if self.newKey is True: BIP, Address = gen.genBIPKey(self.BippyApp.chosenCurrency, self.passphrase, self.entropy, '', self.isCompressed) else: #otherwise, we encrypt the existing key BIP, Address = gen.encBIPKey(self.privateKey, self.BippyApp.chosenCurrency, self.passphrase, self.isCompressed) resultsScreen = self.BippyApp.mainScreenManager.get_screen( self.BippyApp.get_string('Results_Screen')) resultsScreen.display_bip(BIP, Address) #clear the UI Clock.schedule_once(self.reset_ui, 5) return
def encrypt(self, dt): """ Perform the actual encryption """ if self.newKey is True: BIP, bAddress, sAddress = gen.genBIPKey( self.passphrase, self.entropy, '', ) else: # otherwise, we encrypt the existing key BIP, bAddress, sAddress = gen.encBIPKey(self.privateKey, self.passphrase) resultsScreen = self.NuBippyApp.mainScreenManager.get_screen('Results') resultsScreen.display_bip(BIP, bAddress, sAddress) # clear the UI Clock.schedule_once(self.reset_ui, 5) return