> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/platform/platform-services/consent-management/design/data-model.md). Agents can also search and read this documentation through its [MCP server](https://docs.openg2p.org/~gitbook/mcp).

# Data model

The entities the Consent Manager stores, and the JSON-LD documents it exchanges: the partner-signed consent object, the consent artefact, and the Kantara / ISO 27560 consent receipt.

The Consent Manager keeps two kinds of structures:

* **Stored entities** — the records it owns (consent requests, artefacts, receipts, logs). Partners and policies live in Partner Management: records name the partner by its **audience** (e.g. `bank-a`) and the policy applied by `policy_ref` (`data_controller:farmer-registry`), `policy_version` and `policy_id` (PM's id of that version). Terms sent by a token presenter, or a consent template, are recorded as `policy_ref: template:loan-profile@1`, with no `policy_id` or `policy_version`.
* **Exchanged documents** — JSON-LD documents passed in and out: the consent object a partner signs, and the artefact and receipt the CM issues. (The origination flow also takes a standard OIDC ID token; the CM keeps only its hash and claims, in the AuthContext.)

Status changes only add: a new status and timestamp are written, earlier timestamps are kept, and the decision log is never changed.

## Entity overview

```mermaid
erDiagram
  CONSENT_REQUEST ||--o| AUTH_CONTEXT : "bound by (origination)"
  CONSENT_REQUEST ||--o| CONSENT_ARTEFACT : produces
  CONSENT_ARTEFACT ||--|| CONSENT_RECEIPT : "proven by"
  CONSENT_ARTEFACT ||--o{ REVOCATION_RECORD : "may be revoked by"
  CONSENT_ARTEFACT ||--o{ DECISION_LOG : "evaluated in"
```

### ConsentArtefact (CM-issued, canonical)

The consent as the CM stores it. A **partner-signed** consent yields **one artefact per (`jti`, `data_controller`)**: validated by two registries, it has two artefacts and two receipts, each revocable on its own. An **originated** consent yields one artefact per approved request, holding the approved grants. A department CM stores one per accepted **consent token**.

| Field                                   | Type       | Notes                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| consent\_id                             | UUID       | Primary key                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| subject\_id\_type / subject\_id\_value  | str        | The data subject                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| subject\_identifiers                    | json       | The subject's other identifiers recorded with the consent, `[{type, value}]` (e.g. the `FARMER_ID` the partner portal records); a lookup or subject check may match any of them                                                                                                                                                                                                                                                                               |
| controller\_id                          | str        | Data controller (registry). Null for an originated consent with several approved grants                                                                                                                                                                                                                                                                                                                                                                       |
| partner\_id                             | str        | The partner the consent was given to: its audience (e.g. `bank-a`)                                                                                                                                                                                                                                                                                                                                                                                            |
| purpose                                 | json       | `{code, text}`                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| data\_scopes                            | list\[str] | Consented fields for this controller's grant (pre-policy-intersection)                                                                                                                                                                                                                                                                                                                                                                                        |
| effective\_data\_scopes                 | list\[str] | `data_scopes ∩ policy.allowed_data_scopes` at issue time                                                                                                                                                                                                                                                                                                                                                                                                      |
| grants                                  | json       | Originated consents only: `[{data_controller, data_scopes, granted_scopes, effective_data_scopes, policy_version, policy_id, policy_ref}]`                                                                                                                                                                                                                                                                                                                    |
| object\_jti                             | str        | The partner-signed consent's (or consent token's) `jti`; unique together with `controller_id`                                                                                                                                                                                                                                                                                                                                                                 |
| valid\_from / valid\_until              | datetime   |                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| fetch\_type                             | enum       | `oneshot`, `periodic`                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| auth\_context\_id                       | UUID       | FK → AuthContext (origination flow); null otherwise                                                                                                                                                                                                                                                                                                                                                                                                           |
| source                                  | enum       | `embedded` (partner-signed), `originated` (collected by the CM) or `receipt` (a consent token, department role)                                                                                                                                                                                                                                                                                                                                               |
| assurance                               | json       | Originated consents: how the subject confirmed (method, evidence, verifier, national-ID authentication)                                                                                                                                                                                                                                                                                                                                                       |
| consent\_request\_id                    | UUID       | The request it was made from (originated)                                                                                                                                                                                                                                                                                                                                                                                                                     |
| policy\_version                         | int        | Version of the partner's policy in Partner Management evaluated at issue                                                                                                                                                                                                                                                                                                                                                                                      |
| policy\_id                              | str        | PM's id of that policy version                                                                                                                                                                                                                                                                                                                                                                                                                                |
| policy\_ref                             | str        | The policy's key, `kind:key`: `data_controller:farmer-registry`, or `template:loan-profile@1` (no PM policy: a consent template, or terms sent by a token presenter). On an originated consent with several grants, set only when all grants share one reference (a consent made from a template)                                                                                                                                                             |
| template                                | str        | Exchange role: the consent template code (e.g. `loan-profile@1`) the consent was made from, or that a token presenter sent with a partner-signed one. A label for display and audit; the purpose and grants are what the consent is for. A [lookup at a registry](https://docs.openg2p.org/platform/platform-services/consent-management/design/verification-and-enforcement.md#consent-by-lookup-at-a-registry) skips consents that have one. Null otherwise |
| status                                  | enum       | `active`, `revoked`, `expired`                                                                                                                                                                                                                                                                                                                                                                                                                                |
| created\_at / revoked\_at / expired\_at | datetime   | Append-only                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

**Lookup indexes.** They serve consent by lookup with one index range per request, whatever the number of consents:

* `ix_consent_artefacts_purpose_lookup`, partial on `status = 'active'` (`partner_id`, `subject_id_type`, `subject_id_value`, `purpose ->> 'code'`, `valid_until DESC`) — [caller-terms mode](https://docs.openg2p.org/platform/platform-services/consent-management/design/verification-and-enforcement.md#caller-terms-mode);
* `ix_consent_artefacts_controller_lookup`, partial likewise (`partner_id`, `subject_id_type`, `subject_id_value`, `controller_id`, `valid_until DESC`) — [at a registry](https://docs.openg2p.org/platform/platform-services/consent-management/design/verification-and-enforcement.md#consent-by-lookup-at-a-registry). An originated consent with several grants (no `controller_id`) is matched on its `grants` within the same (partner, subject) range;
* `ix_consent_artefacts_subject_identifiers`, GIN (`jsonb_path_ops`) on `subject_identifiers` (not partial) — a lookup by one of the subject's other identifiers (`subject_identifiers @> [{"type", "value"}]`).

### AuthContext

Created after the CM validates an ID token (origination API) or a national-ID login (partner portal). The raw token is **never** stored, only its hash.

| Field                | Type     | Notes                                          |
| -------------------- | -------- | ---------------------------------------------- |
| auth\_context\_id    | UUID     | Primary key                                    |
| consent\_request\_id | UUID     | FK → ConsentRequest                            |
| auth\_provider       | str      | e.g. `keycloak`                                |
| auth\_method         | str      | `otp`, `biometric`, … (from `amr`)             |
| auth\_timestamp      | datetime |                                                |
| issuer               | str      | `iss`                                          |
| id\_token\_hash      | str      | `sha256:…`                                     |
| token\_validated     | bool     |                                                |
| verified\_claims     | json     | `iss, sub, aud, amr, iat, exp, auth_time, kid` |

### ConsentReceipt

Kantara / ISO 27560-aligned, **signed with the CM's own `.p12` key**. Anyone can verify it against the CM's `GET /.well-known/jwks.json`, without Partner Management. Document: [below](#consent-receipt-kantara-iso-27560).

| Field          | Type     | Notes                                                            |
| -------------- | -------- | ---------------------------------------------------------------- |
| receipt\_id    | UUID     | Primary key                                                      |
| consent\_id    | UUID     | FK → ConsentArtefact                                             |
| artefact\_hash | str      | `sha256:…` over the canonical artefact                           |
| algorithm      | enum     | `EdDSA` (ed25519), `ES256`, or `RS256` — the CM `.p12` key's alg |
| kid            | str      | CM key id used to sign                                           |
| signature      | text     | base64url signature over the artefact hash                       |
| version        | str      | Receipt schema version                                           |
| issued\_at     | datetime |                                                                  |

### Other entities

| Entity                                           | Key fields                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **ConsentRequest** (origination, partner portal) | id, subject, subject\_identifiers, controller\_id (null when several grants), partner\_id (the partner's audience), requested\_scopes (union), grants (`[{data_controller, data_scopes, policy_version, policy_id, policy_ref}]` or null), template (a label), purpose, validity, method (`assisted`), status (`pending`, `pending_verification`, `approved`, `denied`, `rejected`, `cancelled`, `expired`), verification (who, when, note), timestamps |
| **ConsentEvidence** (partner portal)             | id, consent\_request\_id, kind (signed form), filename, content type, size, sha256, storage key (object store), uploaded by/at                                                                                                                                                                                                                                                                                                                          |
| **SubjectAuthSession** (partner portal)          | A national-ID login in progress: state, nonce, PKCE verifier, status, expiry (5 minutes), the resulting auth context                                                                                                                                                                                                                                                                                                                                    |
| **RevocationRecord**                             | revocation\_id, consent\_id, originated\_by (`subject`/`controller`/`partner`), reason, revoked\_by (the staff user, when staff revoked it on the subject's request), created\_at                                                                                                                                                                                                                                                                       |
| **DecisionLog** (immutable)                      | id, consent\_id (null on most denials), partner\_id (the partner's audience, when known), object\_jti, data\_controller (when known), request\_ctx\_hash, decision, reason\_code, detail, policy\_version / policy\_id / policy\_ref (null when no policy was read), receipt\_jti / receipt\_issuer (decisions on a consent token), created\_at                                                                                                         |
| **IssuedReceipt** (exchange role)                | A consent token issued: jti, consent\_id (the artefact it was issued from), data\_controller, presenter, partner, expires\_at — see [Exchange consent tokens](https://docs.openg2p.org/platform/platform-services/consent-management/design/exchange-consent-tokens.md)                                                                                                                                                                                 |

***

## Exchanged documents (JSON-LD)

### Consent object (partner-signed)

A partner that collects consent in its own system **signs this as a compact JWS** (RFC 7515) and embeds it in the registry request; the CM accepts it only if the partner's policy sets `allow_partner_consents`. The claims below are the **JWS payload**; the protected header carries `alg` and `kid`. The CM verifies the signature with the partner's key from Partner Management. `jti` and `issued_at` give replay protection.

The data to share is given as **`grants`**, one per registry. The single-registry form (`data_controller` + `data_scopes` at the top level) is accepted as one grant; a consent may not mix the two.

```json
// JWS payload (claims). Wire form: base64url(header).base64url(payload).base64url(signature)
{
  "@context": "https://openg2p.org/contexts/consent_object.jsonld",
  "@type": "ConsentObject",
  "jti": "b2f1...-unique-per-object",
  "subject_id": { "type": "national_id", "value": "FARMER_1234" },
  "aud": "bank-a",
  "purpose": { "code": "share_farm_profile", "text": "Share farmer profile with Partner A" },
  "grants": [
    { "data_controller": "farmer-registry",
      "data_scopes": ["farmer-registry.personal_details", "farmer-registry.main_crops", "farmer-registry.land"] },
    { "data_controller": "crop-sown-registry",
      "data_scopes": ["crop-sown-registry.crop_season", "crop-sown-registry.measures"] }
  ],
  "fetch_type": "oneshot",
  "validity": { "valid_from": "2025-05-01T12:00:00Z", "valid_until": "2026-05-01T12:00:00Z" },
  "issued_at": "2025-05-01T11:59:50Z"
}
```

There is no inline `signature` field — the JWS wrapper carries it (header `alg`/`kid` + the signature segment).

### Consent Artefact

The canonical document the receipt's hash covers.

```json
{
  "@context": "https://openg2p.org/contexts/consent_artefact.jsonld",
  "@type": "ConsentArtefact",
  "consent_id": "5b0e…",
  "subject_id": "FARMER_1234",
  "subject_id_type": "national_id",
  "data_controller": "farmer-registry",
  "partner_id": "bank-a",
  "source": "embedded",
  "purpose": { "code": "share_farm_profile", "text": "Share farmer profile with Partner A" },
  "data_scopes": ["farmer-registry.personal_details", "farmer-registry.main_crops", "farmer-registry.land"],
  "effective_data_scopes": ["farmer-registry.personal_details", "farmer-registry.main_crops"],
  "fetch_type": "oneshot",
  "policy_version": 3,
  "validity": { "consent_timestamp": "2025-05-01T12:00:00+00:00", "expiry_timestamp": "2026-05-01T12:00:00+00:00" }
}
```

> This is the Farmer Registry's artefact for the consent above: its grant only. `effective_data_scopes` leaves out `farmer-registry.land` because the partner's policy for this registry does not allow it. An originated consent with several approved grants carries them under `grants` instead.

### Consent Receipt (Kantara / ISO 27560)

Created with the artefact and **signed with the CM's own `.p12` key**: proof of the consent for the subject, audits and disputes. The controller's name, contact and DPO, retention and jurisdiction are not filled in yet.

```json
{
  "@context": "https://openg2p.org/contexts/consent_receipt.jsonld",
  "@type": "ConsentReceipt",
  "version": "1.1",
  "issued_at": "2025-05-01T12:02:12+00:00",
  "data_controller": { "id": "farmer-registry" },
  "data_controllers": [ { "id": "farmer-registry" } ],
  "subject_id": "FARMER_1234",
  "purposes": [
    { "code": "share_farm_profile", "text": "Share farmer profile with Partner A",
      "legal_basis": "consent",
      "data_categories": ["farmer-registry.personal_details", "farmer-registry.main_crops"] }
  ],
  "data_categories": ["farmer-registry.personal_details", "farmer-registry.main_crops"],
  "third_parties": ["bank-a"],
  "withdrawal": {
    "method": "Ask the organisation operating this Consent Manager to revoke it (consent ID 5b0e…)."
  },
  "consent_artefact": { "@id": "5b0e…", "hash": "sha256:7b0a933e7cd398a…" },
  "signature": {
    "algorithm": "EdDSA", "kid": "cm-2025-01",
    "value": "BASE64URL(cm_private_key.sign(artefact_hash))"
  }
}
```

The receipt is stored with its own `receipt_id`, which `/validate` returns and [`GET /consent/v1/receipts/{receipt_id}`](https://docs.openg2p.org/platform/platform-services/consent-management/api/verification-api.md) serves. `withdrawal.method` is the deployment's text (`CONSENT_MANAGER_RECEIPT_WITHDRAWAL_METHOD`, where an operator names its contact or URL; [Deployment](https://docs.openg2p.org/platform/platform-services/consent-management/deployment.md)): today staff revoke on the subject's request. When the beneficiary API is deployed, `withdrawal.additional_methods` also lists its subject endpoint (`POST …/consent/v1/my/consents/{id}/revoke`). `data_controllers` lists every controller the receipt covers: the one controller for an embedded consent (one receipt per registry), or one entry per approved grant — `{id, data_categories}` — for an originated consent with grants, where `data_controller` is null if there are several.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/platform/platform-services/consent-management/design/data-model.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
