Self-host a registrar
This guide deploys packages/server, the reference registrar, to Cloudflare Workers on your own domain. The registrar serves the did:guardian resources, an OpenID Connect provider, an account dashboard, an admin console, and the Managed Identity API. guardianspec.org runs the same code.
What you need
- A Cloudflare account with Workers and D1.
- A domain whose DNS is on Cloudflare. Every identity you create is
did:guardian:<your-domain>:<name>. You can't change the domain later. - Node.js and npm.
1. Clone and build
The registrar imports @did-guardian/lib. Build the lib before you deploy.
git clone https://github.com/did-method-guardian/did-method-guardian
cd did-method-guardian
npm install
npm run build
cd packages/server
npx wrangler login
2. Create the database
npx wrangler d1 create guardian-server
Copy the printed database_id into d1_databases[0].database_id in wrangler.jsonc. It replaces REPLACE_ME.
Apply the migrations:
npx wrangler d1 migrations apply guardian-server --remote
Wrangler lists one migration, 0001_initial.sql, and asks you to confirm.
3. Set your domain
In wrangler.jsonc, change vars.REGISTRAR_DOMAIN from guardianspec.org to your domain:
"vars": {
"REGISTRAR_DOMAIN": "acme.com"
}
Do this before anyone registers. The registrar's DIDs, OIDC issuer and URLs all derive from this value.
4. Route the Worker to your domain
wrangler.jsonc ships with no routes. Add one.
If the registrar has the whole hostname to itself, use a custom domain:
"routes": [
{ "pattern": "acme.com", "custom_domain": true }
]
If the hostname also serves another site, route only the registrar's paths. End every pattern with *.
"routes": [
{ "pattern": "acme.com/.well-known/guardian/*", "zone_name": "acme.com" },
{ "pattern": "acme.com/.well-known/openid-configuration*", "zone_name": "acme.com" },
{ "pattern": "acme.com/.well-known/jwks.json*", "zone_name": "acme.com" },
{ "pattern": "acme.com/.well-known/oauth-protected-resource*", "zone_name": "acme.com" },
{ "pattern": "acme.com/.well-known/agent-card.json*", "zone_name": "acme.com" },
{ "pattern": "acme.com/.well-known/webfinger*", "zone_name": "acme.com" },
{ "pattern": "acme.com/register*", "zone_name": "acme.com" },
{ "pattern": "acme.com/verify-email*", "zone_name": "acme.com" },
{ "pattern": "acme.com/authorize*", "zone_name": "acme.com" },
{ "pattern": "acme.com/token*", "zone_name": "acme.com" },
{ "pattern": "acme.com/userinfo*", "zone_name": "acme.com" },
{ "pattern": "acme.com/revoke*", "zone_name": "acme.com" },
{ "pattern": "acme.com/oauth/*", "zone_name": "acme.com" },
{ "pattern": "acme.com/api/me/pending-signatures*", "zone_name": "acme.com" },
{ "pattern": "acme.com/guardian-login*", "zone_name": "acme.com" },
{ "pattern": "acme.com/guardian-logout*", "zone_name": "acme.com" },
{ "pattern": "acme.com/relay-sign*", "zone_name": "acme.com" },
{ "pattern": "acme.com/account*", "zone_name": "acme.com" },
{ "pattern": "acme.com/admin*", "zone_name": "acme.com" }
]
5. Deploy and set secrets
npx wrangler deploy
npx wrangler secret put KEY_ENCRYPTION_KEY
npx wrangler secret put ROOT_WARD_LOGIN_SECRET
For KEY_ENCRYPTION_KEY, enter 32 random bytes in base64. Generate them with openssl rand -base64 32. The registrar uses this key to encrypt every held key and each OIDC signing key with AES-256-GCM. Store it safely and never change it. A changed key makes all of that data unreadable. Rotation is not supported yet. Each stored value names the key it was encrypted under by a key id, the first 8 bytes of the key's SHA-256 digest in hex. If the key has changed, the error names both key ids.
For ROOT_WARD_LOGIN_SECRET, enter a password for the root identity. Set it before the first registration. See The root identity.
The registrar hashes passwords and login secrets with PBKDF2-HMAC-SHA256 at 100,000 iterations. That cost fits the Workers Free plan, which allows 10 ms of CPU per request. On a paid plan, raise it to the OWASP recommendation by adding "PBKDF2_ITERATIONS": "600000" to vars in wrangler.jsonc and deploying again. Each stored hash records its own count, so existing passwords keep working after a change. At the next successful login, a hash with a lower count is hashed again with the new count. The registrar rejects values below 100,000.
The registrar generates its OIDC signing keys on first use, one per algorithm, and stores them encrypted in D1. You don't set them.
Access tokens are always signed with ML-DSA-44. ID tokens are signed with ES256 or ML-DSA-44, as each client chooses at registration. ES256 is the default, because most relying-party libraries cannot verify ML-DSA-44 yet. To offer only ML-DSA-44, add this to vars and deploy again:
"OIDC_ES256": "disabled"
The JWKS and discovery then list only the ML-DSA-44 key, every ID token is ML-DSA-44, and a client registration that asks for ES256 is refused. See Post-quantum security.
wrangler.jsonc already sets "compatibility_flags": ["webcrypto_modern_algorithms"]. Keep it. It gives the registrar the runtime's built-in ML-DSA-44, which costs about 0.15 to 0.25 ms of CPU per signature. Without it, the registrar falls back to a pure JavaScript ML-DSA-44. That works, but uses more CPU.
6. Check the deployment
curl https://acme.com/.well-known/openid-configuration
The response names "issuer": "https://acme.com".
Register your first identity:
curl -X POST https://acme.com/register \
-H "Content-Type: application/json" \
-d '{"name": "alice"}'
{"did":"did:guardian:acme.com:alice","login_secret":"<secret>"}
Save the login secret. It is shown once. Add "password": "..." to the body to choose your own instead.
The first registration also creates the root identity. Resolve it:
curl https://acme.com/.well-known/guardian/_
The root identity
Each registrar has one root identity with no name: did:guardian:<your-domain>. The registrar creates it on the first accepted create, never on a read (REQ-10-10, REQ-10-2). It signs the attestation in every other identity's create.
The registrar stores ROOT_WARD_LOGIN_SECRET when it creates the root identity. If you set the secret after the first registration, it takes effect at the next registration on this registrar.
To sign in as root, enter any of these in the name field: _, acme.com, @acme.com, or _@acme.com. Use _@acme.com on forms that require a name@domain shape.
The root login secret has no self-service recovery. To reset it, follow the database procedure in the README.
To bring your own root key pair, set both ROOT_WARD_PUBLIC_KEY and ROOT_WARD_PRIVATE_KEY as secrets before the first registration.
Close public registration
By default anyone can POST /register. To allow only accounts you create, set this in vars:
"REGISTRATION_MODE": "closed"
Closed mode refuses anonymous creates. A request that carries a Managed Identity API access token with the create:managed-identity scope still works.
A closed registrar can't create its root identity on its own. Bootstrap it in this order:
- Deploy with registration open and
ROOT_WARD_LOGIN_SECRETset. - Register one named identity. Choose a name you'll keep, since names are never reused.
- Set
REGISTRATION_MODEto"closed"and runnpx wrangler deployagain.
Then sign in as root at https://acme.com/admin. Create accounts at /admin/create-account, and manage OAuth clients at /admin/apps.
Optional settings
Each setting is described in the comments in wrangler.jsonc and in env.ts.
- Rate limiting. Run
npx wrangler kv namespace create guardian-rate-limit. Put the id in the commentedRATE_LIMIT_KVblock and uncomment it. Without it,/register,/guardian-loginand submitted creates have no rate limit. - Email. Set
EMAIL_PROVIDERtocloudflare-native,mailchannelsorresend. Forcloudflare-native, also uncomment thesend_emailbinding. For the others, setMAILCHANNELS_API_KEYorRESEND_API_KEYas a secret. Inbound forwarding needs Cloudflare Email Routing. See section 5 of the server README. - Federated trust. Set
FEDERATED_TRUSTED_ISSUERSto a comma-separated list of registrar hostnames, for example"other-registrar.example". This registrar then accepts their access tokens at/userinfo,POST /registerand token exchange. A token is accepted only when itssubis an identity on the issuing registrar's domain.
Next steps
- Sign in via custom OIDC with your new registrar.
- Read the registrar API for every endpoint.