Crate bamboo_rs_core[][src]

Expand description

bamboo-rs-core

Verify, Publish and Decode bamboo entries.

About

From the spec:

A cryptographically secure, distributed, single-writer append-only log that supports transitive partial replication and local deletion of data.

Powered by science, this log format can serve as a more efficient alternative to secure-scuttlebutt’s linked lists or hypercore’s merkle forests.

bamboo-rs-core exposes low level functions and types which can be built with no_std.

Example

publish, verify and decode the first Entry in a bamboo log.

NB: Publishing and verifying the first entry is the most simple case. The subsequent entries require passing the previous seq_num, the previous entry, and lipmaa_link.

use bamboo_rs_core::{publish, verify, decode, yamf_hash::new_blake2b, Entry, Signature, YamfHash, Keypair, entry::MAX_ENTRY_SIZE};
use rand::rngs::OsRng;

let mut csprng: OsRng = OsRng {};
let key_pair: Keypair = Keypair::generate(&mut csprng);
let log_id = 0;

let payload = "hello bamboo!";
let mut out = [0u8; MAX_ENTRY_SIZE];

let size = publish(
    &mut out,
    &key_pair,
    log_id,
    payload.as_bytes(),
    false,
    None,
    None,
    None,
)
.unwrap();

let entry = decode(&out[..size]).unwrap();

let is_verified = verify(&out[..size], Some(payload.as_bytes()), None, None).is_ok();
let payload_hash = new_blake2b(payload.as_bytes());

assert!(is_verified);
assert_eq!(entry.log_id, log_id);
assert_eq!(entry.payload_hash, payload_hash);
assert_eq!(entry.author, key_pair.public);
assert_eq!(entry.lipmaa_link, None);
assert_eq!(entry.backlink, None);
assert_eq!(entry.is_end_of_feed, false);

Re-exports

pub use entry::verify::verify_batch;
pub use entry::decode;
pub use entry::decode;
pub use entry::publish;
pub use entry::publish;
pub use entry::verify;
pub use entry::verify;
pub use entry::Entry;
pub use signature::Signature;
pub use signature::ED25519_SIGNATURE_SIZE;

Modules

entry
signature
yamf_hash

Structs

Keypair

An ed25519 keypair.

PublicKey

An ed25519 public key.

SecretKey

An EdDSA secret key.

Enums

YamfHash

Variants of YamfHash

Constants

BLAKE2B_HASH_SIZE
OUTBYTES

The max hash length.

Functions

lipmaa

Calculates the lipmaa link number given the current sequence number.

Type Definitions

SignatureError

Errors which may occur while processing signatures and keypairs.