Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::HashChainEntry Struct Reference

A single link in the cryptographic hash chain. More...

#include <audit_chain.hpp>

Public Member Functions

void compute_entry_hash ()
 Derive entry_hash from the other fields.
 
bool verify () const
 Check that entry_hash is consistent with the other fields.
 
std::vector< uint8_t > serialize () const
 Serialize this entry as 112 little-endian bytes.
 

Static Public Member Functions

static expected< HashChainEntrydeserialize (const uint8_t *data, size_t size)
 Reconstruct a HashChainEntry from 112 bytes.
 

Public Attributes

int64_t sequence_number = 0
 0-indexed position in the chain, monotonically increasing.
 
int64_t timestamp_ns = 0
 Nanoseconds since Unix epoch when this entry was created.
 
std::array< uint8_t, 32 > prev_hash {}
 SHA-256 hash of the previous entry (all zeros for the first entry, or a user-supplied continuation hash when spanning files).
 
std::array< uint8_t, 32 > data_hash {}
 SHA-256 hash of the record/row data that this entry covers.
 
std::array< uint8_t, 32 > entry_hash {}
 SHA-256 commitment over (sequence_number, timestamp_ns, prev_hash, data_hash).
 

Detailed Description

A single link in the cryptographic hash chain.

Each entry commits to:

  • Its own data (via data_hash)
  • All prior entries (transitively, via prev_hash)
  • Its position in the chain (via sequence_number)
  • When it was created (via timestamp_ns)

The entry_hash binds all of these fields together:

entry_hash = SHA-256(LE64(sequence_number) || LE64(timestamp_ns)
int64_t sequence_number
0-indexed position in the chain, monotonically increasing.
std::array< uint8_t, 32 > entry_hash
SHA-256 commitment over (sequence_number, timestamp_ns, prev_hash, data_hash).
int64_t timestamp_ns
Nanoseconds since Unix epoch when this entry was created.
std::array< uint8_t, 32 > prev_hash
SHA-256 hash of the previous entry (all zeros for the first entry, or a user-supplied continuation ha...
std::array< uint8_t, 32 > data_hash
SHA-256 hash of the record/row data that this entry covers.

Definition at line 274 of file audit_chain.hpp.

Member Function Documentation

◆ compute_entry_hash()

void signet::forge::HashChainEntry::compute_entry_hash ( )
inline

Derive entry_hash from the other fields.

Must be called after setting sequence_number, timestamp_ns, prev_hash, and data_hash. The AuditChainWriter calls this automatically; manual callers must invoke it explicitly.

Note
Builds an 80-byte preimage: LE64(seq) || LE64(ts) || prev_hash || data_hash.

Definition at line 300 of file audit_chain.hpp.

◆ deserialize()

static expected< HashChainEntry > signet::forge::HashChainEntry::deserialize ( const uint8_t *  data,
size_t  size 
)
inlinestatic

Reconstruct a HashChainEntry from 112 bytes.

Parameters
dataPointer to the serialized binary data.
sizeNumber of bytes available at data.
Returns
The deserialized entry, or an error if the buffer is too small.
Note
Does NOT verify entry_hash – call verify() separately.

Definition at line 366 of file audit_chain.hpp.

◆ serialize()

std::vector< uint8_t > signet::forge::HashChainEntry::serialize ( ) const
inline

Serialize this entry as 112 little-endian bytes.

Layout:

[0:8) sequence_number (int64_t LE)
[8:16) timestamp_ns (int64_t LE)
[16:48) prev_hash (32 bytes, raw)
[48:80) data_hash (32 bytes, raw)
[80:112) entry_hash (32 bytes, raw)
Returns
112-byte vector in the canonical binary format.

Definition at line 348 of file audit_chain.hpp.

◆ verify()

bool signet::forge::HashChainEntry::verify ( ) const
inline

Check that entry_hash is consistent with the other fields.

Recomputes the expected entry_hash and compares it to the stored value. Uses constant-time comparison to prevent timing side channels.

Returns
True if the entry is self-consistent (entry_hash matches recomputed hash).

Definition at line 318 of file audit_chain.hpp.

Member Data Documentation

◆ data_hash

std::array<uint8_t, 32> signet::forge::HashChainEntry::data_hash {}

SHA-256 hash of the record/row data that this entry covers.

Definition at line 286 of file audit_chain.hpp.

◆ entry_hash

std::array<uint8_t, 32> signet::forge::HashChainEntry::entry_hash {}

SHA-256 commitment over (sequence_number, timestamp_ns, prev_hash, data_hash).

This is the cryptographic binding that makes the chain tamper-evident.

Definition at line 291 of file audit_chain.hpp.

◆ prev_hash

std::array<uint8_t, 32> signet::forge::HashChainEntry::prev_hash {}

SHA-256 hash of the previous entry (all zeros for the first entry, or a user-supplied continuation hash when spanning files).

Definition at line 283 of file audit_chain.hpp.

◆ sequence_number

int64_t signet::forge::HashChainEntry::sequence_number = 0

0-indexed position in the chain, monotonically increasing.

Definition at line 276 of file audit_chain.hpp.

◆ timestamp_ns

int64_t signet::forge::HashChainEntry::timestamp_ns = 0

Nanoseconds since Unix epoch when this entry was created.

Definition at line 279 of file audit_chain.hpp.


The documentation for this struct was generated from the following file: