Ejemplo n.º 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)
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)
Ejemplo n.º 3
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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
 def get_state_ids(self, signer_company_bcid: str) -> str:
     return dict[get_certificate_id_key(
     ):concat_fqid(signer_company_bcid, self.id)]
Ejemplo n.º 6
0
 def get_state_ids(self, signer_company_id: str) -> dict:
     return dict[get_key_id_key():concat_fqid(signer_company_id, self.id)]
Ejemplo n.º 7
0
 def retrieve_certificate(self, company_id, id: str) -> TxData:
     # Fetches the API and returns a certificate from the state.
     return self.api_handler.retrieve_certificate(concat_fqid(company_id, id))
Ejemplo n.º 8
0
 def retrieve_last_key_tx(self, company_id, id: str) -> TxResult:
     # Fetches the API and returns the last tx related to a key fqid.
     return self.api_handler.retrieve_last_key_tx(concat_fqid(company_id, id))
Ejemplo n.º 9
0
 def retrieve_key_txs(self, company_id, id: str, page, tx_per_page: int) -> TxResults:
     # Fetches the API and returns all txs related to a key fqid.
     return self.api_handler.retrieve_key_txs(concat_fqid(company_id, id), page, tx_per_page)
Ejemplo n.º 10
0
 def retrieve_key(self, company_id, id: str) -> KeyV1:
     # Fetches the API and returns a key from the state.
     return self.api_handler.retrieve_key(concat_fqid(company_id, id))
Ejemplo n.º 11
0
 def retrieve_secret(self, company_id, id: str) -> TxData:
     # Fetches the API and returns a secret from the state.
     return self.api_handler.retrieve_secret(concat_fqid(company_id, id))