Validate Blocks
Block validation recomputes contentHash and blockHash, compares both values with the stored identities, and reports whether the complete Block record is internally consistent.
Why Validation Should Happen at Boundaries
Stored or transported content can change independently from recorded identities. Recomputing both hashes before processing a Block detects mismatched content, lineage, or stored identity fields without interpreting the payload.
Validate the Block
import {validateBlock} from '@alx-protocol/sdk';
const result = validateBlock(block);
if (!result.ok) {
console.error({
blockHash: result.blockHash,
contentHash: result.contentHash,
});
process.exitCode = 1;
}
A successful result confirms that the supplied content and parent set reproduce both stored identities.
When ok is false, inspect each match value and compare the stored and recomputed hashes. For a non-root Block, run graph validation separately to confirm that referenced parents exist and the graph is structurally valid.
When to Validate
Validate a Block after loading the Block from storage, receiving the Block from another system, or before using the Block as a graph or commitment input.