def main(): # Bob wants to read a nacl box secret from Alice to decrypt an off-chain data # Common Katena network information api_url = Settings.api_url # Alice Katena network information alice_company_bcid = Settings.Company.bcid # Create a Katena API helper transactor = Transactor(api_url) # Nacl box information bob_crypt_key_info = Settings.OffChain.x25519_keys["bob"] bob_crypt_private_key = create_private_key_x25519_from_base64(bob_crypt_key_info.private_key_str) # Secret id Bob wants to retrieve secret_id = Settings.secret_id try: # Retrieve txs related to the secret fqid tx_results = transactor.retrieve_secret_txs(alice_company_bcid, secret_id, 1, Settings.tx_per_page) print("Tx list :") println_json(tx_results, TxResultsSchema) # Retrieve the last tx related to the secret fqid tx_result = transactor.retrieve_last_secret_tx(alice_company_bcid, secret_id) print("Last tx :") println_json(tx_result, TxResultSchema) # Retrieve the last state of a secret with that fqid secret = transactor.retrieve_secret(alice_company_bcid, secret_id) print("Secret :") println_json(secret, TxDataSchema) # Bob will use its private key and the sender's public key (needs to be Alice's) to decrypt a message decrypted_content = bob_crypt_private_key.open( secret.get_content(), secret.get_sender(), secret.get_nonce() ).decode("utf-8") if decrypted_content == "": decrypted_content = "Unable to decrypt" print("Decrypted content : {}".format(decrypted_content)) 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 main(): # Alice wants to retrieve the keys of its company # Common Katena network information api_url = Settings.api_url # Alice Katena network information alice_company_bcid = Settings.Company.bcid # Create a Katena API helper transactor = Transactor(api_url) try: # Retrieve the keys from Katena keys = transactor.retrieve_company_keys(alice_company_bcid, 1, Settings.tx_per_page) print("Keys list :") println_json(keys, KeyV1Schema, True) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to retrieve txs related to a certificate # Common Katena network information api_url = Settings.api_url # Alice Katena network information alice_company_bcid = Settings.Company.bcid # Create a Katena API helper transactor = Transactor(api_url) # Certificate id Alice wants to retrieve certificate_id = Settings.certificate_id try: # Retrieve txs related to the certificate fqid tx_results = transactor.retrieve_certificate_txs( alice_company_bcid, certificate_id, 1, Settings.tx_per_page) print("Tx list :") println_json(tx_results, TxResultsSchema) # Retrieve the last tx related to the certificate fqid tx_result = transactor.retrieve_last_certificate_tx( alice_company_bcid, certificate_id) print("Last tx :") println_json(tx_result, TxResultSchema) # Retrieve the last state of a certificate with that fqid certificate = transactor.retrieve_certificate(alice_company_bcid, certificate_id) print("Certificate :") println_json(certificate, TxDataSchema) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to create 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() # Choose role between DEFAULT_ROLE_ID or COMPANY_ADMIN_ROLE_ID role = DEFAULT_ROLE_ID try: # Send a version 1 of a key create on Katena tx_result = transactor.send_key_create_v1_tx(key_id, new_public_key, role) print("Result :") println_json(tx_result, SendTxResultSchema) except (ApiException, ClientException) as e: print(e)
def main(): # Alice wants to retrieve a key and its related txs # Common Katena network information api_url = Settings.api_url # Alice Katena network information alice_company_bcid = Settings.Company.bcid # Create a Katena API helper transactor = Transactor(api_url) # Key id Alice wants to retrieve key_id = Settings.key_id try: # Retrieve txs related to the key fqid tx_results = transactor.retrieve_key_txs(alice_company_bcid, key_id, 1, Settings.tx_per_page) print("Tx list :") println_json(tx_results, TxResultsSchema) # Retrieve the last tx related to the key fqid tx_result = transactor.retrieve_last_key_tx(alice_company_bcid, key_id) print("Last tx :") println_json(tx_result, TxResultSchema) # Retrieve the last state of a key with that fqid key = transactor.retrieve_key(alice_company_bcid, key_id) print("Key :") println_json(key, KeyV1Schema) except (ApiException, ClientException) as e: print(e)