def main(): # Alice wants to rotate a key for its company # Common Katena network information api_url = Settings.api_url chain_id = Settings.chain_id # Alice Katena network information alice_company_bcid = Settings.Company.bcid alice_sign_key_info = Settings.Company.ed25519_keys['alice'] alice_sign_private_key = create_private_key_ed25519_from_base64(alice_sign_key_info.private_key_str) alice_sign_key_id = alice_sign_key_info.id # Create Katena API helpers tx_signer = TxSigner(concat_fqid(alice_company_bcid, alice_sign_key_id), alice_sign_private_key) transactor = Transactor(api_url, chain_id, tx_signer) # Information Alice want to send key_id = Settings.key_id new_private_key = generate_new_private_key_ed25519() new_public_key = new_private_key.get_public_key() try: # Send a version 1 of a key rotate on Katena tx_result = transactor.send_key_rotate_v1_tx(key_id, new_public_key) print("Result :") println_json(tx_result, SendTxResultSchema) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to certify raw off-chain information # Common Katena network information api_url = Settings.api_url chain_id = Settings.chain_id # Alice Katena network information alice_company_bcid = Settings.Company.bcid alice_sign_key_info = Settings.Company.ed25519_keys['alice'] alice_sign_private_key = create_private_key_ed25519_from_base64( alice_sign_key_info.private_key_str) alice_sign_key_id = alice_sign_key_info.id # Create Katena API helpers tx_signer = TxSigner(concat_fqid(alice_company_bcid, alice_sign_key_id), alice_sign_private_key) transactor = Transactor(api_url, chain_id, tx_signer) # Off-chain information Alice wants to send certificate_id = Settings.certificate_id raw_data_signature = "off_chain_data_raw_signature_from_py" try: # Send a raw certificate, version 1, to Katena tx_result = transactor.send_certificate_raw_v1_tx( certificate_id, raw_data_signature.encode('utf-8')) print("Result :") println_json(tx_result, SendTxResultSchema) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to certify an ed25519 signature of an off-chain data # Common Katena network information api_url = Settings.api_url chain_id = Settings.chain_id # Alice Katena network information alice_company_bcid = Settings.Company.bcid alice_sign_key_info = Settings.Company.ed25519_keys['alice'] alice_sign_private_key = create_private_key_ed25519_from_base64(alice_sign_key_info.private_key_str) alice_sign_key_id = alice_sign_key_info.id # Create Katena API helpers tx_signer = TxSigner(concat_fqid(alice_company_bcid, alice_sign_key_id), alice_sign_private_key) transactor = Transactor(api_url, chain_id, tx_signer) # Off-chain information Alice wants to send certificate_id = Settings.certificate_id david_sign_key_info = Settings.OffChain.ed25519_keys['david'] david_sign_private_key = create_private_key_ed25519_from_base64(david_sign_key_info.private_key_str) data_signature = david_sign_private_key.sign("off_chain_data_to_sign_from_py".encode("utf-8")) try: # Send a version 1 of a certificate ed25519 on Katena tx_result = transactor.send_certificate_ed25519_v1_tx(certificate_id, david_sign_private_key.get_public_key(), data_signature) print("Result :") println_json(tx_result, SendTxResultSchema) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to send a nacl box secret to Bob to encrypt an off-chain data # Common Katena network information api_url = Settings.api_url chain_id = Settings.chain_id # Alice Katena network information alice_company_bcid = Settings.Company.bcid alice_sign_key_info = Settings.Company.ed25519_keys['alice'] alice_sign_private_key = create_private_key_ed25519_from_base64( alice_sign_key_info.private_key_str) alice_sign_key_id = alice_sign_key_info.id # Create Katena API helpers tx_signer = TxSigner(concat_fqid(alice_company_bcid, alice_sign_key_id), alice_sign_private_key) transactor = Transactor(api_url, chain_id, tx_signer) # Nacl box information (Alice encrypt data with its private key + recipient public key) alice_crypt_key_info = Settings.OffChain.x25519_keys['alice'] alice_crypt_private_key = create_private_key_x25519_from_base64( alice_crypt_key_info.private_key_str) bob_crypt_key_info = Settings.OffChain.x25519_keys['bob'] bob_crypt_public_key = create_public_key_x25519_from_base64( bob_crypt_key_info.public_key_str) # Off-chain information Alice wants to send to Bob secret_id = Settings.secret_id content = "off_chain_secret_to_crypt_from_py" # Alice uses its private key and Bob's public key to encrypt the message encrypted_message, nonce = alice_crypt_private_key.seal( content.encode("utf-8"), bob_crypt_public_key) try: # Send a version 1 of a secret nacl box on Katena tx_result = transactor.send_secret_nacl_box_v1_tx( secret_id, alice_crypt_private_key.get_public_key(), nonce, encrypted_message) print("Result :") println_json(tx_result, SendTxResultSchema) except (ApiException, ClientException) as e: print(e)
def sign_tx(self, tx_signer: TxSigner, chain_id: str, nonce_time: datetime, tx_data: TxData) -> Tx: # Creates a tx data state, signs it and returns a tx ready to be encoded and sent. tx_data_state = self.get_tx_data_state(chain_id, nonce_time, tx_data) tx_signature = tx_signer.get_private_key().sign(tx_data_state) return Tx(nonce_time, tx_data, tx_signer.get_key_id(), tx_signature)