games_app/backend/dist/services/securityService.d.ts
2026-11-15 16:14:38 +02:00

76 lines
3.3 KiB
TypeScript

/**
* Platform security: ledger integrity, alerts, withdrawal suspension, admin notifications.
*/
import * as ledgerIntegrityRepository from '../repositories/ledgerIntegrityRepository';
import type { SecurityAlert, SecurityAlertSeverity, SecurityAlertStatus } from '../models/security.model';
/** Ledger entry types that may credit or debit user balances. */
export declare const AUTHORIZED_LEDGER_TYPES: Set<string>;
export declare class SecurityBlockedError extends Error {
constructor(message: string);
}
export declare function assertUserCanWithdraw(userId: string): Promise<void>;
export declare function suspendUserForSecurity(userId: string, reason: string, alertType: string, severity?: SecurityAlertSeverity): Promise<void>;
export declare function raiseAlert(input: {
userId?: string | null;
severity: SecurityAlertSeverity;
alertType: string;
title: string;
details?: string;
metadata?: Record<string, unknown>;
suspendUser?: boolean;
}): Promise<SecurityAlert>;
export declare function notifyAdminsOfAlert(alert: SecurityAlert): Promise<void>;
export declare function resolveAlert(alertId: string, adminUserId: string, status: SecurityAlertStatus, resolutionNote?: string, reactivateWithdrawals?: boolean): Promise<SecurityAlert | null>;
export type IntegrityIssue = {
userId: string;
walletTypeId: number;
accountId: string;
available: string;
locked: string;
entriesSum: string;
issue: string;
entryId?: string;
amount?: string;
};
/**
* Detects balance inflation/deflation without a matching ledger entry change.
*
* Lock/unlock (withdrawal reserve / cancel) reshuffles available↔locked while keeping
* (available + locked) and entries_sum unchanged — that must NOT count as tamper.
* Real direct tamper changes the total while entries stay the same.
*/
export declare function isDirectBalanceTamper(snap: Pick<ledgerIntegrityRepository.LedgerSnapshotRow, 'available_balance' | 'locked_balance' | 'entries_sum' | 'last_entry_at'>, meta: Pick<ledgerIntegrityRepository.AccountLedgerMeta, 'available_balance' | 'locked_balance' | 'entries_sum' | 'last_entry_at'>): boolean;
export declare function runLedgerIntegrityCheck(): Promise<IntegrityIssue[]>;
export declare function getSecuritySettings(): Promise<{
alertEmails: string[];
}>;
export declare function updateSecuritySettings(alertEmails: string[]): Promise<{
alertEmails: string[];
}>;
export declare function listSecurityAlerts(opts: {
status?: SecurityAlertStatus;
userId?: string;
limit?: number;
offset?: number;
}): Promise<{
items: {
id: string;
userId: string | null;
severity: "low" | "medium" | "high" | "critical";
alertType: string;
status: "open" | "investigating" | "resolved" | "dismissed";
title: string;
details: string | null;
metadata: Record<string, unknown> | null;
resolvedBy: string | null;
resolvedAt: Date | null;
resolutionNote: string | null;
createdAt: Date;
updatedAt: Date;
}[];
total: number;
}>;
export declare function getIntegrityCheckIntervalMs(): number;
/** Dismisses false-positive alerts caused by the security_alerts INSERT detection loop (pre-fix). */
export declare function dismissSpuriousTamperAlerts(adminUserId: string): Promise<number>;
//# sourceMappingURL=securityService.d.ts.map