Skip to content

Mainnet#126

Merged
Josie123-Dev merged 10 commits into
GuardZero144:mainfrom
Mainnet-ops:mainnet
Jul 23, 2026
Merged

Mainnet#126
Josie123-Dev merged 10 commits into
GuardZero144:mainfrom
Mainnet-ops:mainnet

Conversation

@Mainnet-ops

Copy link
Copy Markdown

Closes #49

Summary

  • Add automated credential backup system that schedules backups, monitors health, rotates old backups, sends alerts, and tests restoration
  • Integrate with IPFS for decentralized backup storage and existing NestJS services for data collection
  • Add 18 unit tests covering service and controller logic

Changes

New module (backend/src/backup/):

  • Entities: BackupRecord, BackupAlert, BackupConfig with TypeORM integration
  • Service: Core backup logic with scheduled backups (hourly cron), health monitoring (configurable interval), rotation (retention policy + max count), and restoration testing (dry-run support)
  • Controller: 9 REST endpoints for backup management, restoration, health checks, rotation, alerts, and configuration
  • DTOs: Input validation for create, restore, and config update operations
  • Module: NestJS module wiring with TypeORM, Schedule, IPFS, and dependent services

Modified files:

  • ipfs.service.ts — Added uploadJson and fetchJson helper methods
  • identity.service.ts — Added findAllByWallet and restore methods
  • verification.service.ts — Added findAllByWallet and restore methods
  • data-sharing.service.ts — Added findAllByOwner and restore methods
  • app.module.ts — Integrated BackupModule
  • .env.example — Added 7 backup configuration variables

Testing

  • 18 test cases across backup.service.spec.ts (7) and backup.controller.spec.ts (11)
  • Tests cover: backup creation (success/failure), health checks, rotation with retention, config management (get/create defaults), all controller endpoints
  • External dependencies mocked for isolation
  • Note: npm test requires installing dependencies; pre-existing @nestjs/redis package issue prevents install (outside this PR's scope)

Tradeoffs

  • Backup data stored as full JSON snapshots on IPFS (simpler than incremental, but larger per backup). Incremental support is possible via the BackupType enum but not implemented yet.
  • Health monitoring compares SHA-256 checksums of re-fetched data against stored values — if IPFS data mutates (shouldn't happen with CIDs), it flags as unhealthy.
  • Webhook alerts are fire-and-forget with no retry — sufficient for notification purposes but won't guarantee delivery.

Architecture

The backup system follows the same patterns as the existing AuditRetentionService — interval-based background workers using Nest lifecycle hooks + @nestjs/schedule cron. Each wallet has an independent BackupConfig controlling cadence, retention, and feature toggles. All backup data is stored on IPFS with checksums for integrity verification.

Out of scope

  • Incremental backup implementation (entity models support it via BackupType.INCREMENTAL)
  • Email/SMS alert delivery (webhook-only for now)
  • Backup encryption (IPFS content is already encrypted at the credential level)

“Mainnet-ops” added 10 commits July 23, 2026 06:07
- Add BackupRecord entity with status tracking and IPFS integration
- Add BackupAlert entity for monitoring and notification
- Add BackupConfig entity for per-wallet backup configuration
- Support full, incremental, and selective backup types
- CreateBackupDto for initiating backups with wallet address and type
- UpdateBackupConfigDto for configuring backup settings
- RestoreBackupDto for restoring from backup with dry-run support
- Validation decorators for input sanitization
- Automated backup creation with IPFS storage
- Scheduled backups via cron and interval-based triggers
- Backup health monitoring with checksum verification
- Backup rotation with configurable retention policies
- Restoration testing with dry-run support
- Alert creation with webhook notifications
- POST /backup - Create new backup
- GET /backup/wallet/:walletAddress - List backups
- POST /backup/restore - Restore from backup
- GET /backup/health - Run health check
- POST /backup/rotation - Trigger rotation
- POST /backup/restoration-test - Run restoration tests
- GET/PUT /backup/config/:walletAddress - Manage backup config
- GET /backup/alerts/:walletAddress - Get alerts
- PUT /backup/alerts/:id/acknowledge - Acknowledge alert
- Register backup entities with TypeORM
- Import ScheduleModule for cron-based triggers
- Import dependent modules (IPFS, Identity, Verification, DataSharing)
- Export BackupService for cross-module usage
- uploadJson for backup data storage with auto-generated filenames
- fetchJson for retrieving backup data from IPFS
- Consistent error handling with InternalServerErrorException
- Add findAllByWallet methods for backup data collection
- Add restore methods for backup restoration
- Enable backup system to query and restore credential data
- Maintain backward compatibility with existing API
- Add BackupModule to AppModule imports
- Enable backup functionality across the application
- Follow existing module integration patterns
- Test backup creation with success and failure scenarios
- Test health check functionality
- Test rotation with old backup cleanup
- Test configuration management
- Test all controller endpoints
- Mock external dependencies for isolation
- Add BACKUP_AUTO_ENABLED for enabling/disabling automatic backups
- Add BACKUP_HEALTH_CHECK_INTERVAL_HOURS for health monitoring
- Add BACKUP_ROTATION_CHECK_INTERVAL_DAYS for rotation scheduling
- Add BACKUP_RESTORATION_TEST_INTERVAL_DAYS for restoration tests
- Document all backup-related environment variables
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Josie's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sure-data Ready Ready Preview, Comment Jul 23, 2026 7:24am

@Josie123-Dev
Josie123-Dev merged commit 2626545 into GuardZero144:main Jul 23, 2026
3 checks passed
@Josie123-Dev

Copy link
Copy Markdown
Member

thank you for contributing to this project @Mainnet-ops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Hard] Add credential backup automation

2 participants