posemesh-node-registration

Crates.ioposemesh-node-registration
lib.rsposemesh-node-registration
version0.2.0
created_at2025-09-18 03:30:31.570567+00
updated_at2026-01-20 01:45:28.570962+00
descriptionPosemesh node registration client and Axum handlers for DDS callbacks.
homepage
repository
max_upload_size
id1844211
size88,503
(tatiesmars)

documentation

README

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

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

Example: Mounting the HTTP Routes

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

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.
  • Enforcing a cross-process file lock so that only one registrar runs at a time.
  • Exponential backoff with jitter when DDS requests fail.
Commit count: 0

cargo fmt