def test_key_pair_info(): return { 'private_hex' : PRIVATE_TEST_KEY, 'private_bytes': to_bytes(PRIVATE_TEST_KEY), 'private_text': PRIVATE_TEST_KEY_TEXT, 'private_password': PRIVATE_TEST_KEY_PASSWORD, 'private_mnemonic': PRIVATE_KEY_MNEMONIC, 'public_key': PUBLIC_KEY }
def get_test_account(): private_key = Ed25519PrivateKey.from_private_bytes( to_bytes(PRIVATE_TEST_KEY)) public_key = private_key.public_key() public_key_bytes = public_key.public_bytes( encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw) public_address = remove_0x_prefix(to_hex(public_key_bytes)) assert (public_address == PUBLIC_ADDRESS) return private_key, public_address
def sign(self, hash_text): """ Sign a hash text using the private key. :param str hash_text: Hex string of the hash to sign :returns: Hex string of the signed text .. code-block:: python >>> sig = key_pair.sign('7e2f1062f5fc51ed65a28b5945b49425aa42df6b7e67107efec357794096e05e') >>> print(sig) '5d41b964c63d1087ad66e58f4f9d3fe2b7bd0560b..' """ hash_data = to_bytes(hexstr=hash_text) signed_hash_bytes = self._private_key.sign(hash_data) return to_hex(signed_hash_bytes)
def test_submit_transaction(convex_url): private_key, public_address = generate_test_keys() address = create_account(convex_url, public_address) request_funds(convex_url, address) # faucet request amount # prepare prepare_data = {'address': f'#{address}', 'source': '(map inc [1 2 3])'} url = f'{convex_url}/api/v1/transaction/prepare' print('prepare send', prepare_data) response = requests.post(url, data=json.dumps(prepare_data)) if response.status_code != 200: print('prepare error', response.text) assert (response.status_code == 200) result = response.json() #submit print(result) hash_data = to_bytes(hexstr=result['hash']) signed_hash_bytes = private_key.sign(hash_data) signed_hash = to_hex(signed_hash_bytes) submit_data = { 'address': f'#{address}', 'accountKey': public_address, 'hash': result['hash'], 'sig': remove_0x_prefix(signed_hash) } url = f'{convex_url}/api/v1/transaction/submit' print('submit send', submit_data) response = requests.post(url, data=json.dumps(submit_data)) if response.status_code != 200: print('submit error', response.text, response.status_code) assert (response.status_code == 200) print(response.json())
def test_key_pair_address_bytes(test_key_pair_info): key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes']) assert (key_pair) assert (key_pair.public_key_bytes == to_bytes( hexstr=test_key_pair_info['public_key']))