#p2p #data-type #extensible #secure #distributed #exchange #extension

p2panda-core

Extensible data-types for secure, distributed and efficient exchange of data

1 unstable release

0.1.0 Dec 6, 2024

#459 in Parser implementations

Download history 327/week @ 2024-12-02 335/week @ 2024-12-09

662 downloads per month
Used in 5 crates

MIT/Apache

90KB
1.5K SLoC

p2panda-core

Extensible, secure and distributed data-types

Highly extensible data-types of the p2panda protocol for secure, distributed and efficient exchange of data, supporting networks from the internet to packet radio, LoRa or BLE.

The primary data structure is an append-only implementation which supports history deletion, multi-writer ordering, fork-tolerance, efficient partial sync, compatibility with any CRDT and is extensible depending on your application requirements.

Features

  • Cryptographic signatures for authorship verification and tamper-proof messages
  • Authors can maintain one or many logs
  • Single-writer logs which can be combined to support multi-writer collaboration
  • Compatible with any application data and CRDT
  • Various ordering algorithms
  • Supports efficient, partial sync
  • Compatible with any networking scenario (even broadcast-only, for example for packet radio)
  • Fork-tolerant
  • Pruning of outdated messages
  • Highly extensible with custom features, for example prefix-deletion, ephemeral "self-destructing" messages, etc.

Examples

Create and sign operation

use p2panda_core::{Body, Header, PrivateKey};

let private_key = PrivateKey::new();

let body = Body::new("Hello, Panda!".as_bytes());
let mut header = Header {
    version: 1,
    public_key: private_key.public_key(),
    signature: None,
    payload_size: body.size(),
    payload_hash: Some(body.hash()),
    timestamp: 1733170247,
    seq_num: 0,
    backlink: None,
    previous: vec![],
    extensions: None::<()>,
};

header.sign(&private_key);

Custom extensions

Custom functionality can be added using extensions, for example, access-control tokens, self-destructing messages, or encryption schemas.

use p2panda_core::{Extension, Header, PrivateKey};
use serde::{Serialize, Deserialize};

// Extend our operations with an "expiry" field we can use to implement
// "ephemeral messages" in our application, which get automatically deleted
// after the expiration timestamp is due.
#[derive(Clone, Debug, Default, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct Expiry(u64);

// Multiple extensions can be combined in a custom type.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
struct CustomExtensions {
    expiry: Expiry,
}

// Implement `Extension<T>` for each extension we want to add to our
// custom extensions.
impl Extension<Expiry> for CustomExtensions {
    fn extract(&self) -> Option<Expiry> {
        Some(self.expiry.to_owned())
    }
}

// Create a custom extension instance, this can be added to an operation's
// header.
let extensions = CustomExtensions {
    expiry: Expiry(1733170246),
};

// Extract the extension we are interested in.
let expiry: Expiry = extensions.extract().expect("expiry field should be set");

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in p2panda by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


This project has received funding from the European Union’s Horizon 2020 research and innovation programme within the framework of the NGI-POINTER Project funded under grant agreement No 871528, NGI-ASSURE No 957073 and NGI0-ENTRUST No 101069594.

Dependencies

~4–6MB
~133K SLoC