# Environment & Setup

*Those steps are only required when self-hosting DID wallet-server. You can skip this section if you deploy from Empeiria's One-Click Deployment Portal.*

## Prerequisites

* Node.js 20+
* npm 10+ (or Yarn)
* PostgreSQL 14+ (tested with 17.x)

## Configuration (.env)

Create a `.env` file in the wallet‑server root. Key variables:

* PORT: HTTP port (default 3000)
* DB\_HOST, DB\_PORT, DB\_USERNAME, DB\_PASSWORD, DB\_DATABASE
* DB\_MIGRATIONS\_RUN: `true` to auto‑run TypeORM migrations on boot
* JWT\_PROVIDER\_PUBLIC\_KEY: Base64‑encoded DER (SPKI) public key used to verify access tokens
* DID\_WEB\_DOMAIN: required FQDN/host for did:web
* DID\_WEB\_JSON\_PATH: optional base path (may include `:id` placeholder)
* DID\_WEB\_PORT: optional port if serving did:web on non‑default ports
* ENABLE\_DEBUG\_SIGN\_ENDPOINT: `true` to expose `/auth/debug/*` endpoints (never enable in prod)

Example:

```
PORT=3000

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=wallet
DB_MIGRATIONS_RUN=true

# Public key as Base64 DER (SPKI). Do not paste PEM.
JWT_PROVIDER_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...

# did:web configuration
DID_WEB_DOMAIN=example.com
# Optional: base path; supports ":id" placeholder
DID_WEB_JSON_PATH=/did/user/:id
# Optional: include if non‑default
DID_WEB_PORT=443

# Debug (local only)
ENABLE_DEBUG_SIGN_ENDPOINT=false
```

Tip: Use the debug keypair endpoint (see Security) to generate compatible Base64 keys for local testing.

## Install & Run

```
npm install
npm run start:dev
# or
npm run build && npm run start:prod
```

Swagger: `http://localhost:<PORT>/api-docs` OpenAPI JSON: `http://localhost:<PORT>/swagger.json`

## Database

* Migrations run automatically when `DB_MIGRATIONS_RUN=true` (and are explicitly run at boot).
* Tables include DID documents, keys, secrets, and verifiable credentials.

## did:web Hosting Notes

* The server serves `did.json` at `GET /did/user/:id/did.json` for each user.
* The actual `did:web` DID is built from `DID_WEB_DOMAIN` and `DID_WEB_JSON_PATH`.
* See “did:web & Hosting” for path rules and examples.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.empe.io/develop/wallet-server/environment-and-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
