def test_load_key(self): pri_k, pub_k = ECCipher.load_key_pair(self.private_key_file_path, self.password) self.assertIsNotNone(pri_k) self.assertIsNotNone(pub_k) pri_key = ECCipher.load_private_key(self.private_key_file_path, self.password) self.assertIsNotNone(pri_key) msg = 'test123' sig = ECCipher.create_signature(pri_key, msg) print('sig:', sig) self.assertIsNotNone(sig) create_pub_key = ECCipher.create_public_key_from_private_key(pri_key) self.assertIsNotNone(create_pub_key) load_pub_key = ECCipher.load_public_key(self.private_key_file_path, self.password) self.assertIsNotNone(load_pub_key) v1 = ECCipher.verify_sign(load_pub_key, sig, msg) self.assertTrue(v1) v2 = ECCipher.verify_sign(create_pub_key, sig, msg) self.assertTrue(v2) addr = ECCipher.get_address_from_public_key(load_pub_key) print(addr) self.assertIsNotNone(addr)
def test_generate_key_pair_signature_and_verify(self): private_key_file_path = join_with_root(private_key_file) password_path = join_with_root(private_key_password_file) with open(password_path) as f: password = f.read() print(password) new_pri_key, pub_key = ECCipher.load_key_pair(private_key_file_path, password) sample = b"qZaQ6S" print("gen prikey:", new_pri_key) self.assertIsNotNone(new_pri_key) new_signature = ECCipher.create_signature(new_pri_key, sample) print("new_signature is:", new_signature) self.assertIsNotNone(new_signature) # pub_key = ECCipher.create_public_key(new_pub_key) is_valid_sign = ECCipher.verify_sign(pub_key, new_signature, sample) print("is valid new_signature:", is_valid_sign) self.assertTrue(is_valid_sign)
def derive_proxy_data(msg): msg = unpackb(msg, raw=False) public_key = ECCipher.create_public_key(msg['public_key']) data = msg['data'] signature = msg['signature'] valid = ECCipher.verify_sign(public_key, signature, data) if valid: return data
def sign_message_verify(sign_message): try: public_key = ECCipher.create_public_key(sign_message.public_key) valid = ECCipher.verify_sign(public_key, sign_message.signature, sign_message.data) except: return False else: return valid
def verify_geth_signature(pub_key, signature, raw_data_string): raw_data = raw_data_string.encode(encoding="utf-8") return ECCipher.verify_sign(pub_key, signature, raw_data)