Elydora Docs

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

FieldTypeRequiredDescription
prev_echstringYesThe previous chain hash in the sequence. The first operation uses the genesis constant.
payload_hashstringYesSHA-256 hash of the current operation's canonicalized payload.
operation_idstringYesUUID of the current operation.
issued_atnumberYesUnix millisecond timestamp of the current operation.
chain_hashstringYesbase64url(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 "|".

typescript
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.

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.