Skip to main content
This guide shows a minimal server-side DID authentication integration using:
  • @nuwa-ai/identity-kit
  • Express middleware
  • Rooch DID resolution (did:rooch:*)
Reference implementation: nuwa-kit/typescript/examples/did-check.

What You Build

  • Public endpoints: /health, /info
  • Protected endpoint: /whoami
  • Middleware that verifies Authorization: DIDAuthV1 ...

1) Install

2) Bootstrap Identity Environment

Your backend only needs DID resolution to verify signatures. You do not need a service private key for verification-only endpoints.

3) Add DIDAuth Middleware

4) Protect Routes

Request Format

Backend expects this header:
You can generate this on the client side with DIDAuth.v1.createSignature() + DIDAuth.v1.toAuthorizationHeader(), or with nuwa-id CLI (nuwa-id curl / nuwa-id auth-header).

Configuration

Local Validation

Run the complete example:
Then send a DID-authenticated request from an agent/client (for example with nuwa-id) to:
  • GET http://localhost:3004/whoami

Production Notes

  • Keep middleware strict: fail closed on missing or invalid auth headers.
  • Log caller DID and key id for auditing.
  • If you front with API Gateway/Proxy, preserve the original Authorization header.
  • For public internet deployments, add rate limiting before DIDAuth verification.
  • verifyAuthHeader() uses an in-memory nonce store by default. In multi-instance deployments, pass a shared nonceStore (for example Redis-backed) to keep replay protection consistent across replicas.