# Applying for accreditation

<!-- GENERATED from packages/gavr/src/application.ts by `pnpm --filter @gadvisory/gavr spec:generate`. Do not edit by hand. -->

How a party with no standing becomes an authority. It files an application,
unsigned, because it holds no key the registry knows yet, and a secretariat
admits it with `authority.admit` or refuses it with `authority.refuse` (see
[operations.md](operations.md)). The filing itself confers nothing: it
creates no authority, registers no key, and holds its slug only while it is
undecided.

Only `GNEA` and `GNIA` may be applied for. **A root tier is earned, never declared**:
the filing is unauthenticated, so a kind on it carries no standing, and the
root tiers hold power over other participants. An active authority asks the
secretariat for `authority.elevate` instead.

## Filing

`POST /authorities/applications`, with a JSON body:

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `slug` | string | yes | 2 to 64 characters; matches `^[a-z0-9][a-z0-9-]*$`. The slug asked for. Held against other filings while this one is undecided, and permanent once admitted: it is the directory key. |
| `displayName` | string | yes | 1 to 200 characters. The name the directory shows. |
| `description` | string | no | At most 2000 characters. What the body is and what it will publish. |
| `contactEmail` | string | yes | At most 320 characters; an e-mail address. Where the secretariat reaches the applicant. |
| `homepageUrl` | string | no | At most 500 characters; a URL. |
| `kind` | string | yes | One of `GNEA`, `GNIA`. A root tier is not open to application: apply as a `GNEA`, and the secretariat may elevate an active authority later. |
| `publicKey` | string | no | Matches `^[A-Za-z0-9_-]{43}$`. The body's first self-custody key, which the secretariat registers when it admits the filing. |
| `scope` | array of scope rule | no, default `[]` | At most 200 entries; rules as [scope.md](scope.md) defines them. The remit asked for. Checked at admission against whoever accredits the body. |

The answer is a 202, because nothing the applicant owns was created yet:

```json
{
  "id": "<the filing's id>",
  "state": "PENDING",
  "claimSecret": "gavrclaim_<43 characters>"
}
```

**The claim secret is in this answer and nowhere else, ever.** The registry
cannot issue it again, because the applicant holds nothing it could
authenticate a reissue with. Store it: without it nobody can read the filing
back, correct it or withdraw it, and it ends only when a secretariat decides
it. It starts with `gavrclaim_`, so a leaked one is recognisable, and the
prefix is part of the secret.

One undecided filing may ask for a given slug, and one may carry a given key;
the registry also caps how many filings wait undecided at once. Refusals and
their statuses are in [refusals.md](refusals.md#applying-for-accreditation).
A registry may also answer 429 to a caller that files too often.

## The claim secret

The routes below take it as `Authorization: Bearer <secret>`; the scheme is
case-insensitive. Their refusals are in
[refusals.md](refusals.md#reading-or-changing-a-filing).

**It keeps working after the filing is decided, for reading only.** An
admitted applicant reads `ADMITTED` and the id of the authority it became; a
refused one reads why. Correcting and withdrawing refuse a decided filing
with `not-pending`. From admission on, the body acts through signed actions
like every authority, and the secret authorises nothing.

## Reading it back

`GET /authorities/applications/:id` answers `{ "application": { ... } }`:

| Field | Means |
| --- | --- |
| `id` | The id the filing was answered with. |
| `state` | `PENDING`, `ADMITTED`, `REFUSED` or `WITHDRAWN`. |
| `requestedSlug` | The slug asked for. |
| `requestedKind` | The kind asked for. |
| `displayName` | As filed or last amended. |
| `description` | As filed or last amended, or null. |
| `contactEmail` | As filed or last amended. |
| `homepageUrl` | As filed or last amended, or null. |
| `publicKey` | As filed or last amended, or null. |
| `requestedScope` | The remit asked for, as the scope rules the registry stored, each with the `id` and `purpose` it gave them. |
| `refusalReason` | Why the secretariat refused, as the code it gave `authority.refuse`. Set only on a refused filing. |
| `admittedAuthorityId` | The id of the authority the filing became. Set only on an admitted filing. |
| `createdAt` | When it was filed, an RFC 3339 instant in UTC. |
| `decidedAt` | When it was admitted, refused or withdrawn, or null while it is pending. |

## Correcting it

`PATCH /authorities/applications/:id`, while the filing is pending, with a
JSON body:

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `displayName` | string | no | 1 to 200 characters. |
| `description` | string or null | no | At most 2000 characters. `null` clears it. |
| `contactEmail` | string | no | At most 320 characters; an e-mail address. |
| `homepageUrl` | string or null | no | At most 500 characters; a URL. `null` clears it. |
| `publicKey` | string or null | no | Matches `^[A-Za-z0-9_-]{43}$`. `null` clears it. |
| `scope` | array of scope rule | no | At most 200 entries; rules as [scope.md](scope.md) defines them. Replaces the whole remit asked for: send every rule you want to keep. |

At least one field. An absent field is left as it is; a field outside the table is refused rather than ignored, and `slug` and `kind` cannot be amended: withdraw and file again.

It answers as the read does, with the corrected filing.

## Withdrawing it

`POST /authorities/applications/:id/withdraw`, while the filing is pending,
with no body. It answers `{ "id": "<the filing's id>", "state": "WITHDRAWN" }`.
The filing is not deleted: it stays as the record that somebody applied and
thought better of it, and the slug and key it held are free again.

## States

A decided filing never changes again.

| State | Means |
| --- | --- |
| `PENDING` | Filed and undecided. It holds its slug and its key against other filings, and the applicant may correct or withdraw it. |
| `ADMITTED` | A secretariat admitted it: the authority exists, and `admittedAuthorityId` names it. |
| `REFUSED` | A secretariat refused it, and `refusalReason` says why. |
| `WITHDRAWN` | The applicant withdrew it before anybody decided. |
