def test_create_tx(self): priv, pub = keyPair.GenerateKeyPair() client = spvClient.SPVClient(priv, pub) t = client.createTransaction(pub, 10, "test") self.assertTrue(t.validate(), "Client-made transaction must be valid") self.assertEqual(t.data["Amount"], 10, "Amount must not differ")
def createNew(): global user, miners_list priv, pub = keyPair.GenerateKeyPair() user = spvClient.SPVClient(privatekey=priv, publickey=pub) miners_list = user.getMiners(miner_server) return "Public Key: {}<br>Private Key: {}".format(pub.to_string().hex(), priv.to_string().hex())
def test_Simple(self): # generate sender sender_private_key, sender_public_key = keyPair.GenerateKeyPair() # generate recv receiver_private_key, receiver_public_key = keyPair.GenerateKeyPair() # amount amount = 10000 comment = "testRun" # create transaction t = transaction.Transaction(sender_public_key, receiver_public_key, amount, comment) t.sign(sender_private_key) # validate is ok self.assertTrue(t.validate()) # change to json json_form = t.to_json() # assume received recv_json = json.loads(json_form) # create transaction new_t = transaction.Transaction( _sender_public_key=recv_json["Sender"], _receiver_public_key=recv_json["Receiver"], _amount=recv_json["Amount"], _comment=recv_json["Comment"], _reward=recv_json["Reward"], _signature=recv_json["Signature"]) # change the signatures back t.from_json() new_t.from_json() self.assertEqual(new_t.data, t.data, "both do not give the same data")
def newUser(): global internal_storage priv, pub = keyPair.GenerateKeyPair() internal_storage["Private_key"] = priv.to_string().hex() internal_storage["Public_key"] = pub.to_string().hex() newUser = open("Newuser.html").read() info = "Public Key: {}<br>" \ "Private Key: {}<br>" \ "Please save these 2 (They are unrecoverable)".\ format(pub.to_string().hex(), priv.to_string().hex()) return info + newUser
def test_conversion(self): priv, pub = keyPair.GenerateKeyPair() pubHex = pub.to_string().hex() privHex = priv.to_string().hex() print(pubHex) print(privHex) nextA = ecdsa.SigningKey.from_string(bytes.fromhex(privHex)) nextB = ecdsa.VerifyingKey.from_string(bytes.fromhex(pubHex)) print(nextA.to_string().hex()) print(nextB.to_string().hex()) msg = "KDCoin" print(keyPair.signWithPrivateKey(msg, priv))
def newUser(): global internal_storage, interruptQueue, saved_block priv, pub = keyPair.GenerateKeyPair() internal_storage["Private_key"] = priv.to_string().hex() internal_storage["Public_key"] = pub.to_string().hex() newUser = open("Newuser.html").read() info = "Public Key: {}<br>" \ "Private Key: {}<br>" \ "Please save these 2 (They are unrecoverable)".format( pub.to_string().hex(), priv.to_string().hex() ) pub_key = internal_storage["Public_key"] priv_key = internal_storage["Private_key"] internal_storage["Miner"] = attacker.Attacker(_pub=pub_key, _priv=priv_key) # announce yourself getNeighbours(self_address) generator = internal_storage["Miner"].mineBlock() try: interruptQueue = next(generator) block_data = next(generator) internal_storage["Miner"].broadcastBlock( _block_data=block_data, _neighbours=internal_storage["Neighbour_nodes"], _self_addr=self_address, ) if saved_block is None: print("Saving Block...") saved_block = block_data except StopIteration: print("AttackerApp New Interrupted") return info + newUser
def createInitialBlockchain(): priv, pub = keyPair.GenerateKeyPair() t = transaction.Transaction(_sender_public_key=pub, _receiver_public_key=pub, _amount=100, _comment="Reward", _reward=True) t.sign(priv) b = block.Block([t]) q_find = manager.Queue() q2 = manager.Queue() p = b.build(q_find, q2) p.start() p.join() nonce = q_find.get() print("Nonce1:", nonce) b.completeBlockWithNonce(nonce) b.executeChange() bc = blockChain.Blockchain(_block=b) return priv, pub, b, bc
def createNewAccount(self): priv, pub = keyPair.GenerateKeyPair() self.client = spvClient.SPVClient(privatekey=priv, publickey=pub) return priv, pub