openapi: 3.1.0
info:
  title: OHN-39 Network Trust and Accreditation
  version: 1.1.0
  description: Accreditation policy is configuration (OHN39_ACCEPTED_TRUST_TIERS in the TypeScript baseline; ohn.m39.accepted-trust-tiers / OHN_M39_ACCEPTED_TRUST_TIERS in the Java service); without it enrollment and certificate verification fail closed with 503 not_configured, and a tier outside the list is 422 tier_not_accepted. Synthetic-ready trust and accreditation service contracts. Production use requires accepted OHN-01/OHN-38/OHN-16 integrations and security authorization. OHN membership never implies government accreditation without evidence.
jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema
servers:
  - url: /
security:
  - bearerAuth: []
tags:
  - name: Enrollments
  - name: Certificates
  - name: Endpoints
  - name: Workflows
  - name: Reports
paths:
  /api/ohn/v1/trust/health:
    get:
      operationId: ohn39_health
      security: []
      responses:
        '200': { description: Service health, content: { application/json: { schema: { type: object } } } }
  /health/ohn-39:
    get:
      operationId: ohn39_platformHealth
      security: []
      description: Platform health probe; checks the OHN-39 database connection.
      responses:
        '200': { description: Healthy, content: { application/json: { schema: { type: object } } } }
        '503': { description: Database unavailable, content: { application/json: { schema: { type: object } } } }
  /api/ohn/v1/trust/auth/token:
    post:
      operationId: ohn39_issueSyntheticToken
      security: []
      description: Available only outside production when OHN39_SYNTHETIC_AUTH=true. Served by the TypeScript baseline only; the Java service does not issue tokens (they come from the platform gateway, ES256, audience ohn-39) and answers 404 here.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SyntheticTokenCommand' }
      responses:
        '200': { description: Synthetic token, content: { application/json: { schema: { type: object, required: [access_token], properties: { access_token: { type: string } } } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/trust/enrollments:
    post:
      operationId: ohn39_createEnrollment
      x-inventory-id: OHN-39-API-001
      x-form-id: OHN-39-F001-SUBMIT
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { $ref: '#/components/requestBodies/TrustEnrollment' }
      responses:
        '201': { description: Enrollment application committed, content: { application/json: { schema: { $ref: '#/components/schemas/TrustEnrollmentView' } } } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
    get:
      operationId: ohn39_listEnrollments
      parameters:
        - { name: cursor, in: query, schema: { type: string, format: uuid } }
        - { name: page_size, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: status, in: query, schema: { $ref: '#/components/schemas/EnrollmentState' } }
        - { name: trust_tier, in: query, schema: { $ref: '#/components/schemas/TrustTier' } }
        - { name: organization_id, in: query, schema: { type: string, format: uuid } }
      responses:
        '200': { description: Scoped trust review queue, content: { application/json: { schema: { $ref: '#/components/schemas/EnrollmentListResponse' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/enrollments/{id}:
    get:
      operationId: ohn39_getEnrollment
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
      responses:
        '200': { description: Enrollment detail with workflow history and linked evidence, content: { application/json: { schema: { $ref: '#/components/schemas/TrustEnrollmentDetail' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/enrollments/{id}/approve:
    post:
      operationId: ohn39_approveEnrollment
      x-inventory-id: OHN-39-API-002
      description: Advances the trust onboarding workflow one guarded state. Emits trust.enrollment.approved when the enrollment becomes trusted. Returns 202 with pending reconciliation when the jurisdiction dependency is unavailable.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody: { $ref: '#/components/requestBodies/ApproveEnrollment' }
      responses:
        '200': { description: Transition committed with audit receipt, content: { application/json: { schema: { $ref: '#/components/schemas/TrustEnrollmentView' } } } }
        '202': { description: Local fact committed; downstream confirmation pending, content: { application/json: { schema: { $ref: '#/components/schemas/TrustEnrollmentView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/certificates/verify:
    post:
      operationId: ohn39_verifyCertificate
      x-form-id: OHN-39-F002-SUBMIT
      description: Records certificate chain verification evidence. Expired certificates are rejected with 422 expired_certificate and never establish trust. Answers 503 not_configured when no accreditation policy is configured and 422 tier_not_accepted for a tier outside it.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { $ref: '#/components/requestBodies/CertificateVerification' }
      responses:
        '201': { description: Verification evidence, certificate record and endpoint trust status committed, content: { application/json: { schema: { $ref: '#/components/schemas/AccreditationEvidenceView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/certificates:
    get:
      operationId: ohn39_getCertificateDashboard
      responses:
        '200': { description: Certificate dashboard KPIs, status distribution, trend and exception worklist, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/endpoints/{id}/verification:
    get:
      operationId: ohn39_getEndpointVerification
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
      responses:
        '200': { description: Source comparison, evidence, decision inputs and history for one endpoint, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/endpoints/{id}/bindings:
    post:
      operationId: ohn39_bindEndpointBaseUrl
      x-added-in: 1.1.0
      description: (v1.1, ADR-0002) Binds an endpoint id that has a trust status to the base URL it serves, so partners can look trust up by base URL. certificate_administrator only. The base URL is normalised (lower-case scheme and host, no default port, no trailing slash, no query). One active binding per base URL per organization and jurisdiction.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [base_url, reason]
              properties:
                base_url: { type: string, format: uri, minLength: 8, maxLength: 2048 }
                reason: { type: string, minLength: 10, maxLength: 1000 }
      responses:
        '201': { description: Binding stored with audit receipt, content: { application/json: { schema: { type: object, required: [id, endpoint_id, base_url, state, version, receipt], properties: { id: { type: string, format: uuid }, endpoint_id: { type: string, format: uuid }, base_url: { type: string }, state: { type: string, enum: [active, retired] }, version: { type: integer }, receipt: { type: object } } } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
  /api/ohn/v1/trust/endpoint-bindings:
    get:
      operationId: ohn39_listEndpointBindings
      x-added-in: 1.2.0
      description: Active endpoint-to-address bindings of the caller's organisation (trust_reviewer, certificate_administrator), so screens name an endpoint by the address it serves.
      responses:
        '200':
          description: Active bindings
          content:
            application/json:
              schema:
                type: object
                required: [data]
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      required: [id, endpoint_id, base_url, state, version, updated_at]
                      properties:
                        id: { type: string, format: uuid }
                        endpoint_id: { type: string, format: uuid }
                        base_url: { type: string }
                        state: { type: string }
                        version: { type: integer, minimum: 1 }
                        updated_at: { type: string, format: date-time }
        '401': { description: Unauthenticated }
        '403': { description: Role not permitted }
  /api/ohn/v1/trust/endpoint-verifications:
    get:
      operationId: ohn39_lookupEndpointVerification
      x-added-in: 1.1.0
      description: (v1.1, ADR-0002) Partner trust lookup by organization, base URL and certificate reference, scoped to the token's jurisdiction and organization (organization_id must equal the token's). Fail closed; only a trusted, unrevoked, unexpired status for exactly this certificate is "verified".
      parameters:
        - { name: organization_id, in: query, required: true, schema: { type: string, format: uuid } }
        - { name: base_url, in: query, required: true, schema: { type: string, minLength: 8, maxLength: 2048 } }
        - { name: certificate_ref, in: query, required: true, schema: { type: string, minLength: 1, maxLength: 256 } }
      responses:
        '200':
          description: Lookup result (also returned, as unverified/endpoint_not_bound, when no binding exists)
          content:
            application/json:
              schema:
                type: object
                required: [api_version, status, reason, endpoint_id, evidence_ref, not_after, checked_at]
                properties:
                  api_version: { type: string, const: 1.1.0 }
                  status: { type: string, enum: [verified, unverified, revoked, expired] }
                  reason: { type: string, enum: [trusted, endpoint_not_bound, no_trust_status, certificate_mismatch, certificate_revoked, endpoint_revoked, endpoint_quarantined, certificate_expired, not_trusted, revocation_unknown] }
                  endpoint_id: { type: [string, 'null'], format: uuid }
                  evidence_ref: { type: [string, 'null'], format: uuid }
                  not_after: { type: [string, 'null'], format: date-time }
                  checked_at: { type: string, format: date-time }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/endpoints/{id}/attestations:
    post:
      operationId: ohn39_attestEndpoint
      x-screen-id: OHN-39-P005
      description: Records the outcome of an endpoint ownership challenge. A passed challenge, approved by a different person (dual control), is the positive attestation the onboarding step endpoint_attested requires. A failed challenge is recorded as kind=challenge, state=challenge_failed and never counts.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [challenge_result, challenge_evidence, reason, approver]
              properties:
                challenge_result: { type: string, enum: [passed, failed] }
                challenge_evidence: { type: string, format: uuid }
                reason: { type: string, minLength: 10, maxLength: 4096 }
                approver: { type: string, format: uuid }
      responses:
        '201': { description: Attestation recorded with receipt, content: { application/json: { schema: { $ref: '#/components/schemas/EndpointAttestationView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/endpoints/{id}/revoke:
    post:
      operationId: ohn39_revokeEndpoint
      x-inventory-id: OHN-39-API-003
      x-form-id: OHN-39-F003-SUBMIT
      description: Suspends trust for the listed endpoints, quarantines them, blocks client credentials and emits trust.status.revoked atomically. Dual control - the approver must differ from the requesting operator. Returns 202 with pending reconciliation when the jurisdiction dependency is unavailable.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody: { $ref: '#/components/requestBodies/EndpointRevoke' }
      responses:
        '201': { description: Suspension committed; credentials blocked, content: { application/json: { schema: { $ref: '#/components/schemas/EndpointAttestationView' } } } }
        '202': { description: Local fact committed; downstream confirmation pending, content: { application/json: { schema: { $ref: '#/components/schemas/EndpointAttestationView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/suspensions/{id}/reinstate:
    post:
      operationId: ohn39_reinstateSuspension
      description: Completes the trust compromise response workflow by reinstating suspended endpoints after human review.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody: { $ref: '#/components/requestBodies/ReinstateSuspension' }
      responses:
        '200': { description: Suspension revalidated, content: { application/json: { schema: { $ref: '#/components/schemas/EndpointAttestationView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/workflows/{id}/transitions:
    post:
      operationId: ohn39_transitionWorkflow
      description: Advances a certificate rollover workflow (expiry_warning, new_chain_proven, overlap_window, old_revoked) with optimistic concurrency.
      parameters:
        - { $ref: '#/components/parameters/ResourceId' }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody: { $ref: '#/components/requestBodies/WorkflowTransition' }
      responses:
        '200': { description: Rollover transition committed, content: { application/json: { schema: { $ref: '#/components/schemas/AccreditationEvidenceView' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/suspensions:
    get:
      operationId: ohn39_listSuspensions
      parameters:
        - { name: cursor, in: query, schema: { type: string, format: uuid } }
        - { name: page_size, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: status, in: query, schema: { $ref: '#/components/schemas/CompromiseState' } }
      responses:
        '200': { description: Scoped suspension history, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/evidence:
    get:
      operationId: ohn39_listEvidence
      parameters:
        - { name: cursor, in: query, schema: { type: string } }
        - { name: page_size, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: record_type, in: query, schema: { type: string, enum: [enrollment, evidence, attestation, suspension] } }
        - { name: endpoint_id, in: query, schema: { type: string, format: uuid } }
      responses:
        '200': { description: Combined trust evidence history in the authorized scope, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/reports/{id}:
    get:
      operationId: ohn39_getReport
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, enum: [OHN-39-R001, OHN-39-R002, OHN-39-R003] } }
        - { name: tier, in: query, schema: { $ref: '#/components/schemas/TrustTier' } }
        - { name: period_from, in: query, schema: { type: string, format: date-time } }
        - { name: period_to, in: query, schema: { type: string, format: date-time } }
        - { name: expiry_window_days, in: query, description: 'Default 30. Not range-checked on this GET (the export body is: 1 to 3650); a non-numeric value matches no certificate.', schema: { type: number } }
        - { name: organization_id, in: query, schema: { type: string, format: uuid } }
        - { name: status, in: query, schema: { type: string } }
      responses:
        '200': { description: Authorized report with deterministic metrics and provenance, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/reports/{id}/export:
    post:
      operationId: ohn39_createExport
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, enum: [OHN-39-R001, OHN-39-R002, OHN-39-R003] } }
        - { $ref: '#/components/parameters/IdempotencyKey' }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ExportCommand' }
      responses:
        '201': { description: Signed one-time export created with audit receipt, content: { application/json: { schema: { type: object } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Validation' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
  /api/ohn/v1/trust/exports/{token}:
    get:
      operationId: ohn39_downloadExport
      parameters:
        - { name: token, in: path, required: true, schema: { type: string } }
      responses:
        '200': { description: One-time signed export content, content: { text/csv: {}, application/pdf: {} } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Denied' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
        '503': { $ref: '#/components/responses/Unavailable' }
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  parameters:
    ResourceId:
      name: id
      in: path
      required: true
      schema: { type: string, format: uuid }
      description: Resource-scoped id; verified by the authoritative owner service
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema: { type: string, minLength: 1, maxLength: 255 }
      description: Client-generated key per intent; same key and payload replays the original receipt, same key with a different payload returns 409.
  schemas:
    TrustTier:
      type: string
      enum: [bronze, silver, gold, platinum]
    RevocationStatus:
      type: string
      enum: [not_revoked, revoked, unknown]
    EnrollmentState:
      type: string
      enum: [application, evidence_verified, endpoint_attested, approved, trusted, suspended, revoked]
    CompromiseState:
      type: string
      enum: [compromise_reported, endpoint_quarantined, tokens_revoked, revalidated, challenge_failed]
    TrustEnrollmentCommand:
      type: object
      additionalProperties: false
      required: [organization_id, endpoint_ref, accreditation_document, trust_tier, issuing_authority]
      properties:
        organization_id: { type: string, format: uuid }
        endpoint_ref: { type: string, format: uuid }
        accreditation_document: { type: string, format: uuid }
        trust_tier: { $ref: '#/components/schemas/TrustTier' }
        issuing_authority: { type: string, format: uuid }
    EnrollmentApproveCommand:
      type: object
      additionalProperties: false
      required: [expected_version, evidence_ref, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    CertificateVerificationCommand:
      type: object
      additionalProperties: false
      required: [endpoint_id, certificate_chain_ref, revocation_status, not_after, validation_evidence, subject, issuer, serial_number, trust_tier, issuing_authority, accreditation_document]
      properties:
        endpoint_id: { type: string, format: uuid }
        certificate_chain_ref: { type: string, format: uuid }
        revocation_status: { $ref: '#/components/schemas/RevocationStatus' }
        not_after: { type: string, format: date-time }
        validation_evidence: { type: string, format: uuid }
        subject: { type: string, minLength: 1, maxLength: 512 }
        issuer: { type: string, minLength: 1, maxLength: 512 }
        serial_number: { type: string, minLength: 1, maxLength: 128 }
        trust_tier: { $ref: '#/components/schemas/TrustTier' }
        issuing_authority: { type: string, format: uuid }
        accreditation_document: { type: string, format: uuid }
    EndpointRevokeCommand:
      type: object
      additionalProperties: false
      required: [organization_id, reason, affected_endpoint_ids, effective_at, approver]
      properties:
        organization_id: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
        affected_endpoint_ids: { type: string, minLength: 1, maxLength: 8192, description: Whitespace or comma separated UUID list }
        effective_at: { type: string, format: date-time }
        approver: { type: string, format: uuid }
    WorkflowTransitionCommand:
      type: object
      additionalProperties: false
      required: [expected_version, to_state, evidence_ref, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        to_state: { type: string, minLength: 1, maxLength: 64 }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    ReinstateSuspensionCommand:
      type: object
      additionalProperties: false
      required: [expected_version, evidence_ref, reason]
      properties:
        expected_version: { type: integer, minimum: 1 }
        evidence_ref: { type: string, format: uuid }
        reason: { type: string, minLength: 10, maxLength: 4096 }
    ExportCommand:
      type: object
      additionalProperties: false
      required: [format]
      properties:
        format: { type: string, enum: [csv, pdf] }
        country: { type: string, maxLength: 128 }
        tier: { $ref: '#/components/schemas/TrustTier' }
        period_from: { type: string, format: date-time }
        period_to: { type: string, format: date-time }
        expiry_window_days: { type: integer, minimum: 1, maximum: 3650 }
        organization_id: { type: string, format: uuid }
        status: { type: string, maxLength: 64 }
    SyntheticTokenCommand:
      type: object
      additionalProperties: false
      required: [principal_id, role, jurisdiction, organization_id, purpose]
      properties:
        principal_id: { type: string, format: uuid }
        role: { type: string, enum: [trust_reviewer, certificate_administrator, unauthorized_viewer] }
        jurisdiction: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        purpose: { type: string, enum: [trust_onboarding, certificate_verification, trust_suspension, trust_reporting] }
    Provenance:
      type: object
      additionalProperties: false
      required: [source_system_id, provenance_ref]
      properties:
        source_system_id: { type: string, format: uuid }
        provenance_ref: { type: string, format: uuid }
    Receipt:
      type: object
      additionalProperties: false
      required: [receipt_id, committed_at, aggregate_id, aggregate_type, version, status]
      properties:
        receipt_id: { type: string, format: uuid }
        committed_at: { type: string, format: date-time }
        aggregate_id: { type: string, format: uuid }
        aggregate_type: { type: string }
        version: { type: integer }
        status: { type: string, enum: [committed, pending] }
    TrustEnrollmentView:
      type: object
      additionalProperties: false
      required: [id, organization_id, endpoint_ref, accreditation_document, trust_tier, issuing_authority, state, version, created_at, updated_at]
      properties:
        id: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        endpoint_ref: { type: string, format: uuid }
        accreditation_document: { type: string, format: uuid }
        trust_tier: { $ref: '#/components/schemas/TrustTier' }
        issuing_authority: { type: string, format: uuid }
        state: { $ref: '#/components/schemas/EnrollmentState' }
        version: { type: integer }
        accredited_at: { type: string, format: date-time, nullable: true }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
        provenance: { $ref: '#/components/schemas/Provenance' }
        receipt: { $ref: '#/components/schemas/Receipt' }
    TrustEnrollmentDetail:
      allOf:
        - { $ref: '#/components/schemas/TrustEnrollmentView' }
        - type: object
          properties:
            workflow_history: { type: array, items: { type: object } }
            evidence: { type: array, items: { type: object } }
            attestations: { type: array, items: { $ref: '#/components/schemas/EndpointAttestationView' } }
    EnrollmentListResponse:
      type: object
      additionalProperties: false
      required: [data, next_cursor, page_size, summary]
      properties:
        data: { type: array, items: { $ref: '#/components/schemas/TrustEnrollmentView' } }
        next_cursor: { type: string, format: uuid, nullable: true }
        page_size: { type: integer }
        summary: { type: object, additionalProperties: { type: integer } }
    AccreditationEvidenceView:
      type: object
      additionalProperties: false
      required: [id, organization_id, endpoint_id, certificate_chain_ref, revocation_status, not_after, validation_evidence, state, version]
      properties:
        id: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        endpoint_id: { type: string, format: uuid }
        certificate_chain_ref: { type: string, format: uuid }
        revocation_status: { $ref: '#/components/schemas/RevocationStatus' }
        not_after: { type: string, format: date-time }
        validation_evidence: { type: string, format: uuid }
        state: { type: string, enum: [expiry_warning, new_chain_proven, overlap_window, old_revoked] }
        version: { type: integer }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
        provenance: { $ref: '#/components/schemas/Provenance' }
        certificate: { type: object }
        workflow_id: { type: string, format: uuid }
        workflow_state: { type: string }
        receipt: { $ref: '#/components/schemas/Receipt' }
    EndpointAttestationView:
      type: object
      additionalProperties: false
      required: [id, organization_id, kind, reason, affected_endpoint_ids, effective_at, approver, state, version]
      properties:
        id: { type: string, format: uuid }
        organization_id: { type: string, format: uuid }
        kind: { type: string, enum: [attestation, challenge, suspension] }
        reason: { type: string }
        affected_endpoint_ids: { type: string }
        effective_at: { type: string, format: date-time }
        approver: { type: string, format: uuid }
        state: { $ref: '#/components/schemas/CompromiseState' }
        version: { type: integer }
        revoked_at: { type: string, format: date-time, nullable: true }
        reinstated_at: { type: string, format: date-time, nullable: true }
        reinstatement_evidence: { type: string, format: uuid, nullable: true }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
        provenance: { $ref: '#/components/schemas/Provenance' }
        workflow_state: { type: string }
        event_id: { type: string, format: uuid }
        receipt: { $ref: '#/components/schemas/Receipt' }
        downstream: { type: string }
  requestBodies:
    TrustEnrollment:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/TrustEnrollmentCommand' }
    ApproveEnrollment:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/EnrollmentApproveCommand' }
    CertificateVerification:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/CertificateVerificationCommand' }
    EndpointRevoke:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/EndpointRevokeCommand' }
    ReinstateSuspension:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/ReinstateSuspensionCommand' }
    WorkflowTransition:
      required: true
      content:
        application/json:
          schema: { $ref: '#/components/schemas/WorkflowTransitionCommand' }
  responses:
    BadRequest:
      description: Malformed request
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { type: string } } } } }
    Unauthorized:
      description: Unauthenticated
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { const: unauthenticated } } } } }
    Denied:
      description: Denied by policy
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { const: denied_by_policy } } } } }
    NotFound:
      description: Not found or non-disclosing resource refusal
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { const: not_found } } } } }
    Conflict:
      description: Conflict, stale version or idempotency mismatch
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { type: string } } } } }
    Validation:
      description: Domain validation failed
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { type: string }, details: { type: object } } } } }
    RateLimited:
      description: Rate limited
      headers: { Retry-After: { schema: { type: string } } }
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { const: rate_limited } } } } }
    Unavailable:
      description: Dependency unavailable
      content: { application/json: { schema: { type: object, required: [error], properties: { error: { const: dependency_unavailable } } } } }
