feat(api): expose HTTP REST endpoints for DID resolution, mailbox relay, and health

Aperta
#3 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
api

Direzione di ricerca

Start in src/main.rs, where the node builds NodeConfig, MailboxStore and KeyTransparencyLog and prints a health line before exiting, then look at src/health.rs, src/merkle.rs and src/relay.rs for the data they expose. The new router belongs in src/http_server.rs, which must stay under 300 lines. Check docs/API.md for the response schemas and tests/node_test.rs for the existing tests, which must keep passing. Done means all five endpoints return the documented status codes and JSON, and fmt, clippy and test pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area::node effort::l impact::critical priority::critical source::user status::review type::feature

Part of Meta-Issue alfonsodg/sonaraim#2
Ref alfonsodg/sonaraim-node#2

Problem

src/main.rs:1-34 currently initializes NodeConfig, MailboxStore, and KeyTransparencyLog, prints a single JSON health line to stdout, and exits. It does not bind an HTTP listener on NODE_HTTP_HOST:NODE_HTTP_PORT (8040) to serve the documented REST endpoints (GET /health, POST /v1/identity, GET /v1/identity/{did}, POST /v1/relay/envelopes, GET /v1/relay/mailboxes/{mailbox_id}).

Affected Files & Locations

  • src/main.rs:1-34
  • src/health.rs:1-75
  • src/merkle.rs:42-269
  • src/relay.rs:34-127
  • src/http_server.rs (new HTTP server & router module, < 300 lines)
  • tests/node_test.rs:1-167

Evidence

// src/main.rs:27-33
let health = HealthStatus::new(&config.node_id, "0.1.0", 0, log.tree_size());
println!("{}", health.to_json());

Impact and Blast Radius

sonaraim-b2b, sonaraim-admin, and sonaraim-app depend on sonaraim-node's HTTP API (8040) to register and resolve DIDs, verify Merkle inclusion proofs, publish SealedEnvelope messages, and drain recipient mailboxes.

Historical Context and Anti-Regression

Builds on e62fca0 (Issue #1). All 5 existing unit tests in tests/node_test.rs must continue passing without modification.

Proposed Solution

  1. Implement src/http_server.rs exposing:
    • GET /health -> 200 OK
    • POST /v1/identity -> 201 Created (registers did:sonaraim or did:web and returns Merkle proof)
    • GET /v1/identity/{did} -> 200 OK / 404 Not Found
    • POST /v1/relay/envelopes -> 202 Accepted (stores SealedEnvelope and returns wake_up_token)
    • GET /v1/relay/mailboxes/{mailbox_id} -> 200 OK (drains active envelopes for mailbox)
  2. Standardize error responses using {"error": {"code": "...", "message": "..."}}.

Acceptance Criteria

  • HTTP server binds to configured NODE_HTTP_HOST:NODE_HTTP_PORT (or ephemeral port 0 in tests).
  • Every exposed endpoint and HTTP method (GET /health, POST /v1/identity, GET /v1/identity/{did}, POST /v1/relay/envelopes, GET /v1/relay/mailboxes/{mailbox_id}) is tested with valid and invalid payloads (200, 201, 202, 400, 404, 405).
  • All files remain under 300 lines and pass cargo fmt --check, cargo clippy -- -D warnings, and cargo test.

Validation Criteria

Level Applies Test Scenario Pass
Unit Yes tests/node_test.rs Request parsing, route dispatch, error formatting 100% pass (cargo test)
Integration Yes tests/node_test.rs Live TCP HTTP requests exercising all 5 endpoints and methods Status codes and JSON bodies verified
Contract Yes docs/API.md Response JSON structure matches docs/API.md specification 100% schema match
E2E Yes curl verification on Sandbox (REMOTE.md) Live HTTP requests against running sonaraim-node container HTTP 200/201/202 verified
Lingua principale
Rust
Stelle
0
Fork
0
Merge medio
4m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di alfonsodg/sonaraim-node

Tutte le issue di alfonsodg/sonaraim-node

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.