pub struct Header<E = ()> {
pub version: Version,
pub verifying_key: VerifyingKey,
pub signature: Signature,
pub payload_size: PayloadSize,
pub payload_hash: Option<Hash>,
pub seq_num: SeqNum,
pub backlink: Option<Hash>,
pub extensions: E,
/* private fields */
}Expand description
Header of a p2panda operation with known extensions type.
The header holds all metadata required to cryptographically secure and authenticate a message
Body and it’s custom extensions.
See AnyHeader for dealing with headers when you don’t care about the concrete extensions
type (E).
§Example
use p2panda_core::{Header, SigningKey};
let signing_key = SigningKey::generate();
let header = Header::builder()
.body(b"Hello, Icebear!")
// Sign the header with the author's private key.
.build(&signing_key, ());Fields§
§version: VersionOperation format version, allowing backwards compatibility when specification changes.
verifying_key: VerifyingKeyAuthor of this operation.
signature: SignatureSignature by author over all fields in header, providing authenticity.
payload_size: PayloadSizeNumber 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.
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 additional data.
Implementations§
Source§impl<E> Header<E>where
E: Extensions,
impl<E> Header<E>where
E: Extensions,
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, HeaderError>
pub fn decode(bytes: &[u8]) -> Result<Self, HeaderError>
Attempts decoding header from bytes.
This might fail if integrity checks failed or header formatting is invalid.
Trait Implementations§
Source§impl<'a, E> Arbitrary<'a> for Header<E>where
E: Default + Extensions,
Available on crate feature arbitrary only.
impl<'a, E> Arbitrary<'a> for Header<E>where
E: Default + Extensions,
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
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 moreSource§impl<E> Chain<Hash> for Header<E>where
E: Extensions,
impl<E> Chain<Hash> for Header<E>where
E: Extensions,
Source§impl<E> Default for Header<E>where
E: Default,
Available on crate features test_utils only.
impl<E> Default for Header<E>where
E: Default,
test_utils only.Source§fn default() -> Self
fn default() -> Self
This is for hacky low-level access to this type, don’t use this in production.
Size and digest get re-computed whenever called in test environments. Note that we can’t
re-encode extensions_cbor if E was changed in a test. Ideally you don’t want to test
extensions-related code here anyway.