Cipherion
Sdk IntegrationsJavaScript SDK

Configuration

Configure the Cipherion client for your needs

Learn how to configure the Cipherion client with various options.

Basic Configuration

import { CipherionClient } from '@cipherion/client';

const client = new CipherionClient({
  baseUrl: 'https://api.cipherion.in',
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
  passphrase: 'your-secure-passphrase-min-12-chars',
  timeout: 30000,
  retries: 3,
  logLevel: 'info',
  enableLogging: true
});

Configuration Options

Required Options

OptionTypeDescription
baseUrlstringAPI base URL (e.g., https://api.cipherion.in)
projectIdstringYour project identifier from Cipherion dashboard
apiKeystringAPI authentication key
passphrasestringEncryption passphrase (minimum 12 characters)

Optional Options

OptionTypeDefaultDescription
timeoutnumber30000Request timeout in milliseconds
retriesnumber3Maximum retry attempts for failed requests
logLevelstring'info'Log level: 'error', 'warn', 'info', 'debug'
enableLoggingbooleantrueEnable/disable logging

Environment Variables

Using environment variables is the recommended approach:

.env
CIPHERION_BASE_URL=https://api.cipherion.in
CIPHERION_PROJECT_ID=proj_abc123xyz
CIPHERION_API_KEY=sk_live_abc123xyz
CIPHERION_PASSPHRASE=MySecurePassphrase123!
// Configuration loaded from environment variables
const client = new CipherionClient();

Configuration by Environment

Development

const client = new CipherionClient({
  baseUrl: process.env.DEV_CIPHERION_BASE_URL,
  projectId: process.env.DEV_PROJECT_ID,
  apiKey: process.env.DEV_API_KEY,
  passphrase: process.env.DEV_PASSPHRASE,
  logLevel: 'debug',
  enableLogging: true,
  timeout: 60000
});

Production

const client = new CipherionClient({
  baseUrl: process.env.CIPHERION_BASE_URL,
  projectId: process.env.CIPHERION_PROJECT_ID,
  apiKey: process.env.CIPHERION_API_KEY,
  passphrase: process.env.CIPHERION_PASSPHRASE,
  logLevel: 'error',
  enableLogging: true,
  timeout: 30000,
  retries: 5
});

Runtime Configuration Updates

You can update non-sensitive configuration at runtime:

// Get current configuration (without sensitive data)
const config = client.getConfig();
console.log(config);

// Update configuration
client.updateConfig({
  timeout: 60000,
  logLevel: 'debug',
  enableLogging: false
});

You cannot update apiKey or passphrase after initialization. Create a new client instance instead.

Logging Configuration

Log Levels

  • error: Only errors
  • warn: Warnings and errors
  • info: General information (recommended for production)
  • debug: Detailed debugging information (development only)

Example

const client = new CipherionClient({
  logLevel: process.env.NODE_ENV === 'production' ? 'error' : 'debug',
  enableLogging: true
});

Disable Logging

const client = new CipherionClient({
  enableLogging: false
});

Passphrase Requirements

Your passphrase must meet these requirements:

  • Minimum 12 characters
  • Mix of uppercase and lowercase letters recommended
  • Include numbers and special characters recommended
// ✅ Good
passphrase: "MySecure#Passphrase2024!"

// ❌ Bad - too short
passphrase: "password"

// ❌ Bad - too weak
passphrase: "123456789012"

Multiple Client Instances

You can create multiple clients for different purposes:

// Client for user data
const userClient = new CipherionClient({
  passphrase: process.env.USER_PASSPHRASE
});

// Client for payment data
const paymentClient = new CipherionClient({
  passphrase: process.env.PAYMENT_PASSPHRASE
});

// Use appropriate client
await userClient.deepEncrypt(userData);
await paymentClient.deepEncrypt(paymentData);

Configuration Validation

The SDK validates configuration on initialization:

try {
  const client = new CipherionClient({
    passphrase: 'short' // Less than 12 characters
  });
} catch (error) {
  console.error('Invalid configuration:', error.message);
  // "Passphrase must be at least 12 characters long"
}

Best Practices

  1. Never hardcode credentials
   // ❌ Bad
   const client = new CipherionClient({
     apiKey: 'sk-123456',
     passphrase: 'mysecret'
   });
   
   // ✅ Good
   const client = new CipherionClient();
  1. Use different credentials per environment
   const credentials = {
     development: {
       apiKey: process.env.DEV_API_KEY,
       passphrase: process.env.DEV_PASSPHRASE
     },
     production: {
       apiKey: process.env.PROD_API_KEY,
       passphrase: process.env.PROD_PASSPHRASE
     }
   };
   
   const client = new CipherionClient(
     credentials[process.env.NODE_ENV]
   );
  1. Store passphrases securely
    • Use secret management services (AWS Secrets Manager, HashiCorp Vault)
    • Never commit passphrases to version control
    • Rotate passphrases regularly