Crate taple_core

source ·
Expand description

TAPLE is a DLT focused on traceability characterized by its level of scalability, its flexibility to be employed in different devices and use cases and its reduced resource consumption, including power consumption.

The TAPLE crate provides the library that allows instantiating nodes of this DLT in order to create a functional network through a single structure containing all the required logic. Applications can interact with these nodes through the API they expose, thus enabling read and write operations against the network. The API also allows the design and creation of customized clients for the technology according to the user’s needs.

In addition to the node itself, the library also exposes a series of data structures specific to the protocol that can be obtained when interacting with the API or, in some cases, may be necessary to interact with it.

Basic usage

use std::str::FromStr;

use taple_core::crypto::*;
use taple_core::request::*;
use taple_core::signature::*;
use taple_core::*;

/**
 * Basic usage of TAPLE Core. It includes:
 * - Node inicialization with on-memory DB (only for testing purpouse)
 * - Minimal governance creation example
 */
#[tokio::main]
async fn main() {
     // Generate ramdom node ID key pair
     let node_key_pair = crypto::KeyPair::Ed25519(Ed25519KeyPair::from_seed(&[]));

    // Configure minimal settings
    let settings = {
        let mut settings = Settings::default();
        settings.node.secret_key = hex::encode(node_key_pair.secret_key_bytes());
        settings
    };

    // Build node
    let (mut node, api) = Node::build(settings, MemoryManager::new()).expect("TAPLE node built");

    // Create a minimal governance
    // Compose and sign the subject creation request
    let governance_key = api
        .add_keys(KeyDerivator::Ed25519)
        .await
        .expect("Error getting server response");
    let create_subject_request = EventRequest::Create(StartRequest {
        governance_id: DigestIdentifier::default(),
        name: "".to_string(),
        namespace: "".to_string(),
        schema_id: "governance".to_string(),
        public_key: governance_key,
    });
    let signed_request = Signed::<EventRequest> {
        content: create_subject_request.clone(),
        signature: Signature::new(&create_subject_request, &node_key_pair).unwrap(),
    };

    // Send the signed request to the node
    let _request_id = api.external_request(signed_request).await.unwrap();

    // Wait until event notification
    let subject_id = if let Notification::NewEvent { sn: _, subject_id } = node
        .recv_notification()
        .await
        .expect("NewEvent notification received")
    {
        subject_id
    } else {
        panic!("Unexpected notification");
    };

    // Get the new subject data
    let subject = api
        .get_subject(DigestIdentifier::from_str(&subject_id).unwrap())
        .await
        .unwrap_or_else(|_| panic!("Error getting subject"));

    println!("Subject ID: {}", subject.subject_id.to_str());

    node.shutdown_gracefully().await;
}

Re-exports

Modules

  • This module provides the structs and traits for the generation of key pairs for cryptographic operations.
  • Possible errors of a TAPLE Node
  • Identifiers module
  • Contains all valid event requests
  • Define the data structures related to signatures

Macros

Structs

Enums

  • Errors that may occur when using the TAPLE API
  • An enum representing the state of an approval entity.
  • Errors that can be generated by Taple database implementations
  • Enumeration with digest derivator types
  • An enum representing a TAPLE event request.
  • An enumeration of key derivator types.
  • Represents a valid listening address for TAPLE. Internally, they are constituted as a MultiAddr.
  • Errors that can occur during the generation of a [ListenAddr].
  • Notifications generated by [NotificationHandler]. These notifications identify the type of message and its content. In addition, the message is accompanied by the data used to construct the message, so that it can be used to construct customized messages.

Traits