فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

feat: validate restored chain

davoodmehraban89 committed Oct 20, 2026 at 08:37 UTC ca157512f697e43ebe9a2ccada35e53bcda26358
1 file changed +6 -1
src/core/AuditService.js
+6 -1
@@ -85,8 +85,13 @@ class AuditServiceImpl {
85 (row.occurredAtUtc !== undefined && !validUtc(row.occurredAtUtc))) {
86 throw new Error('رکورد تاریخچه ممیزی نامعتبر است');
87 }
88 + const existing = await tx.getAllByIndex('audit_events', 'companyId', row.companyId);
89 + const history = existing.sort((a,b) => (a.chainIndex ?? 0) - (b.chainIndex ?? 0));
90 + const copy = normalizeLegacyAudit(row, history.length, history.at(-1)?.eventHash ?? null);
91 + if (copy.chainIndex !== history.length || copy.prevHash !== (history.at(-1)?.eventHash ?? null) || copy.eventHash !== auditHash(copy)) {
92 + throw new Error('زنجیره ممیزی فایل پشتیبان نامعتبر است');
93 + }
94 authorization.delete(row);
89 - const copy = { ...row };
95 trustedAuditRows.add(copy);
96 await tx.add('audit_events', copy);
97 }