فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(A03): link each committed audit event to previous hash
davoodmehraban89 committed
Oct 20, 2026 at 08:36 UTC
c7f48c03d0f19229dad14a2c9c79e4e48007cafe
1 file changed
+6
src/core/AuditService.js
+6
@@ -48,6 +48,12 @@ class AuditServiceImpl {
48
};
49
// add() cannot overwrite an earlier event and a unique commandKey makes
50
// replay fail atomically. No externally mutable audit status is stored.
51
+ const history = await tx.getAllByIndex('audit_events', 'companyId', companyId);
52
+ const ordered = history.sort((a,b) => (a.chainIndex ?? 0) - (b.chainIndex ?? 0));
53
+ const previous = ordered.at(-1);
54
+ event.chainIndex = ordered.length;
55
+ event.prevHash = previous?.eventHash ?? null;
56
+ event.eventHash = auditHash(event);
57
trustedAuditRows.add(event);
58
await tx.add('audit_events', event);
59
return event;