# Compliance · HashChainMiddleware (/docs/compliance/hashchain-middleware)



`HashChainMiddleware` stamped a `rowHash` and `prevHash` on each event before the host's `EventLogWriter` persisted it. It was single-scope: one instance per `(tenantId, chatId)` pair.

<Callout type="warn" title="Deprecated — use EventLogWriter + verifyChainForChat">
  `createHashChainMiddleware` and its types carry `@deprecated` in
  `@pleach/compliance`. They keep working; new code shouldn't adopt them.
</Callout>

The anchors it stamps cover less than the real chain hash, and nothing verifies them. `EventLogWriter` ignores them and stamps its own hashes at write time, so `verifyChainForChat` never checks them.

The replacement already runs on every chat-scoped write. Let `EventLogWriter` (`@pleach/core/eventLog`) stamp the chain. Then verify with `verifyChainForChat` (`@pleach/core/eventLog`) or `ComplianceRuntime.verifyChain` (`@pleach/compliance`). Read `sequenceNumbersVerified` beside `valid`.

If you still import the helper, this is the import:

```ts
import { createHashChainMiddleware } from "@pleach/compliance/hashchain";
```

`verifyAfterBatch` returns `chainValid` with an `outcome`. An empty batch reports `chainValid: true` (nothing to verify), and verification-unavailable reports `chainValid: false`. A verification error doesn't throw; an integrity break throws `ChainVerificationError`. Pair `chainValid` with `outcome`.

The per-call ledger needs no middleware either: `PostgresProviderDecisionLedger` stamps its own call-row chain by default.

For the full chain, see [Hash chain](/docs/hash-chain) and [The call-row chain](/docs/hash-chain#the-call-row-chain).
