posemesh-node-registration 0.2.1

Posemesh node registration client and Axum handlers for DDS callbacks.
Documentation
# Posemesh Node Registration SDK

This crate packages the logic required for nodes to register with the discovery service.

## Modules

- `crypto`: helpers for secp256k1 key loading, Ethereum address derivation, and SIWE signature generation.
- `http`: an `axum` router that handles legacy DDS callbacks (e.g. `/internal/v1/registrations`) and health probes.
- `state`: in-memory cache plus persistence primitives for registration status and a cross-process lock.
- `register`: async registration client that periodically signs and submits SIWE-based registration payloads to DDS.

## Adding the Dependency

```toml
# Cargo.toml
[dependencies]
posemesh-node-registration = "0.2.1"
```

## Example: Mounting the HTTP Routes

```rust
use axum::Router;
use posemesh_node_registration::http::{router_dds, DdsState};

fn build_app() -> Router {
    let dds_state = DdsState;

    // Merge with your existing routes as needed
    router_dds(dds_state)
}
```

The callback handler automatically persists secrets in-memory via `state::write_node_secret`. 
Consumers that need to read the cached secret can call `state::read_node_secret()`.

## Example: Spawning the Registration Loop

```rust
use posemesh_node_registration::register::{self, RegistrationConfig};

async fn spawn_registration(config: RegistrationConfig) {
    tokio::spawn(register::run_registration_loop(config));
}

fn build_registration_config() -> RegistrationConfig {
    RegistrationConfig {
        dds_base_url: "https://dds.auki.network".into(),
        node_version: "1.0.0".into(),
        reg_secret: "my-reg-secret".into(),
        secp256k1_privhex: std::env::var("SECP256K1_PRIVHEX").expect("missing key"),
        client: reqwest::Client::builder()
            .timeout(std::time::Duration::from_secs(10))
            .build()
            .expect("client"),
        register_interval_secs: 60,
        max_retry: -1,
        capabilities: vec![
            "/reconstruction/global-refinement/v1".into(),
            "/reconstruction/local-refinement/v1".into(),
        ],
    }
}
```

`run_registration_loop` takes care of:

- Generating SIWE messages/signatures for registration payloads.
- Persisting registration state for downstream consumers.
- Parking once the runtime has successfully acquired registration, then re-arming only on recovery signals.
- Enforcing a process-local lock so that only one registrar task runs at a time.
- Exponential backoff with jitter when DDS requests fail, while rate-limiting repeated `409 Conflict` warnings.