
- API server with ChaCha20-Poly1305 encryption - TypeScript SDK client with full functionality - Complete documentation in docs/ - Environment variable processing with composite variables - HTTPS-only API on port 6666 - Storage structure for configuration files - Tests and examples included Features: - Quantum-resistant encryption (ChaCha20-Poly1305) - Variable substitution from .env files - Comprehensive TypeScript SDK - Full API documentation and specifications - Deployment guides and security model
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
/**
|
|
* Exemple d'utilisation basique du SDK Vault 4NK
|
|
*/
|
|
|
|
import { VaultClient, createVaultClient, VaultCrypto } from '../src/index';
|
|
|
|
async function basicExample() {
|
|
console.log('🚀 Exemple d\'utilisation basique du SDK Vault 4NK');
|
|
console.log('=' .repeat(50));
|
|
|
|
try {
|
|
// 1. Création du client avec la clé de déchiffrement
|
|
const client = createVaultClient(
|
|
'https://vault.4nkweb.com:6666',
|
|
'quantum_resistant_demo_key_32_bytes!' // Clé de démonstration
|
|
);
|
|
|
|
// 2. Vérification de la connectivité
|
|
console.log('🔍 Test de connectivité...');
|
|
const isConnected = await client.ping();
|
|
console.log(`✅ Connecté: ${isConnected ? 'Oui' : 'Non'}`);
|
|
|
|
if (!isConnected) {
|
|
throw new Error('Impossible de se connecter à l\'API Vault');
|
|
}
|
|
|
|
// 3. Informations sur l'API
|
|
console.log('\n📋 Informations API...');
|
|
const info = await client.info();
|
|
console.log(` Nom: ${info.name}`);
|
|
console.log(` Version: ${info.version}`);
|
|
console.log(` Domaine: ${info.domain}`);
|
|
console.log(` Port: ${info.port}`);
|
|
console.log(` Chiffrement: ${info.encryption}`);
|
|
|
|
// 4. État de santé
|
|
console.log('\n🏥 État de santé...');
|
|
const health = await client.health();
|
|
console.log(` Statut: ${health.status}`);
|
|
console.log(` Service: ${health.service}`);
|
|
console.log(` Algorithme: ${health.algorithm}`);
|
|
|
|
// 5. Récupération d'un fichier
|
|
console.log('\n📁 Récupération d\'un fichier...');
|
|
const file = await client.getFile('dev', 'bitcoin/bitcoin.conf');
|
|
console.log(` Fichier: ${file.filename}`);
|
|
console.log(` Taille: ${file.size} caractères`);
|
|
console.log(` Chiffré: ${file.encrypted ? 'Oui' : 'Non'}`);
|
|
console.log(` Algorithme: ${file.algorithm || 'N/A'}`);
|
|
|
|
// Affichage d'un échantillon du contenu
|
|
const sample = file.content.substring(0, 200);
|
|
console.log(` Échantillon: ${sample}...`);
|
|
|
|
// 6. Récupération de plusieurs fichiers
|
|
console.log('\n📚 Récupération de plusieurs fichiers...');
|
|
const files = await client.getFiles([
|
|
{ env: 'dev', filePath: 'tor/torrc' },
|
|
{ env: 'dev', filePath: 'sdk_relay/sdk_relay.conf' }
|
|
]);
|
|
|
|
files.forEach((file, index) => {
|
|
console.log(` Fichier ${index + 1}: ${file.filename} (${file.size} chars)`);
|
|
});
|
|
|
|
console.log('\n🎉 Exemple terminé avec succès!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Erreur:', error instanceof Error ? error.message : error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Exécution de l'exemple
|
|
if (require.main === module) {
|
|
basicExample();
|
|
}
|
|
|
|
export { basicExample };
|