pub struct Header<E = ()> {
pub version: u64,
pub public_key: PublicKey,
pub signature: Option<Signature>,
pub payload_size: u64,
pub payload_hash: Option<Hash>,
pub timestamp: u64,
pub seq_num: u64,
pub backlink: Option<Hash>,
pub previous: Vec<Hash>,
pub extensions: Option<E>,
}Expand description
Header of a p2panda operation.
The header holds all metadata required to cryptographically secure and authenticate a message
Body and, if required, apply ordering to collections of messages from the same or many
authors.
§Example
use p2panda_core::{Body, Header, Operation, PrivateKey};
let private_key = PrivateKey::new();
let body = Body::new("Hello, Sloth!".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::<()>,
};
// Sign the header with the author's private key.
header.sign(&private_key);Fields§
§version: u64Operation format version, allowing backwards compatibility when specification changes.
public_key: PublicKeyAuthor of this operation.
signature: Option<Signature>Signature by author over all fields in header, providing authenticity.
payload_size: u64Number of bytes of the body of this operation, must be zero if no body is given.
payload_hash: Option<Hash>Hash of the body of this operation, must be included if payload_size is non-zero and omitted otherwise.
Keeping the hash here allows us to delete the payload (off-chain data) while retaining the ability to check the signature of the header.
timestamp: u64Time in microseconds since the Unix epoch.
seq_num: u64Number of operations this author has published to this log, begins with 0 and is always incremented by 1 with each new operation by the same author.
backlink: Option<Hash>Hash of the previous operation of the same author and log. Can be omitted if first operation in log.
previous: Vec<Hash>List of hashes of the operations we refer to as the “previous” ones. These are operations from other authors. Can be left empty if no partial ordering is required or no other author has been observed yet.
extensions: Option<E>Custom meta data.
Implementations§
Source§impl<E> Header<E>where
E: Extensions,
impl<E> Header<E>where
E: Extensions,
Sourcepub fn sign(&mut self, private_key: &PrivateKey)
pub fn sign(&mut self, private_key: &PrivateKey)
Add a signature to the header using the provided PrivateKey.
This method signs the byte representation of a header with any existing signature removed before adding back the newly generated signature.
Sourcepub fn verify(&self) -> bool
pub fn verify(&self) -> bool
Verify that the signature contained in this Header was generated by the claimed
public key.
Trait Implementations§
Source§impl<'arbitrary, E: Arbitrary<'arbitrary>> Arbitrary<'arbitrary> for Header<E>
impl<'arbitrary, E: Arbitrary<'arbitrary>> Arbitrary<'arbitrary> for Header<E>
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read more