feat: 初始化项目结构并添加核心功能模块

- 新增文档模板和导航结构
- 实现服务器基础API路由和控制器
- 添加扩展插件配置和前端框架
- 引入多租户和权限管理模块
- 集成日志和数据库配置
- 添加核心业务模型和类型定义
This commit is contained in:
2026-03-17 22:07:19 +08:00
parent c0870dce50
commit 136c2fa579
728 changed files with 107690 additions and 5614 deletions

View File

@@ -0,0 +1,106 @@
import { Request, Response } from 'express';
import { SecretDeliveryService } from '../../core/protocols/SecretDeliveryService';
import { NodeIdentityService } from '../../core/security/NodeIdentityService';
import { ReputationZKPService } from '../../core/ai/ReputationZKPService';
export class NodeController {
/**
* [FE_SEC_01] 获取节点的 ZKP 隐私声誉证明
*/
static async getZkpProof(req: Request, res: Response) {
try {
const { nodeId } = req.query;
if (!nodeId) return res.status(400).json({ success: false, error: 'nodeId is required' });
const proof = await ReputationZKPService.generateReputationProof(nodeId as string);
res.json({ success: true, data: proof });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
/**
* [FE_SEC_01] 校验节点的 ZKP 证明
*/
static async verifyZkpProof(req: Request, res: Response) {
try {
const { nodeId, proof, publicSignals } = req.body;
if (!nodeId || !proof || !publicSignals) {
return res.status(400).json({ success: false, error: 'Missing nodeId, proof, or publicSignals' });
}
const isValid = await ReputationZKPService.verifyReputationProof(proof, publicSignals);
res.json({ success: true, data: { isValid } });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
static async getAll(req: Request, res: Response) {
res.json({ success: true, data: [] });
}
/**
* [CORE_SEC_04] 节点身份注册 (基于硬件指纹)
*/
static async register(req: Request, res: Response) {
try {
const { nodeId, hardwareFingerprint, publicKey } = req.body;
if (!nodeId || !hardwareFingerprint || !publicKey) {
return res.status(400).json({ success: false, error: 'Missing registration fields' });
}
const success = await NodeIdentityService.registerNode({
nodeId,
hardwareFingerprint,
publicKey
});
if (!success) {
return res.status(403).json({ success: false, error: 'Fingerprint mismatch or unauthorized access' });
}
res.json({ success: true, message: 'Node registration pending approval' });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
/**
* [CORE_SEC_03] 为节点任务请求会话密钥
*/
static async requestSession(req: Request, res: Response) {
try {
const { nodeId, shopId, taskId } = req.body;
if (!nodeId || !shopId || !taskId) {
return res.status(400).json({ success: false, error: 'Missing required fields' });
}
const session = await SecretDeliveryService.createSession(nodeId, shopId, taskId);
res.json({ success: true, data: { sessionId: session.sessionId, expiresAt: session.expiresAt } });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
/**
* [CORE_SEC_03] 节点获取加密凭据负载
*/
static async getCredential(req: Request, res: Response) {
try {
const { sessionId, credentialId } = req.query;
if (!sessionId || !credentialId) {
return res.status(400).json({ success: false, error: 'Missing sessionId or credentialId' });
}
const payload = await SecretDeliveryService.getDeliveryPayload(
String(sessionId),
Number(credentialId)
);
res.json({ success: true, data: payload });
} catch (err: any) {
res.status(500).json({ success: false, error: err.message });
}
}
}