This commit introduces a complete transparency infrastructure including: Core Transparency Modules: - AuditLog: Immutable, cryptographically-linked audit trail for all actions - EventStream: Real-time SSE streaming and webhook support - TransparencyDashboard: Aggregated metrics and system health monitoring - DigitalSignatures: Cryptographic verification for handoffs and certificates API Endpoints: - /api/transparency/dashboard - Full platform metrics - /api/transparency/audit - Query and log audit entries - /api/transparency/events - SSE stream and event history - /api/transparency/webhooks - Webhook management - /api/transparency/signatures - Digital signature operations - /api/transparency/certificate/[plantId] - Plant authenticity certificates - /api/transparency/export - Multi-format data export - /api/transparency/report - Compliance reporting - /api/transparency/health - System health checks Features: - Immutable audit logging with chain integrity verification - Real-time event streaming via Server-Sent Events - Webhook support with HMAC signature verification - Digital signatures for transport handoffs and ownership transfers - Certificate of Authenticity generation for plants - Multi-format data export (JSON, CSV, summary) - Public transparency portal at /transparency - System health monitoring for all components Documentation: - Comprehensive TRANSPARENCY.md guide with API examples
7.4 KiB
LocalGreenChain Transparency System
Overview
The LocalGreenChain Transparency System provides complete visibility into platform operations, ensuring trust, accountability, and compliance for all stakeholders - growers, consumers, certifiers, and regulators.
Key Features
1. Immutable Audit Logging
Every action on the platform is recorded in an immutable, cryptographically-linked audit log.
Tracked Actions:
- Plant registrations and clones
- Transport events and handoffs
- Demand signals and supply commitments
- Farm operations and batch management
- System events and configuration changes
- API calls and user activities
API Endpoints:
GET /api/transparency/audit - Query audit entries
POST /api/transparency/audit - Log custom audit entry
Query Parameters:
startDate,endDate- Date range filteractions- Filter by action types (comma-separated)categories- Filter by categoriesseverities- Filter by severity levelsactorId- Filter by actorresourceType,resourceId- Filter by resourceformat- Output format (json, csv, summary)
2. Real-Time Event Stream
Server-Sent Events (SSE) for real-time notifications and webhook support for integrations.
Event Types:
plant.*- Plant lifecycle eventstransport.*- Transport eventsdemand.*- Demand and supply eventsfarm.*- Farm operation eventsagent.*- Agent task and alert eventsblockchain.*- Blockchain eventssystem.*- System health eventsaudit.*- Audit events
API Endpoints:
GET /api/transparency/events - Get recent events
GET /api/transparency/events?stream=true - SSE connection
POST /api/transparency/events - Emit custom event
Webhook Management:
GET /api/transparency/webhooks - List webhooks
POST /api/transparency/webhooks - Register webhook
DELETE /api/transparency/webhooks - Remove webhook
PATCH /api/transparency/webhooks - Update webhook
3. Transparency Dashboard
Comprehensive metrics aggregation across all platform components.
API Endpoint:
GET /api/transparency/dashboard
Returns:
- System health status
- Plant registry metrics
- Transport statistics
- Environmental impact metrics
- Blockchain status
- Agent activity
- Active alerts
Public Portal:
Visit /transparency for the public-facing dashboard.
4. Digital Signatures
Cryptographic verification for transport handoffs, ownership transfers, and certifications.
Features:
- ECDSA/RSA key pair generation
- Identity registration and verification
- Single and multi-party signatures
- Transport handoff signing
- Certificate of Authenticity generation
API Endpoints:
GET /api/transparency/signatures - Get signature stats
POST /api/transparency/signatures - Various signature actions
GET /api/transparency/certificate/[plantId] - Generate plant certificate
Signature Actions:
register_identity- Register a new signing identitygenerate_keypair- Generate a key pairsign- Create a signatureverify_data- Verify a signaturetransport_handoff- Sign transport handoff
5. Data Export & Reporting
Export transparency data in multiple formats for compliance and analysis.
API Endpoint:
GET /api/transparency/export
Export Types:
dashboard- Dashboard metricsaudit- Audit log entriesevents- Event stream dataplants- Plant registrytransport- Transport historysignatures- Digital signaturesfull- Complete export
Formats:
json- Structured JSON datacsv- Spreadsheet-compatiblesummary- Human-readable text
Report Generation:
GET /api/transparency/report
6. System Health Monitoring
Real-time health status of all platform components.
API Endpoint:
GET /api/transparency/health
Components Monitored:
- Blockchain storage
- Agent system
- API layer
- Data storage
Usage Examples
Query Audit Log
// Get last 24 hours of plant registrations
const response = await fetch('/api/transparency/audit?' + new URLSearchParams({
startDate: new Date(Date.now() - 86400000).toISOString(),
actions: 'PLANT_REGISTER,PLANT_CLONE',
format: 'json'
}));
const data = await response.json();
Subscribe to Events (SSE)
const eventSource = new EventSource('/api/transparency/events?stream=true');
eventSource.addEventListener('plant.registered', (event) => {
const data = JSON.parse(event.data);
console.log('New plant registered:', data);
});
eventSource.addEventListener('transport.completed', (event) => {
const data = JSON.parse(event.data);
console.log('Transport completed:', data);
});
Register a Webhook
const response = await fetch('/api/transparency/webhooks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'https://your-server.com/webhook',
types: ['plant.registered', 'transport.completed']
})
});
const { data } = await response.json();
// Store data.secret securely for verifying webhooks
Generate Plant Certificate
const response = await fetch('/api/transparency/certificate/plant_123?format=json');
const { data } = await response.json();
console.log('Certificate:', data.certificate);
console.log('Verification:', data.verification);
Sign Transport Handoff
const response = await fetch('/api/transparency/signatures', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'transport_handoff',
plantId: 'plant_123',
fromParty: 'grower_001',
toParty: 'transporter_001',
location: { lat: 40.7128, lng: -74.0060 },
privateKey: '-----BEGIN PRIVATE KEY-----...'
})
});
Export Data
// Export audit log as CSV
window.location.href = '/api/transparency/export?type=audit&format=csv';
// Generate full report
const response = await fetch('/api/transparency/report?format=summary');
const report = await response.text();
Security Considerations
- Audit Integrity: Audit entries are cryptographically linked; tampering is detectable
- Signature Security: Private keys are never stored on the server
- Webhook Security: Webhooks include HMAC signatures for verification
- Data Privacy: Personal data can be anonymized in exports
- Rate Limiting: Consider implementing rate limiting for production
Integration with Existing Systems
The transparency system integrates with:
- PlantChain: Plant registration events are automatically logged
- TransportChain: Transport events trigger audit entries and notifications
- AgentOrchestrator: Agent activities are tracked and monitored
- DemandForecaster: Demand signals are logged for transparency
Best Practices
- Subscribe to Critical Events: Set up webhooks for important events
- Regular Exports: Schedule regular data exports for compliance
- Monitor Health: Check
/api/transparency/healthin monitoring systems - Verify Certificates: Always verify plant certificates before transactions
- Sign Handoffs: Use digital signatures for all transport handoffs
Public Transparency Portal
Access the public transparency portal at /transparency to view:
- Real-time system health
- Platform metrics
- Environmental impact
- Blockchain status
- Active alerts
The portal auto-refreshes every 30 seconds and provides export links for all data.