Skip to content
pleach
Compliance

Compliance · HashChainMiddleware

Deprecated. HashChainMiddleware's beforeWrite anchors are not the event-log hash chain and nothing verifies them. EventLogWriter stamps the chain itself; verify with verifyChainForChat or ComplianceRuntime.verifyChain.

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.

Deprecated — use EventLogWriter + verifyChainForChat

createHashChainMiddleware and its types carry @deprecated in @pleach/compliance. They keep working; new code shouldn't adopt them.

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:

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 and The call-row chain.