taple_core/lib.rs
1#![recursion_limit = "256"]
2//! TAPLE is a DLT focused on traceability characterized by its level of scalability,
3//! its flexibility to be employed in different devices and use cases and its reduced resource consumption,
4//! including power consumption.
5//!
6//! The TAPLE crate provides the library that allows instantiating nodes of this DLT in order to create a
7//! functional network through a single structure containing all the required logic.
8//! Applications can interact with these nodes through the API they expose, thus enabling read and write operations
9//! against the network. The API also allows the design and creation of customized clients for the technology
10//! according to the user's needs.
11//!
12//! In addition to the node itself, the library also exposes a series of data structures specific to the protocol
13//! that can be obtained when interacting with the API or, in some cases, may be necessary to interact with it.
14//!
15//! # Basic usage
16//! ```
17//! use std::str::FromStr;
18//!
19//! use taple_core::crypto::*;
20//! use taple_core::request::*;
21//! use taple_core::signature::*;
22//! use taple_core::*;
23//!
24//! /**
25//! * Basic usage of TAPLE Core. It includes:
26//! * - Node inicialization with on-memory DB (only for testing purpouse)
27//! * - Minimal governance creation example
28//! */
29//! #[tokio::main]
30//! async fn main() {
31//! // Generate ramdom node ID key pair
32//! let node_key_pair = crypto::KeyPair::Ed25519(Ed25519KeyPair::from_seed(&[]));
33//!
34//! // Configure minimal settings
35//! let settings = {
36//! let mut settings = Settings::default();
37//! settings.node.secret_key = hex::encode(node_key_pair.secret_key_bytes());
38//! settings
39//! };
40//!
41//! // Build node
42//! let (mut node, api) = Node::build(settings, MemoryManager::new()).expect("TAPLE node built");
43//!
44//! // Create a minimal governance
45//! // Compose and sign the subject creation request
46//! let governance_key = api
47//! .add_keys(KeyDerivator::Ed25519)
48//! .await
49//! .expect("Error getting server response");
50//! let create_subject_request = EventRequest::Create(StartRequest {
51//! governance_id: DigestIdentifier::default(),
52//! name: "".to_string(),
53//! namespace: "".to_string(),
54//! schema_id: "governance".to_string(),
55//! public_key: governance_key,
56//! });
57//! let signed_request = Signed::<EventRequest> {
58//! content: create_subject_request.clone(),
59//! signature: Signature::new(&create_subject_request, &node_key_pair).unwrap(),
60//! };
61//!
62//! // Send the signed request to the node
63//! let _request_id = api.external_request(signed_request).await.unwrap();
64//!
65//! // Wait until event notification
66//! let subject_id = if let Notification::NewEvent { sn: _, subject_id } = node
67//! .recv_notification()
68//! .await
69//! .expect("NewEvent notification received")
70//! {
71//! subject_id
72//! } else {
73//! panic!("Unexpected notification");
74//! };
75//!
76//! // Get the new subject data
77//! let subject = api
78//! .get_subject(DigestIdentifier::from_str(&subject_id).unwrap())
79//! .await
80//! .unwrap_or_else(|_| panic!("Error getting subject"));
81//!
82//! println!("Subject ID: {}", subject.subject_id.to_str());
83//!
84//! node.shutdown_gracefully().await;
85//! }
86//! ```
87//!
88pub(crate) mod api;
89pub(crate) mod approval;
90pub(crate) mod authorized_subjecs;
91pub(crate) mod commons;
92pub(crate) mod database;
93pub(crate) mod distribution;
94pub mod error;
95pub(crate) mod evaluator;
96pub(crate) mod governance;
97pub(crate) mod ledger;
98pub mod message;
99pub(crate) mod network;
100pub(crate) mod utils;
101pub(crate) mod validation;
102
103pub(crate) mod event;
104pub(crate) mod protocol;
105
106mod node;
107pub use api::{Api, ApiError};
108pub use commons::crypto;
109pub use commons::identifier;
110pub use commons::identifier::{Derivable, DigestIdentifier, KeyIdentifier, SignatureIdentifier};
111pub use commons::models::approval::ApprovalRequest;
112pub use commons::models::approval::ApprovalResponse;
113pub use commons::models::approval::{ApprovalEntity, ApprovalState};
114pub use commons::models::evaluation::EvaluationRequest;
115pub use commons::models::evaluation::EvaluationResponse;
116pub use commons::models::event::Event;
117pub use commons::models::event::Metadata;
118pub use commons::models::request;
119pub use commons::models::request::EventRequest;
120pub use commons::models::signature;
121pub use commons::models::state::SubjectData;
122pub use commons::{
123 errors::ListenAddrErrors,
124 identifier::derive::{digest::DigestDerivator, KeyDerivator},
125 models::notification::Notification,
126 models::timestamp::TimeStamp,
127 models::validation::ValidationProof,
128 models::value_wrapper::ValueWrapper,
129 settings::{ListenAddr, NetworkSettings, NodeSettings, Settings},
130};
131pub(crate) use database::DB;
132pub use database::{
133 DatabaseCollection, DatabaseManager, Error as DbError, MemoryCollection, MemoryManager,
134};
135pub use error::Error;
136pub use node::Node;