feat: multi-clinic Temetro Network with per-clinic identity (v0.8.0)

The relay is now multi-clinic. Each clinic authenticates to the /hub
namespace by signing a challenge with its own Ed25519 clinic signing key
(a per-clinic identity, not a shared RELAY_TOKEN), and the relay routes
every device response back to only the clinic that originated the request
(keyed by requestId) — so clinics never see each other's traffic.

Backend:
- clinic_signing_keys.network_enabled + GET/PUT /api/signing/network
  (owner/admin) to join/leave the network.
- relay-client keeps one authenticated hub connection per network-enabled
  org (connectOrg/disconnectOrg, hubs map keyed by orgId); emitToWallet/
  sendToWallet take orgId; offline flush is org-scoped.
- Wallet import/push return 409 until a clinic joins.
- RELAY_TOKEN is now optional/legacy (open relay needs no shared secret).

Frontend:
- "Join Temetro Network" toggle in Settings → Signing, localized in all
  five languages (en, fr, de, so, ar).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-07-05 18:30:19 +03:00
parent ef76afc3ca
commit 99aa534e88
24 changed files with 4986 additions and 43 deletions
+7 -7
View File
@@ -31,8 +31,10 @@ const schema = z.object({
// Temetro Network relay (github.com/temetro/temetro-network). Both this
// backend and patient phones connect to it; it routes the encrypted wallet
// messages between them. RELAY_URL is the relay's public URL (also baked into
// the QR a patient scans); RELAY_TOKEN is the shared secret this backend
// presents on the relay's /hub namespace (must match the relay's RELAY_TOKEN).
// the QR a patient scans). Each clinic authenticates to the relay's /hub with
// its own Ed25519 signing key, so no shared secret is needed. RELAY_TOKEN is
// now *optional/legacy* — set it only for a private relay that also gates on a
// shared token (must then match the relay's RELAY_TOKEN).
RELAY_URL: z.string().min(1).default("http://localhost:8080"),
RELAY_TOKEN: z.string().default(""),
// Public, device-reachable URL of this backend's wallet relay, baked into the
@@ -87,11 +89,9 @@ if (env.NODE_ENV === "production") {
);
process.exit(1);
}
if (!env.RELAY_TOKEN) {
console.warn(
"⚠️ RELAY_TOKEN is unset in production — the Temetro Network /hub connection is unauthenticated. Set a shared secret: openssl rand -base64 32",
);
}
// RELAY_TOKEN is optional now: clinics authenticate to the relay with their
// own Ed25519 signing key, so an unset token is the normal "open relay" case —
// no warning needed.
}
export const isProd = env.NODE_ENV === "production";