-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI Risk Engine Hook (QVAC-style)
More file actions
69 lines (42 loc) · 2.28 KB
/
Copy pathAI Risk Engine Hook (QVAC-style)
File metadata and controls
69 lines (42 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// AI Risk Engine Hook (QVAC-style) // ============================================= // Goal: // - AI is READ-ONLY // - AI cannot sign / send transactions // - AI only scores & explains risk
/* Directory (new):
ai/ └── risk-engine/ ├── RiskTypes.ts ├── RiskModel.ts └── RiskHook.ts */
// ============================================= // ai/risk-engine/RiskTypes.ts // =============================================
export type RiskLevel = 'LOW' | 'MEDIUM' | 'HIGH';
export interface RiskReport { level: RiskLevel; score: number; // 0 - 100 reasons: string[]; }
export interface TransactionIntent { to: string; valueEth: string; data?: string; }
// ============================================= // ai/risk-engine/RiskModel.ts // =============================================
import { RiskReport, TransactionIntent } from './RiskTypes';
export class RiskModel { static analyze(tx: TransactionIntent): RiskReport { let score = 0; const reasons: string[] = [];
// Heuristic 1: Empty data, large transfer
if (!tx.data && Number(tx.valueEth) > 1) {
score += 40;
reasons.push('Large value transfer without contract data');
}
// Heuristic 2: Suspicious address pattern (placeholder)
if (tx.to.startsWith('0x000')) {
score += 60;
reasons.push('Suspicious destination address');
}
let level: RiskReport['level'] = 'LOW';
if (score >= 70) level = 'HIGH';
else if (score >= 30) level = 'MEDIUM';
return {
level,
score,
reasons,
};
} }
// ============================================= // ai/risk-engine/RiskHook.ts // =============================================
import { TransactionIntent, RiskReport } from './RiskTypes'; import { RiskModel } from './RiskModel';
export function runRiskEngine(tx: TransactionIntent): RiskReport { return RiskModel.analyze(tx); }
// ============================================= // INTEGRATION EXAMPLE (Wallet Flow) // =============================================
/* import { runRiskEngine } from '@/ai/risk-engine/RiskHook';
const intent = { to: '0x000abc123...', valueEth: '2.5', };
const risk = runRiskEngine(intent);
if (risk.level === 'HIGH') { // Show warning UI // Require extra user confirmation } */
/* SECURITY GUARANTEES:
AI has NO access to private keys
AI cannot modify transaction
AI cannot auto-execute
Final authority = USER */