hypercore/
lib.rs

1#![forbid(unsafe_code, future_incompatible)]
2#![forbid(rust_2018_idioms, rust_2018_compatibility)]
3#![forbid(missing_debug_implementations)]
4#![forbid(missing_docs)]
5#![warn(unreachable_pub)]
6#![cfg_attr(test, deny(warnings))]
7#![doc(test(attr(deny(warnings))))]
8
9//! ## Introduction
10//!
11//! Hypercore is a secure, distributed append-only log. Built for sharing
12//! large datasets and streams of real time data as part of the [Dat] project.
13//! This is a rust port of [the original Javascript version][holepunch-hypercore]
14//! aiming for interoperability with LTS version. The primary way to use this
15//! crate is through the [Hypercore] struct, which can be created using the
16//! [HypercoreBuilder].
17//!
18//! This crate supports WASM with `cargo build --target=wasm32-unknown-unknown`.
19//!
20//! ## Features
21//!
22//! ### `sparse` (default)
23//!
24//! When using disk storage, clearing values may create sparse files. On by default.
25//!
26//! ### `async-std` (default)
27//!
28//! Use the async-std runtime, on by default. Either this or `tokio` is mandatory.
29//!
30//! ### `tokio`
31//!
32//! Use the tokio runtime. Either this or `async_std` is mandatory.
33//!
34//! ### `cache`
35//!
36//! Use a moka cache for merkle tree nodes to speed-up reading.
37//!
38//! ## Example
39//! ```rust
40//! # #[cfg(feature = "tokio")]
41//! # tokio_test::block_on(async {
42//! # example().await;
43//! # });
44//! # #[cfg(feature = "async-std")]
45//! # async_std::task::block_on(async {
46//! # example().await;
47//! # });
48//! # async fn example() {
49//! use hypercore::{HypercoreBuilder, Storage};
50//!
51//! // Create an in-memory hypercore using a builder
52//! let mut hypercore = HypercoreBuilder::new(Storage::new_memory().await.unwrap())
53//!     .build()
54//!     .await
55//!     .unwrap();
56//!
57//! // Append entries to the log
58//! hypercore.append(b"Hello, ").await.unwrap();
59//! hypercore.append(b"world!").await.unwrap();
60//!
61//! // Read entries from the log
62//! assert_eq!(hypercore.get(0).await.unwrap().unwrap(), b"Hello, ");
63//! assert_eq!(hypercore.get(1).await.unwrap().unwrap(), b"world!");
64//! # }
65//! ```
66//!
67//! Find more examples in the [examples] folder.
68//!
69//! [Dat]: https://github.com/datrs
70//! [holepunch-hypercore]: https://github.com/holepunchto/hypercore
71//! [Hypercore]: crate::core::Hypercore
72//! [HypercoreBuilder]: crate::builder::HypercoreBuilder
73//! [examples]: https://github.com/datrs/hypercore/tree/master/examples
74
75pub mod encoding;
76pub mod prelude;
77#[cfg(feature = "replication")]
78pub mod replication;
79
80mod bitfield;
81mod builder;
82mod common;
83mod core;
84mod crypto;
85mod data;
86mod oplog;
87mod storage;
88mod tree;
89
90#[cfg(feature = "cache")]
91pub use crate::builder::CacheOptionsBuilder;
92pub use crate::builder::HypercoreBuilder;
93pub use crate::common::{
94    DataBlock, DataHash, DataSeek, DataUpgrade, HypercoreError, Node, Proof, RequestBlock,
95    RequestSeek, RequestUpgrade, Store,
96};
97pub use crate::core::{AppendOutcome, Hypercore, Info};
98pub use crate::crypto::{generate_signing_key, sign, verify, PartialKeypair};
99pub use crate::storage::{Storage, StorageTraits};
100pub use ed25519_dalek::{
101    SecretKey, Signature, SigningKey, VerifyingKey, KEYPAIR_LENGTH, PUBLIC_KEY_LENGTH,
102    SECRET_KEY_LENGTH,
103};