LicenseChain.CSharp.SDK 1.0.0

dotnet add package LicenseChain.CSharp.SDK --version 1.0.0
                    
NuGet\Install-Package LicenseChain.CSharp.SDK -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LicenseChain.CSharp.SDK" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LicenseChain.CSharp.SDK" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="LicenseChain.CSharp.SDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LicenseChain.CSharp.SDK --version 1.0.0
                    
#r "nuget: LicenseChain.CSharp.SDK, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LicenseChain.CSharp.SDK@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LicenseChain.CSharp.SDK&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=LicenseChain.CSharp.SDK&version=1.0.0
                    
Install as a Cake Tool

LicenseChain C# SDK

License C# .NET

Official C# SDK for LicenseChain - Secure license management for .NET 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

# Install via Package Manager Console
Install-Package LicenseChain.SDK

# Or via .NET CLI
dotnet add package LicenseChain.SDK

Method 2: PackageReference

Add to your .csproj:

<PackageReference Include="LicenseChain.SDK" Version="1.0.0" />

Method 3: Manual Installation

  1. Download the latest release from GitHub Releases
  2. Add the DLL reference to your project
  3. Install required dependencies

๐Ÿš€ Quick Start

Basic Setup

using LicenseChain.SDK;

class Program
{
    static async Task Main(string[] args)
    {
        // Initialize the client
        var client = new LicenseChainClient(new LicenseChainConfig
        {
            ApiKey = "your-api-key",
            AppName = "your-app-name",
            Version = "1.0.0"
        });
        
        // Connect to LicenseChain
        try
        {
            await client.ConnectAsync();
            Console.WriteLine("Connected to LicenseChain successfully!");
        }
        catch (LicenseChainException ex)
        {
            Console.WriteLine($"Failed to connect: {ex.Message}");
            return;
        }
    }
}

User Authentication

// Register a new user
try
{
    var user = await client.RegisterAsync("username", "password", "email@example.com");
    Console.WriteLine("User registered successfully!");
    Console.WriteLine($"User ID: {user.Id}");
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"Registration failed: {ex.Message}");
}

// Login existing user
try
{
    var user = await client.LoginAsync("username", "password");
    Console.WriteLine("User logged in successfully!");
    Console.WriteLine($"Session ID: {user.SessionId}");
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"Login failed: {ex.Message}");
}

License Management

// Validate a license
try
{
    var license = await client.ValidateLicenseAsync("LICENSE-KEY-HERE");
    Console.WriteLine("License is valid!");
    Console.WriteLine($"License Key: {license.Key}");
    Console.WriteLine($"Status: {license.Status}");
    Console.WriteLine($"Expires: {license.Expires}");
    Console.WriteLine($"Features: {string.Join(", ", license.Features)}");
    Console.WriteLine($"User: {license.User}");
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"License validation failed: {ex.Message}");
}

// Get user's licenses
try
{
    var licenses = await client.GetUserLicensesAsync();
    Console.WriteLine($"Found {licenses.Count} licenses:");
    for (int i = 0; i < licenses.Count; i++)
    {
        var license = licenses[i];
        Console.WriteLine($"  {i + 1}. {license.Key} - {license.Status} (Expires: {license.Expires})");
    }
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"Failed to get licenses: {ex.Message}");
}

Hardware ID Validation

// Get hardware ID (automatically generated)
var hardwareId = client.GetHardwareId();
Console.WriteLine($"Hardware ID: {hardwareId}");

// Validate hardware ID with license
try
{
    var isValid = await client.ValidateHardwareIdAsync("LICENSE-KEY-HERE", hardwareId);
    if (isValid)
    {
        Console.WriteLine("Hardware ID is valid for this license!");
    }
    else
    {
        Console.WriteLine("Hardware ID is not valid for this license.");
    }
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"Hardware ID validation failed: {ex.Message}");
}

Webhook Integration

// Set up webhook handler
client.SetWebhookHandler(async (eventName, data) =>
{
    Console.WriteLine($"Webhook received: {eventName}");
    
    switch (eventName)
    {
        case "license.created":
            Console.WriteLine($"New license created: {data["licenseKey"]}");
            break;
        case "license.updated":
            Console.WriteLine($"License updated: {data["licenseKey"]}");
            break;
        case "license.revoked":
            Console.WriteLine($"License revoked: {data["licenseKey"]}");
            break;
    }
});

// Start webhook listener
await client.StartWebhookListenerAsync();

๐Ÿ“š API Endpoints

All endpoints automatically use the /v1 prefix when connecting to https://api.licensechain.app.

Base URL

  • Production: https://api.licensechain.app/v1
  • Development: https://api.licensechain.app/v1

Available Endpoints

Method Endpoint Description
GET /v1/health Health check
POST /v1/auth/login User login
POST /v1/auth/register User registration
GET /v1/apps List applications
POST /v1/apps Create application
GET /v1/licenses List licenses
POST /v1/licenses/verify Verify license
GET /v1/webhooks List webhooks
POST /v1/webhooks Create webhook
GET /v1/analytics Get analytics

Note: The SDK automatically prepends /v1 to all endpoints, so you only need to specify the path (e.g., /auth/login instead of /v1/auth/login).

๐Ÿ“š API Reference

LicenseChainClient

Constructor
var client = new LicenseChainClient(new LicenseChainConfig
{
    ApiKey = "your-api-key",
    AppName = "your-app-name",
    Version = "1.0.0",
    BaseUrl = "https://api.licensechain.app" // Optional
});
Methods
Connection Management
// Connect to LicenseChain
await client.ConnectAsync();

// Disconnect from LicenseChain
await client.DisconnectAsync();

// Check connection status
bool isConnected = client.IsConnected;
User Authentication
// Register a new user
var user = await client.RegisterAsync(username, password, email);

// Login existing user
var user = await client.LoginAsync(username, password);

// Logout current user
await client.LogoutAsync();

// Get current user info
var user = await client.GetCurrentUserAsync();
License Management
// Validate a license
var license = await client.ValidateLicenseAsync(licenseKey);

// Get user's licenses
var licenses = await client.GetUserLicensesAsync();

// Create a new license
var license = await client.CreateLicenseAsync(userId, features, expires);

// Update a license
var license = await client.UpdateLicenseAsync(licenseKey, updates);

// Revoke a license
await client.RevokeLicenseAsync(licenseKey);

// Extend a license
var license = await client.ExtendLicenseAsync(licenseKey, days);
Hardware ID Management
// Get hardware ID
string hardwareId = client.GetHardwareId();

// Validate hardware ID
bool isValid = await client.ValidateHardwareIdAsync(licenseKey, hardwareId);

// Bind hardware ID to license
await client.BindHardwareIdAsync(licenseKey, hardwareId);
Webhook Management
// Set webhook handler
client.SetWebhookHandler(handler);

// Start webhook listener
await client.StartWebhookListenerAsync();

// Stop webhook listener
await client.StopWebhookListenerAsync();
Analytics
// Track event
await client.TrackEventAsync(eventName, properties);

// Get analytics data
var analytics = await client.GetAnalyticsAsync(timeRange);

๐Ÿ”ง Configuration

App Settings

Add to your appsettings.json:

{
  "LicenseChain": {
    "ApiKey": "your-api-key",
    "AppName": "your-app-name",
    "Version": "1.0.0",
    "BaseUrl": "https://api.licensechain.app",
    "Timeout": 30,
    "Retries": 3,
    "Debug": false
  }
}

Dependency Injection

// In Startup.cs or Program.cs
services.AddLicenseChain(options =>
{
    options.ApiKey = Configuration["LicenseChain:ApiKey"];
    options.AppName = Configuration["LicenseChain:AppName"];
    options.Version = Configuration["LicenseChain:Version"];
});

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

๐Ÿ›ก๏ธ Security Features

Hardware ID Protection

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

// Hardware ID is automatically generated and stored
var hardwareId = client.GetHardwareId();

// Validate against license
var isValid = await client.ValidateHardwareIdAsync(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
await client.TrackEventAsync("app.started", new Dictionary<string, object>
{
    ["level"] = 1,
    ["playerCount"] = 10
});

// Track license events
await client.TrackEventAsync("license.validated", new Dictionary<string, object>
{
    ["licenseKey"] = "LICENSE-KEY",
    ["features"] = "premium,unlimited"
});

Performance Monitoring

// Get performance metrics
var metrics = await client.GetPerformanceMetricsAsync();
Console.WriteLine($"API Response Time: {metrics.AverageResponseTime}ms");
Console.WriteLine($"Success Rate: {metrics.SuccessRate:P}");
Console.WriteLine($"Error Count: {metrics.ErrorCount}");

๐Ÿ”„ Error Handling

Custom Exception Types

try
{
    var license = await client.ValidateLicenseAsync("invalid-key");
}
catch (InvalidLicenseException ex)
{
    Console.WriteLine("License key is invalid");
}
catch (ExpiredLicenseException ex)
{
    Console.WriteLine("License has expired");
}
catch (NetworkException ex)
{
    Console.WriteLine("Network connection failed");
}
catch (LicenseChainException ex)
{
    Console.WriteLine($"LicenseChain error: {ex.Message}");
}

Retry Logic

// Automatic retry for network errors
var client = new LicenseChainClient(new LicenseChainConfig
{
    ApiKey = "your-api-key",
    AppName = "your-app-name",
    Version = "1.0.0",
    Retries = 3, // Retry up to 3 times
    RetryDelay = TimeSpan.FromSeconds(1) // Wait 1 second between retries
});

๐Ÿงช Testing

Unit Tests

# Run tests
dotnet test

Integration Tests

# Test with real API
dotnet test --filter Category=Integration

๐Ÿ“ Examples

See the examples/ directory for complete examples:

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

๐Ÿค Contributing

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

Development Setup

  1. Clone the repository
  2. Install .NET 6.0 or later
  3. Build: dotnet build
  4. Test: dotnet test

๐Ÿ“„ License

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

๐Ÿ†˜ Support


Made with โค๏ธ for the .NET community

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 347 12/7/2025

Initial release of LicenseChain C# SDK