Elydora Chain Hash (ECH)
The ECH provides tamper-evident chain-linking between consecutive operations from the same agent. Each chain hash incorporates the previous hash, creating an ordered, verifiable sequence.
Structure
| Field | Type | Required | Description |
|---|---|---|---|
| prev_ech | string | Yes | The previous chain hash in the sequence. The first operation uses the genesis constant. |
| payload_hash | string | Yes | SHA-256 hash of the current operation's canonicalized payload. |
| operation_id | string | Yes | UUID of the current operation. |
| issued_at | number | Yes | Unix millisecond timestamp of the current operation. |
| chain_hash | string | Yes | base64url(SHA-256(prev_ech | payload_hash | operation_id | issued_at)) |
Computation
The chain hash is the base64url SHA-256 of the previous chain hash, the payload hash, the operation ID, and the issued_at timestamp joined with "|".
import { sha256Base64url, ZERO_CHAIN_HASH } from '@elydora/sdk';
function computeChainHash(
prevChainHash: string, // ZERO_CHAIN_HASH for the first operation
payloadHash: string,
operationId: string,
issuedAt: number,
): string {
return sha256Base64url(`${prevChainHash}|${payloadHash}|${operationId}|${issuedAt}`);
}Verification
To verify a chain, walk backwards from the most recent operation and recompute each chain hash. If any computed hash does not match the stored hash, the chain has been tampered with.
- Gap detection — A missing operation in the chain will cause a prev_chain_hash mismatch on the following operation.
- Reorder detection — Reordering operations will break the chain hash sequence.
- Modification detection — Modifying any operation's payload changes its payload_hash, which breaks the chain.
Error: PREV_HASH_MISMATCH
If an agent submits an operation whose prev_chain_hash does not match the server's expected value, the submission is rejected with PREV_HASH_MISMATCH. Causes include a concurrent submission, a missed operation, or a client that computed prev_chain_hash incorrectly.