pub struct Header<E = ()> {
pub version: u64,
pub verifying_key: VerifyingKey,
pub signature: Option<Signature>,
pub payload_size: u64,
pub payload_hash: Option<Hash>,
pub timestamp: Timestamp,
pub seq_num: SeqNum,
pub backlink: Option<Hash>,
pub extensions: 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, SigningKey, Timestamp};
let signing_key = SigningKey::generate();
let body = Body::new("Hello, Sloth!".as_bytes());
let mut header = Header {
version: 1,
verifying_key: signing_key.verifying_key(),
signature: None,
payload_size: body.size(),
payload_hash: Some(body.hash()),
timestamp: Timestamp::now(),
seq_num: 0,
backlink: None,
extensions: (),
};
// Sign the header with the author's private key.
header.sign(&signing_key);Fields§
§version: u64Operation format version, allowing backwards compatibility when specification changes.
verifying_key: VerifyingKeyAuthor 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: TimestampTime in microseconds since the Unix epoch.
seq_num: SeqNumNumber 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.
extensions: ECustom meta data.
Implementations§
Source§impl<E> Header<E>where
E: Extensions,
impl<E> Header<E>where
E: Extensions,
Sourcepub fn sign(&mut self, signing_key: &SigningKey)
pub fn sign(&mut self, signing_key: &SigningKey)
Add a signature to the header using the provided SigningKey.
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