# Audit

Audit records, chain verification, signed checkpoints and exports for offline checking. Aegis Core API, `AuditService`: 4 operations, generated from the OpenAPI document of Aegis Core 0.13.0.

## List records

`GET /v1/audit`

A page of records, filtered; a tenant's callers see their tenant's records alone.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.AuditService/ListRecords`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `after` | query | integer (int64) | Records after this sequence number; 0 starts at the beginning. |
| `limit` | query | integer (int64), nullable | At most this many (100 by default, at most 1,000). |
| `actor` | query | string, nullable | Only records by this actor. |
| `action` | query | string, nullable | Only this action, or every action under it. |
| `key` | query | string, nullable | Only records about this key or subject. |
| `outcome` | query | string, nullable | `ok` or `refused`. |
| `since` | query | integer (int64), nullable | At or after this time. |
| `until` | query | integer (int64), nullable | At or before this time. |

Response `200` (`application/json`): [ListRecordsResponse](#schema-listrecordsresponse)

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

## Checkpoint

`GET /v1/audit/checkpoint`

A checkpoint of the chain signed with Ed25519 and ML-DSA-87.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.AuditService/Checkpoint`

Response `200` (`application/json`): [SignedCheckpoint](#schema-signedcheckpoint)

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

## Export records

`GET /v1/audit/export`

Records with their links and tags, for offline verification.

- Role: `admin` or higher
- gRPC: `/aegis.v1.AuditService/ExportRecords`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `after` | query | integer (int64) | Records after this sequence number. |
| `limit` | query | integer (int64), nullable | At most this many (1,000 by default and at most). |

Response `200` (`application/x-ndjson`): [ExportedRecord](#schema-exportedrecord)

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

## Verify chain

`GET /v1/audit/verify`

Checks every record, link and the sealed head.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.AuditService/VerifyChain`

Response `200` (`application/json`): [VerifyChainResponse](#schema-verifychainresponse)

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

## Schemas

### ExportedRecord

A record with its link and tag.

| Field | Type | Description |
| --- | --- | --- |
| `action` | string | What. |
| `actor` | string | Who. |
| `algorithm` | string | The algorithm. |
| `key` | string | About which key or subject. |
| `outcome` | string | The outcome. |
| `previous` | string | The previous record's tag (hexadecimal). |
| `sequence` | integer (int64) | Its place in the chain. |
| `tag` | string | This record's tag (hexadecimal). |
| `time` | integer (int64) | When. |
| `version` | integer (int64) | The key version. |

### ListRecordsResponse

A page of records.

| Field | Type | Description |
| --- | --- | --- |
| `next` | integer (int64), nullable | The `after` of the next page, if any. |
| `records` | array of [AuditRecord](#schema-auditrecord) | The records. |

### SignedCheckpoint

A signed checkpoint (`aegis-audit-checkpoint-v2`).

| Field | Type | Description |
| --- | --- | --- |
| `digest` | string | SHA-256 over the records up to `sequence`. |
| `ed25519` | [CheckpointSignature](#schema-checkpointsignature), nullable | The Ed25519 signature. |
| `format` | string | The format. |
| `head` | string | Its tag. |
| `ml_dsa_87` | [CheckpointSignature](#schema-checkpointsignature), nullable | The ML-DSA-87 signature. |
| `sequence` | integer (int64) | The newest record covered. |
| `statement` | string | The statement signed. |
| `time` | integer (int64) | When it was signed. |
| `vault` | string | The vault's identifier. |

### VerifyChainResponse

The chain is intact (a broken chain is an error).

| Field | Type | Description |
| --- | --- | --- |
| `checked` | integer (int64) | When it was checked. |
| `head` | [ChainHead](#schema-chainhead), nullable | The newest record. |
| `intact` | boolean | Always true. |
| `records` | integer (int64) | Records checked. |

### AuditRecord

One audit record.

| Field | Type | Description |
| --- | --- | --- |
| `action` | string | What. |
| `actor` | string | Who. |
| `algorithm` | string | The algorithm. |
| `key` | string | About which key or subject. |
| `outcome` | string | `ok`, `ok; <detail>` or `refused: <reason>`. |
| `sequence` | integer (int64) | Its place in the chain. |
| `tag` | string | The record's HMAC in the chain (hexadecimal). |
| `time` | integer (int64) | When, in seconds since the Unix epoch. |
| `version` | integer (int64) | The key version. |

### CheckpointSignature

One family's signature.

| Field | Type | Description |
| --- | --- | --- |
| `public` | string (base64) | The public key. |
| `signature` | string (base64) | The signature. |

### ChainHead

The newest record.

| Field | Type | Description |
| --- | --- | --- |
| `sequence` | integer (int64) | Its sequence. |
| `tag` | string | Its tag (hexadecimal). |
| `time` | integer (int64) | Its time. |
