> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Operations

> How MaihueSigner is run: certificates and representatives, the unattended company signature, stuck groups and retry, monitoring, local development and the runbooks.

## Certificates and representatives

The engine signs with two kinds of PKCS#12 certificates, all read from the
server environment through `internal-signer.config.ts` and never from the
database:

| Certificate | Used for |
| - | - |
| Platform certificate | The final PAdES integrity seal on every PDF |
| One per company representative | Each representative's own PAdES signature on the company seats it signed |

A representative in the catalogue points to its certificate through a
credential reference. The application starts without the certificates loaded;
they are read when an unattended seat signs and when a group is sealed.

| Task | How |
| - | - |
| Add or change a representative | `/api/v3/signature/enterprise-signer` and the workflow membership routes; see [Workflows](https://docs.bbrands.io/signature-engine/workflows.md#admin-api) |
| Replace a representative | Revoke the old one and add the new one; an open group that still needs the revoked one cannot complete its unattended signature |
| Rotate a certificate | Follow the certificate rotation runbook |

## The unattended company signature

With `company_phase = last`, the company side runs after the customers. In
digital contracting the enterprise worker (`contract-enterprise-sign`) calls
`applyUnattendedEnterpriseSignatures`, which signs every pending unattended
seat and, once both sides are complete, seals the PDFs and reports `sealed`.
If attended company seats are still pending, the worker invites those
representatives instead. It is idempotent: a sealed group is
never sealed again.

Every run emits a structured `enterprise_signing.metric` log line with a
`success` or `failure` event.

## Stuck groups and retry

A group counts as stuck when it has not changed for more than 30 minutes and
one of these holds:

* the group is in `awaiting_enterprise_signature`;
* a `company_phase = first` group in `in_progress` or `partially_signed`
  whose company side is still incomplete; or
* a sealed group whose contract is still in `pending_signature`,
  `in_signature`, `partially_signed` or `awaiting_enterprise_signature`.

| Tool | Permission | What it does |
| - | - | - |
| Cron `/api/v3/cron/signature/enterprise-stuck` (every 10 minutes in production) | — | Scans for stuck groups and emits a `stuck_scan` metric when it finds any |
| `GET /api/v3/signature/enterprise-signer/stuck` | `signature-enterprise-signer:stuck` | Lists the stuck groups and, like the cron, emits a `stuck_scan` metric when it finds any |
| `POST /api/v3/signature/enterprise-signer/retry` with `contract_id` and `signature_id` | `signature-enterprise-signer:retry` | Enqueues the company-side job again |

The scan only reports; retrying is a manual decision.

## Monitoring

Better Stack alerts on the engine's structured logs; the configuration lives
in `infra/betterstack/` and is described in
[Monitoring — Terraform](https://docs.bbrands.io/monitoring/terraform.md).

| Alert | Fires when |
| - | - |
| Signature Engine / Enterprise unattended failure | An unattended company signature job failed |
| Signature Engine / Enterprise stuck scan | The scan found stuck groups |

## Local development

* **Queues.** With `QUEUE_PROVIDER=inline`, the company-side job runs in the
  same process, so a full signature can be completed locally.
* **Certificates.** Sealing needs the platform certificate configured in the
  local environment (see `backend/horizon-api/.env.example`). Local seeds can
  point a representative to a placeholder credential, which then uses the
  platform certificate; production refuses that placeholder.
* **Without the API.** The portal's mock mode simulates the signature and what
  happens after it; see
  [Digital contracting — Operations](https://docs.bbrands.io/digital-contracting/operations.md#running-the-flow-locally).

## Runbooks

Step-by-step runbooks live in the repository under `docs/operations/`:

| Runbook | Use |
| - | - |
| `signature-certificate-rotation.md` | Rotate the platform or representative certificates |
| `signature-enterprise-representative-replacement.md` | Replace a representative used by a workflow |
| `signature-engine-go-live.md` | Checklist before enabling unattended company signing in an environment |
| `digital-contract-manual-review-local.md` | Local demo of the review and the unattended signature |

## Code

| Concern | Path |
| - | - |
| Configuration and certificates | `lib/integration/signature-provider/internal-signer/internal-signer.config.ts` |
| Unattended signing | `lib/integration/signature-provider/internal-signer/internal-signer.client.ts` (`applyUnattendedEnterpriseSignatures`) |
| Metrics and stuck scan | `lib/integration/signature-provider/internal-signer/enterprise-signing.observability.ts` |
| Stuck and retry routes | `app/api/v3/signature/enterprise-signer/` |
| Cron | `app/api/v3/cron/signature/enterprise-stuck/` |

Paths are relative to `backend/horizon-api/` unless they start with
`infra/` or `docs/`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.