/api/program/detect-lost-encryption

GET

Scans the active wallet for encrypted coin files and detects which RAIDA servers have lost encryption keys.

Description

The `/api/program/detect-lost-encryption` endpoint analyzes all encrypted coin files in the Bank and Fracked folders of the active wallet. For each coin, it examines the POWN string to determine which of the 25 RAIDA servers have valid encryption keys ('p' status) versus those that have lost keys (any non-'p' status).

This diagnostic endpoint is critical for identifying encryption key loss situations where coins are encrypted but the client-server shared secrets have been corrupted or lost. Without valid encryption keys, encrypted operations with those RAIDAs will fail.

⚠️ Critical Threshold

If 13 or more RAIDAs (out of 25) have lost encryption keys, your encrypted coins may become inaccessible. The threshold for CloudCoin authenticity is 13+ passes, so losing 13+ RAIDA connections is considered critical.

💡 Use Cases

This endpoint is essential for:

  • Recovery workflows: Pre-flight check before attempting encrypted operations
  • Encryption key management: Identify which RAIDAs need key restoration
  • Wallet health checks: Periodic diagnostics to detect encryption degradation
  • Troubleshooting: Diagnose why encrypted operations are failing
  • Migration planning: Assess encryption status before moving wallets

How It Works

  1. Folder Scan: Reads all `.bin` files from Bank and Fracked folders
  2. Coin Analysis: For each coin file, reads the header including the POWN string
  3. POWN String Parsing: Examines all 25 characters (one per RAIDA) in the POWN string
  4. Key Detection: A RAIDA has a valid key if its POWN character is 'p' (pass/authenticated)
  5. Lost Key Identification: RAIDAs with any non-'p' status ('f', 'e', 'n', 'u', etc.) are considered to have lost keys
  6. Summary Generation: Counts total coins, lost RAIDAs, and provides recommendations
ℹ️ POWN String Characters

The POWN string uses these status codes:

  • p - Pass (valid encryption key)
  • f - Fail (counterfeit/rejected)
  • e - Error (RAIDA error response)
  • n - No reply (timeout)
  • u - Untried (never authenticated)
  • b - Broken encryption key
  • d - Dropped (network error)

Parameters

This endpoint does not require any parameters. It automatically analyzes the currently active wallet.

📌 Prerequisite

An active wallet must be set. If no wallet is active, the endpoint returns an error. Use /api/program/login to set the active wallet first.

Response

Returns a JSON object with detailed encryption key status information.

Response Properties

status string
Always "success" for successful detection.
operation string
Always "detect-lost-encryption".
summary object
Summary statistics about the scan.
bank_coins integer
Number of coins scanned in Bank folder.
fracked_coins integer
Number of coins scanned in Fracked folder.
total_coins integer
Total coins analyzed (bank_coins + fracked_coins).
lost_raida_count integer
Number of RAIDAs (0-25) that have lost encryption keys.
lost_raidas array of integers
List of RAIDA IDs (0-24) that have lost encryption keys.
raida_status array of objects
Detailed per-RAIDA encryption key status.
raida_id integer
RAIDA server ID (0-24).
has_key boolean
True if this RAIDA has at least one valid encryption key (at least one coin with 'p' status).
recommendation string
Recommended action based on the number of lost RAIDAs.

Example Response - Healthy Wallet

{
  "status": "success",
  "operation": "detect-lost-encryption",
  "summary": {
    "bank_coins": 42,
    "fracked_coins": 3,
    "total_coins": 45,
    "lost_raida_count": 0
  },
  "lost_raidas": [],
  "raida_status": [
    { "raida_id": 0, "has_key": true },
    { "raida_id": 1, "has_key": true },
    { "raida_id": 2, "has_key": true },
    // ... all 25 RAIDAs have keys
    { "raida_id": 24, "has_key": true }
  ],
  "recommendation": "All RAIDAs have encryption keys available."
}

Example Response - Lost Connections Detected

{
  "status": "success",
  "operation": "detect-lost-encryption",
  "summary": {
    "bank_coins": 42,
    "fracked_coins": 3,
    "total_coins": 45,
    "lost_raida_count": 5
  },
  "lost_raidas": [3, 7, 12, 18, 22],
  "raida_status": [
    { "raida_id": 0, "has_key": true },
    { "raida_id": 1, "has_key": true },
    { "raida_id": 2, "has_key": true },
    { "raida_id": 3, "has_key": false },
    // ...
    { "raida_id": 7, "has_key": false },
    // ...
    { "raida_id": 24, "has_key": true }
  ],
  "recommendation": "Lost connections detected. Run /api/fix-encryption to restore."
}

Example Response - Critical Status

{
  "status": "success",
  "operation": "detect-lost-encryption",
  "summary": {
    "bank_coins": 42,
    "fracked_coins": 3,
    "total_coins": 45,
    "lost_raida_count": 15
  },
  "lost_raidas": [0, 1, 3, 4, 7, 9, 11, 12, 14, 15, 16, 18, 20, 22, 23],
  "raida_status": [
    { "raida_id": 0, "has_key": false },
    { "raida_id": 1, "has_key": false },
    { "raida_id": 2, "has_key": true },
    // ... 15 RAIDAs have lost keys
    { "raida_id": 24, "has_key": true }
  ],
  "recommendation": "CRITICAL: Lost connections exceed threshold. Run /api/fix-encryption immediately."
}

Error Responses

Error: No Active Wallet

{
  "status": "error",
  "message": "No active wallet",
  "error_code": 501
}

Examples

JavaScript (fetch)

const API_HOST = 'http://localhost:8080';

async function detectLostEncryption() {
    try {
        const response = await fetch(`${API_HOST}/api/program/detect-lost-encryption`);
        const result = await response.json();

        if (result.status === 'success') {
            console.log('Encryption Status Report:');
            console.log(`Total Coins Scanned: ${result.summary.total_coins}`);
            console.log(`  - Bank: ${result.summary.bank_coins}`);
            console.log(`  - Fracked: ${result.summary.fracked_coins}`);
            console.log(`\nLost RAIDAs: ${result.summary.lost_raida_count}/25`);

            if (result.lost_raidas.length > 0) {
                console.log('RAIDAs with lost keys:', result.lost_raidas.join(', '));
            }

            console.log(`\nRecommendation: ${result.recommendation}`);

            // Check if critical
            if (result.summary.lost_raida_count >= 13) {
                console.warn('⚠️ CRITICAL: Immediate action required!');
            }
        } else {
            console.error('Error:', result.message);
        }
    } catch (error) {
        console.error('Request failed:', error);
    }
}

detectLostEncryption();

cURL

# Detect lost encryption connections
curl -X GET "http://localhost:8080/api/program/detect-lost-encryption"

# Pretty print with jq (if installed)
curl -s "http://localhost:8080/api/program/detect-lost-encryption" | jq .

# Check only the lost RAIDA count
curl -s "http://localhost:8080/api/program/detect-lost-encryption" | jq '.summary.lost_raida_count'

# List which RAIDAs have lost keys
curl -s "http://localhost:8080/api/program/detect-lost-encryption" | jq '.lost_raidas'

Go

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

const ApiHost = "http://localhost:8080"

type Summary struct {
    BankCoins       int `json:"bank_coins"`
    FrackedCoins    int `json:"fracked_coins"`
    TotalCoins      int `json:"total_coins"`
    LostRaidaCount  int `json:"lost_raida_count"`
}

type RaidaStatus struct {
    RaidaID int  `json:"raida_id"`
    HasKey  bool `json:"has_key"`
}

type DetectResponse struct {
    Status         string        `json:"status"`
    Operation      string        `json:"operation"`
    Summary        Summary       `json:"summary"`
    LostRaidas     []int         `json:"lost_raidas"`
    RaidaStatus    []RaidaStatus `json:"raida_status"`
    Recommendation string        `json:"recommendation"`
}

func main() {
    resp, err := http.Get(fmt.Sprintf("%s/api/program/detect-lost-encryption", ApiHost))
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)

    var result DetectResponse
    if err := json.Unmarshal(body, &result); err != nil {
        panic(err)
    }

    fmt.Println("Encryption Status Report:")
    fmt.Printf("Total Coins Scanned: %d\n", result.Summary.TotalCoins)
    fmt.Printf("  - Bank: %d\n", result.Summary.BankCoins)
    fmt.Printf("  - Fracked: %d\n", result.Summary.FrackedCoins)
    fmt.Printf("\nLost RAIDAs: %d/25\n", result.Summary.LostRaidaCount)

    if len(result.LostRaidas) > 0 {
        fmt.Print("RAIDAs with lost keys: ")
        for i, id := range result.LostRaidas {
            if i > 0 {
                fmt.Print(", ")
            }
            fmt.Printf("%d", id)
        }
        fmt.Println()
    }

    fmt.Printf("\nRecommendation: %s\n", result.Recommendation)

    if result.Summary.LostRaidaCount >= 13 {
        fmt.Println("⚠️ CRITICAL: Immediate action required!")
    }
}

Understanding the Results

Severity Levels

0 Lost RAIDAs Healthy
All encryption keys are intact. No action needed.
1-12 Lost RAIDAs Warning
Some keys lost but coins remain valid (13+ passes still achievable). Run /api/fix-encryption to restore connections.
13+ Lost RAIDAs Critical
Below authenticity threshold. Encrypted coins may be inaccessible. Run /api/fix-encryption immediately.

What Causes Lost Encryption Keys?

  • Database corruption: RAIDA server database corruption can lose stored shared secrets
  • Network timeouts: Failed encryption handshakes during key establishment
  • Server restarts: Non-persistent memory storage being cleared
  • Manual key changes: Administrative changes to RAIDA encryption data
  • Coin imports: Importing coins from another wallet with different encryption keys

Recovery Process

If lost encryption connections are detected, follow this recovery workflow:

  1. Detect: Run this endpoint to identify which RAIDAs have lost keys
  2. Fix: Use /api/program/fix-encryption to restore connections
  3. Verify: Run this endpoint again to confirm all keys are restored
  4. Monitor: Periodically check encryption health to catch issues early
🔧 How Fix Works

The /api/program/fix-encryption endpoint uses the CloudCoin healing protocol (Get Ticket + Fix) to recover lost encryption connections. It collects authentication tickets from RAIDAs with valid keys and uses them to restore keys on RAIDAs that lost them.

Related Endpoints

/api/program/login

Set the active wallet for operations. Required before running detect-lost-encryption.

/api/program/fix-encryption

Recover lost encryption connections by running the healing protocol to restore RAIDA keys.

/api/coins/detect

Authenticate coins with RAIDA servers. Updates POWN strings that this endpoint analyzes.