| Crates.io | p2panda-core |
| lib.rs | p2panda-core |
| version | 0.4.0 |
| created_at | 2024-12-06 17:45:08.39719+00 |
| updated_at | 2025-07-07 16:09:24.063128+00 |
| description | Extensible data-types for secure, distributed and efficient exchange of data |
| homepage | |
| repository | https://github.com/p2panda/p2panda |
| max_upload_size | |
| id | 1474487 |
| size | 107,498 |
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.
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 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
// header.
impl Extension<Expiry> for CustomExtensions {
fn extract(header: &Header<Self>) -> Option<Expiry> {
header
.extensions
.as_ref()
.map(|extensions| extensions.expiry.clone())
}
}
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.