> ## 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.

# Identity

> How digital contracting verifies each signer with Floid: the RUT and identity card checks, when an earlier verification is reused, what is stored and the re-entry challenge.

Every customer signer proves their identity before reading the contract
summary. The check runs against Floid, which confirms with the Chilean civil
registry that the identity card is valid for that RUT.

## The identity step

The portal sends `PATCH /api/v3/contract/{id}/identity` with two fields:

| Field | Meaning |
| - | - |
| `rut` | The signer's Chilean RUT, with check digit |
| `document_number` | The serial number printed on the identity card |

```mermaid theme={null}
flowchart TD
    start["PATCH /contract/{id}/identity"] --> digit{"Valid RUT<br/>check digit?"}
    digit -->|no| e400["400"]
    digit -->|yes| match{"Same RUT as the<br/>registered signer?"}
    match -->|no| e409["409 rut-mismatch"]
    match -->|yes| reuse{"Verified after this<br/>contract started?"}
    reuse -->|yes| ok["Stage → SUMMARY<br/>(no Floid call)"]
    reuse -->|no| floid{"Floid: card<br/>active?"}
    floid -->|no| e422["422 identity-rejected"]
    floid -->|RUT not found| e404["404"]
    floid -->|unavailable| e503["503 (pending row recorded)"]
    floid -->|yes| store["Store the verification"] --> ok
```

1. **RUT format.** The RUT is normalized and its check digit validated.
2. **Registered RUT.** The RUT must match the one registered for the signer.
   In a person contract, the account holder matches the account's RUT; other
   members (or a holder whose account has no RUT) match the RUT of their own
   person account or, failing that, the RUT registered before. A company
   administrator matches the RUT of their own person account (or, for
   contracts registered before that account existed, the RUT written at
   registration).
3. **Reuse.** A verification is valid for twelve months, but contracting
   reuses it only if it happened **after this contract started**
   (`POST …/start` sets `started_at`). If the contract has not started yet,
   any current verification counts. In both cases Floid is not called.
4. **Floid.** Otherwise the backend asks Floid whether the card serial is
   active for that RUT.
5. **Result.** On a first verification the step answers a small patch:
   identity validated and `stage: SUMMARY`. A re-entry check answers the
   flags plus a new session, and a call by the account holder on a
   contract that already left `draft` answers the flags only.

## What is stored

| Record | Content |
| - | - |
| [User DNI](https://docs.bbrands.io/schemas/user/user-dni.md) | The signer's RUT, created or updated |
| [User identity verification](https://docs.bbrands.io/schemas/user/user-identity-verification.md) | Status, provider (`floid`), method (`serial_validation`), `verified_at` and `expires_at` |
| `user.identity_verified` queue event | A processed event that stamps the approval on the user |

The identity card serial is never stored. When Floid is unavailable on a
first verification, a `pending` verification is recorded with the reason
`provider-unavailable` so the attempt is traceable.

## Who sees the result

* For the account holder on a `draft` contract, the patch is also published on
  `private-contract-{id}`, so other open tabs move to the summary.
* A later company administrator is on their own step, so their result only
  goes back over HTTP and never moves the account holder's wizard.

## Re-entry challenge

When a customer comes back with a new one-time link after their identity was
verified, the new session must prove the card serial again before it can
request a signing code:

* `ContractState` raises `flags.require_signer_document_number`.
* The same `PATCH /api/v3/contract/{id}/identity` checks the serial with Floid
  and answers with a new session marked as re-verified. If Floid is
  unavailable it answers `503` without recording a pending row.
* Until then, code, sign and reject requests answer
  `422 reentry-serial-required`.

A session that never left the wizard keeps its original token and is not
challenged. See [Session and access](https://docs.bbrands.io/digital-contracting/session-and-access.md).

## Errors

| Code | HTTP | Meaning |
| - | - | - |
| — | `400` | The RUT check digit is wrong, a field has the wrong format, or Floid rejects the data (for example a serial that does not belong to the RUT) |
| — | `403` | The session does not belong to this contract or its user does not take part in it |
| — | `404` | Floid does not find the RUT in the civil registry or reports a data error |
| `rut-mismatch` | `409` | The RUT is not the one registered for this signer |
| `identity-rejected` | `422` | Floid reports the card as not active for that RUT |
| — | `503` | Floid is unavailable; the customer can retry |

## Outside production

A stub can replace the live Floid calls in local and test environments. It
refuses to start when the API points to the production host.

## Code

| Concern | Path |
| - | - |
| Identity step | `app/api/v3/contract/[document_id]/identity/`, `lib/endpoint/contract-identity/` |
| Shared Floid checks (also used by onboarding) | `lib/endpoint/contract-identity/identity-validation.core.ts` |
| Reuse window | `lib/endpoint/user-identity/user-identity.resolver.ts` |
| Re-entry flag | `lib/endpoint/contract-state/require-signer-document-number.ts` |
| Floid client | `lib/endpoint/integration/floid/chile/` |
| Stub guard | `lib/common/integration-stub-policy.ts` |
| Portal step | `frontend/portal-customer/app/components/digital-contract/steps/identity-step.tsx` |


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