예제 #1
0
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)
예제 #2
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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)