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::crypto::Ed25519KeyPair;
use taple_core::crypto::KeyGenerator;
use taple_core::crypto::KeyMaterial;
use taple_core::get_default_settings;
use taple_core::request::StartRequest;
use taple_core::signature::Signature;
use taple_core::signature::Signed;
use taple_core::ApiModuleInterface;
use taple_core::Derivable;
use taple_core::DigestIdentifier;
use taple_core::EventRequest;
use taple_core::KeyDerivator;
use taple_core::KeyIdentifier;
use taple_core::MemoryManager;
use taple_core::Notification;
use taple_core::Taple;
/**
* 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() -> Result<(), ()> {
// Generate ramdom node cryptographic material and ID
let node_key_pair = crypto::KeyPair::Ed25519(Ed25519KeyPair::from_seed(&[]));
let node_identifier = KeyIdentifier::new(
node_key_pair.get_key_derivator(),
&node_key_pair.public_key_bytes(),
);
// Build and start up the TAPLE node
let mut settings = get_default_settings();
settings.node.secret_key = Some(hex::encode(&node_key_pair.secret_key_bytes()));
let mut taple = Taple::new(settings, MemoryManager::new());
let mut notifier = taple.get_notification_handler();
let shutdown_manager = taple.get_shutdown_manager();
let api = taple.get_api();
taple.start().await.expect("TAPLE started");
// Create a minimal governance
// Compose and sign the subject creation request
let new_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: new_key,
});
let signed_request = Signed::<EventRequest> {
content: create_subject_request.clone(),
signature: Signature::new(&create_subject_request, node_identifier, &node_key_pair)
.unwrap(),
};
// Send the signed request to the node
let _request_id = api.external_request(signed_request).await.unwrap();
// Wait until notification of subject creation
let subject_id =
if let Notification::NewSubject { subject_id } = notifier.receive().await.unwrap() {
subject_id
} else {
panic!("Unexpected notification");
};
// Get the new subject data
let subject_id =
DigestIdentifier::from_str(&subject_id).expect("DigestIdentifier from str failed");
let subject = api.get_subject(subject_id.clone()).await.expect(&format!(
"Error getting subject content with id: {}",
subject_id.to_str()
));
println!("{:#?}", subject);
// Shutdown the TAPLE node
shutdown_manager.shutdown().await;
Ok(())
}
Re-exports
pub use error::Error;
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
- Allows a TAPLE database implementation to be subjected to a battery of tests. The use must specify both a valid implementation of DatabaseManager and DatabaseCollection
Structs
- A struct representing an approval entity.
- A struct representing an approval request.
- A struct representing an approval response.
- Digest based identifier
- A struct representing an evaluation request.
- A struct representing an evaluation response.
- A struct representing an event.
- Key based identifier
- Collection for in-memory database implementation. It must be created through MemoryManager.
- In-memory database implementation for TAPLE.
- A struct representing the metadata of a TAPLE event.
- P2P network configuration parameters of a TAPLE node.
- Object that allows interaction with a TAPLE node.
- General settings of a TAPLE node.
- Object that allows receiving notifications of the different events of relevance that a node performs and/or detects.
- Signature based identifier
- A struct representing the data associated with a TAPLE subject.
- Structure representing a node of a TAPLE network.
- Configuration parameters of a TAPLE node divided into categories.
- Structure that allows a signal to be emitted to stop the TAPLE node. It can also be used to detect internal shutdown signals, which occur when an internal error occurs.
- A struct representing a timestamp.
- A struct representing a validation proof.
- Wrapper of serde_json::Value implementing serialization and deserialization with Borsh.
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
- Trait that allows implementing the interface of a TAPLE node. The only native implementation is NodeAPI. Users can use the trait to add specific behaviors to an existing node interface. For example, a NodeAPI wrapper could be created that again implements the trait and perform certain intermediate operations, such as incrementing a counter to find out how many API queries have been made.
- A trait representing a collection of key-value pairs in a database.
- Trait to define a database compatible with Taple
- Derivable Identifiers
Functions
- Instance a default settings to start a new Taple Node