@dooor-ai/trust
Version:
TEE Attestation and Confidential Computing utilities for Dooor OS
78 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TEEOperationLoggerService = void 0;
const crypto_1 = require("crypto");
class TEEOperationLoggerService {
constructor() {
this.operations = [];
this.maxOperations = 1000;
}
logOperation(method, endpoint, executionTime, statusCode, userId) {
const timestamp = new Date().toISOString();
const id = `op-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
const operationData = {
id,
timestamp,
method,
endpoint,
executionTime,
statusCode,
userId: userId || 'anonymous'
};
const operationHash = (0, crypto_1.createHash)('sha256')
.update(JSON.stringify(operationData))
.digest('hex');
const operation = {
id,
timestamp,
method,
endpoint,
execution_time_ms: executionTime,
status_code: statusCode,
user_id: userId,
operation_hash: operationHash,
tee_attestation_snippet: `tee-${operationHash.substring(0, 16)}`
};
this.operations.push(operation);
if (this.operations.length > this.maxOperations) {
this.operations = this.operations.slice(-this.maxOperations);
}
return operation;
}
getRecentOperations(limit = 20) {
return this.operations
.slice(-limit)
.reverse();
}
getOperationById(id) {
return this.operations.find(op => op.id === id) || null;
}
getOperationsCount() {
return this.operations.length;
}
getOperationsStats() {
if (this.operations.length === 0) {
return {
total_operations: 0,
avg_execution_time: 0,
success_rate: 0,
endpoints_accessed: []
};
}
const totalTime = this.operations.reduce((sum, op) => sum + op.execution_time_ms, 0);
const successfulOps = this.operations.filter(op => op.status_code >= 200 && op.status_code < 400);
const uniqueEndpoints = [...new Set(this.operations.map(op => op.endpoint))];
return {
total_operations: this.operations.length,
avg_execution_time: Math.round(totalTime / this.operations.length),
success_rate: Math.round((successfulOps.length / this.operations.length) * 100),
endpoints_accessed: uniqueEndpoints
};
}
clearOperations() {
this.operations = [];
console.log(`[TEEOperationLoggerService] Cleared all operation logs`);
}
}
exports.TEEOperationLoggerService = TEEOperationLoggerService;
//# sourceMappingURL=tee-operation-logger.service.js.map