5-Step Quickstart (Public Runtime API v1)
Follow this sequence to connect an application to Trustlith using your Developer Portal workspace:
Step 1 — Register Your Application & Origin
In Developer Portal → Applications, register your application name and exact canonical origin URL (for example https://app.example.com). Every POST /v1/challenges request must submit this exact context.origin string.
Step 2 — Issue, Reveal & Activate a Backend API Credential
- Open Developer Portal → API Credentials for your application.
- Issue a new credential and complete the one-time reveal step.
- Save the credential in your backend server's secret store as
TRUSTLITH_API_KEY. - Click Activate in Portal. Keys that remain
ISSUEDor areREVOKED/EXPIREDfail closed with401.
Security Warning: Never place
TRUSTLITH_API_KEYinside browser JavaScript, mobile apps, or client-visible environment variables (NEXT_PUBLIC_*).
Step 3 — Map an External User
Open Developer Portal → Test Users and register an immutable external user identifier (externalUserId, max 128 chars, for example a database user UUID or "user_12345").
Step 4 — Enroll Trustlith Authenticator
Open Developer Portal → Enrollment (or follow User Enrollment Guide programmatically), generate a one-time QR handoff for the mapped user, and scan it with Trustlith Authenticator on iOS or Android. Wait until the Portal shows an active hardware-bound P-256 device.
Step 5 — Trigger & Verify a Challenge from Your Backend
- Call
POST /v1/challengeswithaction: "login"oraction: "fund_transfer"(see Code Examples). - Instruct your frontend to display a waiting state ("Approve in Trustlith Authenticator within 2 minutes").
- Poll
GET /v1/challenges/:challengeId/statusfrom your backend every2–3seconds (stopping immediately on terminal status or user cancel). - Grant access or execute the sensitive mutation only when your backend observes
status === "APPROVED". Reject cleanly onREJECTED,CANCELLED, orEXPIRED.
User Enrollment Guide (V1)
Before a user can approve login or fund_transfer challenges, they must be mapped in your application and have at least one enrolled Trustlith Authenticator device holding a P-256 key.
Option 1 — Developer Portal Test Workbench (Fastest for Pilot Setup)
- Open Developer Portal → Test Users and register your user's immutable
externalUserId. - Open Developer Portal → Enrollment, choose the user, and click Start First-Device QR Enrollment.
- Scan the rendered QR code using Trustlith Authenticator on iOS or Android and confirm biometric prompt completion.
Option 2 — Programmatic Backend Handoff (POST /v1/enrollments + POST /v1/enrollment-handoffs)
For an active mapped user in tenant_users:
- Create a 10-minute enrollment (
enrollments:create):
```http POST /v1/enrollments Authorization: Bearer <TRUSTLITH_API_KEY> Content-Type: application/json
{ "externalUserId": "user_12345" } `` Returns { enrollmentId, enrollmentToken, expiresAt, developmentOnly }. Keep enrollmentToken` server-side!
- Mint an opaque single-use QR/deep-link handoff (
enrollments:create):
```http POST /v1/enrollment-handoffs Authorization: Bearer <TRUSTLITH_API_KEY> Content-Type: application/json
{ "enrollmentId": "<enrollmentId>", "ceremonyType": "FIRST_DEVICE" } `` Returns { handoffId, ceremonyType, expiresAt, ref } (ref expires within 5 minutes, returned once and never logged). Encode ref into your UI's one-time QR code or mobile deep link; Trustlith Authenticator redeems ref directly against /v1/enrollment-handoffs/redeem without ever seeing enrollmentToken`.
Public Runtime API v1 Reference
Machine-readable schema: docs/openapi.yaml.
Authentication & Scoping Rules
- Header:
Authorization: Bearer <TRUSTLITH_API_KEY>(Application Bearer routes) orAuthorization: Device <retrieval-token>(Authenticator device routes). - Server-Derived Ownership: Never include
tenantIdorapplicationIdinPOST /v1/challengespayloads (400 SCOPE_NOT_ACCEPTED). - Strict Origin Binding:
context.originmust exact-match your application's registered origin (404 USER_OR_ORIGIN_NOT_AVAILABLEon mismatch). - Challenge TTL:
120seconds from creation (expiresAt).
Application Bearer Endpoints
| Method & Path | Required Scope | Request Body | Success Response | |
|---|---|---|---|---|
GET /health |
None | — | 200 { status: "ok", service: "trustlith-api", environment, phase } |
|
POST /v1/enrollments |
enrollments:create |
{ externalUserId } |
201 { enrollmentId, enrollmentToken, expiresAt, developmentOnly } |
|
POST /v1/enrollment-handoffs |
enrollments:create |
`{ enrollmentId, ceremonyType: "FIRST_DEVICE" \ | "ADDITIONAL_DEVICE" }` | 201 { handoffId, ceremonyType, expiresAt, ref } |
POST /v1/challenges |
challenges:create |
`{ externalUserId, action: "login" \ | "fund_transfer", context: { origin, device }, transactionContext? }` | 201 { challengeId, status: "PENDING", expiresAt } |
GET /v1/challenges/:challengeId/status |
challenges:read |
— | 200 { challengeId, status, expiresAt, action } |
|
POST /v1/challenges/:challengeId/cancel |
challenges:cancel |
— | 200 { challengeId, status: "CANCELLED" } |
Challenge status State Machine
PENDING: Waiting for device approval/rejection prior toexpiresAt.APPROVED: Device submitted a verified ES256 P-256 signature overTRUSTLITH-AUTH-V1\0.REJECTED: User explicitly declined the challenge on their Authenticator.CANCELLED: Your backend cancelled an unexpiredPENDINGchallenge via/cancel.EXPIRED: Challenge passedexpiresAt(120s) without signature verification.
Common Error Codes
400 SCOPE_NOT_ACCEPTED—tenantIdorapplicationIdpassed in request JSON.400 INVALID_ACTION/400 INVALID_TRANSACTION— MissingtransactionContext.type: "fund_transfer", malformedamount(^\d{1,12}\.\d{2}$), or non-ISO 3-lettercurrency.401 UNAUTHORIZED— Missing, unactivated, expired, or revoked Bearer credential, or suspended tenant/app.403 FORBIDDEN/403 ENTITLEMENT_INACTIVE— Credential lacks the route's required scope or plan entitlement is inactive.404 USER_OR_ORIGIN_NOT_AVAILABLE—externalUserIdis not mapped/active for this app ORcontext.origindoes not match the registered origin.409 INVALID_STATE_TRANSITION— Attempted/cancelon an already resolved or overdue/expired challenge.429 CHALLENGE_LIMIT_REACHED/429 AUTHENTICATION_LIMIT_REACHED/429 ENROLLMENT_LIMIT_REACHED— Pending ceiling, cooldown, or quota limit reached.