# Envelopes and re-wrap

Describe self-describing envelopes, and re-wrap many of them to a newer key version in background jobs. Aegis Core API, `EnvelopeService`: 6 operations, generated from the OpenAPI document of Aegis Core 0.13.0.

## Describe

`POST /v1/envelopes/describe`

What an envelope says about itself, without opening it.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.EnvelopeService/Describe`

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `envelope` | string (base64) | The envelope. |

Response `200` (`application/json`): [DescribeEnvelopeResponse](#schema-describeenveloperesponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## List rewrap jobs

`GET /v1/rewrap/jobs`

The jobs the caller may see: their own, or every job for an administrator.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EnvelopeService/ListRewrapJobs`

Response `200` (`application/json`): [ListRewrapJobsResponse](#schema-listrewrapjobsresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Start rewrap job

`POST /v1/rewrap/jobs`

Starts a job that re-wraps many envelopes to the newest version or another key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EnvelopeService/StartRewrapJob`

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `items` | array of [RewrapItem](#schema-rewrapitem) | 1 to 10,000 envelopes. |
| `key` | string | The key whose envelopes these are. |
| `to` | string, nullable | Another key, possibly of another algorithm, to move them to. |

Response `202` (`application/json`): [RewrapJob](#schema-rewrapjob)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Get rewrap job

`GET /v1/rewrap/jobs/{id}`

A job's progress.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EnvelopeService/GetRewrapJob`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `id` | path | string, required |  |

Response `200` (`application/json`): [RewrapJob](#schema-rewrapjob)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Cancel rewrap job

`POST /v1/rewrap/jobs/{id}/cancel`

Stops a job after the batch under way.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EnvelopeService/CancelRewrapJob`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `id` | path | string, required |  |

Response `200` (`application/json`): [RewrapJob](#schema-rewrapjob)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Rewrap job results

`GET /v1/rewrap/jobs/{id}/results`

A job's results so far, by item.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EnvelopeService/RewrapJobResults`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `id` | path | string, required |  |
| `after` | query | integer (int64) | The first item index (0 is the first item). |
| `limit` | query | integer (int64), nullable | At most this many (100 by default, at most 1,000). |

Response `200` (`application/json`): [RewrapJobResultsResponse](#schema-rewrapjobresultsresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Schemas

### DescribeEnvelopeResponse

What it says about itself.

| Field | Type | Description |
| --- | --- | --- |
| `aead` | string, nullable | The HPKE AEAD of an envelope sealed to a KEM. |
| `algorithm` | string | The algorithm. |
| `associated_data` | boolean, nullable | Whether associated data is bound (AGV2). |
| `context` | boolean, nullable | Whether a signature was made with a context. |
| `form` | string, nullable | The message form of a signature: `pure`, `prehash:<function>`, `external-mu`, `internal`. |
| `format` | string | `AGV1`, `AGV2` or `AGS2`. |
| `kdf` | string, nullable | The HPKE KDF of an envelope sealed to a KEM. |
| `key` | string | The key that made it. |
| `kind` | string | `ciphertext` or `signature`. |
| `revision` | string, nullable | The specification revision (not in AGV1). |
| `version` | integer (int64) | The key version. |

### ListRewrapJobsResponse

The jobs.

| Field | Type | Description |
| --- | --- | --- |
| `jobs` | array of [RewrapJob](#schema-rewrapjob) | The jobs the caller may see. |

### RewrapItem

One envelope to re-wrap.

| Field | Type | Description |
| --- | --- | --- |
| `associated_data` | string (base64) | The associated data it is bound to. |
| `envelope` | string (base64) | The envelope. |

### RewrapJob

A bulk re-wrap job.

| Field | Type | Description |
| --- | --- | --- |
| `by` | string | Who started it. |
| `done` | integer (int64) | Envelopes handled. |
| `error` | string, nullable | Why it failed. |
| `failed` | integer (int64) | Envelopes refused. |
| `finished` | integer (int64), nullable | When it ended. |
| `id` | string | Its identifier. |
| `key` | string | The source key. |
| `rewrapped` | integer (int64) | Envelopes re-wrapped. |
| `started` | integer (int64) | When it started. |
| `state` | string | `running`, `done`, `cancelled` or `failed`. |
| `to` | string, nullable | The target key, if another. |
| `total` | integer (int64) | Envelopes in the job. |
| `unchanged` | integer (int64) | Envelopes already current. |

### RewrapJobResultsResponse

Results by item.

| Field | Type | Description |
| --- | --- | --- |
| `next` | integer (int64), nullable | The `after` of the next page, if any. |
| `results` | array of [RewrapResult](#schema-rewrapresult) | The page. |
| `state` | string | The job's state. |

### RewrapResult

What happened to one envelope.

| Field | Type | Description |
| --- | --- | --- |
| `envelope` | string (base64), nullable | The new envelope. |
| `error` | string, nullable | Why it was refused. |
| `index` | integer (int64) | Its index in the job. |
| `unchanged` | boolean | Already in the newest format under the target's newest version. |
