**Motivations:** - Complete documentation for dashboard, domains, ports and environment configuration - Add new services (ClamAV API, Watermark API) to the infrastructure - Enhance dashboard with new pages and improved functionality - Improve deployment scripts and service configurations **Root causes:** - Missing comprehensive documentation for infrastructure setup - Need for antivirus scanning service integration - Need for watermark service integration - Dashboard required additional pages and features **Correctifs:** - Added comprehensive documentation in docs/ (DASHBOARD.md, DOMAINS_AND_PORTS.md, ENVIRONMENT.md) - Updated systemd service files with proper environment variables - Enhanced nginx proxy configuration script - Updated maintenance documentation **Evolutions:** - Added new ClamAV API service (api-clamav) for file scanning - Added new Watermark API service (api-filigrane) for document watermarking - Enhanced signet-dashboard with new learn.html page - Improved dashboard UI with better styles and navigation - Enhanced app.js with new functionality and better error handling - Updated API documentation page with complete endpoint descriptions - Added deployment scripts for watermark and nginx configuration - Updated hash and UTXO lists with latest data - Enhanced server.js with new routes and improved Bitcoin RPC integration **Pages affectées:** - docs/DASHBOARD.md: New comprehensive dashboard documentation - docs/DOMAINS_AND_PORTS.md: New infrastructure domains and ports documentation - docs/ENVIRONMENT.md: New environment variables documentation - docs/MAINTENANCE.md: Updated maintenance procedures - docs/README.md: Updated main documentation - signet-dashboard/public/app.js: Enhanced with new features - signet-dashboard/public/styles.css: Improved styling - signet-dashboard/public/index.html: Enhanced main page - signet-dashboard/public/learn.html: New educational page - signet-dashboard/public/api-docs.html: Enhanced API documentation - signet-dashboard/public/hash-list.html: Updated hash list page - signet-dashboard/public/utxo-list.html: Updated UTXO list page - signet-dashboard/public/join-signet.html: Updated join signet page - signet-dashboard/src/server.js: Enhanced server with new routes - signet-dashboard/start.sh: Updated startup script - signet-dashboard/signet-dashboard.service: Updated systemd service - api-anchorage/anchorage-api.service: Updated systemd service - api-faucet/faucet-api.service: Updated systemd service - configure-nginx-proxy.sh: Enhanced nginx configuration script - add-watermark-certificate.sh: New watermark certificate script - deploy-watermark-nginx.sh: New deployment script - api-clamav/: New ClamAV API service - api-filigrane/: New Watermark API service - hash_list.txt, utxo_list.txt: Updated with latest data - anchor_count.txt: Updated anchor count
251 lines
5.8 KiB
Markdown
251 lines
5.8 KiB
Markdown
# API Filigrane Bitcoin Signet
|
|
|
|
**Auteur** : Équipe 4NK
|
|
**Date** : 2026-01-25
|
|
**Version** : 1.0.0
|
|
|
|
## Description
|
|
|
|
API REST pour ajouter un filigrane à des documents, les convertir en PDF, et les ancrer sur la blockchain Bitcoin Signet. Cette API permet d'ancrer à la fois le document original et le document filigrané.
|
|
|
|
## Caractéristiques
|
|
|
|
- **Port** : `3022`
|
|
- **Format** : JSON REST API
|
|
- **Conversion** : Tous types de documents → PDF
|
|
- **Filigrane** : Ajout de texte, dates, signatures, informations blockchain
|
|
- **Ancrage** : Appel automatique à l'API d'ancrage pour les deux documents
|
|
|
|
## Installation
|
|
|
|
### Prérequis
|
|
|
|
- Node.js >= 18.0.0
|
|
- Accès à l'API d'ancrage (port 3010)
|
|
- Accès au dashboard blockchain (port 3020) pour les infos de bloc
|
|
|
|
### Installation des Dépendances
|
|
|
|
```bash
|
|
cd api-filigrane
|
|
npm install
|
|
```
|
|
|
|
### Configuration
|
|
|
|
1. Créer le fichier `.env` :
|
|
|
|
```bash
|
|
# API Configuration
|
|
WATERMARK_API_PORT=3022
|
|
WATERMARK_API_HOST=0.0.0.0
|
|
|
|
# API Keys (séparées par des virgules)
|
|
API_KEYS=your-api-key-here,another-api-key
|
|
|
|
# Anchor API Configuration
|
|
ANCHOR_API_URL=http://localhost:3010
|
|
|
|
# Blockchain API Configuration (pour récupérer les infos de bloc)
|
|
BLOCKCHAIN_API_URL=http://localhost:3020
|
|
|
|
# Logging
|
|
LOG_LEVEL=info
|
|
NODE_ENV=production
|
|
```
|
|
|
|
**Important** :
|
|
- `API_KEYS` : Définir au moins une clé API valide (séparées par des virgules)
|
|
- `ANCHOR_API_URL` : URL de l'API d'ancrage
|
|
- `BLOCKCHAIN_API_URL` : URL du dashboard blockchain pour récupérer les infos de bloc
|
|
|
|
## Démarrage
|
|
|
|
### Mode Développement
|
|
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
### Mode Production
|
|
|
|
```bash
|
|
npm start
|
|
```
|
|
|
|
### Avec PM2 (recommandé pour production)
|
|
|
|
```bash
|
|
# Installer PM2 globalement
|
|
sudo npm install -g pm2
|
|
|
|
# Démarrer l'API avec PM2
|
|
pm2 start src/server.js --name watermark-api
|
|
|
|
# Sauvegarder la configuration PM2
|
|
pm2 save
|
|
|
|
# Configurer PM2 pour démarrer au boot
|
|
pm2 startup
|
|
# Suivre les instructions affichées
|
|
```
|
|
|
|
## Endpoints
|
|
|
|
### GET /health
|
|
|
|
Vérifie l'état de santé de l'API.
|
|
|
|
**Authentification** : Non requise
|
|
|
|
**Réponse** :
|
|
```json
|
|
{
|
|
"ok": true,
|
|
"service": "watermark-api",
|
|
"version": "1.0.0",
|
|
"timestamp": "2026-01-25T12:00:00.000Z"
|
|
}
|
|
```
|
|
|
|
### POST /api/watermark/document
|
|
|
|
Ajoute un filigrane à un document, le convertit en PDF, et ancre les deux versions (originale et filigranée).
|
|
|
|
**Authentification** : Requise (clé API dans le header `x-api-key`)
|
|
|
|
**Headers** :
|
|
```
|
|
x-api-key: your-api-key-here
|
|
Content-Type: application/json
|
|
```
|
|
|
|
**Body** :
|
|
```json
|
|
{
|
|
"apiKey": "your-api-key-here",
|
|
"textContent": "Texte à convertir en PDF",
|
|
"fileData": "base64-encoded-file-data",
|
|
"fileName": "document.pdf",
|
|
"mimeType": "application/pdf",
|
|
"watermarkOptions": {
|
|
"enabled": true,
|
|
"text": "Texte libre du filigrane",
|
|
"signature": "Signature cryptographique",
|
|
"watermarkedFileName": "document-watermarked.pdf",
|
|
"originalFileName": "document-original.pdf",
|
|
"dateUTC": true,
|
|
"dateLocal": true,
|
|
"blockNumber": true,
|
|
"blockHash": true,
|
|
"documentHash": true
|
|
}
|
|
}
|
|
```
|
|
|
|
**Réponse (succès)** :
|
|
```json
|
|
{
|
|
"success": true,
|
|
"options": { ... },
|
|
"original": {
|
|
"txid": "...",
|
|
"status": "pending",
|
|
"confirmations": 0,
|
|
"file": {
|
|
"name": "document-original.pdf",
|
|
"extension": "pdf",
|
|
"data": "base64-encoded-pdf-data"
|
|
}
|
|
},
|
|
"watermarked": {
|
|
"txid": "...",
|
|
"status": "pending",
|
|
"confirmations": 0,
|
|
"file": {
|
|
"name": "document-watermarked.pdf",
|
|
"extension": "pdf",
|
|
"data": "base64-encoded-pdf-data"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Options de Filigrane
|
|
|
|
- **text** : Texte libre à afficher dans le filigrane (optionnel)
|
|
- **signature** : Signature cryptographique à afficher (optionnel)
|
|
- **watermarkedFileName** : Nom du fichier PDF filigrané (optionnel, utilise le nom d'origine avec extension .pdf si non fourni)
|
|
- **originalFileName** : Nom du fichier original (optionnel, utilise "origin.md" si texte saisi et non fourni)
|
|
- **dateUTC** : Ajouter la date UTC dans le filigrane (case à cocher)
|
|
- **dateLocal** : Ajouter la date locale dans le filigrane (case à cocher)
|
|
- **blockNumber** : Ajouter le numéro de bloc actuel (case à cocher)
|
|
- **blockHash** : Ajouter le hash du bloc actuel (case à cocher)
|
|
- **documentHash** : Ajouter le hash du document d'origine (case à cocher)
|
|
|
|
Le filigrane est ajouté en bas à gauche de chaque page du PDF.
|
|
|
|
## Conversion de Documents
|
|
|
|
L'API convertit automatiquement :
|
|
- **Images** : PNG, JPG, etc. → PDF (PNG converti en JPG puis en PDF)
|
|
- **Texte** : Tous types de texte → PDF
|
|
- **PDF** : Conservé tel quel
|
|
|
|
## Architecture
|
|
|
|
```
|
|
Client (Dashboard)
|
|
↓ HTTPS
|
|
API Filigrane (port 3022)
|
|
↓ HTTP
|
|
API Ancrage (port 3010)
|
|
↓ RPC
|
|
Bitcoin Signet Node (port 38332)
|
|
```
|
|
|
|
## Sécurité
|
|
|
|
- **Authentification** : Clé API requise pour tous les endpoints sauf `/health`
|
|
- **Validation** : Validation stricte des entrées
|
|
- **Limite de taille** : 50MB par défaut pour les requêtes
|
|
|
|
## Dépannage
|
|
|
|
### L'API ne démarre pas
|
|
|
|
- Vérifier que le port 3022 n'est pas utilisé : `netstat -tlnp | grep 3022`
|
|
- Vérifier les logs : `pm2 logs watermark-api`
|
|
- Vérifier la configuration dans `.env`
|
|
|
|
### Erreur "Failed to anchor document"
|
|
|
|
- Vérifier que l'API d'ancrage est accessible : `curl http://localhost:3010/health`
|
|
- Vérifier que la clé API est valide
|
|
- Vérifier les logs de l'API d'ancrage
|
|
|
|
### Erreur de conversion PDF
|
|
|
|
- Vérifier que les dépendances sont installées : `npm install`
|
|
- Vérifier les logs pour les erreurs spécifiques
|
|
|
|
## Structure des Fichiers
|
|
|
|
```
|
|
api-filigrane/
|
|
├── package.json
|
|
├── README.md
|
|
├── start.sh
|
|
├── .env.example
|
|
└── src/
|
|
├── server.js # Serveur Express
|
|
├── logger.js # Logger
|
|
└── routes/
|
|
├── watermark.js # Routes de filigrane
|
|
└── health.js # Routes de santé
|
|
```
|
|
|
|
## Licence
|
|
|
|
MIT
|