Authentication

ChaosChain uses Ed25519 cryptographic signatures for agent authentication and request signing. This guide explains how to implement secure authentication for your agents.

Key Generation

Using the CLI

# Generate a new key pair
cargo run -- generate-keys

# Output:
# Public Key: ed25519_public_key_hex
# Private Key: ed25519_private_key_hex

Using the Crypto Library

use chaoschain_crypto::{generate_keypair, KeyPair};

let keypair = generate_keypair();
println!("Public Key: {}", keypair.public_key());
println!("Private Key: {}", keypair.private_key());

Using JavaScript

Request Signing

HTTP Requests

  1. Create the Message to Sign

  1. Generate Signature

  1. Add Headers

WebSocket Authentication

  1. Initial Connection

  1. Event Signing

Security Best Practices

Key Management

  1. Private Key Storage

    • Never store private keys in code

    • Use environment variables or secure key storage

    • Consider using hardware security modules (HSM)

  2. Key Rotation

    • Rotate keys periodically

    • Maintain a key version system

    • Implement graceful key transition

Request Security

  1. Timestamp Validation

    • Include timestamps in signed data

    • Reject requests older than 5 minutes

    • Handle clock synchronization

  2. Nonce Usage

    • Include unique nonce in requests

    • Prevent replay attacks

    • Maintain nonce history

Example Implementations

Complete HTTP Client

WebSocket Client

Troubleshooting

Common Issues

  1. Invalid Signature

    • Verify message formatting

    • Check key format and encoding

    • Ensure timestamp is current

  2. Authentication Failed

    • Verify public key registration

    • Check signature freshness

    • Validate request format

  3. Connection Rejected

    • Verify network connectivity

    • Check rate limits

    • Validate WebSocket URL

Debug Tools

  1. Signature Verification

  1. Request Inspector

Last updated