Skip to content

Keycrate Rust SDK ​

Installation ​

bash
cargo add keycrate

Quick Start ​

rust
use keycrate::{LicenseAuthClient, AuthenticateOptions};

#[tokio::main]
async fn main() {
    let client = LicenseAuthClient::new(
        "https://api.keycrate.dev",
        "your-app-id"
    );

    let opts = AuthenticateOptions {
        license: Some("your-license-key".to_string()),
        ..Default::default()
    };

    match client.authenticate(opts).await {
        Ok(result) => {
            if result.success {
                println!("License verified!");
                if let Some(data) = &result.data {
                    if let Some(key) = data.get("key").and_then(|k| k.as_str()) {
                        println!("License key: {}", key);
                    }
                }
            } else {
                println!("Error: {}", result.message);
            }
        }
        Err(e) => eprintln!("Request failed: {}", e),
    }
}

Authentication ​

License Key ​

rust
let opts = AuthenticateOptions {
    license: Some("your-license-key".to_string()),
    ..Default::default()
};

let result = client.authenticate(opts).await?;

Username & Password ​

rust
let opts = AuthenticateOptions {
    username: Some("user@example.com".to_string()),
    password: Some("password123".to_string()),
    ..Default::default()
};

let result = client.authenticate(opts).await?;

With HWID (Hardware ID) ​

rust
let opts = AuthenticateOptions {
    license: Some("your-license-key".to_string()),
    hwid: Some("device-id-12345".to_string()),
    ..Default::default()
};

let result = client.authenticate(opts).await?;

Registration ​

rust
use keycrate::RegisterOptions;

let opts = RegisterOptions {
    license: "your-license-key".to_string(),
    username: "newuser@example.com".to_string(),
    password: "securepassword".to_string(),
};

let result = client.register(opts).await?;

if result.success {
    println!("Registration successful!");
} else {
    println!("Error: {}", result.message);
}

API Reference ​

LicenseAuthClient::new(host, appId) ​

Creates and returns a new client instance.

Parameters:

  • host (impl Into<String>): Base URL of the API
  • appId (impl Into<String>): Your application ID

Returns: LicenseAuthClient

client.authenticate(opts) ​

Authenticate using either a license key or username/password.

Parameters:

  • opts.license (Option<String>): License key
  • opts.username (Option<String>): Username
  • opts.password (Option<String>): Password
  • opts.hwid (Option<String>): Hardware ID

Returns: Result<AuthResponse, Box<dyn Error>>

Note: Either license OR (username + password) must be provided.

client.register(opts) ​

Register credentials for a license.

Parameters:

  • opts.license (String): License key (required)
  • opts.username (String): Username (required)
  • opts.password (String): Password (required)

Returns: Result<AuthResponse, Box<dyn Error>>

Response Structure ​

All endpoints return a response with the following structure:

rust
AuthResponse {
    success: bool,
    message: String,
    data: Option<serde_json::Value>,
}

The data field contains additional information depending on the operation:

json
{
    "key": "license-key-string",
    "expires_at": "2025-12-31T23:59:59Z",
    "hwid_reset_allowed": true,
    "last_hwid_reset_at": "2025-01-15T10:30:00Z",
    "hwid_reset_cooldown": 86400
}

Error Handling ​

rust
match client.authenticate(opts).await {
    Ok(result) => {
        if result.success {
            println!("✓ License verified");
        } else {
            if result.message.contains("expired") {
                eprintln!("Your license has expired");
                if let Some(data) = &result.data {
                    if let Some(expires) = data.get("expires_at").and_then(|v| v.as_str()) {
                        eprintln!("Expired on: {}", expires);
                    }
                }
            } else if result.message.contains("HWID") {
                eprintln!("Device mismatch");
                if let Some(data) = &result.data {
                    if let Some(true) = data.get("hwid_reset_allowed").and_then(|v| v.as_bool()) {
                        eprintln!("You can reset your HWID");
                    }
                }
            } else {
                eprintln!("Error: {}", result.message);
            }
        }
    }
    Err(e) => eprintln!("Request failed: {}", e),
}

in-depth examples : ​

Repo Card