corestore 0.1.0

Create and manage collections of related Hypercores, like JavaScript's corestore
Documentation

corestore

crates.io docs.rs

Create and manage collections of related Hypercores, and replicate them all over one connection. The Rust counterpart of JavaScript's corestore, with the same on-disk layout.

Example

use corestore::Corestore;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), corestore::Error> {
    let store = Corestore::new_mem().await;

    // A named core is created on first use, with a key pair derived from the store's primary
    // key and the name.
    let feed = store.get_from_name("my-feed").await?;
    feed.append(b"hello").await?;
    assert_eq!(feed.get(0).await?, Some(b"hello".to_vec()));

    // The same name always gives the same core.
    let same_feed = store.get_from_name("my-feed").await?;
    assert_eq!(same_feed.key_pair().public, feed.key_pair().public);
    Ok(())
}
  • Corestore::new_disk(path) keeps the store on disk. Reopening the path restores its primary key, so named cores keep their identity across restarts.
  • get_from_verifying_key opens someone else's core, read-only.
  • replicate(stream) replicates every core in the store, including ones opened later, over one encrypted connection (a hypercore::hypercore_handshake CipherTrait stream). Poll the returned CorestoreConnection to drive it.

Status

Get and create cores by name or key, in memory or on disk (matching JS's disk output), and replicate them. Not yet implemented: namespaces.

License

MIT OR Apache-2.0