Skip to content

LicenseChain/LicenseChain-CPP-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LicenseChain C++ SDK

License C++ CMake

Official C++ SDK for LicenseChain - Secure license management for C++ applications.

πŸš€ Features

  • πŸ” Secure Authentication - User registration, login, and session management
  • πŸ“œ License Management - Create, validate, update, and revoke licenses
  • πŸ›‘οΈ Hardware ID Validation - Prevent license sharing and unauthorized access
  • πŸ”” Webhook Support - Real-time license events and notifications
  • πŸ“Š Analytics Integration - Track license usage and performance metrics
  • ⚑ High Performance - Optimized for production workloads
  • πŸ”„ Async Operations - Non-blocking HTTP requests and data processing
  • πŸ› οΈ Easy Integration - Simple API with comprehensive documentation

πŸ“¦ Installation

Method 1: CMake (Recommended)

# Clone the repository
git clone https://github.com/LicenseChain/LicenseChain-CPP-SDK.git
cd LicenseChain-CPP-SDK

# Create build directory
mkdir build && cd build

# Configure with CMake
cmake ..

# Build the library
make -j$(nproc)

# Install (optional)
sudo make install

Method 2: Package Manager

Add to your CMakeLists.txt:

find_package(LicenseChain REQUIRED)
target_link_libraries(your_target LicenseChain::LicenseChain)

Method 3: Manual Installation

  1. Download the latest release from GitHub Releases
  2. Extract the headers and libraries to your project
  3. Link against the LicenseChain library

πŸš€ Quick Start

Basic Setup

#include <licensechain/licensechain_client.h>
#include <iostream>

int main() {
    // Initialize the client
    LicenseChain::Client client({
        .apiKey = "your-api-key",
        .appName = "your-app-name",
        .version = "1.0.0"
    });
    
    // Connect to LicenseChain
    auto result = client.connect();
    if (!result.success) {
        std::cerr << "Failed to connect to LicenseChain: " << result.error << std::endl;
        return 1;
    }
    
    std::cout << "Connected to LicenseChain successfully!" << std::endl;
    return 0;
}

User Authentication

// Register a new user
auto registerResult = client.register("username", "password", "email@example.com");
if (registerResult.success) {
    std::cout << "User registered successfully!" << std::endl;
} else {
    std::cerr << "Registration failed: " << registerResult.error << std::endl;
}

// Login existing user
auto loginResult = client.login("username", "password");
if (loginResult.success) {
    std::cout << "User logged in successfully!" << std::endl;
    std::cout << "Session ID: " << loginResult.sessionId << std::endl;
} else {
    std::cerr << "Login failed: " << loginResult.error << std::endl;
}

License Management

// Validate a license
auto validateResult = client.validateLicense("LICENSE-KEY-HERE");
if (validateResult.success) {
    std::cout << "License is valid!" << std::endl;
    std::cout << "License Key: " << validateResult.license.key << std::endl;
    std::cout << "Status: " << validateResult.license.status << std::endl;
    std::cout << "Expires: " << validateResult.license.expires << std::endl;
    std::cout << "Features: ";
    for (const auto& feature : validateResult.license.features) {
        std::cout << feature << " ";
    }
    std::cout << std::endl;
    std::cout << "User: " << validateResult.license.user << std::endl;
} else {
    std::cerr << "License validation failed: " << validateResult.error << std::endl;
}

// Get user's licenses
auto licensesResult = client.getUserLicenses();
if (licensesResult.success) {
    std::cout << "Found " << licensesResult.licenses.size() << " licenses:" << std::endl;
    for (size_t i = 0; i < licensesResult.licenses.size(); ++i) {
        const auto& license = licensesResult.licenses[i];
        std::cout << "  " << (i + 1) << ". " << license.key 
                  << " - " << license.status 
                  << " (Expires: " << license.expires << ")" << std::endl;
    }
}

Hardware ID Validation

// Get hardware ID (automatically generated)
std::string hardwareId = client.getHardwareId();
std::cout << "Hardware ID: " << hardwareId << std::endl;

// Validate hardware ID with license
auto hardwareResult = client.validateHardwareId("LICENSE-KEY-HERE", hardwareId);
if (hardwareResult.success) {
    std::cout << "Hardware ID is valid for this license!" << std::endl;
} else {
    std::cerr << "Hardware ID validation failed: " << hardwareResult.error << std::endl;
}

Webhook Integration

// Set up webhook handler
client.setWebhookHandler([](const std::string& event, const std::map<std::string, std::string>& data) {
    std::cout << "Webhook received: " << event << std::endl;
    
    if (event == "license.created") {
        std::cout << "New license created: " << data.at("licenseKey") << std::endl;
    } else if (event == "license.updated") {
        std::cout << "License updated: " << data.at("licenseKey") << std::endl;
    } else if (event == "license.revoked") {
        std::cout << "License revoked: " << data.at("licenseKey") << std::endl;
    }
});

// Start webhook listener
client.startWebhookListener();

πŸ“š API Reference

LicenseChain::Client

Constructor

LicenseChain::Client client({
    .apiKey = "your-api-key",
    .appName = "your-app-name",
    .version = "1.0.0",
    .baseUrl = "https://api.licensechain.app"  // Optional
});

Methods

Connection Management
// Connect to LicenseChain
auto result = client.connect();

// Disconnect from LicenseChain
client.disconnect();

// Check connection status
bool isConnected = client.isConnected();
User Authentication
// Register a new user
auto result = client.register(username, password, email);

// Login existing user
auto result = client.login(username, password);

// Logout current user
client.logout();

// Get current user info
auto user = client.getCurrentUser();
License Management
// Validate a license
auto result = client.validateLicense(licenseKey);

// Get user's licenses
auto result = client.getUserLicenses();

// Create a new license
auto result = client.createLicense(userId, features, expires);

// Update a license
auto result = client.updateLicense(licenseKey, updates);

// Revoke a license
auto result = client.revokeLicense(licenseKey);

// Extend a license
auto result = client.extendLicense(licenseKey, days);
Hardware ID Management
// Get hardware ID
std::string hardwareId = client.getHardwareId();

// Validate hardware ID
auto result = client.validateHardwareId(licenseKey, hardwareId);

// Bind hardware ID to license
auto result = client.bindHardwareId(licenseKey, hardwareId);
Webhook Management
// Set webhook handler
client.setWebhookHandler(handler);

// Start webhook listener
client.startWebhookListener();

// Stop webhook listener
client.stopWebhookListener();
Analytics
// Track event
client.trackEvent(eventName, properties);

// Get analytics data
auto result = client.getAnalytics(timeRange);

πŸ”§ Configuration

Environment Variables

Set these in your environment or through your build process:

# Required
export LICENSECHAIN_API_KEY=your-api-key
export LICENSECHAIN_APP_NAME=your-app-name
export LICENSECHAIN_APP_VERSION=1.0.0

# Optional
export LICENSECHAIN_BASE_URL=https://api.licensechain.app
export LICENSECHAIN_DEBUG=true

Advanced Configuration

LicenseChain::Client client({
    .apiKey = "your-api-key",
    .appName = "your-app-name",
    .version = "1.0.0",
    .baseUrl = "https://api.licensechain.app",
    .timeout = 30, // Request timeout in seconds
    .retries = 3,  // Number of retry attempts
    .debug = false // Enable debug logging
});

πŸ›‘οΈ Security Features

Hardware ID Protection

The SDK automatically generates and manages hardware IDs to prevent license sharing:

// Hardware ID is automatically generated and stored
std::string hardwareId = client.getHardwareId();

// Validate against license
auto isValid = client.validateHardwareId(licenseKey, hardwareId);

Secure Communication

  • All API requests use HTTPS
  • API keys are securely stored and transmitted
  • Session tokens are automatically managed
  • Webhook signatures are verified

License Validation

  • Real-time license validation
  • Hardware ID binding
  • Expiration checking
  • Feature-based access control

πŸ“Š Analytics and Monitoring

Event Tracking

// Track custom events
client.trackEvent("app.started", {
    {"level", 1},
    {"playerCount", 10}
});

// Track license events
client.trackEvent("license.validated", {
    {"licenseKey", "LICENSE-KEY"},
    {"features", "premium,unlimited"}
});

Performance Monitoring

// Get performance metrics
auto metrics = client.getPerformanceMetrics();
std::cout << "API Response Time: " << metrics.avgResponseTime << "ms" << std::endl;
std::cout << "Success Rate: " << (metrics.successRate * 100) << "%" << std::endl;
std::cout << "Error Count: " << metrics.errorCount << std::endl;

πŸ”„ Error Handling

Custom Error Types

try {
    auto result = client.validateLicense("invalid-key");
    if (!result.success) {
        switch (result.errorType) {
            case LicenseChain::ErrorType::INVALID_LICENSE:
                std::cerr << "License key is invalid" << std::endl;
                break;
            case LicenseChain::ErrorType::EXPIRED_LICENSE:
                std::cerr << "License has expired" << std::endl;
                break;
            case LicenseChain::ErrorType::NETWORK_ERROR:
                std::cerr << "Network connection failed" << std::endl;
                break;
        }
    }
} catch (const std::exception& e) {
    std::cerr << "Exception: " << e.what() << std::endl;
}

Retry Logic

// Automatic retry for network errors
LicenseChain::Client client({
    .apiKey = "your-api-key",
    .appName = "your-app-name",
    .version = "1.0.0",
    .retries = 3, // Retry up to 3 times
    .retryDelay = 1000 // Wait 1 second between retries
});

πŸ§ͺ Testing

Unit Tests

# Run tests
cd build
ctest --output-on-failure

Integration Tests

# Test with real API
./tests/integration_tests

πŸ“ Examples

See the examples/ directory for complete examples:

  • basic_usage.cpp - Basic SDK usage
  • advanced_features.cpp - Advanced features and configuration
  • webhook_integration.cpp - Webhook handling

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Clone the repository
  2. Install dependencies: sudo apt-get install libcurl4-openssl-dev
  3. Build: mkdir build && cd build && cmake .. && make
  4. Test: ctest

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ”— Related Projects


Made with ❀️ for the C++ community

About

Official C++ SDK for LicenseChain - Secure license management for C++ applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published